Skip to content

Commit a70bdbc

Browse files
committed
Change RMC parsing so that datetime values are available even when
there's no GPS fix. Fixes adafruit#105
1 parent 2671a7f commit a70bdbc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

adafruit_gps.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
https://github.com/adafruit/circuitpython/releases
2727
2828
"""
29+
2930
import time
3031
from micropython import const
3132

@@ -61,7 +62,7 @@
6162
# 0 - _GLL
6263
"dcdcscC",
6364
# 1 - _RMC
64-
"scdcdcffsDCC",
65+
"scDCDCFFsDCC",
6566
# 2 - _GGA
6667
"sdcdciiffsfsIS",
6768
# 3 - _GSA
@@ -588,6 +589,7 @@ def _parse_rmc(self, data: List[str]) -> bool:
588589
self.fix_quality = 1
589590
else:
590591
self.fix_quality = 0
592+
return True # break early since no fix means no following values will be populated
591593

592594
# Latitude
593595
self.latitude = _read_degrees(parsed_data, 2, "s")

tests/adafruit_gps_test.py

+12
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ def test_GPS_update_timestamp_timestamp_utc_was_not_none_new_date_none():
162162
assert gps.timestamp_utc == exp_struct
163163

164164

165+
def test_GPS_update_time_from_RTC_without_fix():
166+
r = b"$GPRMC,210648.000,V,,,,,0.71,105.86,050425,,,N*4E\r\n"
167+
with mock.patch.object(GPS, "readline", return_value=r):
168+
gps = GPS(uart=UartMock())
169+
gps.update()
170+
exp_time = time.struct_time((2025, 4, 5, 21, 6, 48, 0, 0, -1))
171+
assert gps.has_fix is False
172+
assert gps.timestamp_utc == exp_time
173+
assert gps.datetime == exp_time
174+
assert gps.nmea_sentence == "$GPRMC,210648.000,V,,,,,0.71,105.86,050425,,,N*4E"
175+
176+
165177
def test_GPS_update_with_unknown_talker():
166178
r = b"$XYRMC,215032.086,A,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A*7c\r\n"
167179
with mock.patch.object(GPS, "readline", return_value=r):

0 commit comments

Comments
 (0)