From 3d0c4f0240820fbcc82ef5aef605d8731045c25a Mon Sep 17 00:00:00 2001 From: tuftedocelot Date: Wed, 20 May 2020 19:56:07 -0500 Subject: [PATCH] Add previously existing work --- pyModeS/decoder/acas.py | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/pyModeS/decoder/acas.py b/pyModeS/decoder/acas.py index 139d1ff..24919fd 100644 --- a/pyModeS/decoder/acas.py +++ b/pyModeS/decoder/acas.py @@ -3,10 +3,60 @@ Decoding Air-Air Surveillance (ACAS) DF=0/16 [To be implemented] """ +from __future__ import absolute_import, print_function, division from pyModeS import common +def threat_type(msg): + """ + Determine the threat type indicator + + ===== ======= + Value Meaning + ===== ======= + 0 No identity data in TID + 1 TID has Mode S address (ICAO) + 2 TID has altitude, range, and bearing + 3 Not assigned + :param msg: + :return: indicator of threat type + """ + mb = common.hex2bin(msg)[32:] + tti = common.bin2int(mb[28:30]) + return tti + + +def threat_identity(msg): + mb = common.hex2bin(msg)[32:] + tti = threat_type(msg) + + # The ICAO of the threat is announced + if tti == 1: + return common.icao(mb[30:55]) + else: + raise RuntimeError("%s: Missing threat identity (ICAO)") + + +def threat_location(msg): + """ + Get the altitude, range, and bearing of the threat + Altitude is the Mode C altitude + :param msg: + :return: tuple of the Mode C altitude, range, and bearing + """ + mb = common.hex2bin(msg)[32:] + tti = threat_type(msg) + + # Altitude, range, and bearing of threat + if tti == 2: + grey = mb[31] + mb[32] + mb[33] + mb[34] + mb[35] + mb[36] + mb[38] + mb[38] + mb[39] + mb[40] + mb[41] + mb[42] + mb[43] + mode_c_alt = common.gray2alt(grey) + _range = common.bin2int(mb[44:51]) + bearing = common.bin2int(mb[51:57]) + return mode_c_alt, _range, bearing + + def has_multiple_threats(msg): """ Indicate if the ACAS is processing zero, one, or more than one threat