Update gps_client.py return -1 if no socket

pi-sensors-auto-gps
Alan Johnston 4 days ago committed by GitHub
parent cb80a03df3
commit 4454747453
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -11,55 +11,54 @@ run this way: python3 example1.py.txt
import gps # the gpsd interface module import gps # the gpsd interface module
import time import time
session = gps.gps(mode=gps.WATCH_ENABLE)
start = time.perf_counter()
mode = -1 mode = -1
lat = 0 lat = 0
lon = 0 lon = 0
alt = 0 alt = 0
try: try:
while (session.read() == 0) and ((time.perf_counter() - start) < 2) and (mode < 2):
# print(gps.MODE_SET)
# print(session.valid)
if (session.valid):
# not useful, probably not a TPV message
# continue
# print('Mode: %s(%d) Time: ' % session = gps.gps(mode=gps.WATCH_ENABLE)
# (("Invalid", "NO_FIX", "2D", "3D")[session.fix.mode],
# session.fix.mode), end="") start = time.perf_counter()
# print time, if we have it
print("%d " % session.fix.mode, end="") try:
if (session.fix.mode > mode): while (session.read() == 0) and ((time.perf_counter() - start) < 2) and (mode < 2):
mode = session.fix.mode # print(gps.MODE_SET)
# if gps.TIME_SET & session.valid: # print(session.valid)
# print(session.fix.time, end="") if (session.valid):
# else: # not useful, probably not a TPV message
# print('n/a', end="") # continue
# print('Mode: %s(%d) Time: ' %
# (("Invalid", "NO_FIX", "2D", "3D")[session.fix.mode],
# session.fix.mode), end="")
# print time, if we have it
print("%d " % session.fix.mode, end="")
if (session.fix.mode > mode):
mode = session.fix.mode
# if gps.TIME_SET & session.valid:
# print(session.fix.time, end="")
# else:
# print('n/a', end="")
if gps.isfinite(session.fix.latitude): if gps.isfinite(session.fix.latitude):
lat = session.fix.latitude lat = session.fix.latitude
if gps.isfinite(session.fix.longitude): if gps.isfinite(session.fix.longitude):
lon = session.fix.longitude lon = session.fix.longitude
if gps.isfinite(session.fix.altitude): if gps.isfinite(session.fix.altitude):
alt = session.fix.altitude alt = session.fix.altitude
print("%.6f %.6f %.6f" % print("%.6f %.6f %.6f" %
(session.fix.latitude, session.fix.longitude, session.fix.altitude)) (session.fix.latitude, session.fix.longitude, session.fix.altitude))
# else: # else:
# print(" 0 0 0") # print(" 0 0 0")
except KeyboardInterrupt: except KeyboardInterrupt:
# got a ^C. Say bye, bye # got a ^C. Say bye, bye
print('') print('')
# Got ^C, or fell out of the loop. Cleanup, and leave. # Got ^C, or fell out of the loop. Cleanup, and leave.
session.close() session.close()
print("%d %.6f %.6f %.1f" % (mode, lat, lon, alt)) print("%d %.6f %.6f %.1f" % (mode, lat, lon, alt))
exit(0) exit(0)

Loading…
Cancel
Save

Powered by TurnKey Linux.