forked from jdgordon/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsv_test.go
186 lines (182 loc) · 5.13 KB
/
gsv_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
var gsvtests = []struct {
name string
raw string
err string
msg GSV
}{
{
name: "good sentence",
raw: "$GLGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*6B",
msg: GSV{
TotalMessages: 3,
MessageNumber: 1,
NumberSVsInView: 11,
Info: []GSVInfo{
{SVPRNNumber: 3, Elevation: 3, Azimuth: 111, SNR: 0},
{SVPRNNumber: 4, Elevation: 15, Azimuth: 270, SNR: 0},
{SVPRNNumber: 6, Elevation: 1, Azimuth: 10, SNR: 12},
{SVPRNNumber: 13, Elevation: 6, Azimuth: 292, SNR: 0},
},
},
},
{
name: "short sentence",
raw: "$GLGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,12*56",
msg: GSV{
TotalMessages: 3,
MessageNumber: 1,
NumberSVsInView: 11,
Info: []GSVInfo{
{SVPRNNumber: 3, Elevation: 3, Azimuth: 111, SNR: 0},
{SVPRNNumber: 4, Elevation: 15, Azimuth: 270, SNR: 0},
{SVPRNNumber: 6, Elevation: 1, Azimuth: 10, SNR: 12},
},
},
},
{
name: "sentence with no satellite in view",
raw: "$GBGSV,1,1,00,0*77",
msg: GSV{
TotalMessages: 1,
MessageNumber: 1,
NumberSVsInView: 0,
Info: nil,
},
},
{
name: "good sentence with system id",
raw: "$GAGSV,3,1,09,02,00,179,,04,09,321,,07,11,134,11,11,10,227,,7*7F",
msg: GSV{
TotalMessages: 3,
MessageNumber: 1,
NumberSVsInView: 9,
Info: []GSVInfo{
{SVPRNNumber: 2, Elevation: 0, Azimuth: 179, SNR: 0},
{SVPRNNumber: 4, Elevation: 9, Azimuth: 321, SNR: 0},
{SVPRNNumber: 7, Elevation: 11, Azimuth: 134, SNR: 11},
{SVPRNNumber: 11, Elevation: 10, Azimuth: 227, SNR: 0},
},
SystemID: 7,
},
},
{
name: "invalid number of svs",
raw: "$GLGSV,3,1,11.2,03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*77",
err: "nmea: GLGSV invalid number of SVs in view: 11.2",
},
{
name: "invalid number of messages",
raw: "$GLGSV,A3,1,11,03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*2A",
err: "nmea: GLGSV invalid total number of messages: A3",
},
{
name: "invalid message number",
raw: "$GLGSV,3,A1,11,03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*2A",
err: "nmea: GLGSV invalid message number: A1",
},
{
name: "invalid SV prn number",
raw: "$GLGSV,3,1,11,A03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*2A",
err: "nmea: GLGSV invalid SV prn number: A03",
},
{
name: "invalid elevation",
raw: "$GLGSV,3,1,11,03,A03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*2A",
err: "nmea: GLGSV invalid elevation: A03",
},
{
name: "invalid azimuth",
raw: "$GLGSV,3,1,11,03,03,A111,00,04,15,270,00,06,01,010,12,13,06,292,00*2A",
err: "nmea: GLGSV invalid azimuth: A111",
},
{
name: "invalid SNR",
raw: "$GLGSV,3,1,11,03,03,111,A00,04,15,270,00,06,01,010,12,13,06,292,00*2A",
err: "nmea: GLGSV invalid SNR: A00",
},
{
name: "good sentence",
raw: "$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*77",
msg: GSV{
TotalMessages: 3,
MessageNumber: 1,
NumberSVsInView: 11,
Info: []GSVInfo{
{SVPRNNumber: 3, Elevation: 3, Azimuth: 111, SNR: 0},
{SVPRNNumber: 4, Elevation: 15, Azimuth: 270, SNR: 0},
{SVPRNNumber: 6, Elevation: 1, Azimuth: 10, SNR: 12},
{SVPRNNumber: 13, Elevation: 6, Azimuth: 292, SNR: 0},
},
},
},
{
name: "short",
raw: "$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,12*4A",
msg: GSV{
TotalMessages: 3,
MessageNumber: 1,
NumberSVsInView: 11,
Info: []GSVInfo{
{SVPRNNumber: 3, Elevation: 3, Azimuth: 111, SNR: 0},
{SVPRNNumber: 4, Elevation: 15, Azimuth: 270, SNR: 0},
{SVPRNNumber: 6, Elevation: 1, Azimuth: 10, SNR: 12},
},
},
},
{
name: "invalid number of SVs",
raw: "$GPGSV,3,1,11.2,03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*6b",
err: "nmea: GPGSV invalid number of SVs in view: 11.2",
},
{
name: "invalid total number of messages",
raw: "$GPGSV,A3,1,11,03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*36",
err: "nmea: GPGSV invalid total number of messages: A3",
},
{
name: "invalid message number",
raw: "$GPGSV,3,A1,11,03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*36",
err: "nmea: GPGSV invalid message number: A1",
},
{
name: "invalid SV prn number",
raw: "$GPGSV,3,1,11,A03,03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*36",
err: "nmea: GPGSV invalid SV prn number: A03",
},
{
name: "invalid elevation",
raw: "$GPGSV,3,1,11,03,A03,111,00,04,15,270,00,06,01,010,12,13,06,292,00*36",
err: "nmea: GPGSV invalid elevation: A03",
},
{
name: "invalid azimuth",
raw: "$GPGSV,3,1,11,03,03,A111,00,04,15,270,00,06,01,010,12,13,06,292,00*36",
err: "nmea: GPGSV invalid azimuth: A111",
},
{
name: "invalid SNR",
raw: "$GPGSV,3,1,11,03,03,111,A00,04,15,270,00,06,01,010,12,13,06,292,00*36",
err: "nmea: GPGSV invalid SNR: A00",
},
}
func TestGSV(t *testing.T) {
for _, tt := range gsvtests {
t.Run(tt.name, func(t *testing.T) {
m, err := Parse(tt.raw)
if tt.err != "" {
assert.Error(t, err)
assert.EqualError(t, err, tt.err)
} else {
assert.NoError(t, err)
gsv := m.(GSV)
gsv.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, gsv)
}
})
}
}