Skip to content

Commit 882646d

Browse files
committed
Fixed error where list of GPSs could not decrease in size, also removed some debug prints
1 parent 724eec8 commit 882646d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

adafruit_gps.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __init__(self, uart, debug=False):
9797
self.fix_quality = None
9898
self.fix_quality_3d = None
9999
self.satellites = None
100+
self.satellites_prev = None
100101
self.horizontal_dilution = None
101102
self.altitude_m = None
102103
self.height_geoid = None
@@ -126,7 +127,6 @@ def update(self):
126127
try:
127128
sentence = self._parse_sentence()
128129
except UnicodeError:
129-
print("UnicodeError")
130130
return None
131131
if sentence is None:
132132
return False
@@ -196,12 +196,10 @@ def _parse_sentence(self):
196196

197197
sentence = self._uart.readline()
198198
if sentence is None or sentence == b'' or len(sentence) < 1:
199-
print("Sentence is none")
200199
return None
201200
try:
202201
sentence = str(sentence, 'ascii').strip()
203202
except UnicodeError:
204-
print("UnicodeError")
205203
return None
206204
# Look for a checksum and validate it if present.
207205
if len(sentence) > 7 and sentence[-3] == '*':
@@ -211,15 +209,13 @@ def _parse_sentence(self):
211209
for i in range(1, len(sentence)-3):
212210
actual ^= ord(sentence[i])
213211
if actual != expected:
214-
print("Actual != expected")
215212
return None # Failed to validate checksum.
216213
# Remove checksum once validated.
217214
sentence = sentence[:-3]
218215
# Parse out the type of sentence (first string after $ up to comma)
219216
# and then grab the rest as data within the sentence.
220217
delimiter = sentence.find(',')
221218
if delimiter == -1:
222-
print("Bad delimiter")
223219
return None # Invalid sentence, no comma after data type.
224220
data_type = sentence[1:delimiter]
225221
return (data_type, sentence[delimiter+1:])
@@ -415,3 +411,16 @@ def _parse_gpgsv(self, args):
415411
self.sats = {}
416412
for satnum in satdict:
417413
self.sats[satnum] = satdict[satnum]
414+
415+
try:
416+
if self.satellites < self.satellites_prev:
417+
for i in self.sats:
418+
try:
419+
if int(i[-2]) >= self.satellites:
420+
del self.sats[i]
421+
except ValueError:
422+
if int(i[-1]) >= self.satellites:
423+
del self.sats[i]
424+
except TypeError:
425+
pass
426+
self.satellites_prev = self.satellites

0 commit comments

Comments
 (0)