gpt4 book ai didi

python - gpsd python 客户端

转载 作者:太空宇宙 更新时间:2023-11-04 01:42:44 29 4
gpt4 key购买 nike

我正在尝试为 Gpsd 编写一个非常简单的 python 客户端,但是我有执行脚本一段时间后出现此错误:

Traceback (most recent call last):
File "gps_cap.py", line 13, in <module>
g.stream()
File "/usr/lib/python2.6/site-packages/gps/gps.py", line 348, in stream
gpsjson.stream(self, flags)
File "/usr/lib/python2.6/site-packages/gps/client.py", line 176, in stream
return self.send(arg + "}")
File "/usr/lib/python2.6/site-packages/gps/client.py", line 111, in send
self.sock.send(commands)
socket.error: [Errno 104] Connection reset by peer

这是我的 python 代码:

import os
from gps import *
from time import *

g = gps(mode=WATCH_ENABLE)
while 1:
os.system('clear')
g.poll()
if PACKET_SET:
g.stream()

print
print ' GPS reading'
print '----------------------------------------'
print 'latitude ' , g.fix.latitude
print 'longitude ' , g.fix.longitude
print 'time utc ' , g.utc,' + ', g.fix.time
print 'altitude ' , g.fix.altitude
print 'epc ' , g.fix.epc
print 'epd ' , g.fix.epd
print 'eps ' , g.fix.eps
print 'epx ' , g.fix.epx
print 'epv ' , g.fix.epv
print 'ept ' , g.fix.ept
print 'speed ' , g.fix.speed
print 'climb ' , g.fix.climb
print 'track ' , g.fix.track
print 'mode ' , g.fix.mode
print
print 'sats ' , g.satellites

sleep(1)

也许有人可以帮助解决这个问题?我在 ArchLinux 机器上运行 Gpsd 2.95。

谢谢!

最佳答案

我知道这个问题已经很老了,但我还是把我的答案放在这里,以防将来有人需要它:

#! /usr/bin/python
# Written by Dan Mandle http://dan.mandle.me September 2012
# License: GPL 2.0
import os
from gps import *
from time import *
import time
import threading

gpsd = None #seting the global variable

os.system('clear') #clear the terminal (optional)

class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd #bring it in scope
gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
self.current_value = None
self.running = True #setting the thread running to true

def run(self):
global gpsd
while gpsp.running:
gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer

if __name__ == '__main__':
gpsp = GpsPoller() # create the thread
try:
gpsp.start() # start it up
while True:
#It may take a second or two to get good data
#print gpsd.fix.latitude,', ',gpsd.fix.longitude,' Time: ',gpsd.utc

os.system('clear')

print
print ' GPS reading'
print '----------------------------------------'
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(5) #set to whatever

except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
print "\nKilling Thread..."
gpsp.running = False
gpsp.join() # wait for the thread to finish what it's doing
print "Done.\nExiting."

此代码与线程一起工作,并将向屏幕提供良好的 gpsd 数据输出。它可以用 Ctrl + C 终止。

所有学分转到http://www.danmandle.com/blog/getting-gpsd-to-work-with-python/

关于python - gpsd python 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3295065/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com