You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
#! /usr/bin/env python3
|
|
"""
|
|
example Python gpsd client
|
|
run this way: python3 example1.py.txt
|
|
"""
|
|
|
|
# from https://gpsd.gitlab.io/gpsd/gpsd-client-example-code.html
|
|
|
|
import gps # the gpsd interface module
|
|
|
|
session = gps.gps(mode=gps.WATCH_ENABLE)
|
|
|
|
try:
|
|
while 0 == session.read():
|
|
if not (gps.MODE_SET & session.valid):
|
|
# not useful, probably not a TPV message
|
|
continue
|
|
|
|
print('Mode: %s(%d) Time: ' %
|
|
(("Invalid", "NO_FIX", "2D", "3D")[session.fix.mode],
|
|
session.fix.mode), end="")
|
|
# print time, if we have it
|
|
if gps.TIME_SET & session.valid:
|
|
print(session.fix.time, end="")
|
|
else:
|
|
print('n/a', end="")
|
|
|
|
if ((gps.isfinite(session.fix.latitude) and
|
|
gps.isfinite(session.fix.longitude))):
|
|
print(" Lat %.6f Lon %.6f" %
|
|
(session.fix.latitude, session.fix.longitude))
|
|
else:
|
|
print(" Lat n/a Lon n/a")
|
|
|
|
except KeyboardInterrupt:
|
|
# got a ^C. Say bye, bye
|
|
print('')
|
|
|
|
# Got ^C, or fell out of the loop. Cleanup, and leave.
|
|
session.close()
|
|
exit(0)
|