reformat code with Black
This commit is contained in:
@@ -4,10 +4,12 @@ from pyModeS import adsb, ehs
|
||||
|
||||
# === Decode sample data file ===
|
||||
|
||||
|
||||
def adsb_decode_all(n=None):
|
||||
print("===== Decode ADS-B sample data=====")
|
||||
import csv
|
||||
f = open('tests/data/sample_data_adsb.csv', 'rt')
|
||||
|
||||
f = open("tests/data/sample_data_adsb.csv", "rt")
|
||||
|
||||
msg0 = None
|
||||
msg1 = None
|
||||
@@ -37,5 +39,6 @@ def adsb_decode_all(n=None):
|
||||
alt = adsb.altitude(m)
|
||||
print(ts, m, icao, tc, pos, alt)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
adsb_decode_all(n=100)
|
||||
|
||||
@@ -3,12 +3,13 @@ from pyModeS import commb, common, bds
|
||||
|
||||
# === Decode sample data file ===
|
||||
|
||||
|
||||
def bds_info(BDS, m):
|
||||
if BDS == "BDS10":
|
||||
info = [commb.ovc10(m)]
|
||||
|
||||
elif BDS == "BDS17":
|
||||
info = ([i[-2:] for i in commb.cap17(m)])
|
||||
info = [i[-2:] for i in commb.cap17(m)]
|
||||
|
||||
elif BDS == "BDS20":
|
||||
info = [commb.cs20(m)]
|
||||
@@ -20,13 +21,30 @@ def bds_info(BDS, m):
|
||||
info = (commb.wind44(m), commb.temp44(m), commb.p44(m), commb.hum44(m))
|
||||
|
||||
elif BDS == "BDS44REV":
|
||||
info = (commb.wind44(m, rev=True), commb.temp44(m, rev=True), commb.p44(m, rev=True), commb.hum44(m, rev=True))
|
||||
info = (
|
||||
commb.wind44(m, rev=True),
|
||||
commb.temp44(m, rev=True),
|
||||
commb.p44(m, rev=True),
|
||||
commb.hum44(m, rev=True),
|
||||
)
|
||||
|
||||
elif BDS == "BDS50":
|
||||
info = (commb.roll50(m), commb.trk50(m), commb.gs50(m), commb.rtrk50(m), commb.tas50(m))
|
||||
info = (
|
||||
commb.roll50(m),
|
||||
commb.trk50(m),
|
||||
commb.gs50(m),
|
||||
commb.rtrk50(m),
|
||||
commb.tas50(m),
|
||||
)
|
||||
|
||||
elif BDS == "BDS60":
|
||||
info = (commb.hdg60(m), commb.ias60(m), commb.mach60(m), commb.vr60baro(m), commb.vr60ins(m))
|
||||
info = (
|
||||
commb.hdg60(m),
|
||||
commb.ias60(m),
|
||||
commb.mach60(m),
|
||||
commb.vr60baro(m),
|
||||
commb.vr60ins(m),
|
||||
)
|
||||
|
||||
else:
|
||||
info = None
|
||||
@@ -39,8 +57,7 @@ def commb_decode_all(df, n=None):
|
||||
|
||||
print("===== Decode Comm-B sample data (DF=%s)=====" % df)
|
||||
|
||||
f = open('tests/data/sample_data_commb_df%s.csv' % df, 'rt')
|
||||
|
||||
f = open("tests/data/sample_data_commb_df%s.csv" % df, "rt")
|
||||
|
||||
for i, r in enumerate(csv.reader(f)):
|
||||
if n and i > n:
|
||||
@@ -55,21 +72,21 @@ def commb_decode_all(df, n=None):
|
||||
code = common.altcode(m) if df == 20 else common.idcode(m)
|
||||
|
||||
if not BDS:
|
||||
print(ts, m, icao, df, '%5s'%code, 'UNKNOWN')
|
||||
print(ts, m, icao, df, "%5s" % code, "UNKNOWN")
|
||||
continue
|
||||
|
||||
if len(BDS.split(",")) > 1:
|
||||
print(ts, m, icao, df, '%5s' % code, end=' ')
|
||||
print(ts, m, icao, df, "%5s" % code, end=" ")
|
||||
for i, _bds in enumerate(BDS.split(",")):
|
||||
if i == 0:
|
||||
print(_bds, *bds_info(_bds, m))
|
||||
else:
|
||||
print(' ' * 55, _bds, *bds_info(_bds, m))
|
||||
print(" " * 55, _bds, *bds_info(_bds, m))
|
||||
|
||||
else:
|
||||
print(ts, m, icao, df, '%5s'%code, BDS, *bds_info(BDS, m))
|
||||
print(ts, m, icao, df, "%5s" % code, BDS, *bds_info(BDS, m))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
commb_decode_all(df=20, n=100)
|
||||
commb_decode_all(df=21, n=100)
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
from pyModeS import bds
|
||||
|
||||
def test_bds_infer():
|
||||
assert bds.infer("8D406B902015A678D4D220AA4BDA") == 'BDS08'
|
||||
assert bds.infer("8FC8200A3AB8F5F893096B000000") == 'BDS06'
|
||||
assert bds.infer("8D40058B58C901375147EFD09357") == 'BDS05'
|
||||
assert bds.infer("8D485020994409940838175B284F") == 'BDS09'
|
||||
|
||||
assert bds.infer("A800178D10010080F50000D5893C") == 'BDS10'
|
||||
assert bds.infer("A0000638FA81C10000000081A92F") == 'BDS17'
|
||||
assert bds.infer("A0001838201584F23468207CDFA5") == 'BDS20'
|
||||
assert bds.infer("A0001839CA3800315800007448D9") == 'BDS40'
|
||||
assert bds.infer("A000139381951536E024D4CCF6B5") == 'BDS50'
|
||||
assert bds.infer("A00004128F39F91A7E27C46ADC21") == 'BDS60'
|
||||
def test_bds_infer():
|
||||
assert bds.infer("8D406B902015A678D4D220AA4BDA") == "BDS08"
|
||||
assert bds.infer("8FC8200A3AB8F5F893096B000000") == "BDS06"
|
||||
assert bds.infer("8D40058B58C901375147EFD09357") == "BDS05"
|
||||
assert bds.infer("8D485020994409940838175B284F") == "BDS09"
|
||||
|
||||
assert bds.infer("A800178D10010080F50000D5893C") == "BDS10"
|
||||
assert bds.infer("A0000638FA81C10000000081A92F") == "BDS17"
|
||||
assert bds.infer("A0001838201584F23468207CDFA5") == "BDS20"
|
||||
assert bds.infer("A0001839CA3800315800007448D9") == "BDS40"
|
||||
assert bds.infer("A000139381951536E024D4CCF6B5") == "BDS50"
|
||||
assert bds.infer("A00004128F39F91A7E27C46ADC21") == "BDS60"
|
||||
|
||||
|
||||
def test_bds_is50or60():
|
||||
assert bds.is50or60("A0001838201584F23468207CDFA5", 0, 0, 0) == None
|
||||
assert bds.is50or60("A0000000FFDA9517000464000000", 182, 237, 1250) == 'BDS50'
|
||||
assert bds.is50or60("A0000000919A5927E23444000000", 413, 54, 18700) == 'BDS60'
|
||||
assert bds.is50or60("A0000000FFDA9517000464000000", 182, 237, 1250) == "BDS50"
|
||||
assert bds.is50or60("A0000000919A5927E23444000000", 413, 54, 18700) == "BDS60"
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
from pyModeS import bds, commb
|
||||
|
||||
# from pyModeS import ehs, els # deprecated
|
||||
|
||||
def test_bds20_callsign():
|
||||
assert bds.bds20.cs20("A000083E202CC371C31DE0AA1CCF") == 'KLM1017_'
|
||||
assert bds.bds20.cs20("A0001993202422F2E37CE038738E") == 'IBK2873_'
|
||||
|
||||
assert commb.cs20("A000083E202CC371C31DE0AA1CCF") == 'KLM1017_'
|
||||
assert commb.cs20("A0001993202422F2E37CE038738E") == 'IBK2873_'
|
||||
def test_bds20_callsign():
|
||||
assert bds.bds20.cs20("A000083E202CC371C31DE0AA1CCF") == "KLM1017_"
|
||||
assert bds.bds20.cs20("A0001993202422F2E37CE038738E") == "IBK2873_"
|
||||
|
||||
assert commb.cs20("A000083E202CC371C31DE0AA1CCF") == "KLM1017_"
|
||||
assert commb.cs20("A0001993202422F2E37CE038738E") == "IBK2873_"
|
||||
|
||||
|
||||
def test_bds40_functions():
|
||||
@@ -21,14 +23,14 @@ def test_bds40_functions():
|
||||
|
||||
def test_bds50_functions():
|
||||
assert bds.bds50.roll50("A000139381951536E024D4CCF6B5") == 2.1
|
||||
assert bds.bds50.roll50("A0001691FFD263377FFCE02B2BF9") == -0.4 # signed value
|
||||
assert bds.bds50.roll50("A0001691FFD263377FFCE02B2BF9") == -0.4 # signed value
|
||||
assert bds.bds50.trk50("A000139381951536E024D4CCF6B5") == 114.258
|
||||
assert bds.bds50.gs50("A000139381951536E024D4CCF6B5") == 438
|
||||
assert bds.bds50.rtrk50("A000139381951536E024D4CCF6B5") == 0.125
|
||||
assert bds.bds50.tas50("A000139381951536E024D4CCF6B5") == 424
|
||||
|
||||
assert commb.roll50("A000139381951536E024D4CCF6B5") == 2.1
|
||||
assert commb.roll50("A0001691FFD263377FFCE02B2BF9") == -0.4 # signed value
|
||||
assert commb.roll50("A0001691FFD263377FFCE02B2BF9") == -0.4 # signed value
|
||||
assert commb.trk50("A000139381951536E024D4CCF6B5") == 114.258
|
||||
assert commb.gs50("A000139381951536E024D4CCF6B5") == 438
|
||||
assert commb.rtrk50("A000139381951536E024D4CCF6B5") == 0.125
|
||||
|
||||
@@ -2,57 +2,63 @@ from pyModeS import common
|
||||
|
||||
|
||||
def test_conversions():
|
||||
assert common.hex2bin('6E406B') == "011011100100000001101011"
|
||||
assert common.bin2hex('011011100100000001101011') == "6E406B"
|
||||
assert common.hex2bin("6E406B") == "011011100100000001101011"
|
||||
assert common.bin2hex("011011100100000001101011") == "6E406B"
|
||||
assert common.int2hex(11160538) == "AA4BDA"
|
||||
|
||||
|
||||
def test_crc_decode():
|
||||
assert common.crc_legacy("8D406B902015A678D4D220AA4BDA") == 0
|
||||
|
||||
assert common.crc("8D406B902015A678D4D220AA4BDA") == 0
|
||||
assert common.crc('8d8960ed58bf053cf11bc5932b7d') == 0
|
||||
assert common.crc('8d45cab390c39509496ca9a32912') == 0
|
||||
assert common.crc('8d49d3d4e1089d00000000744c3b') == 0
|
||||
assert common.crc('8d74802958c904e6ef4ba0184d5c') == 0
|
||||
assert common.crc('8d4400cd9b0000b4f87000e71a10') == 0
|
||||
assert common.crc('8d4065de58a1054a7ef0218e226a') == 0
|
||||
assert common.crc("8d8960ed58bf053cf11bc5932b7d") == 0
|
||||
assert common.crc("8d45cab390c39509496ca9a32912") == 0
|
||||
assert common.crc("8d49d3d4e1089d00000000744c3b") == 0
|
||||
assert common.crc("8d74802958c904e6ef4ba0184d5c") == 0
|
||||
assert common.crc("8d4400cd9b0000b4f87000e71a10") == 0
|
||||
assert common.crc("8d4065de58a1054a7ef0218e226a") == 0
|
||||
|
||||
assert common.crc("c80b2dca34aa21dd821a04cb64d4") == 10719924
|
||||
assert common.crc("a800089d8094e33a6004e4b8a522") == 4805588
|
||||
assert common.crc("a8000614a50b6d32bed000bbe0ed") == 5659991
|
||||
assert common.crc("a0000410bc900010a40000f5f477") == 11727682
|
||||
assert common.crc("8d4ca251204994b1c36e60a5343d") == 16
|
||||
assert common.crc("b0001718c65632b0a82040715b65") == 353333
|
||||
|
||||
assert common.crc('c80b2dca34aa21dd821a04cb64d4') == 10719924
|
||||
assert common.crc('a800089d8094e33a6004e4b8a522') == 4805588
|
||||
assert common.crc('a8000614a50b6d32bed000bbe0ed') == 5659991
|
||||
assert common.crc('a0000410bc900010a40000f5f477') == 11727682
|
||||
assert common.crc('8d4ca251204994b1c36e60a5343d') == 16
|
||||
assert common.crc('b0001718c65632b0a82040715b65') == 353333
|
||||
|
||||
def test_crc_encode():
|
||||
parity = common.crc("8D406B902015A678D4D220AA4BDA", encode=True)
|
||||
assert common.int2hex(parity) == "AA4BDA"
|
||||
|
||||
|
||||
def test_icao():
|
||||
assert common.icao("8D406B902015A678D4D220AA4BDA") == "406B90"
|
||||
assert common.icao("A0001839CA3800315800007448D9") == '400940'
|
||||
assert common.icao("A000139381951536E024D4CCF6B5") == '3C4DD2'
|
||||
assert common.icao("A000029CFFBAA11E2004727281F1") == '4243D0'
|
||||
assert common.icao("A0001839CA3800315800007448D9") == "400940"
|
||||
assert common.icao("A000139381951536E024D4CCF6B5") == "3C4DD2"
|
||||
assert common.icao("A000029CFFBAA11E2004727281F1") == "4243D0"
|
||||
|
||||
|
||||
def test_modes_altcode():
|
||||
assert common.altcode("A02014B400000000000000F9D514") == 32300
|
||||
|
||||
|
||||
def test_modes_idcode():
|
||||
assert common.idcode("A800292DFFBBA9383FFCEB903D01") == '1346'
|
||||
assert common.idcode("A800292DFFBBA9383FFCEB903D01") == "1346"
|
||||
|
||||
|
||||
def test_graycode_to_altitude():
|
||||
assert common.gray2alt('00000000010') == -1000
|
||||
assert common.gray2alt('00000001010') == -500
|
||||
assert common.gray2alt('00000011011') == -100
|
||||
assert common.gray2alt('00000011010') == 0
|
||||
assert common.gray2alt('00000011110') == 100
|
||||
assert common.gray2alt('00000010011') == 600
|
||||
assert common.gray2alt('00000110010') == 1000
|
||||
assert common.gray2alt('00001001001') == 5800
|
||||
assert common.gray2alt('00011100100') == 10300
|
||||
assert common.gray2alt('01100011010') == 32000
|
||||
assert common.gray2alt('01110000100') == 46300
|
||||
assert common.gray2alt('01010101100') == 50200
|
||||
assert common.gray2alt('11011110100') == 73200
|
||||
assert common.gray2alt('10000000011') == 126600
|
||||
assert common.gray2alt('10000000001') == 126700
|
||||
assert common.gray2alt("00000000010") == -1000
|
||||
assert common.gray2alt("00000001010") == -500
|
||||
assert common.gray2alt("00000011011") == -100
|
||||
assert common.gray2alt("00000011010") == 0
|
||||
assert common.gray2alt("00000011110") == 100
|
||||
assert common.gray2alt("00000010011") == 600
|
||||
assert common.gray2alt("00000110010") == 1000
|
||||
assert common.gray2alt("00001001001") == 5800
|
||||
assert common.gray2alt("00011100100") == 10300
|
||||
assert common.gray2alt("01100011010") == 32000
|
||||
assert common.gray2alt("01110000100") == 46300
|
||||
assert common.gray2alt("01010101100") == 50200
|
||||
assert common.gray2alt("11011110100") == 73200
|
||||
assert common.gray2alt("10000000011") == 126600
|
||||
assert common.gray2alt("10000000001") == 126700
|
||||
|
||||
Reference in New Issue
Block a user