Skip to content

Commit 9572d13

Browse files
committed
GPS: improve detection of malformed lines.
1 parent a49510d commit 9572d13

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

gps/as_GPS.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,16 @@ async def _run(self, loop):
192192
# Update takes a line of text
193193
async def _update(self, line):
194194
line = line.rstrip() # Copy line
195+
# Basic integrity check: may have received partial line e.g on power up
196+
if not line.startswith('$') or not '*' in line or len(line) > self._SENTENCE_LIMIT:
197+
return
195198
if self.FULL_CHECK: # 9ms on Pyboard
196199
try:
197200
next(c for c in line if ord(c) < 10 or ord(c) > 126)
198201
return # Bad character received
199202
except StopIteration:
200203
pass # All good
201204
await asyncio.sleep(0)
202-
if len(line) > self._SENTENCE_LIMIT or not '*' in line:
203-
return # Too long or malformed
204205

205206
a = line.split(',')
206207
segs = a[:-1] + a[-1].split('*')

0 commit comments

Comments
 (0)