-
Notifications
You must be signed in to change notification settings - Fork 0
/
pocsagencode_test.go
106 lines (93 loc) · 3.03 KB
/
pocsagencode_test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package pocsagencode
import (
"log"
"os"
"testing"
)
func init() {
// SetLogger(log.New(os.Stdout, "POCSAG ", log.LstdFlags))
// Comment below to enable debug logging
SetLogger(nil)
}
func Test_Encode_NumericPadding(t *testing.T) {
SetLogger(log.New(os.Stdout, "POCSAG ", log.LstdFlags))
defer SetLogger(nil)
enc, left := Generate([]*Message{
&Message{1300100, FunctionA, "123", true},
})
if len(left) != 0 {
t.Errorf("expect no message left, got %v", left)
}
expect := Burst{
// 18 words, 576 bits of preamble
0xAAAAAAAA, 0xAAAAAAAA,
0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA,
0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA,
// The real data starts here
0x7CD215D8, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197,
0x7A89C197, 0x4F5A0109, 0xC2619CE1, 0x7A89C197, 0x7A89C197,
}
if len(enc) != len(expect) {
t.Errorf("expected:\n%s\ngot:\n%s\n", expect, enc)
} else {
for i, w := range expect {
if w != enc[i] {
t.Errorf("expected:%X got:%X at index %d\n", w, enc[i], i)
}
}
}
}
func Test_Encode_Numeric(t *testing.T) {
enc, left := Generate([]*Message{
&Message{1300100, FunctionA, "12[3]", true},
})
if len(left) != 0 {
t.Errorf("expect no message left, got %v", left)
}
expect := Burst{
// 18 words, 576 bits of preamble
0xAAAAAAAA, 0xAAAAAAAA,
0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA,
0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA,
// The real data starts here
0x7CD215D8, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197,
0x7A89C197, 0x4F5A0109, 0xC27E3D14, 0x7A89C197, 0x7A89C197,
}
if len(enc) != len(expect) {
t.Errorf("expected:\n%s\ngot:\n%s\n", expect, enc)
} else {
for i, w := range expect {
if w != enc[i] {
t.Errorf("expected:%X got:%X at index %d\n", w, enc[i], i)
}
}
}
}
func Test_Encode_Alpha(t *testing.T) {
// SetLogger(log.New(os.Stdout, "POCSAG ", log.LstdFlags))
enc, left := Generate([]*Message{
&Message{1300100, FunctionA, "happy christmas!", false},
})
if len(left) != 0 {
t.Errorf("expect no message left, got %v", left)
}
expect := Burst{
// 18 words, 576 bits of preamble
0xAAAAAAAA, 0xAAAAAAAA,
0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA,
0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA,
// The real dat starts here
0x7CD215D8, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197, 0x7A89C197,
0x7A89C197, 0x4F5A0109, 0x8B861C9F, 0xC3CF04CD, 0xD8C5A3C6, 0xF979C8DE, 0xBDB878F3, 0x9E110386,
0x7A89C197, 0x7CD215D8, 0x7A89C197,
}
if len(enc) != len(expect) {
t.Errorf("expected:\n%s\ngot:\n%s\n", expect, enc)
} else {
for i, w := range expect {
if w != enc[i] {
t.Errorf("expected:%X got:%X at index %d\n", w, enc[i], i)
}
}
}
}