update BDS 4,4 decoder, default to revised version
This commit is contained in:
117
pyModeS/ehs.py
117
pyModeS/ehs.py
@@ -209,36 +209,38 @@ def pbaro(msg):
|
||||
# DF 20/21, BDS 4,4
|
||||
# ------------------------------------------
|
||||
|
||||
def isBDS44(msg):
|
||||
def isBDS44(msg, rev=True):
|
||||
"""Check if a message is likely to be BDS code 4,4
|
||||
Meteorological routine air report
|
||||
|
||||
WARNING: there is two different definition for BDS4,4. This part of the
|
||||
decoder is likely to be wrong...
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message string
|
||||
rev (bool): using revised version
|
||||
|
||||
Returns:
|
||||
bool: True or False
|
||||
"""
|
||||
|
||||
# status bit 5, 15, 24, 36, 49
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
result = True
|
||||
|
||||
# --- current version ---
|
||||
result = result & checkbits(d, 5, 6, 23) \
|
||||
& checkbits(d, 35, 36, 46) & checkbits(d, 47, 48, 49) \
|
||||
& checkbits(d, 50, 51, 56)
|
||||
if not rev:
|
||||
# status bit 5, 35, 47, 50
|
||||
result = result & checkbits(d, 5, 6, 23) \
|
||||
& checkbits(d, 35, 36, 46) & checkbits(d, 47, 48, 49) \
|
||||
& checkbits(d, 50, 51, 56)
|
||||
|
||||
# # --- revised future version ---
|
||||
# result = result & checkbits(d, 5, 6, 14) \
|
||||
# & checkbits(d, 15, 16, 23) & checkbits(d, 24, 25, 35) \
|
||||
# & checkbits(d, 36, 37, 47) & checkbits(d, 49, 50, 56)
|
||||
|
||||
if wind(msg) and wind(msg)[0] > 250:
|
||||
else:
|
||||
# status bit 5, 15, 24, 36, 49
|
||||
|
||||
result = result & checkbits(d, 5, 6, 14) \
|
||||
& checkbits(d, 15, 16, 23) & checkbits(d, 24, 25, 35) \
|
||||
& checkbits(d, 36, 37, 47) & checkbits(d, 49, 50, 56)
|
||||
|
||||
vw = wind(msg, rev=rev)
|
||||
if vw and vw[0] > 250:
|
||||
result &= False
|
||||
|
||||
# if temperature(msg):
|
||||
@@ -248,78 +250,123 @@ def isBDS44(msg):
|
||||
return result
|
||||
|
||||
|
||||
def wind(msg):
|
||||
def wind(msg, rev=True):
|
||||
"""reported wind speed and direction
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS44) string
|
||||
rev (bool): using revised version
|
||||
|
||||
Returns:
|
||||
(int, float): speed (kt), direction (degree)
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
status = int(d[4])
|
||||
if not status:
|
||||
return None
|
||||
if not rev:
|
||||
status = int(d[4])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
speed = util.bin2int(d[5:14]) # knots
|
||||
direction = util.bin2int(d[14:23]) * 180.0 / 256.0 # degree
|
||||
|
||||
else:
|
||||
spd_status = int(d[4])
|
||||
dir_status = int(d[14])
|
||||
|
||||
if (not spd_status) or (not dir_status):
|
||||
return None
|
||||
|
||||
speed = util.bin2int(d[5:14]) # knots
|
||||
direction = util.bin2int(d[15:23]) * 180.0 / 128.0 # degree
|
||||
|
||||
speed = util.bin2int(d[5:14]) # knots
|
||||
direction = util.bin2int(d[14:23]) * 180.0 / 256.0 # degree
|
||||
return round(speed, 0), round(direction, 1)
|
||||
|
||||
|
||||
def temperature(msg):
|
||||
def temperature(msg, rev=True):
|
||||
"""reported air temperature
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS44) string
|
||||
rev (bool): using revised version
|
||||
|
||||
Returns:
|
||||
float: tmeperature in Celsius degree
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
sign = int(d[23]) # 1 -> minus
|
||||
temp = util.bin2int(d[24:34]) * 0.25 # celsius
|
||||
temp = round(temp, 1)
|
||||
return -1 * temp if sign else temp
|
||||
if not rev:
|
||||
sign = int(d[23])
|
||||
temp = util.bin2int(d[24:34]) * 0.125 # celsius
|
||||
temp = round(temp, 1)
|
||||
|
||||
else:
|
||||
status = int(d[23])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
sign = int(d[24])
|
||||
temp = util.bin2int(d[25:35]) * 0.125 # celsius
|
||||
temp = round(temp, 1)
|
||||
|
||||
return temp if sign else -1*temp
|
||||
|
||||
|
||||
def pressure(msg):
|
||||
def pressure(msg, rev=True):
|
||||
"""reported average static pressure
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS44) string
|
||||
rev (bool): using revised version
|
||||
|
||||
Returns:
|
||||
int: static pressure in hPa
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
status = int(d[34])
|
||||
if not status:
|
||||
return None
|
||||
if not rev:
|
||||
status = int(d[34])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
p = util.bin2int(d[35:46]) # hPa
|
||||
|
||||
else:
|
||||
status = int(d[35])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
p = util.bin2int(d[36:47]) # hPa
|
||||
|
||||
p = util.bin2int(d[35:46]) # hPa
|
||||
return p
|
||||
|
||||
|
||||
def humidity(msg):
|
||||
def humidity(msg, rev=True):
|
||||
"""reported humidity
|
||||
|
||||
Args:
|
||||
msg (String): 28 bytes hexadecimal message (BDS44) string
|
||||
rev (bool): using revised version
|
||||
|
||||
Returns:
|
||||
float: percentage of humidity, [0 - 100] %
|
||||
"""
|
||||
d = util.hex2bin(data(msg))
|
||||
|
||||
status = int(d[49])
|
||||
if not status:
|
||||
return None
|
||||
if not rev:
|
||||
status = int(d[49])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
hm = util.bin2int(d[50:56]) * 100.0 / 64 # %
|
||||
|
||||
else:
|
||||
status = int(d[48])
|
||||
if not status:
|
||||
return None
|
||||
|
||||
hm = util.bin2int(d[49:56]) # %
|
||||
|
||||
hm = util.bin2int(d[50:56]) * 100.0 / 64 # %
|
||||
return round(hm, 1)
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,8 @@ def ehs_decode_all(n=None):
|
||||
ehs.alt_fms(m), ehs.pbaro(m))
|
||||
|
||||
if vBDS == "BDS44":
|
||||
print(ts, m, icao, vBDS, ehs.wind(m))
|
||||
print(ts, m, icao, vBDS, ehs.wind(m),
|
||||
ehs.temperature(m), ehs.pressure(m))
|
||||
|
||||
if vBDS == "BDS50":
|
||||
print(ts, m, icao, vBDS, ehs.roll(m), ehs.track(m),
|
||||
|
||||
Reference in New Issue
Block a user