首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python - GPSD在非线程池中的使用

Python - GPSD在非线程池中的使用
EN

Stack Overflow用户
提问于 2016-05-22 19:22:11
回答 1查看 846关注 0票数 0

我正在使用python实现一个GPSD轮询:遵循这里的python示例:http://www.catb.org/gpsd/client-howto.html#_python_examples

我不能使用这里的代码是有原因的:https://gist.github.com/wolfg1969/4653340,因为我必须在我的系统中对大约10个进程进行守护进程,所以为了便于实现,我会使用catb进程。

我有一个关于以下代码的问题,为什么它在两个周期后停止?我该怎么解决这个问题呢?谢谢。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2016-05-26 17:07:18

由于这个问题,我很好奇如何处理gpsd中的JSON数据,以满足较低或较慢的gps定位要求。

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

我听说在4800波特的时候一秒内会发生很多事情。毫不奇怪,守护进程在大约8到15秒内放弃了一个完整的缓冲区,或者每当它超时的时候。

我写了a threading shim for a Python 2-3 gpsd client

这和the python client,需要导入机制和睡眠来减慢它,如果没有其他东西。

代码语言:javascript
复制
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代码不工作的原因,它在哪里中断或停止,以及错误消息是什么?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37373671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档