Skip to content

Commit 6e5d1b1

Browse files
committed
chore(CR): Added property, and added _read_sentsence
1 parent f453df2 commit 6e5d1b1

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

adafruit_gps.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, uart, debug=False):
115115
self.total_mess_num = None
116116
self.mess_num = None
117117
self.debug = debug
118-
self.sentence = None
118+
self.raw_sentence = None
119119

120120
def update(self):
121121
"""Check for updated data from the GPS module and process it
@@ -176,7 +176,12 @@ def datetime(self):
176176
"""Return struct_time object to feed rtc.set_time_source() function"""
177177
return self.timestamp_utc
178178

179-
def _parse_sentence(self):
179+
@property
180+
def raw_sentence(self):
181+
"""Return raw_sentence which is the raw NMEA sentence read from the GPS"""
182+
return self.raw_sentence
183+
184+
def _read_sentence(self):
180185
# Parse any NMEA sentence that is available.
181186
# pylint: disable=len-as-condition
182187
# This needs to be refactored when it can be tested.
@@ -201,9 +206,21 @@ def _parse_sentence(self):
201206
actual ^= ord(sentence[i])
202207
if actual != expected:
203208
return None # Failed to validate checksum.
204-
self.sentence = sentence
205-
# Remove checksum once validated.
206-
sentence = sentence[:-3]
209+
210+
# copy the raw sentence
211+
self.raw_sentence = sentence
212+
213+
return sentence
214+
215+
def _parse_sentence(self):
216+
sentence = self._read_sentence()
217+
218+
# sentence is a valid NMEA with a valid checksum
219+
if sentence is None:
220+
return None
221+
222+
# Remove checksum once validated.
223+
sentence = sentence[:-3]
207224
# Parse out the type of sentence (first string after $ up to comma)
208225
# and then grab the rest as data within the sentence.
209226
delimiter = sentence.find(',')

0 commit comments

Comments
 (0)