-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtcm_test.go
113 lines (92 loc) · 2.23 KB
/
rtcm_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
107
108
109
110
111
112
113
package rtcm
import (
"fmt"
"os"
"testing"
)
var (
msgs = []int{
1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009,
1010, 1011, 1012, 1013, 1019,
1020, 1029,
1030, 1031, 1032, 1033,
1042, 1044, 1045,
1057, 1058, 1059,
1060, 1063, 1064, 1065, 1066,
1071, 1072, 1073, 1074, 1075, 1076, 1077,
1081, 1082, 1083, 1084, 1085, 1086, 1087,
1091, 1092, 1093, 1094, 1095, 1096, 1097,
1104, 1107,
1111, 1112, 1113, 1114, 1115, 1116, 1117,
1121, 1122, 1123, 1124, 1125, 1126, 1127,
1230,
}
)
func TestCdecode(t *testing.T) {
for _, msgType := range msgs {
msgType := msgType
file := fmt.Sprintf("%d_frame.bin", msgType)
data, err := os.ReadFile("./data/" + file)
if err != nil {
t.Error(err)
}
rtcm, err := Cdecode(data)
if err != nil {
t.Error(err)
}
if rtcm.crc != 0 {
t.Fatalf("%s crc error", file)
}
if int(rtcm.mtype) != msgType {
t.Fatalf("expected to get %d, but got %d", msgType, rtcm.mtype)
}
}
}
func TestDecode(t *testing.T) {
for _, msgType := range msgs {
msgType := msgType
file := fmt.Sprintf("%d_frame.bin", msgType)
data, err := os.ReadFile("./data/" + file)
if err != nil {
t.Error(err)
}
rtcm, err := Decode(data)
if err != nil {
t.Error(err)
}
if rtcm.Crc != 0 {
t.Fatalf("%s crc error", file)
}
if int(rtcm.Type) != msgType {
t.Fatalf("expected to get %d, but got %d", msgType, rtcm.Type)
}
}
}
func TestCheckCrc(t *testing.T) {
for _, msgType := range msgs {
msgType := msgType
file := fmt.Sprintf("%d_frame.bin", msgType)
data, err := os.ReadFile("./data/" + file)
if err != nil {
t.Error(err)
}
crc := CheckCrc(data)
if crc != true {
t.Fatalf("expected to get %T, but got %T", true, crc)
}
}
}
func TestEcefToLla(t *testing.T) {
ecef := [3]float64{-4472357.536800, 2670485.179400, -3669374.426300}
lla := EcefToLla(ecef)
expected := [3]float64{-35.343483611276, 149.1581921915763, 618.0140473050997}
if lla[0] != expected[0] {
t.Fatalf("expected latitude to %f, but got %f", expected[0], lla[0])
}
if lla[1] != expected[1] {
t.Fatalf("expected longitude to %f, but got %f", expected[1], lla[1])
}
if lla[2] != expected[2] {
t.Fatalf("expected altitude to %f, but got %f", expected[2], lla[2])
}
}