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,29 +11,28 @@ 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:
session = gps.gps(mode=gps.WATCH_ENABLE)
start = time.perf_counter()
try:
while (session.read() == 0) and ((time.perf_counter() - start) < 2) and (mode < 2): while (session.read() == 0) and ((time.perf_counter() - start) < 2) and (mode < 2):
# print(gps.MODE_SET) # print(gps.MODE_SET)
# print(session.valid) # print(session.valid)
if (session.valid): if (session.valid):
# not useful, probably not a TPV message # not useful, probably not a TPV message
# continue # continue
# print('Mode: %s(%d) Time: ' % # print('Mode: %s(%d) Time: ' %
# (("Invalid", "NO_FIX", "2D", "3D")[session.fix.mode], # (("Invalid", "NO_FIX", "2D", "3D")[session.fix.mode],
# session.fix.mode), end="") # session.fix.mode), end="")
# print time, if we have it # print time, if we have it
print("%d " % session.fix.mode, end="") print("%d " % session.fix.mode, end="")
if (session.fix.mode > mode): if (session.fix.mode > mode):
@ -52,14 +51,14 @@ try:
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.