[Git][NTPsec/ntpsec][master] ntploggps: Resolve issue #730 by ensuring relevant fields valid.

James Browning (@jamesb_fe80) gitlab at mg.gitlab.com
Wed Mar 2 12:08:56 UTC 2022



James Browning pushed to branch master at NTPsec / ntpsec


Commits:
d1897775 by James Browning at 2022-03-01T16:24:32-08:00
ntploggps: Resolve issue #730 by ensuring relevant fields valid.

gpsd appears to be sending SKY sentences without satellites[].
gpsd also appears to be (sometimes) 'uSat' which has the number.
So, grab 'device', 'tdop' and (the sum of used satellites[] or 'uSat').
Check that non of them are invalid, then package them for use.

Also, address potential issue where on multi-device systems,
another device can steal the thunder of the reporting device.
That however, can never occur.

- - - - -


1 changed file:

- ntpclients/ntploggps.py


Changes:

=====================================
ntpclients/ntploggps.py
=====================================
@@ -159,14 +159,28 @@ class GpsPoller(threading.Thread):
                 self.running = False
                 break
             if hasattr(self.gpsd, "data"):
-                if self.gpsd.data.get("class") == "SKY":
-                    self.satellites_used = 0
-                    self.tdop = self.gpsd.data.get("tdop", 0)
-                    for sat in self.gpsd.data.get("satellites", []):
-                        if sat["used"]:
-                            self.satellites_used += 1
-                elif self.gpsd.data.get("class") == "TPV":
-                    self.device = self.gpsd.data.get("device")
+                if self.gpsd.data.get("class", None) == "SKY":
+                    satellite_list = self.gpsd.data.get(
+                        "satellites", None
+                    )
+                    if satellite_list is not None:
+                        count_used_satellites = sum(
+                            map(lambda x: x.used, satellite_list)
+                        )
+                    time_dilution = self.gpsd.data.get("tdop", None)
+                    device_path = self.gpsd.data.get("device", None)
+                    if count_used_satellites is None:
+                        count_used_satellites = self.gpsd.data.get(
+                            "uSat", None
+                        )
+                    if None not in [
+                        count_used_satellites,
+                        time_dilution,
+                        device_path,
+                    ]:
+                        self.satellites_used = count_used_satellites
+                        self.tdop = time_dilution
+                        self.device = device_path
 
     @property
     def time(self):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/d1897775df7b103c135787b88ef31cbc59719be3

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/d1897775df7b103c135787b88ef31cbc59719be3
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20220302/e8900664/attachment-0001.htm>


More information about the vc mailing list