def battery_report_decode(message): #cmd_id = 0x0011 bat_drain = message[2:4] bat_voltage = message[4:6] bat_state = message[6:7] bat_drain = utils.u16_unpack(bat_drain) bat_voltage = utils.u16_unpack(bat_voltage) bat_state = utils.u8_unpack(bat_state) return bat_drain, bat_voltage, bat_state
def error_bridge_decode(message): #cmd_id = 0x8012 error_code = message[2:3] command = message[3:5] error_code = utils.u8_unpack(error_code) command = utils.u16_unpack(command) return error_code, command
def get_pdata(pdata): len_msg = len(pdata) message = pdata[:len_msg - 2] msg_crc = pdata[len_msg - 2:len_msg] msg_crc = utils.u16_unpack(msg_crc) crc_val = utils.get_crc(message) cmd_id = message[:2] message = message[2:] if (msg_crc != crc_val): print "crc error: " + hexlify(crc_val) return cmd_id, message
def decrypt_rx(adata, key): nonce = adata[:24] message = adata[30:] decrypted = decrypt(message, nonce, key) len_msg = len(decrypted) message = decrypted[:len_msg - 2] msg_crc = decrypted[len_msg - 2:len_msg] msg_crc = utils.u16_unpack(msg_crc) crc_val = utils.get_crc(message) auth_id = message[0:4] auth_id = utils.u32_unpack(auth_id) message = message[4:] if (msg_crc != crc_val): print "crc error: " + str(hex(crc_val)) utils.verify_crc(decrypted) return auth_id, message, decrypted
def get_cmd_id(message): cmd_id = message[0:2] cmd_id = utils.u16_unpack(cmd_id) return cmd_id