-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetgps.py
33 lines (29 loc) · 867 Bytes
/
getgps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gps
# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
i=0
while i<1:
try:
report = session.next()
# Wait for a 'TPV' report and display the current time
# To see all report data, uncomment the line below
#print report
if report['class'] == 'TPV':
if hasattr(report, 'lon'):
lon=report.lon
if hasattr(report, 'lat'):
lat=report.lat
if hasattr(report, 'time'):
time=report.time
if hasattr(report, 'alt'):
alt=report.alt
i=1
print time,lat,lon,alt
except KeyError:
pass
except KeyboardInterrupt:
quit()
except StopIteration:
session = None
print "GPSD has terminated"