Skip to content

Fixed an issue mentioned in issue #19 where a UnicodeError would be raised when there was noise over UART #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Feather boards and many other circuitpython boards will round to two decimal pla
>>> float('1234.5678')
1234.57

This isn't ideal for gps data as this lowers the accuracty from 0.1m to 11m.
This isn't ideal for gps data as this lowers the accuracy from 0.1m to 11m.

This can be fixed by using string formatting when the gps data is outputted.

Expand Down
10 changes: 8 additions & 2 deletions adafruit_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def update(self):
"""
# Grab a sentence and check its data type to call the appropriate
# parsing function.
sentence = self._parse_sentence()
try:
sentence = self._parse_sentence()
except UnicodeError:
return None
if sentence is None:
return False
if self.debug:
Expand Down Expand Up @@ -145,7 +148,10 @@ def _parse_sentence(self):
sentence = self._uart.readline()
if sentence is None or sentence == b'' or len(sentence) < 1:
return None
sentence = str(sentence, 'ascii').strip()
try:
sentence = str(sentence, 'ascii').strip()
except UnicodeError:
return None
# Look for a checksum and validate it if present.
if len(sentence) > 7 and sentence[-3] == '*':
# Get included checksum, then calculate it and compare.
Expand Down