From 46ffb7923462deb2cc8b33cd0ab7e06d0e4cdb51 Mon Sep 17 00:00:00 2001 From: Junzi Sun Date: Wed, 2 Dec 2020 22:29:42 +0100 Subject: [PATCH] add VDS check in ACAS decoding --- pyModeS/decoder/acas.py | 35 +++++++++++++++++++++++++++++++- pyModeS/decoder/bds/bds61_st2.py | 4 ++-- tests/test_acas.py | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/pyModeS/decoder/acas.py b/pyModeS/decoder/acas.py index 9af8018..47a2dd8 100644 --- a/pyModeS/decoder/acas.py +++ b/pyModeS/decoder/acas.py @@ -3,6 +3,24 @@ Decoding Air-Air Surveillance (ACAS) DF=0/16 """ from pyModeS import common +import warnings + +warnings.simplefilter("always", UserWarning) + + +def isACAS(msg: str) -> bool: + """Check if the message is an ACAS coordination message. + + :param msg: 28 hexdigits string + :return: if VDS is 3,1 + """ + mv = common.hex2bin(common.data(msg)) + + vds = mv[0:8] + if vds == "00110000": + return True + else: + return False def rac(msg: str) -> str: @@ -11,10 +29,14 @@ def rac(msg: str) -> str: :param msg: 28 hexdigits string :return: RACs """ - mv = common.hex2bin(common.data(msg)) + if not isACAS(msg): + warnings.warn("Not an ACAS coordination message.") + return None RAC = [] + mv = common.hex2bin(common.data(msg)) + if mv[22] == "1": RAC.append("do not pass below") @@ -39,6 +61,10 @@ def rat(msg: str) -> bool: :param msg: 28 hexdigits string :return: if RA has been terminated """ + if not isACAS(msg): + warnings.warn("Not an ACAS coordination message.") + return None + mv = common.hex2bin(common.data(msg)) mte = int(mv[26]) return mte @@ -50,6 +76,10 @@ def mte(msg: str) -> bool: :param msg: 28 hexdigits string :return: if there are multiple threats """ + if not isACAS(msg): + warnings.warn("Not an ACAS coordination message.") + return None + mv = common.hex2bin(common.data(msg)) mte = int(mv[27]) return mte @@ -61,6 +91,9 @@ def ara(msg: str) -> str: :param msg: 28 bytes hexadecimal message string :return: RA charactristics """ + if not isACAS(msg): + warnings.warn("Not an ACAS coordination message.") + return None mv = common.hex2bin(common.data(msg)) mte = int(mv[27]) diff --git a/pyModeS/decoder/bds/bds61_st2.py b/pyModeS/decoder/bds/bds61_st2.py index 846de0a..2726873 100644 --- a/pyModeS/decoder/bds/bds61_st2.py +++ b/pyModeS/decoder/bds/bds61_st2.py @@ -60,7 +60,7 @@ def threat_location(msg: str) -> Tuple: def has_multiple_threats(msg: str) -> bool: - """ Indicate if the ACAS is processing multiple threats simultaneously. + """Indicate if the ACAS is processing multiple threats simultaneously. :param msg: 28 hexdigits string :return: if there are multiple threats @@ -76,7 +76,7 @@ def active_resolution_advisories(msg: str) -> str: :param msg: 28 bytes hexadecimal message string :return: RA charactristics """ - return acars.ara(msg) + return acas.ara(msg) def is_ra_terminated(msg: str) -> bool: diff --git a/tests/test_acas.py b/tests/test_acas.py index 90cb12f..963e258 100644 --- a/tests/test_acas.py +++ b/tests/test_acas.py @@ -25,7 +25,7 @@ msgs = [ "8526D57E4D963C92CDEE1B6C7C49", "802A613C93F65A7FF803A51B5ADB", "85B6C54279B67BE2A0001998FFDA", - "851944F15881648338D1AF4B7A27", + "851944F1 5881648338D1AF 4B7A27", "8321014858208000787905B0E800", "866DD078EDEBD330404FFFAE9BA5", "80E196905AB503260E835D849E35",