Skip to content

Commit 84480ed

Browse files
Update the processing of GSV messages, to include a time reference
to when it was received. The data stored in self.sats dictionary is: key is TTNN where TT = the talker name, eg. GL for GLONASS NN = the number of the satellite, currently a 1 or 2 digit number value is a 5 entry list (V0, V1, V2, V3, V4) V0 = satellite number TTNN as used for the key V1 = satellite elevation in degrees V2 = satellite azimuth in degrees V3 = satellite signal to noise ratio in dB, or None V4 = timestamp, time.monotonic(), of last GSV message
1 parent 8786f1f commit 84480ed

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

adafruit_gps.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def __init__(self, uart, debug=False):
9090
self.height_geoid = None
9191
self.speed_knots = None
9292
self.track_angle_deg = None
93-
self._sats = None
94-
self.sats = None
93+
self._sats = None # Temporary holder for information from GSV messages
94+
self.sats = None # Completed information from GSV messages
9595
self.isactivedata = None
9696
self.true_track = None
9797
self.mag_track = None
@@ -467,14 +467,23 @@ def _parse_gpgsv(self, talker, args):
467467
sat_tup = data[3:]
468468

469469
satlist = []
470+
timestamp = time.monotonic()
470471
for i in range(len(sat_tup) // 4):
471-
j = i * 4
472-
satnum = "{}{}".format(talker, _parse_int(sat_tup[0 + j])) # Satellite number
473-
satdeg = _parse_int(sat_tup[1 + j]) # Elevation in degrees
474-
satazim = _parse_int(sat_tup[2 + j]) # Azimuth in degrees
475-
satsnr = _parse_int(sat_tup[3 + j]) # signal-to-noise ratio in dB
476-
value = (satnum, satdeg, satazim, satsnr)
477-
satlist.append(value)
472+
try:
473+
j = i * 4
474+
# Satellite number
475+
satnum = "{}{}".format(talker, _parse_int(sat_tup[0 + j]))
476+
# Elevation in degrees
477+
satdeg = _parse_int(sat_tup[1 + j])
478+
# Azimuth in degrees
479+
satazim = _parse_int(sat_tup[2 + j])
480+
# signal-to-noise ratio in dB
481+
satsnr = _parse_int(sat_tup[3 + j])
482+
value = (satnum, satdeg, satazim, satsnr, timestamp)
483+
satlist.append(value)
484+
except ValueError:
485+
# Something wasn't an int
486+
pass
478487

479488
if self._sats is None:
480489
self._sats = []
@@ -488,11 +497,13 @@ def _parse_gpgsv(self, talker, args):
488497
if self.sats is None:
489498
self.sats = {}
490499
else:
491-
# Remove all old data from self.sats which
492-
# match the current talker
500+
# Remove all satellites which haven't
501+
# been seen for 30 seconds
502+
timestamp = time.monotonic()
493503
old = []
494504
for i in self.sats:
495-
if i[0:2] == talker:
505+
sat = self.sats[i]
506+
if (timestamp - sat[4]) > 30:
496507
old.append(i)
497508
for i in old:
498509
self.sats.pop(i)

0 commit comments

Comments
 (0)