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