From 6f6b50776d48aa4d7a1974a17d87f7e1b15b98d4 Mon Sep 17 00:00:00 2001 From: Junzi Sun Date: Mon, 5 Aug 2019 10:37:17 +0200 Subject: [PATCH] rename functions for seleted altitudes in BDS40 --- README.rst | 4 ++-- pyModeS/decoder/bds/bds40.py | 37 +++++++++++++++++++++++++++--------- tests/sample_run_commb.py | 2 +- tests/test_commb.py | 8 ++++---- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index 2c341dc..0d1fa9b 100644 --- a/README.rst +++ b/README.rst @@ -225,8 +225,8 @@ Mode-S Enhanced Surveillance (EHS) .. code:: python # BDS 4,0 - pms.commb.alt40mcp(msg) # MCP/FCU selected altitude (ft) - pms.commb.alt40fms(msg) # FMS selected altitude (ft) + pms.commb.selalt40mcp(msg) # MCP/FCU selected altitude (ft) + pms.commb.selalt40fms(msg) # FMS selected altitude (ft) pms.commb.p40baro(msg) # Barometric pressure (mb) # BDS 5,0 diff --git a/pyModeS/decoder/bds/bds40.py b/pyModeS/decoder/bds/bds40.py index ef422e1..cf96cbe 100644 --- a/pyModeS/decoder/bds/bds40.py +++ b/pyModeS/decoder/bds/bds40.py @@ -18,10 +18,11 @@ # Selected vertical intention # ------------------------------------------ - from __future__ import absolute_import, print_function, division +import warnings from pyModeS.decoder.common import hex2bin, bin2int, data, allzeros, wrongstatus + def is40(msg): """Check if a message is likely to be BDS code 4,0 @@ -65,7 +66,7 @@ def is40(msg): return True -def alt40mcp(msg): +def selalt40mcp(msg): """Selected altitude, MCP/FCU Args: @@ -76,14 +77,14 @@ def alt40mcp(msg): """ d = hex2bin(data(msg)) - if d[0] == '0': + if d[0] == "0": return None - alt = bin2int(d[1:13]) * 16 # ft + alt = bin2int(d[1:13]) * 16 # ft return alt -def alt40fms(msg): +def selalt40fms(msg): """Selected altitude, FMS Args: @@ -94,10 +95,10 @@ def alt40fms(msg): """ d = hex2bin(data(msg)) - if d[13] == '0': + if d[13] == "0": return None - alt = bin2int(d[14:26]) * 16 # ft + alt = bin2int(d[14:26]) * 16 # ft return alt @@ -112,8 +113,26 @@ def p40baro(msg): """ d = hex2bin(data(msg)) - if d[26] == '0': + if d[26] == "0": return None - p = bin2int(d[27:39]) * 0.1 + 800 # millibar + p = bin2int(d[27:39]) * 0.1 + 800 # millibar return p + + +def alt40mcp(msg): + warnings.simplefilter("once", DeprecationWarning) + warnings.warn( + "alt40mcp() has been renamed to selalt40mcp(). It will be removed in the future.", + DeprecationWarning, + ) + return selalt40mcp(msg) + + +def alt40fms(msg): + warnings.simplefilter("once", DeprecationWarning) + warnings.warn( + "alt40fms() has been renamed to selalt40fms(). It will be removed in the future.", + DeprecationWarning, + ) + return selalt40mcp(msg) diff --git a/tests/sample_run_commb.py b/tests/sample_run_commb.py index 2ef3036..dde33ef 100644 --- a/tests/sample_run_commb.py +++ b/tests/sample_run_commb.py @@ -14,7 +14,7 @@ def bds_info(BDS, m): info = [commb.cs20(m)] elif BDS == "BDS40": - info = (commb.alt40mcp(m), commb.alt40fms(m), commb.p40baro(m)) + info = (commb.selalt40mcp(m), commb.selalt40fms(m), commb.p40baro(m)) elif BDS == "BDS44": info = (commb.wind44(m), commb.temp44(m), commb.p44(m), commb.hum44(m)) diff --git a/tests/test_commb.py b/tests/test_commb.py index 9043765..6c0117e 100644 --- a/tests/test_commb.py +++ b/tests/test_commb.py @@ -10,12 +10,12 @@ def test_bds20_callsign(): def test_bds40_functions(): - assert bds.bds40.alt40mcp("A000029C85E42F313000007047D3") == 3008 - assert bds.bds40.alt40fms("A000029C85E42F313000007047D3") == 3008 + assert bds.bds40.selalt40mcp("A000029C85E42F313000007047D3") == 3008 + assert bds.bds40.selalt40fms("A000029C85E42F313000007047D3") == 3008 assert bds.bds40.p40baro("A000029C85E42F313000007047D3") == 1020.0 - assert commb.alt40mcp("A000029C85E42F313000007047D3") == 3008 - assert commb.alt40fms("A000029C85E42F313000007047D3") == 3008 + assert commb.selalt40mcp("A000029C85E42F313000007047D3") == 3008 + assert commb.selalt40fms("A000029C85E42F313000007047D3") == 3008 assert commb.p40baro("A000029C85E42F313000007047D3") == 1020.0