def parse_cmd(binary_cmd): code = binary_cmd[0] & 0x0000FFFF # lower 16 bits param = binary_cmd[0] >> 16 # higher 16 bits payload_mode = CmdMode(code & CmdMode.Mask) if payload_mode == CmdMode.Payload32: command = cmd1(code & CmdMode.CmdOpMask) value = binary_cmd[1] else: command = cmd0(code & CmdMode.CmdOpMask) value = param return command, value
def deserialize_command_stream(blob): assert isinstance(blob, bytes) payload_bytes = struct.unpack("<{0}I".format(len(blob) // 4), blob) cmms = [] # remove_header payload_bytes = payload_bytes[8:] idx = 0 while idx < len(payload_bytes): cmd = [] code = payload_bytes[idx] idx += 1 cmd.append(code) payload_mode = CmdMode(code & CmdMode.Mask) if payload_mode == CmdMode.Payload32: value = payload_bytes[idx] idx += 1 cmd.append(value) cmms.append(cmd) return cmms