-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversions.go
37 lines (31 loc) · 954 Bytes
/
conversions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
func fmFrequencyToBytes(frequency float64) []byte {
freqInt := int(frequency * 100)
freqBytes := make([]byte, 2)
freqBytes[0] = byte(freqInt & 0xFF)
freqBytes[1] = byte((freqInt >> 8) & 0xFF)
return freqBytes
}
func fmBytesToFrequency(response []byte) float64 {
if response[3] == 94 {
return float64(int(response[4])|int(response[5])<<8) / 100.0
} else {
return float64(int(response[3])|int(response[4])<<8) / 100.0
}
}
func amFrequencyToBytes(frequency int) []byte {
freqBytes := make([]byte, 2)
freqBytes[0] = byte(frequency & 0xFF)
freqBytes[1] = byte((frequency >> 8) & 0xFF)
return freqBytes
}
func amBytesToFrequency(bytesResponse []byte) int {
var freqBytes []byte
if bytesResponse[4] == 94 {
freqBytes = []byte{bytesResponse[3], bytesResponse[5] - 64}
} else {
freqBytes = []byte{bytesResponse[4] - 64, bytesResponse[6] - 64}
}
frequency := int(freqBytes[1])<<8 | int(freqBytes[0])
return frequency
}