0

Python を使用して GPSD ポーリングを実装しています: ここの Python の例に従ってください: http://www.catb.org/gpsd/client-howto.html#_python_examples

ここでコードを使用できない理由があります: https://gist.github.com/wolfg1969/4653340 システムで約 10 個のプロセスをデーモン化する必要があるため、簡単に実装するには catb を使用します。

次のコードについて質問があります。なぜ 2 サイクル後に停止するのですか? どうすればこれを修正できますか?ありがとう。

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

質問のため、GPS の位置要件が低いまたは遅い場合に、gpsd から JSON データをスレッド化する方法に興味がありました。

クライアントが gpsd と通信するソケットがいっぱいになったり、読み取られたりダンプされたりしない場合、gpsd はそのソケットを閉じます。

1 秒間に 4800 ボーで多くのことが起こると言われています。デーモンが約 8 ~ 15 秒で、または でタイムアウトになるたびに、バッファがいっぱいになるのをあきらめるのは当然のことです。

Python 2-3 gpsdクライアント用のスレッド shim を作成しました

それとpython clientは、メカニズムをインポートし、他に何もしない場合は遅くするためにスリープする必要があります。

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 に答える