major bug fix, signed values in ehs (two's complement)

This commit is contained in:
Junzi Sun 2017-07-25 23:29:03 +02:00
parent 98e5d81ae1
commit c6952e4e63
3 changed files with 92 additions and 44 deletions

View File

@ -392,18 +392,28 @@ def temp44(msg, rev=False):
d = util.hex2bin(data(msg))
if not rev:
if d[22] == '0':
return None
# if d[22] == '0':
# return None
sign = int(d[23])
temp = util.bin2int(d[24:34]) * 0.125 # celsius
value = util.bin2int(d[24:34])
if sign:
value = value - 1024
temp = value * 0.125 # celsius
temp = round(temp, 1)
else:
if d[23] == '0':
return None
# if d[23] == '0':
# return None
sign = int(d[24])
temp = util.bin2int(d[25:35]) * 0.125 # celsius
value = util.bin2int(d[25:35])
if sign:
value = value - 1024
temp = value * 0.125 # celsius
temp = round(temp, 1)
return -1*temp if sign else temp
@ -531,8 +541,12 @@ def roll50(msg):
return None
sign = int(d[1]) # 1 -> left wing down
value = util.bin2int(d[2:11]) * 45.0 / 256.0 # degree
angle = -1 * value if sign else value
value = util.bin2int(d[2:11])
if sign:
value = value - 512
angle = value * 45.0 / 256.0 # degree
return round(angle, 1)
@ -551,9 +565,18 @@ def trk50(msg):
return None
sign = int(d[12]) # 1 -> west
value = util.bin2int(d[13:23]) * 90.0 / 512.0 # degree
angle = 360 - value if sign else value
return round(angle, 1)
value = util.bin2int(d[13:23])
if sign:
value = value - 1024
trk = value * 90.0 / 512.0
# convert from [-180, 180] to [0, 360]
if trk < 0:
trk = 360 + trk
return round(trk, 1)
def gs50(msg):
@ -592,8 +615,11 @@ def rtrk50(msg):
return None
sign = int(d[35]) # 1 -> minus
value = util.bin2int(d[36:45]) * 8.0 / 256.0 # degree / sec
angle = -1 * value if sign else value
value = util.bin2int(d[36:45])
if sign:
value = value - 512
angle = value * 8.0 / 256.0 # degree / sec
return round(angle, 3)
@ -679,10 +705,19 @@ def hdg53(msg):
if d[0] == '0':
return None
sign = int(d[1]) # 1 -> west
value = util.bin2int(d[2:12]) * 90.0 / 512.0 # degree
angle = 360 - value if sign else value
return round(angle, 1)
sign = int(d[1]) # 1 -> west
value = util.bin2int(d[2:12])
if sign:
value = value - 1024
hdg = value * 90.0 / 512.0 # degree
# convert from [-180, 180] to [0, 360]
if hdg < 0:
hdg = 360 + hdg
return round(hdg, 1)
def ias53(msg):
@ -752,9 +787,12 @@ def vr53(msg):
if d[46] == '0':
return None
sign = d[47] # 1 -> minus
value = util.bin2int(d[48:56]) * 64 # feet/min
roc = -1*value if sign else value
sign = d[47] # 1 -> minus
value = util.bin2int(d[48:56])
if sign:
value = value - 256
roc = value * 64 # feet/min
return roc
@ -795,7 +833,6 @@ def isBDS60(msg):
if mach is not None and mach > 1:
result &= False
# leave out the check from vr60baro, due to very noisy measurement
vri = vr60ins(msg)
@ -820,8 +857,17 @@ def hdg60(msg):
return None
sign = int(d[1]) # 1 -> west
value = util.bin2int(d[2:12]) * 90 / 512.0 # degree
hdg = 360 - value if sign else value
value = util.bin2int(d[2:12])
if sign:
value = value - 1024
hdg = value * 90 / 512.0 # degree
# convert from [-180, 180] to [0, 360]
if hdg < 0:
hdg = 360 + hdg
return round(hdg, 1)
@ -876,8 +922,12 @@ def vr60baro(msg):
return None
sign = d[35] # 1 -> minus
value = util.bin2int(d[36:45]) * 32 # feet/min
roc = value if sign else -1*value
value = util.bin2int(d[36:45])
if sign:
value = value - 512
roc = value * 32 # feet/min
return roc
@ -896,8 +946,12 @@ def vr60ins(msg):
return None
sign = d[46] # 1 -> minus
value = util.bin2int(d[47:56]) * 32 # feet/min
roc = value if sign else -1*value
value = util.bin2int(d[47:56])
if sign:
value = value - 512
roc = value * 32 # feet/min
return roc

View File

@ -62,7 +62,7 @@ def ehs_decode_all(n=None):
if vBDS == "BDS44":
print(ts, m, icao, vBDS, ehs.wind44(m),
ehs.temp44(m), ehs.p44(m))
ehs.temp44(m), ehs.p44(m), ehs.hum44(m))
if vBDS == "BDS50":
print(ts, m, icao, vBDS, ehs.roll50(m), ehs.trk50(m),
@ -79,5 +79,5 @@ def ehs_decode_all(n=None):
print(ts, m, icao, 'UNKNOWN')
if __name__ == '__main__':
# adsb_decode_all(100)
adsb_decode_all(100)
ehs_decode_all(100)

View File

@ -14,10 +14,9 @@ def test_df20alt():
def test_ehs_BDS():
assert ehs.BDS("A0001838201584F23468207CDFA5") == 'BDS20'
assert ehs.BDS("A0001839CA3800315800007448D9") == 'BDS40'
assert ehs.BDS("A0000691E8D9DF1AFFB7F740A137") == 'BDS44'
assert ehs.BDS("A000031DBAA9DD18622C441330E9") == 'BDS44'
assert ehs.BDS("A000139381951536E024D4CCF6B5") == 'BDS50'
assert ehs.BDS("A000029CFFBAA11E2004727281F1") == 'BDS60'
assert ehs.BDS("A00004128F39F91A7E27C46ADC21") == 'BDS60'
def test_ehs_BDS20_callsign():
assert ehs.callsign("A000083E202CC371C31DE0AA1CCF") == 'KLM1017_'
@ -29,26 +28,21 @@ def test_ehs_BDS40_functions():
assert ehs.alt40fms("A000029C85E42F313000007047D3") == 3008
assert ehs.p40baro("A000029C85E42F313000007047D3") == 1020.0
def test_ehs_BDS44_functions():
assert ehs.wind44("A0000691E8D9DF1AFFB7F740A137") == (54.0, 168.0)
assert ehs.temp44("A0000691E8D9DF1AFFB7F740A137") == -13.4
assert ehs.p44("A0000691E8D9DF1AFFB7F740A137") == 2029
assert ehs.hum44("A0000691E8D9DF1AFFB7F740A137") == 85.9
def test_ehs_BDS50_functions():
assert ehs.roll50("A000139381951536E024D4CCF6B5") == 2.1
assert ehs.trk50("A000139381951536E024D4CCF6B5") == 114.3
assert ehs.gs50("A000139381951536E024D4CCF6B5") == 438
assert ehs.rtrk50("A000139381951536E024D4CCF6B5") == 0.125
assert ehs.tas50("A000139381951536E024D4CCF6B5") == 424
# signed values
assert ehs.roll50("A0001691FFD263377FFCE02B2BF9") == -0.4
def test_ehs_BDS60_functions():
assert ehs.hdg60("A000029CFFBAA11E2004727281F1") == 180.9
assert ehs.ias60("A000029CFFBAA11E2004727281F1") == 336
assert ehs.mach60("A000029CFFBAA11E2004727281F1") == 0.48
assert ehs.vr60baro("A000029CFFBAA11E2004727281F1") == 0
assert ehs.vr60ins("A000029CFFBAA11E2004727281F1") == 3648
assert ehs.hdg60("A00004128F39F91A7E27C46ADC21") == 42.7
assert ehs.ias60("A00004128F39F91A7E27C46ADC21") == 252
assert ehs.mach60("A00004128F39F91A7E27C46ADC21") == 0.42
assert ehs.vr60baro("A00004128F39F91A7E27C46ADC21") == -1920
assert ehs.vr60ins("A00004128F39F91A7E27C46ADC21") == -1920
def test_graycode_to_altitude():
assert modes_common.gray2alt('00000000010') == -1000