我正在使用 python 实现 GPSD 轮询:遵循此处的 python 示例:http: //www.catb.org/gpsd/client-howto.html#_python_examples
我不能在这里使用代码是有原因的: https : //gist.github.com/wolfg1969/4653340 因为我必须在我的系统中守护大约 10 个进程,所以我会选择 catb 一个以便于实施。
我对以下代码有疑问,为什么它会在两个周期后停止?我该如何解决这个问题?谢谢。
def GpsDetection():
global gpsd
gpsd = gps(mode=WATCH_ENABLE)
try:
while 1:
# Do stuff
report = gpsd.next()
# Check report class for 'DEVICE' messages from gpsd. If we're expecting messages from multiple devices we should
# inspect the message to determine which device has just become available. But if we're just listening
# to a single device, this may do.
print report
if report['class'] == 'DEVICE':
# Clean up our current connection.
gpsd.close()
# Tell gpsd we're ready to receive messages.
gpsd = gps(mode=WATCH_ENABLE)
# Do more stuff
print "GPSD Data is showing now!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
print datetime.datetime.now()
print 'latitude ' , gpsd.fix.latitude
print 'longitude ' , gpsd.fix.longitude
print 'time utc ' , gpsd.utc,' + ', gpsd.fix.time
print 'altitude (m)' , gpsd.fix.altitude
print 'eps ' , gpsd.fix.eps
print 'epx ' , gpsd.fix.epx
print 'epv ' , gpsd.fix.epv
print 'ept ' , gpsd.fix.ept
print 'speed (m/s) ' , gpsd.fix.speed
print 'climb ' , gpsd.fix.climb
print 'track ' , gpsd.fix.track
print 'mode ' , gpsd.fix.mode
print
print 'sats ' , gpsd.satellites
time.sleep(1)
except StopIteration:
print "GPSD has terminated"
return