Skip to content

Commit 41a4adf

Browse files
committed
Enhanced parsing of timestamp_utc
1 parent b9e06e9 commit 41a4adf

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

adafruit_gps.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050

5151
_SENTENCE_PARAMS = (
5252
# 0 - _GLL
53-
"dcdcfcC",
53+
"dcdcscC",
5454
# 1 - _RMC
55-
"fcdcdcffiDCC",
55+
"scdcdcffsDCC",
5656
# 2 - _GGA
57-
"fdcdciiffsfsIS",
57+
"sdcdciiffsfsIS",
5858
# 3 - _GSA
5959
"ciIIIIIIIIIIIIfff",
6060
# 4 - _GSA_4_11
@@ -68,7 +68,7 @@
6868
# 8 - _GSV19
6969
"iiiiiiIiiiIiiiIiiiI",
7070
# 9 - _RMC_4_1
71-
"fcdcdcffiDCCC",
71+
"scdcdcffsDCCC",
7272
)
7373

7474

@@ -394,9 +394,9 @@ def _parse_sentence(self):
394394
return (data_type, sentence[delimiter + 1 :])
395395

396396
def _update_timestamp_utc(self, time_utc, date=None):
397-
hours = time_utc // 10000
398-
mins = (time_utc // 100) % 100
399-
secs = time_utc % 100
397+
hours = int(time_utc[0:2])
398+
mins = int(time_utc[2:4])
399+
secs = int(time_utc[4:6])
400400
if date is None:
401401
if self.timestamp_utc is None:
402402
day, month, year = 0, 0, 0
@@ -405,9 +405,9 @@ def _update_timestamp_utc(self, time_utc, date=None):
405405
month = self.timestamp_utc.tm_mon
406406
year = self.timestamp_utc.tm_year
407407
else:
408-
day = date // 10000
409-
month = (date // 100) % 100
410-
year = 2000 + date % 100
408+
day = int(date[0:2])
409+
month = int(date[2:4])
410+
year = 2000 + int(date[4:6])
411411

412412
self.timestamp_utc = time.struct_time(
413413
(year, month, day, hours, mins, secs, 0, 0, -1)
@@ -429,7 +429,7 @@ def _parse_gll(self, data):
429429
self.longitude = _read_degrees(data, 2, "w")
430430

431431
# UTC time of position
432-
self._update_timestamp_utc(int(data[4]))
432+
self._update_timestamp_utc(data[4])
433433

434434
# Status Valid(A) or Invalid(V)
435435
self.isactivedata = data[5]
@@ -450,7 +450,7 @@ def _parse_rmc(self, data):
450450
return False # Params didn't parse
451451

452452
# UTC time of position and date
453-
self._update_timestamp_utc(int(data[0]), data[8])
453+
self._update_timestamp_utc(data[0], data[8])
454454

455455
# Status Valid(A) or Invalid(V)
456456
self.isactivedata = data[1]
@@ -494,7 +494,7 @@ def _parse_gga(self, data):
494494
return False # Params didn't parse
495495

496496
# UTC time of position
497-
self._update_timestamp_utc(int(data[0]))
497+
self._update_timestamp_utc(data[0])
498498

499499
# Latitude
500500
self.latitude = _read_degrees(data, 1, "s")

0 commit comments

Comments
 (0)