Skip to content

Commit 988c297

Browse files
barbacbdKnio
andauthored
Added the additional [optional] types to the RMC message including: (#144)
* Added the additional [optional] types to the RMC message including: - Mode Indicator - Navigation Status The tests were added as a single test case with many subcases. * ** reformat the super call to meet requirements for py2.7 * Update nmea_utils.py * Update nmea_utils.py * Update nmea_utils.py Co-authored-by: Tom Flanagan <[email protected]>
1 parent b7898b7 commit 988c297

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

pynmea2/nmea_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ def is_valid(self):
112112
return self.status == 'A'
113113

114114

115+
class ValidRMCStatusFix(ValidStatusFix):
116+
#pylint: disable=no-member
117+
@property
118+
def is_valid(self):
119+
status = super(ValidRMCStatusFix, self).is_valid
120+
if self.name_to_idx["mode_indicator"] < len(self.data):
121+
status &= self.mode_indicator in tuple('ADEFMPRS')
122+
if self.name_to_idx["nav_status"] < len(self.data):
123+
status &= self.nav_status in tuple('SCU')
124+
return status
125+
126+
115127
class ValidGSAFix(object):
116128
#pylint: disable=no-member
117129
@property

pynmea2/types/talker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class RMB(TalkerSentence, ValidStatusFix):
344344
("Arrival Alarm", "arrival_alarm"),
345345
) # A = Arrived, V = Not arrived
346346

347-
class RMC(TalkerSentence, ValidStatusFix, LatLonFix, DatetimeFix):
347+
class RMC(TalkerSentence, ValidRMCStatusFix, LatLonFix, DatetimeFix):
348348
""" Recommended Minimum Specific GPS/TRANSIT Data
349349
"""
350350
fields = (
@@ -359,6 +359,8 @@ class RMC(TalkerSentence, ValidStatusFix, LatLonFix, DatetimeFix):
359359
("Datestamp", "datestamp", datestamp),
360360
("Magnetic Variation", "mag_variation"),
361361
("Magnetic Variation Direction", "mag_var_dir"),
362+
("Mode Indicator", "mode_indicator"),
363+
("Navigational Status", "nav_status"),
362364
)
363365

364366
class RTE(TalkerSentence):
@@ -1035,4 +1037,4 @@ class ALK(TalkerSentence,SeaTalk):
10351037
("Data Byte 7", "data_byte7"),
10361038
("Data Byte 8", "data_byte8"),
10371039
("Data Byte 9", "data_byte9")
1038-
)
1040+
)

test/test_types.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,76 @@ def test_RMC():
123123
assert msg.render() == data
124124

125125

126+
def test_RMC_valid():
127+
'''The RMC mode indicator and navigation status values are optional.
128+
Test that when supplied the whole message must be valid. When not supplied
129+
only test validation against supplied values.
130+
131+
Supplied means that a `,` exists it does NOT mean that a value had to be
132+
supplied in the space provided. See
133+
134+
https://orolia.com/manuals/VSP/Content/NC_and_SS/Com/Topics/APPENDIX/NMEA_RMCmess.htm
135+
136+
for more information about the RMC Message additions.
137+
'''
138+
msgs = [
139+
# Original
140+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,*33',
141+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,*24',
142+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,*72',
143+
144+
# RMC Timing Messages
145+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,S*4C',
146+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,N*51',
147+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,*1F',
148+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,S*5B',
149+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,N*46',
150+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,*08',
151+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,S*0D',
152+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,N*10',
153+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,*5E',
154+
155+
# RMC Nav Messags
156+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,S,S*33',
157+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,S,V*36',
158+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,S,*60',
159+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,N,A*3C',
160+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,N,V*2B',
161+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,N,*7D',
162+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,,A*72',
163+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,,V*65',
164+
'$GPRMC,123519.00,A,4807.038,N,01131.000,E,,,230394,,,,*33',
165+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,S,A*36',
166+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,S,V*21',
167+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,S,*77',
168+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,N,A*2B',
169+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,N,V*3C',
170+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,N,*6A',
171+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,,A*65',
172+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,,V*72',
173+
'$GPRMC,123519.00,V,4807.038,N,01131.000,E,,,230394,,,,*24',
174+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,S,A*60',
175+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,S,V*77',
176+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,S,*21',
177+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,N,A*7D',
178+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,N,V*6A',
179+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,N,*3C',
180+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,,A*33',
181+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,,V*24',
182+
'$GPRMC,123519.00,,4807.038,N,01131.000,E,,,230394,,,,*72',
183+
]
184+
185+
# only the first of each section is valid
186+
expected = [False] * 39
187+
expected[0] = True
188+
expected[3] = True
189+
expected[12] = True
190+
191+
for i, msg in enumerate(msgs):
192+
parsed = pynmea2.parse(msg)
193+
assert expected[i] == parsed.is_valid
194+
195+
126196
def test_TXT():
127197
data = '$GNTXT,01,01,02,ROM BASE 2.01 (75331) Oct 29 2013 13:28:17*44'
128198
msg = pynmea2.parse(data)

0 commit comments

Comments
 (0)