[Git][NTPsec/ntpsec][master] Fix ntploggps
Eric S. Raymond
gitlab at mg.gitlab.com
Sun Nov 26 15:54:09 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
3d3cd2f3 by Richard Laager at 2017-11-26T15:53:30+00:00
Fix ntploggps
I ported ntploggps to the new-style API and made it wait for a valid SKY
message. This fixes the delivery of TDOP (which was otherwise always
zero for me) and the satellite count (which was often zero). It also
waits for a valid TPV message, ensuring it can report the device
properly.
With this, my GPS reporting fully works on Ubuntu 16.04 with gpsd 3.15.
- - - - -
1 changed file:
- ntpclients/ntploggps
Changes:
=====================================
ntpclients/ntploggps
=====================================
--- a/ntpclients/ntploggps
+++ b/ntpclients/ntploggps
@@ -132,6 +132,9 @@ class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
+ self.device = None
+ self.satellites_used = None
+ self.tdop = None
# start the streaming of gps data
try:
self.gpsd = gps.gps(mode=gps.WATCH_ENABLE)
@@ -143,23 +146,30 @@ class GpsPoller(threading.Thread):
def run(self):
while gpsp.running:
- try:
- self.gpsd.next() # loop and grab each set of gpsd info
- except:
+ if self.gpsd.read() == -1:
self.running = False
break
-
- def get_time(self):
+ 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")
+
+ @property
+ def time(self):
"Return the gpsd time fix"
- return self.gpsd.fix.time
-
- def log_line(self):
- "Displays the time, device, TDOP, and nSat data collected"
- s = '%s %s %f %d' % (gps.isotime(self.get_time()),
- self.gpsd.device,
- self.gpsd.tdop,
- self.gpsd.satellites_used)
- return s
+ t = self.gpsd.fix.time
+ if isinstance(t, int):
+ return t
+ if isinstance(t, float):
+ if gps.isnan(t):
+ return None
+ return t
+ return gps.isotime(t)
if __name__ == '__main__':
# this is the main thread
@@ -180,10 +190,20 @@ if __name__ == '__main__':
# It may take a second or two to get good data
try:
- if 'nan' != gpsp.get_time() and not gps.isnan(gpsp.get_time()):
- if last_time != gpsp.get_time():
- Logger.info(gpsp.log_line())
- last_time = gpsp.get_time()
+ current_time = gpsp.time
+ device = gpsp.device
+ tdop = gpsp.tdop
+ satellites_used = gpsp.satellites_used
+
+ if current_time is not None and \
+ device is not None and \
+ satellites_used is not None and \
+ tdop is not None:
+ if last_time != current_time:
+ s = '%i %s %f %d' % (current_time, device, tdop,
+ satellites_used)
+ Logger.info(s)
+ last_time = current_time
if args.once:
# just once
break
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/3d3cd2f382c5375f11bf7cec6e98dc7677abdfec
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/3d3cd2f382c5375f11bf7cec6e98dc7677abdfec
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/20171126/f3e89b0e/attachment.html>
More information about the vc
mailing list