forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rmc_test.go
138 lines (134 loc) · 3.31 KB
/
rmc_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
package nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
var rmctests = []struct {
name string
raw string
err string
msg RMC
}{
{
name: "good sentence A",
raw: "$GNRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*6E",
msg: RMC{
Time: Time{true, 22, 05, 16, 0},
Validity: "A",
Latitude: MustParseGPS("5133.82 N"),
Longitude: MustParseGPS("00042.24 W"),
Speed: 173.8,
Course: 231.8,
Date: Date{true, 13, 06, 94},
Variation: -4.2,
FFAMode: "",
NavStatus: "",
},
},
{
name: "good sentence B",
raw: "$GNRMC,142754.0,A,4302.539570,N,07920.379823,W,0.0,,070617,0.0,E,A*21",
msg: RMC{
Time: Time{true, 14, 27, 54, 0},
Validity: "A",
Latitude: MustParseGPS("4302.539570 N"),
Longitude: MustParseGPS("07920.379823 W"),
Speed: 0,
Course: 0,
Date: Date{true, 7, 6, 17},
Variation: 0,
FFAMode: FAAModeAutonomous,
NavStatus: "",
},
},
{
name: "good sentence C",
raw: "$GNRMC,100538.00,A,5546.27711,N,03736.91144,E,0.061,,260318,,,A*60",
msg: RMC{
Time: Time{true, 10, 5, 38, 0},
Validity: "A",
Latitude: MustParseGPS("5546.27711 N"),
Longitude: MustParseGPS("03736.91144 E"),
Speed: 0.061,
Course: 0,
Date: Date{true, 26, 3, 18},
Variation: 0,
FFAMode: FAAModeAutonomous,
NavStatus: "",
},
},
{
name: "bad sentence",
raw: "$GNRMC,220516,D,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*6B",
err: "nmea: GNRMC invalid validity: D",
},
{
name: "good sentence D",
raw: "$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70",
msg: RMC{
Time: Time{true, 22, 5, 16, 0},
Validity: "A",
Latitude: MustParseGPS("5133.82 N"),
Longitude: MustParseGPS("00042.24 W"),
Speed: 173.8,
Course: 231.8,
Date: Date{true, 13, 6, 94},
Variation: -4.2,
FFAMode: "",
NavStatus: "",
},
},
{
name: "good sentence E",
raw: "$GPRMC,142754.0,A,4302.539570,N,07920.379823,W,0.0,,070617,0.0,E,A*3F",
msg: RMC{
Time: Time{true, 14, 27, 54, 0},
Validity: "A",
Latitude: MustParseGPS("4302.539570 N"),
Longitude: MustParseGPS("07920.379823 W"),
Speed: 0,
Course: 0,
Date: Date{true, 7, 6, 17},
Variation: 0,
FFAMode: FAAModeAutonomous,
NavStatus: "",
},
},
{
name: "good sentence F with nav status",
raw: "$GNRMC,102014.00,A,5550.6082,N,03732.2488,E,000.00000,092.9,300518,,,A,V*3B",
msg: RMC{
Time: Time{Valid: true, Hour: 10, Minute: 20, Second: 14, Millisecond: 0},
Validity: "A",
Latitude: 55.843469999999996,
Longitude: 37.537479999999995,
Speed: 0,
Course: 92.9,
Date: Date{Valid: true, DD: 30, MM: 5, YY: 18},
Variation: 0,
FFAMode: FAAModeAutonomous,
NavStatus: NavStatusDataValid,
},
},
{
name: "bad validity",
raw: "$GPRMC,220516,D,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*75",
err: "nmea: GPRMC invalid validity: D",
},
}
func TestRMC(t *testing.T) {
for _, tt := range rmctests {
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)
rmc := m.(RMC)
rmc.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, rmc)
}
})
}
}