0

我正在使用 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
4

1 回答 1

1

由于这个问题,我很好奇如何从 gpsd 线程化 JSON 数据以满足低或慢 gps 位置要求。

如果客户端与 gpsd 通信的套接字已填满、未被读取或转储,则 gpsd 将关闭该套接字。

有人告诉我,一秒钟内 4800 波特会发生很多事情。守护进程在大约 8 到 15 秒内或在超时时放弃一个完整的缓冲区也就不足为奇了。

我为 Python 2-3 gpsd 客户端编写了一个线程填充程序

那和python 客户端,需要导入机制和睡眠来减慢它,如果没有其他方法的话。

from time import sleep
from agps3threaded import AGPS3mechanism

agps_thread = AGPS3mechanism()  # Instantiate AGPS3 Mechanisms
agps_thread.stream_data(host='192.168.0.4')  # From localhost (), or other hosts, by example, (host='gps.ddns.net')
agps_thread.run_thread(usnap=.2)  # Throttle the time to sleep after an empty lookup, default 0.2 two tenths of a second

while True:  # All data is available via instantiated thread data stream attribute.
# line #140-ff of /usr/local/lib/python3.5/dist-packages/gps3/agps.py
    print('-----')
    print(agps_thread.data_stream.time)
    print('Lat:{}'.format(agps_thread.data_stream.lat))
    print('Lon:{}'.format(agps_thread.data_stream.lon))
    print('Speed:{}'.format(agps_thread.data_stream.speed))
    print('Course:{}'.format(agps_thread.data_stream.track))
    print('-----')
    sleep(30)

这将解决您的线程 gpsd 数据问题。

如果您想知道为什么 about 代码不起作用,它在哪里中断或停止,以及错误消息是什么?

于 2016-05-26T09:07:17.967 回答