From 41a4adff44a33fa92ede0a657baf4ff2c56a29c0 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 8 Dec 2021 21:41:28 +0100 Subject: [PATCH 1/4] Enhanced parsing of timestamp_utc --- adafruit_gps.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/adafruit_gps.py b/adafruit_gps.py index 10bc89c..a28a065 100644 --- a/adafruit_gps.py +++ b/adafruit_gps.py @@ -50,11 +50,11 @@ _SENTENCE_PARAMS = ( # 0 - _GLL - "dcdcfcC", + "dcdcscC", # 1 - _RMC - "fcdcdcffiDCC", + "scdcdcffsDCC", # 2 - _GGA - "fdcdciiffsfsIS", + "sdcdciiffsfsIS", # 3 - _GSA "ciIIIIIIIIIIIIfff", # 4 - _GSA_4_11 @@ -68,7 +68,7 @@ # 8 - _GSV19 "iiiiiiIiiiIiiiIiiiI", # 9 - _RMC_4_1 - "fcdcdcffiDCCC", + "scdcdcffsDCCC", ) @@ -394,9 +394,9 @@ def _parse_sentence(self): return (data_type, sentence[delimiter + 1 :]) def _update_timestamp_utc(self, time_utc, date=None): - hours = time_utc // 10000 - mins = (time_utc // 100) % 100 - secs = time_utc % 100 + hours = int(time_utc[0:2]) + mins = int(time_utc[2:4]) + secs = int(time_utc[4:6]) if date is None: if self.timestamp_utc is None: day, month, year = 0, 0, 0 @@ -405,9 +405,9 @@ def _update_timestamp_utc(self, time_utc, date=None): month = self.timestamp_utc.tm_mon year = self.timestamp_utc.tm_year else: - day = date // 10000 - month = (date // 100) % 100 - year = 2000 + date % 100 + day = int(date[0:2]) + month = int(date[2:4]) + year = 2000 + int(date[4:6]) self.timestamp_utc = time.struct_time( (year, month, day, hours, mins, secs, 0, 0, -1) @@ -429,7 +429,7 @@ def _parse_gll(self, data): self.longitude = _read_degrees(data, 2, "w") # UTC time of position - self._update_timestamp_utc(int(data[4])) + self._update_timestamp_utc(data[4]) # Status Valid(A) or Invalid(V) self.isactivedata = data[5] @@ -450,7 +450,7 @@ def _parse_rmc(self, data): return False # Params didn't parse # UTC time of position and date - self._update_timestamp_utc(int(data[0]), data[8]) + self._update_timestamp_utc(data[0], data[8]) # Status Valid(A) or Invalid(V) self.isactivedata = data[1] @@ -494,7 +494,7 @@ def _parse_gga(self, data): return False # Params didn't parse # UTC time of position - self._update_timestamp_utc(int(data[0])) + self._update_timestamp_utc(data[0]) # Latitude self.latitude = _read_degrees(data, 1, "s") From bf26b17d90c3abf37e3d29a1ca5f891c068c4de9 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Dec 2021 16:51:49 +0100 Subject: [PATCH 2/4] Updated timestamp tests for new type format --- tests/adafruit_gps_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/adafruit_gps_test.py b/tests/adafruit_gps_test.py index 9e09c85..7bbc060 100644 --- a/tests/adafruit_gps_test.py +++ b/tests/adafruit_gps_test.py @@ -140,14 +140,14 @@ def test_GPS_update_timestamp_UTC_date_None(): assert gps.datetime is None assert gps.timestamp_utc is None exp_struct = time.struct_time((0, 0, 0, 22, 14, 11, 0, 0, -1)) - gps._update_timestamp_utc(time_utc=221411) + gps._update_timestamp_utc(time_utc='221411') assert gps.timestamp_utc == exp_struct def test_GPS_update_timestamp_UTC_date_not_None(): gps = GPS(uart=UartMock()) exp_struct = time.struct_time((2021, 10, 2, 22, 14, 11, 0, 0, -1)) - gps._update_timestamp_utc(time_utc=221411, date=21021) + gps._update_timestamp_utc(time_utc='221411', date='21021') assert gps.timestamp_utc == exp_struct @@ -157,7 +157,7 @@ def test_GPS_update_timestamp_timestamp_utc_was_not_none_new_date_none(): gps.timestamp_utc = time.struct_time((2021, 10, 2, 22, 10, 11, 0, 0, -1)) exp_struct = time.struct_time((2021, 10, 2, 22, 14, 11, 0, 0, -1)) # update the timestamp - gps._update_timestamp_utc(time_utc=221411) + gps._update_timestamp_utc(time_utc='221411') assert gps.timestamp_utc == exp_struct From 10142fd0d9602afba630d3b746a9d6e965d2bf2b Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Dec 2021 17:50:41 +0100 Subject: [PATCH 3/4] Learning about formatting and black --- tests/adafruit_gps_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/adafruit_gps_test.py b/tests/adafruit_gps_test.py index 7bbc060..53aea9d 100644 --- a/tests/adafruit_gps_test.py +++ b/tests/adafruit_gps_test.py @@ -140,14 +140,14 @@ def test_GPS_update_timestamp_UTC_date_None(): assert gps.datetime is None assert gps.timestamp_utc is None exp_struct = time.struct_time((0, 0, 0, 22, 14, 11, 0, 0, -1)) - gps._update_timestamp_utc(time_utc='221411') + gps._update_timestamp_utc(time_utc="221411") assert gps.timestamp_utc == exp_struct def test_GPS_update_timestamp_UTC_date_not_None(): gps = GPS(uart=UartMock()) exp_struct = time.struct_time((2021, 10, 2, 22, 14, 11, 0, 0, -1)) - gps._update_timestamp_utc(time_utc='221411', date='21021') + gps._update_timestamp_utc(time_utc="221411", date="21021") assert gps.timestamp_utc == exp_struct @@ -157,7 +157,7 @@ def test_GPS_update_timestamp_timestamp_utc_was_not_none_new_date_none(): gps.timestamp_utc = time.struct_time((2021, 10, 2, 22, 10, 11, 0, 0, -1)) exp_struct = time.struct_time((2021, 10, 2, 22, 14, 11, 0, 0, -1)) # update the timestamp - gps._update_timestamp_utc(time_utc='221411') + gps._update_timestamp_utc(time_utc="221411") assert gps.timestamp_utc == exp_struct From ef300a2edbe9d672f8e9f7e00edaeb3d346f7ae3 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Dec 2021 18:07:28 +0100 Subject: [PATCH 4/4] Added leading 0 to date string since it is no longer int and to follow NMEA sentence format of DDMMYY --- tests/adafruit_gps_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/adafruit_gps_test.py b/tests/adafruit_gps_test.py index 53aea9d..8a956f3 100644 --- a/tests/adafruit_gps_test.py +++ b/tests/adafruit_gps_test.py @@ -147,7 +147,7 @@ def test_GPS_update_timestamp_UTC_date_None(): def test_GPS_update_timestamp_UTC_date_not_None(): gps = GPS(uart=UartMock()) exp_struct = time.struct_time((2021, 10, 2, 22, 14, 11, 0, 0, -1)) - gps._update_timestamp_utc(time_utc="221411", date="21021") + gps._update_timestamp_utc(time_utc="221411", date="021021") assert gps.timestamp_utc == exp_struct