claws / adsb

ADS-B tools for Python
MIT License
12 stars 3 forks source link

microsecond error #3

Open Teddyz opened 4 years ago

Teddyz commented 4 years ago

I got a the problem that python complains about missing microseconds. I think this happens if a packet arrives at a whole second. Great if you can tell me how to fix or hide this.

While learning how asyncio works, I see in the documentation that many parts are depreciated from Python v3.8, for example sleep. Probably not a problem in a while.

Thanks!

E:\Download\Programmering\Python\adsb>sbs-session.py
icao24=42425B, last_seen=2020-06-18 23:05:21.907000+00:00, msgs=6948, history=50, lat=57.90756, lon=11.52244, alt=37000, ground_speed=470, track=56, vertical_rate=0, callsign=NWS9460
Exception in callback _ProactorReadPipeTransport._loop_reading(<_OverlappedF...,0,,,,,0\r\n'>)
handle: <Handle _ProactorReadPipeTransport._loop_reading(<_OverlappedF...,0,,,,,0\r\n'>)>
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Program Files (x86)\Python38-32\lib\asyncio\proactor_events.py", line 318, in _loop_reading
    self._data_received(data)
  File "C:\Program Files (x86)\Python38-32\lib\asyncio\proactor_events.py", line 269, in _data_received
    self._protocol.data_received(data)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\adsb\sbs\protocol.py", line 86, in data_received
    self.on_message_received(bytes(msg))
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\adsb\sbs\client.py", line 150, in _on_sbs_message
    self._on_raw_message_received(msg_data)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\adsb\sbs\session.py", line 212, in on_sbs_message
    msg = message.fromString(msg_str)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\adsb\sbs\message.py", line 198, in fromString
    v = datetime.time(hour=int(H),
ValueError: microsecond must be in 0..999999
icao24=42425B, last_seen=2020-06-18 23:05:53.368000+00:00, msgs=7408, history=50, lat=57.94469, lon=11.62965, alt=37000, ground_speed=470, track=57, vertical_rate=0, callsign=NWS9460
KeyboardInterrupt
Task was destroyed but it is pending!
task: <Task pending name='Task-3' coro=<session_aircraft_dumper_task() running at E:\Download\Programmering\Python\adsb\sbs-session.py:62> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at
 0x01197838>()]>>

E:\Download\Programmering\Python\adsb>

Line numbers might not be exactly as in origninal code because I added a few print()-rows

Teddyz commented 4 years ago

I misunderstood the depreciated thing:

Deprecated since version 3.8, will be removed in version 3.10: The loop parameter.

Teddyz commented 4 years ago

I found that I had to change line 198 in message.py from microsecond = int(int(F) * 1e3) to microsecond = int(int(F[:3]) * 1e3) because sometimes Windows manages to include a fourth decimal.

claws commented 4 years ago

Do you have a copy of the raw SBS message that caused this issue?

Teddyz commented 4 years ago

I think it would get stuck on the third line of this example:

MSG,5,111,11111,394A04,111111,2020/07/13,03:39:15.860,2020/07/13,03:39:15.876,,38000,,,,,,,0,,0,0
MSG,5,111,11111,394A04,111111,2020/07/13,03:39:15.964,2020/07/13,03:39:15.974,,38000,,,,,,,0,,0,0
MSG,6,111,11111,394A04,111111,2020/07/13,03:39:15.3405,2020/07/13,03:39:15.993,,,,,,,,3511,0,0,0,0
MSG,5,111,11111,394A04,111111,2020/07/13,03:39:16.097,2020/07/13,03:39:16.104,,38000,,,,,,,0,,0,0
MSG,4,111,11111,394A04,111111,2020/07/13,03:39:16.146,2020/07/13,03:39:16.164,,,479,221,,,-64,,,,,0
MSG,5,111,11111,394A04,111111,2020/07/13,03:39:16.176,2020/07/13,03:39:16.184,AFR267  ,38000,,,,,,,0,,0,0
MSG,3,111,11111,394A04,111111,2020/07/13,03:39:16.329,2020/07/13,03:39:16.349,,38000,,,57.62976,12.77232,,,,,,0
MSG,8,111,11111,394A04,111111,2020/07/13,03:39:16.330,2020/07/13,03:39:16.350,,,,,,,,,,,,0
MSG,5,111,11111,394A04,111111,2020/07/13,03:39:16.498,2020/07/13,03:39:16.503,,38000,,,,,,,0,,0,0
MSG,5,111,11111,394A04,111111,2020/07/13,03:39:16.500,2020/07/13,03:39:16.503,,38000,,,,,,,0,,0,0
claws commented 4 years ago

Hmm, I'm not sure I've ever encountered that in my testing. I'm running on a Raspberry Pi. Something like microsecond = int(F.ljust(6, '0')) is probably better so as to retain the value without truncation.

Teddyz commented 4 years ago

I will test if that works. Doing it right now, but no planes in the air at the moment. Can be because it is 4 am.

My receiver is a SDR Play. They have a modified version of dump1090 that works with this radio. I am running it on Windows.