Code: Select all
from gps import *
import time
import threading
import math
class GpsController(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
self.running = False
def run(self):
self.running = True
while self.running:
# grab EACH set of gpsd info to clear the buffer
self.gpsd.next()
def stopController(self):
self.running = False
def fix(self):
return self.gpsd.fix
def utc(self):
return self.gpsd.utc
def satellites(self):
return self.gpsd.satellites
if __name__ == '__main__':
# create the controller
gpsc = GpsController()
try:
# start controller
gpsc.start()
print "Acquiring signal from satellites. Please wait...\n"
time.sleep(5)
while True:
print "Time UTC: ", gpsc.utc
print "Latitude: ", gpsc.fix.latitude, " N"
print "Longitude: ", gpsc.fix.longitude, " W"
print "Altitude: ", gpsc.fix.altitude, " m"
print "Speed: ", gpsc.fix.speed, " m/s"
print "Heading: ", gpsc.fix.track, " deg (true)"
print "Climb: ", gpsc.fix.climb, " m/min"
print "EPS: ", gpsc.fix.eps
print "EPX: ", gpsc.fix.epx
print "EPX: ", gpsc.fix.epx
print "EPV: ", gpsc.fix.epv
print "EPT: ", gpsc.gpsd.fix.ept
print "Mode: ", gpsc.fix.mode
print "Satellites: ", gpsc.satellites
print "\n"
time.sleep(3)
#Ctrl-C
except KeyboardInterrupt:
print "\nUser Cancelled"
#Error
except:
print "Unexpected Error:", sys.exc_info()[0]
raise
finally:
print "Stopping GPS Controller"
gpsc.stopController()
#wait for the thread to finish
gpsc.join()
print "Done"