def is40(msg): """Check if a message is likely to be BDS code 4,0 Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False """ if allzeros(msg): return False d = hex2bin(data(msg)) # status bit 1, 14, and 27 if wrongstatus(d, 1, 2, 13): return False if wrongstatus(d, 14, 15, 26): return False if wrongstatus(d, 27, 28, 39): return False if wrongstatus(d, 48, 49, 51): return False if wrongstatus(d, 54, 55, 56): return False # bits 40-47 and 52-53 shall all be zero if bin2int(d[39:47]) != 0: return False if bin2int(d[51:53]) != 0: return False return True
def temp45(msg): """Static air temperature. Args: msg (String): 28 bytes hexadecimal message string Returns: float: tmeperature in Celsius degree """ d = hex2bin(data(msg)) sign = int(d[16]) value = bin2int(d[17:26]) if sign: value = value - 512 temp = value * 0.25 # celsius temp = round(temp, 1) return temp
def temp44(msg, rev=False): """reported air temperature Args: msg (String): 28 bytes hexadecimal message (BDS44) string rev (bool): using revised version Returns: float: tmeperature in Celsius degree """ d = hex2bin(data(msg)) if not rev: # if d[22] == '0': # return None sign = int(d[23]) value = 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 sign = int(d[24]) value = bin2int(d[25:35]) if sign: value = value - 1024 temp = value * 0.125 # celsius temp = round(temp, 1) return temp
def roll50(msg): """Roll angle, BDS 5,0 message Args: msg (String): 28 bytes hexadecimal message (BDS50) string Returns: float: angle in degrees, negative->left wing down, positive->right wing down """ d = hex2bin(data(msg)) if d[0] == '0': return None sign = int(d[1]) # 1 -> left wing down value = bin2int(d[2:11]) if sign: value = value - 512 angle = value * 45.0 / 256.0 # degree return round(angle, 1)
def rtrk50(msg): """Track angle rate, BDS 5,0 message Args: msg (String): 28 bytes hexadecimal message (BDS50) string Returns: float: angle rate in degrees/second """ d = hex2bin(data(msg)) if d[34] == '0': return None if d[36:45] == "111111111": return None sign = int(d[35]) # 1 -> negative value, two's complement value = bin2int(d[36:45]) if sign: value = value - 512 angle = value * 8.0 / 256.0 # degree / sec return round(angle, 3)
def cs20(msg): """Aircraft callsign Args: msg (String): 28 bytes hexadecimal message (BDS40) string Returns: string: callsign, max. 8 chars """ chars = '#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######' d = hex2bin(data(msg)) cs = '' cs += chars[bin2int(d[8:14])] cs += chars[bin2int(d[14:20])] cs += chars[bin2int(d[20:26])] cs += chars[bin2int(d[26:32])] cs += chars[bin2int(d[32:38])] cs += chars[bin2int(d[38:44])] cs += chars[bin2int(d[44:50])] cs += chars[bin2int(d[50:56])] return cs
def is20(msg): """Check if a message is likely to be BDS code 2,0 Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False """ if allzeros(msg): return False d = hex2bin(data(msg)) if d[0:8] != '00100000': return False cs = cs20(msg) if '#' in cs: return False return True
def vr53(msg): """Vertical rate Args: msg (String): 28 bytes hexadecimal message (BDS60) string Returns: int: vertical rate in feet/minutes """ d = hex2bin(data(msg)) if d[46] == '0': return None sign = int(d[47]) # 1 -> negative value, two's complement value = bin2int(d[48:56]) if value == 0 or value == 255: # all zeros or all ones return 0 value = value - 256 if sign else value roc = value * 64 # feet/min return roc
def vr60ins(msg): """Vertical rate messured by onbard equiments (IRS, AHRS) Args: msg (String): 28 bytes hexadecimal message (BDS60) string Returns: int: vertical rate in feet/minutes """ d = hex2bin(data(msg)) if d[45] == '0': return None sign = int(d[46]) # 1 -> negative value, two's complement value = bin2int(d[47:56]) if value == 0 or value == 511: # all zeros or all ones return 0 value = value - 512 if sign else value roc = value * 32 # feet/min return roc
def vr60baro(msg): """Vertical rate from barometric measurement, this value may be very noisy. Args: msg (String): 28 bytes hexadecimal message (BDS60) string Returns: int: vertical rate in feet/minutes """ d = hex2bin(data(msg)) if d[34] == '0': return None sign = int(d[35]) # 1 -> negative value, two's complement value = bin2int(d[36:45]) if value == 0 or value == 511: # all zeros or all ones return 0 value = value - 512 if sign else value roc = value * 32 # feet/min return roc
def is44(msg, rev=False): """Check if a message is likely to be BDS code 4,4 Meteorological routine air report Args: msg (String): 28 bytes hexadecimal message string rev (bool): using revised version Returns: bool: True or False """ if allzeros(msg): return False d = hex2bin(data(msg)) if not rev: # status bit 5, 35, 47, 50 if wrongstatus(d, 5, 6, 23): return False if wrongstatus(d, 35, 36, 46): return False if wrongstatus(d, 47, 48, 49): return False if wrongstatus(d, 50, 51, 56): return False # Bits 1-4 indicate source, values > 4 reserved and should not occur if bin2int(d[0:4]) > 4: return False else: # status bit 5, 15, 24, 36, 49 if wrongstatus(d, 5, 6, 14): return False if wrongstatus(d, 15, 16, 23): return False if wrongstatus(d, 24, 25, 35): return False if wrongstatus(d, 36, 37, 47): return False if wrongstatus(d, 49, 50, 56): return False # Bits 1-4 are reserved and should be zero if bin2int(d[0:4]) != 0: return False vw = wind44(msg, rev=rev) if vw is not None and vw[0] > 250: return False if temp44(msg): if temp44(msg) > 60 or temp44(msg) < -80: return False elif temp44(msg) == 0: return False return True