add altitude difference function in adsb, fix bug.

This commit is contained in:
junzis 2017-07-21 15:53:50 +02:00
parent 1220368ada
commit 1e842e4789
4 changed files with 32 additions and 12 deletions

View File

@ -492,7 +492,7 @@ def nic(msg):
int: NIC number (from 0 to 11), -1 if not applicable int: NIC number (from 0 to 11), -1 if not applicable
""" """
if typecode(msg) < 9 or typecode(msg) > 18: if typecode(msg) < 9 or typecode(msg) > 18:
raise RuntimeError("%s: Not a airborne position message" % msg) raise RuntimeError("%s: Not a airborne position message, expecting 8<TC<19" % msg)
msgbin = util.hex2bin(msg) msgbin = util.hex2bin(msg)
tc = typecode(msg) tc = typecode(msg)
@ -553,7 +553,7 @@ def velocity(msg):
return airborne_velocity(msg) return airborne_velocity(msg)
else: else:
raise RuntimeError("incorrect or inconsistant message types") raise RuntimeError("incorrect or inconsistant message types, expecting 4<TC<9 or TC=19")
def speed_heading(msg): def speed_heading(msg):
"""Get speed and heading only from the velocity message """Get speed and heading only from the velocity message
@ -582,21 +582,21 @@ def airborne_velocity(msg):
""" """
if typecode(msg) != 19: if typecode(msg) != 19:
raise RuntimeError("%s: Not a airborne velocity message" % msg) raise RuntimeError("%s: Not a airborne velocity message, expecting TC=19" % msg)
msgbin = util.hex2bin(msg) msgbin = util.hex2bin(msg)
subtype = util.bin2int(msgbin[37:40]) subtype = util.bin2int(msgbin[37:40])
if subtype in (1, 2): if subtype in (1, 2):
v_ew_sign = util.bin2int(msgbin[45]) v_ew_sign = -1 if int(msgbin[45]) else 1
v_ew = util.bin2int(msgbin[46:56]) - 1 # east-west velocity v_ew = util.bin2int(msgbin[46:56]) - 1 # east-west velocity
v_ns_sign = util.bin2int(msgbin[56]) v_ns_sign = -1 if int(msgbin[56]) else 1
v_ns = util.bin2int(msgbin[57:67]) - 1 # north-south velocity v_ns = util.bin2int(msgbin[57:67]) - 1 # north-south velocity
v_we = -1*v_ew if v_ew_sign else v_ew v_we = v_ew_sign * v_ew
v_sn = -1*v_ns if v_ns_sign else v_ns v_sn = v_ns_sign * v_ns
spd = math.sqrt(v_sn*v_sn + v_we*v_we) # unit in kts spd = math.sqrt(v_sn*v_sn + v_we*v_we) # unit in kts
@ -612,9 +612,9 @@ def airborne_velocity(msg):
tag = 'AS' tag = 'AS'
vr_sign = util.bin2int(msgbin[68]) vr_sign = -1 if int(msgbin[68]) else 1
vr = (util.bin2int(msgbin[69:78]) - 1) * 64 # vertical rate, fpm vr = (util.bin2int(msgbin[69:78]) - 1) * 64 # vertical rate, fpm
rocd = -1*vr if vr_sign else vr # rate of climb/descend rocd = vr_sign * vr
return int(spd), round(hdg, 1), int(rocd), tag return int(spd), round(hdg, 1), int(rocd), tag
@ -631,7 +631,7 @@ def surface_velocity(msg):
""" """
if typecode(msg) < 5 or typecode(msg) > 8: if typecode(msg) < 5 or typecode(msg) > 8:
raise RuntimeError("%s: Not a surface message" % msg) raise RuntimeError("%s: Not a surface message, expecting 5<TC<8" % msg)
msgbin = util.hex2bin(msg) msgbin = util.hex2bin(msg)
@ -661,3 +661,22 @@ def surface_velocity(msg):
spd = round(spd, 2) spd = round(spd, 2)
return spd, hdg, 0, 'GS' return spd, hdg, 0, 'GS'
def altitude_diff(msg):
"""Decode the differece between GNSS and barometric altitude
Args:
msg (string): 28 bytes hexadecimal message string, TC=19
Returns:
int: Altitude difference in ft. Negative value indicates GNSS altitude
below barometric altitude.
"""
if typecode(msg) != 19:
raise RuntimeError("incorrect message types, expecting TC=19")
msgbin = util.hex2bin(msg)
sign = -1 if int(msgbin[80]) else 1
value = util.bin2int(msgbin[81:88]) * 25
return sign * value

View File

@ -157,7 +157,7 @@ def isBDS17(msg):
# basic BDS codes for ADS-B shall be supported # basic BDS codes for ADS-B shall be supported
# assuming ADS-B out is installed (2017EU/2020US mandate) # assuming ADS-B out is installed (2017EU/2020US mandate)
if not set(['BDS05', 'BDS06', 'BDS09', 'BDS20']).issubset(l): if not set(['BDS05', 'BDS06', 'BDS09', 'BDS20']).issubset(caps):
result &= False result &= False
return result return result

View File

@ -61,6 +61,7 @@ def test_adsb_velocity():
assert vgs == (159, 182.9, -832, 'GS') assert vgs == (159, 182.9, -832, 'GS')
assert vas == (376, 244.0, -2304, 'AS') assert vas == (376, 244.0, -2304, 'AS')
assert vgs_surface == (19.0, 42.2, 0 , 'GS') assert vgs_surface == (19.0, 42.2, 0 , 'GS')
assert adsb.altitude_diff('8D485020994409940838175B284F') == 575
def test_nic(): def test_nic():

View File

@ -8,7 +8,7 @@ def test_ehs_icao():
def test_df20alt(): def test_df20alt():
assert ehs.df20alt("A02014B400000000000000F9D514") == 33300 assert ehs.df20alt("A02014B400000000000000F9D514") == 32300
def test_ehs_BDS(): def test_ehs_BDS():