Skip to content

Commit

Permalink
gps: add ValueError and test for invalid msg
Browse files Browse the repository at this point in the history
  • Loading branch information
tajgr committed Jun 19, 2024
1 parent ee57b13 commit 16c764a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions osgar/drivers/gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def str2deg(s):
dm, frac = ('0000' + s).split('.')
try:
return float(dm[:-2]) + float(dm[-2:] + '.' + frac) / 60
except Exception as e:
except ValueError as e:
print(e)
return None

Expand Down Expand Up @@ -62,7 +62,7 @@ def parse_nmea(line):
nmea_data["age"] = None if nmea_list[13] == "" else float(nmea_list[13])
stn_id = nmea_list[14].split("*")[0]
nmea_data["stn_id"] = None if stn_id == "" else stn_id
except Exception as e:
except ValueError as e:
print(e)
return None

Expand Down
5 changes: 5 additions & 0 deletions osgar/drivers/test_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ def test_parse_old_GPGGA(self):
nmea_data = gps.parse_nmea(line)
self.assertEqual(nmea_data["lon"], 14.5056)
self.assertEqual(nmea_data["lat"], 50.08374)

def test_parse_err_line(self):
line = b'$GPGGA,051852.000,5005.0244,N,01430.3360,E,1,06,3.8,253\x00.1,M,45.4,M,,0000*58'
self.assertIsNone(gps.parse_nmea(line))

# vim: expandtab sw=4 ts=4

0 comments on commit 16c764a

Please sign in to comment.