Skip to content

Commit 760cc77

Browse files
authored
Fix RMC fix time parsing.
1 parent 885359f commit 760cc77

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

adafruit_gps.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,19 @@ def _parse_GPRMC(self, args):
177177
if data is None or len(data) < 11:
178178
return # Unexpected number of params.
179179
# Parse fix time.
180-
self.fix_time_utc = _parse_float(data[0])
181-
if self.fix_time_utc is not None:
182-
# Set time to a friendly python time struct if available.
183-
hours = self.fix_time_utc // 10000
184-
mins = int((self.fix_time_utc // 100) % 100)
185-
secs = self.fix_time_utc % 100
186-
self.fix_time_utc = time.struct_time((0, 0, 0, hours, mins, secs, 0, 0, -1))
180+
time_utc = _parse_float(data[0])
181+
if time_utc is not None:
182+
hours = time_utc // 10000
183+
mins = int((time_utc // 100) % 100)
184+
secs = time_utc % 100
185+
# Set or update time to a friendly python time struct.
186+
if self.timestamp_utc is not None:
187+
self.timestamp_utc = time.struct_time((
188+
self.timestamp_utc.tm_year, self.timestamp_utc.tm_mon,
189+
self.timestamp_utc.tm_mday, hours, mins, secs, 0, 0, -1))
190+
else:
191+
self.timestamp_utc = time.struct_time((0, 0, 0, hours, mins,
192+
secs, 0, 0, -1))
187193
# Parse status (active/fixed or void).
188194
status = data[1]
189195
self.fix_quality = 0

0 commit comments

Comments
 (0)