velocity default argument for backwards compatibility

This commit is contained in:
Alexander Hirsch 2019-05-17 09:45:16 -07:00
parent fc9b05b6f1
commit 3c14579040
3 changed files with 28 additions and 9 deletions

View File

@ -143,12 +143,16 @@ 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, string, string): speed (kt),
@ -160,14 +164,14 @@ def velocity(msg):
barometer, 'GNSS' for GNSS constellation).
In the case of surface messages, None will be put in place
for direction, vertical rate, and their respective sources.
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<TC<9 or TC=19")

View File

@ -141,13 +141,17 @@ def surface_position_with_ref(msg, lat_ref, lon_ref):
return round(lat, 5), round(lon, 5)
def surface_velocity(msg):
def surface_velocity(msg, rtn_sources=False):
"""Decode surface velocity from from a surface position 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, None, string, string, None): speed (kt),
(int, float, int, string, string, None): speed (kt),
ground track (degree), None for rate of climb/descend (ft/min),
and speed type ('GS' for ground speed), direction source
('gnd_trk' for ground track), None rate of climb/descent source.
@ -183,4 +187,7 @@ def surface_velocity(msg):
spd = kts[i-1] + (mov-movs[i-1]) * step
spd = round(spd, 2)
return spd, trk, None, 'GS', 'gnd_trk', None
if rtn_sources:
return spd, trk, 0, 'GS', 'gnd_trk', None
else:
return spd, trk, 0, 'GS'

View File

@ -25,11 +25,15 @@ 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, string, string): speed (kt),
@ -96,7 +100,11 @@ def airborne_velocity(msg):
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, dir_type, vr_source
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