pyModeS/tests/sample_run_adsb.py

43 lines
868 B
Python
Raw Permalink Normal View History

import csv
2022-11-01 15:32:42 +08:00
import time
2017-07-27 19:41:21 +08:00
2022-11-01 15:32:42 +08:00
from pyModeS.decoder import adsb
2017-07-27 19:41:21 +08:00
print("===== Decode ADS-B sample data=====")
2017-07-27 19:41:21 +08:00
f = open("tests/data/sample_data_adsb.csv", "rt")
2019-09-11 05:25:21 +08:00
msg0 = None
msg1 = None
2019-09-11 05:25:21 +08:00
tstart = time.time()
for i, r in enumerate(csv.reader(f)):
2017-07-27 19:41:21 +08:00
ts = int(r[0])
m = r[1].encode()
2017-07-27 19:41:21 +08:00
icao = adsb.icao(m)
tc = adsb.typecode(m)
2017-07-27 19:41:21 +08:00
if 1 <= tc <= 4:
print(ts, m, icao, tc, adsb.category(m), adsb.callsign(m))
if tc == 19:
print(ts, m, icao, tc, adsb.velocity(m))
if 5 <= tc <= 18:
if adsb.oe_flag(m):
msg1 = m
t1 = ts
else:
msg0 = m
t0 = ts
2017-07-27 19:41:21 +08:00
if msg0 and msg1:
pos = adsb.position(msg0, msg1, t0, t1)
alt = adsb.altitude(m)
print(ts, m, icao, tc, pos, alt)
2017-07-27 19:41:21 +08:00
2019-09-11 05:25:21 +08:00
dt = time.time() - tstart
print("Execution time: {} seconds".format(dt))