2017-03-23 23:10:22 +08:00
|
|
|
from pyModeS import adsb, ehs, util
|
2016-10-05 23:37:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
# === Decode sample data file ===
|
|
|
|
|
|
|
|
def adsb_decode_all(n=None):
|
|
|
|
print("===== Decode all ADS-B sample data=====")
|
|
|
|
import csv
|
|
|
|
f = open('tests/sample_data_adsb.csv', 'rt')
|
|
|
|
|
|
|
|
msg0 = None
|
|
|
|
msg1 = None
|
|
|
|
|
|
|
|
for i, r in enumerate(csv.reader(f)):
|
|
|
|
if n and i > n:
|
|
|
|
break
|
|
|
|
|
|
|
|
ts = r[0]
|
|
|
|
m = r[1]
|
|
|
|
icao = adsb.icao(m)
|
|
|
|
tc = adsb.typecode(m)
|
|
|
|
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
|
|
|
|
|
|
|
|
if msg0 and msg1:
|
|
|
|
pos = adsb.position(msg0, msg1, t0, t1)
|
|
|
|
alt = adsb.altitude(m)
|
|
|
|
print(ts, m, icao, tc, pos, alt)
|
|
|
|
|
|
|
|
|
|
|
|
def ehs_decode_all(n=None):
|
|
|
|
print("===== Decode all Mode-S EHS sample data=====")
|
|
|
|
import csv
|
|
|
|
f = open('tests/sample_data_ehs.csv', 'rt')
|
|
|
|
for i, r in enumerate(csv.reader(f)):
|
|
|
|
if n and i > n:
|
|
|
|
break
|
|
|
|
|
|
|
|
ts = r[1]
|
|
|
|
m = r[2]
|
|
|
|
icao = ehs.icao(m)
|
|
|
|
vBDS = ehs.BDS(m)
|
|
|
|
|
|
|
|
if vBDS:
|
2017-03-23 04:06:51 +08:00
|
|
|
if isinstance(vBDS, list):
|
|
|
|
print(ts, m, icao, vBDS)
|
2016-10-05 23:37:50 +08:00
|
|
|
if vBDS == "BDS20":
|
|
|
|
print(ts, m, icao, vBDS, ehs.callsign(m))
|
|
|
|
|
|
|
|
if vBDS == "BDS40":
|
2017-03-23 04:06:51 +08:00
|
|
|
print(ts, m, icao, vBDS, ehs.alt40mcp(m),
|
|
|
|
ehs.alt40fms(m), ehs.p40baro(m))
|
2016-10-05 23:37:50 +08:00
|
|
|
|
|
|
|
if vBDS == "BDS44":
|
2017-03-23 04:06:51 +08:00
|
|
|
print(ts, m, icao, vBDS, ehs.wind44(m),
|
|
|
|
ehs.temp44(m), ehs.p44(m))
|
2016-10-05 23:37:50 +08:00
|
|
|
|
|
|
|
if vBDS == "BDS50":
|
2017-03-23 04:06:51 +08:00
|
|
|
print(ts, m, icao, vBDS, ehs.roll50(m), ehs.trk50(m),
|
|
|
|
ehs.gs50(m), ehs.rtrk50(m), ehs.tas50(m))
|
|
|
|
|
|
|
|
if vBDS == "BDS53":
|
|
|
|
print(ts, m, icao, vBDS, ehs.hdg53(m), ehs.ias53(m),
|
|
|
|
ehs.mach53(m), ehs.tas53(m), ehs.vr53(m))
|
2016-10-05 23:37:50 +08:00
|
|
|
|
|
|
|
if vBDS == "BDS60":
|
2017-03-23 04:06:51 +08:00
|
|
|
print(ts, m, icao, vBDS, ehs.hdg60(m), ehs.ias60(m),
|
|
|
|
ehs.mach60(m), ehs.vr60baro(m), ehs.vr60ins(m))
|
2016-10-05 23:37:50 +08:00
|
|
|
else:
|
|
|
|
print(ts, m, icao, 'UNKNOWN')
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-03-23 04:06:51 +08:00
|
|
|
# adsb_decode_all(100)
|
2016-10-05 23:37:50 +08:00
|
|
|
ehs_decode_all(100)
|