-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
50 lines (45 loc) · 986 Bytes
/
helpers.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
38
39
40
41
42
43
44
45
46
47
48
49
50
package pocsagencode
import (
"encoding/binary"
"fmt"
"strings"
)
type Burst []uint32
// String return a formated multiline string with the
func (b Burst) String() string {
s := ""
preambleCount := 0
preambleOver := false
for _, w := range b {
if !preambleOver {
if w == pocsagPreambleWord {
preambleCount++
continue
} else {
s += fmt.Sprintf("[%d bits of 1010101010... (0xAA) preamble] ", preambleCount*32)
preambleOver = true
}
}
if w == pocsagFrameSyncWord {
s += "[Batch start/sync] "
}
s += fmt.Sprintf("%X ", w)
}
return s
}
// Bytes returns a []byte
func (b Burst) Bytes() []byte {
buf := make([]byte, len(b)*4)
for i, w := range b {
binary.BigEndian.PutUint32(buf[i*4:], w)
}
return buf
}
// BinStr returns a binary string split into bytes
func (b Burst) BinStr() string {
binStrs := []string{}
for _, b := range b.Bytes() {
binStrs = append(binStrs, fmt.Sprintf("0b%b", b))
}
return strings.Join(binStrs, ", ")
}