[Git][NTPsec/ntpsec][master] moved global variable to be contained within the GpsPoller class.

deamoneye gitlab at mg.gitlab.com
Mon Dec 19 19:41:16 UTC 2016


deamoneye pushed to branch master at NTPsec / ntpsec


Commits:
6651873f by Keane Wolter at 2016-12-19T14:38:02-05:00
moved global variable to be contained within the GpsPoller class.

- - - - -


1 changed file:

- contrib/gps-log


Changes:

=====================================
contrib/gps-log
=====================================
--- a/contrib/gps-log
+++ b/contrib/gps-log
@@ -9,19 +9,28 @@ import sys
 import threading
 from gps import *
 
-gpsd = None #seting the global variable
-
 class GpsPoller(threading.Thread):
     def __init__(self):
         threading.Thread.__init__(self)
-        global gpsd #bring it in scope
-        gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
+        self.gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
         self.running = True
 
     def run(self):
-        global gpsd
         while gpsp.running:
-            gpsd.next() # loop and grab each set of gpsd info
+            self.gpsd.next() # loop and grab each set of gpsd info
+
+    def get_time(self):
+        "Return the gpsd time fix"
+        return self.gpsd.fix.time
+
+    def display(self):
+        "Displays the time, device, TDOP, and nSat data collected"
+        #print(gpsd.fix.latitude,', ',gpsd.fix.longitude,'  Time: ',gpsd.utc)
+        print('%s %s %f %d' % \
+                (isotime(self.get_time()),
+                self.gpsd.device,
+                self.gpsd.tdop,
+                self.gpsd.satellites_used))
 
 if __name__ == '__main__':
     gpsp = GpsPoller() # create the thread
@@ -32,19 +41,12 @@ if __name__ == '__main__':
         print("# Time       Device     TDOP     nSat")
         while True:
             #It may take a second or two to get good data
-            #print(gpsd.fix.latitude,', ',gpsd.fix.longitude,'  Time: ',gpsd.utc)
 
             try:
-                if 'nan' != gpsd.fix.time and not isnan(gpsd.fix.time):
-                    if last_time != gpsd.fix.time:
-                        # new fix, log it.
-                        print( '%s %s %f %d' % \
-                            (isotime(gpsd.fix.time),
-                             gpsd.device,
-                             gpsd.tdop,
-                             gpsd.satellites_used)
-                            )
-                    last_time = gpsd.fix.time
+                if 'nan' != gpsp.get_time() and not isnan(gpsp.get_time()):
+                    if last_time != gpsp.get_time():
+                        gpsp.display()
+                    last_time = gpsp.get_time()
             except AttributeError as e:
                 print( 'parse error\n')
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/6651873fdbdec5f8f804966194f65496a2e85f79
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161219/f2d72d42/attachment.html>


More information about the vc mailing list