我有一个gps代码,可以获取gps数据并写入日志:#!/usr/bin/python
from systemd import journal
import gps
import time
import threading
import datetime
# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
while True:
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, 'time'):
timestamp = (time.time()*1000)
#print timestamp
if hasattr(report, 'lat'):
latitude = report.lat
#print latitude
if hasattr(report, 'lon'):
longitude = report.lon
#print longitude
if hasattr(report, 'alt'):
altitude = report.alt
#print altitude
else:
timestamp = (time.time()*1000)
latitude = 0
longitude = 0
altitude = 0
journal.send(
channel = 'gps',
priority = journal.Priority.INFO,
timestamp = "%f" % (timestamp),
latitude = "%f" % (latitude),
longitude = "%f" % (longitude),
altitude = "%f" % (altitude),
)
except KeyError:
pass
except KeyboardInterrupt:
quit()
except StopIteration:
session = None
print "GPSD has terminated"
我得到一个错误:
^{pr2}$
有趣的是代码有时工作得很好,有时它会给我这个错误。我不明白我应该怎么做才能让它一直正常工作。这和她爆炸有关吗?