diff --git a/pyModeS/decoder/adsb.py b/pyModeS/decoder/adsb.py index e509fce..dacce31 100644 --- a/pyModeS/decoder/adsb.py +++ b/pyModeS/decoder/adsb.py @@ -166,23 +166,47 @@ def speed_heading(msg): return spd, trk_or_hdg -def nic(msg): - """Calculate NIC, navigation integrity category +def oe_flag(msg): + """Check the odd/even flag. Bit 54, 0 for even, 1 for odd. + Args: + msg (string): 28 bytes hexadecimal message string + Returns: + int: 0 or 1, for even or odd frame + """ + msgbin = common.hex2bin(msg) + return int(msgbin[53]) + +# Uncertainty & accuracy +def nic(msg, *argv): + if len(argv) == 1: + # assume ads-b v1, only one supplement bit + return nic_v1(msg, *argv) + elif len(argv) == 3: + # assume ads-b v2, three supplement bits + return nic_v2(msg, *argv) + + +def nic_v1(msg, nic_sup_b): + """Calculate NIC, navigation integrity category for ADS-B version 1 Args: msg (string): 28 bytes hexadecimal message string + nic_sup_b (int or string): NIC supplement Returns: int: NIC number (from 0 to 11), -1 if not applicable """ - if typecode(msg) < 9 or typecode(msg) > 18: - raise RuntimeError("%s: Not a airborne position message, expecting 8 22: + raise RuntimeError("%s: Not a surface position message (5 22: + raise RuntimeError("%s: Not a surface position message (5 18: + raise RuntimeError("%s: Not a airborne position message, expecting 8