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