pyModeS/tests/sample_run_commb.py

92 lines
2.1 KiB
Python
Raw Normal View History

2018-05-17 16:34:14 +08:00
from pyModeS import commb, common, bds
2017-07-27 19:41:21 +08:00
# === Decode sample data file ===
2019-09-11 05:25:21 +08:00
2017-07-27 19:41:21 +08:00
def bds_info(BDS, m):
if BDS == "BDS10":
2018-05-17 16:34:14 +08:00
info = [commb.ovc10(m)]
elif BDS == "BDS17":
2019-09-11 05:25:21 +08:00
info = [i[-2:] for i in commb.cap17(m)]
2017-07-27 19:41:21 +08:00
elif BDS == "BDS20":
2018-05-17 16:34:14 +08:00
info = [commb.cs20(m)]
2017-07-27 19:41:21 +08:00
elif BDS == "BDS40":
info = (commb.selalt40mcp(m), commb.selalt40fms(m), commb.p40baro(m))
2017-07-27 19:41:21 +08:00
elif BDS == "BDS44":
2018-05-17 16:34:14 +08:00
info = (commb.wind44(m), commb.temp44(m), commb.p44(m), commb.hum44(m))
2017-07-27 19:41:21 +08:00
elif BDS == "BDS44REV":
2019-09-11 05:25:21 +08:00
info = (
commb.wind44(m, rev=True),
commb.temp44(m, rev=True),
commb.p44(m, rev=True),
commb.hum44(m, rev=True),
)
2017-07-27 19:41:21 +08:00
elif BDS == "BDS50":
2019-09-11 05:25:21 +08:00
info = (
commb.roll50(m),
commb.trk50(m),
commb.gs50(m),
commb.rtrk50(m),
commb.tas50(m),
)
2017-07-27 19:41:21 +08:00
elif BDS == "BDS60":
2019-09-11 05:25:21 +08:00
info = (
commb.hdg60(m),
commb.ias60(m),
commb.mach60(m),
commb.vr60baro(m),
commb.vr60ins(m),
)
2017-07-27 19:41:21 +08:00
else:
info = None
return info
2018-05-17 16:34:14 +08:00
def commb_decode_all(df, n=None):
2017-07-27 19:41:21 +08:00
import csv
2018-05-17 16:34:14 +08:00
print("===== Decode Comm-B sample data (DF=%s)=====" % df)
2017-07-27 19:41:21 +08:00
2019-09-11 05:25:21 +08:00
f = open("tests/data/sample_data_commb_df%s.csv" % df, "rt")
2017-07-27 19:41:21 +08:00
for i, r in enumerate(csv.reader(f)):
if n and i > n:
break
ts = r[0]
m = r[2]
df = common.df(m)
2018-05-17 16:34:14 +08:00
icao = common.icao(m)
2018-05-17 15:52:50 +08:00
BDS = bds.infer(m)
code = common.altcode(m) if df == 20 else common.idcode(m)
2017-07-27 19:41:21 +08:00
if not BDS:
2019-09-11 05:25:21 +08:00
print(ts, m, icao, df, "%5s" % code, "UNKNOWN")
2017-07-27 19:41:21 +08:00
continue
if len(BDS.split(",")) > 1:
2019-09-11 05:25:21 +08:00
print(ts, m, icao, df, "%5s" % code, end=" ")
2018-05-17 15:52:50 +08:00
for i, _bds in enumerate(BDS.split(",")):
2017-07-27 19:41:21 +08:00
if i == 0:
2018-05-17 15:52:50 +08:00
print(_bds, *bds_info(_bds, m))
2017-07-27 19:41:21 +08:00
else:
2019-09-11 05:25:21 +08:00
print(" " * 55, _bds, *bds_info(_bds, m))
2017-07-27 19:41:21 +08:00
else:
2019-09-11 05:25:21 +08:00
print(ts, m, icao, df, "%5s" % code, BDS, *bds_info(BDS, m))
2017-07-27 19:41:21 +08:00
2018-05-17 16:34:14 +08:00
2019-09-11 05:25:21 +08:00
if __name__ == "__main__":
2018-05-17 16:34:14 +08:00
commb_decode_all(df=20, n=100)
commb_decode_all(df=21, n=100)