diff --git a/pyModeS/decoder/adsb.py b/pyModeS/decoder/adsb.py index d3699ba..bd8daa4 100644 --- a/pyModeS/decoder/adsb.py +++ b/pyModeS/decoder/adsb.py @@ -143,24 +143,36 @@ def altitude(msg): return None -def velocity(msg): +def velocity(msg, rtn_sources=False): """Calculate the speed, heading, and vertical rate (handles both airborne or surface message) Args: msg (string): 28 bytes hexadecimal message string + rtn_source (boolean): If the function will return + the sources for direction of travel and vertical + rate. This will change the return value from a four + element array to a six element array. Returns: - (int, float, int, string): speed (kt), ground track or heading (degree), - rate of climb/descend (ft/min), and speed type - ('GS' for ground speed, 'AS' for airspeed) + (int, float, int, string, string, string): speed (kt), + ground track or heading (degree), + rate of climb/descent (ft/min), speed type + ('GS' for ground speed, 'AS' for airspeed), + direction source ('true_north' for ground track / true north + as refrence, 'mag_north' for magnetic north as reference), + rate of climb/descent source ('Baro' for barometer, 'GNSS' + for GNSS constellation). + + In the case of surface messages, None will be put in place + for vertical rate and its respective sources. """ if 5 <= typecode(msg) <= 8: - return surface_velocity(msg) + return surface_velocity(msg, rtn_sources) elif typecode(msg) == 19: - return airborne_velocity(msg) + return airborne_velocity(msg, rtn_sources) else: raise RuntimeError("incorrect or inconsistant message types, expecting 4 8: @@ -182,4 +188,7 @@ def surface_velocity(msg): spd = kts[i-1] + (mov-movs[i-1]) * step spd = round(spd, 2) - return spd, trk, 0, 'GS' + if rtn_sources: + return spd, trk, 0, 'GS', 'true_north', None + else: + return spd, trk, 0, 'GS' diff --git a/pyModeS/decoder/bds/bds09.py b/pyModeS/decoder/bds/bds09.py index 49ce794..3ccdae6 100644 --- a/pyModeS/decoder/bds/bds09.py +++ b/pyModeS/decoder/bds/bds09.py @@ -25,16 +25,25 @@ from pyModeS.decoder import common import math -def airborne_velocity(msg): +def airborne_velocity(msg, rtn_sources=False): """Calculate the speed, track (or heading), and vertical rate Args: msg (string): 28 bytes hexadecimal message string + rtn_source (boolean): If the function will return + the sources for direction of travel and vertical + rate. This will change the return value from a four + element array to a six element array. Returns: - (int, float, int, string): speed (kt), ground track or heading (degree), - rate of climb/descend (ft/min), and speed type - ('GS' for ground speed, 'AS' for airspeed) + (int, float, int, string, string, string): speed (kt), + ground track or heading (degree), + rate of climb/descent (ft/min), speed type + ('GS' for ground speed, 'AS' for airspeed), + direction source ('true_north' for ground track / true north + as refrence, 'mag_north' for magnetic north as reference), + rate of climb/descent source ('Baro' for barometer, 'GNSS' + for GNSS constellation). """ if common.typecode(msg) != 19: @@ -66,6 +75,7 @@ def airborne_velocity(msg): tag = 'GS' trk_or_hdg = round(trk, 2) + dir_type = 'true_north' else: if mb[13] == '0': @@ -83,12 +93,19 @@ def airborne_velocity(msg): tag = 'IAS' else: tag = 'TAS' + + dir_type = 'mag_north' + vr_source = 'GNSS' if mb[35]=='0' else 'Baro' vr_sign = -1 if mb[36]=='1' else 1 vr = common.bin2int(mb[37:46]) rocd = None if vr==0 else int(vr_sign*(vr-1)*64) - return spd, trk_or_hdg, rocd, tag + if rtn_sources: + return spd, trk_or_hdg, rocd, tag, dir_type, vr_source + else: + return spd, trk_or_hdg, rocd, tag + def altitude_diff(msg): """Decode the differece between GNSS and barometric altitude