本文整理汇总了Python中protocol.Protocol.decode_packet方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.decode_packet方法的具体用法?Python Protocol.decode_packet怎么用?Python Protocol.decode_packet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.decode_packet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_metadata
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import decode_packet [as 别名]
def get_metadata(self):
meta_cmds = [
("interface", Protocol.FE_CMD_INTERFACE),
("firmware", Protocol.FE_CMD_FIRMWARE),
("decoder", Protocol.FE_CMD_DECODER),
("build_date", Protocol.FE_CMD_BUILDDATE),
("compiler", Protocol.FE_CMD_COMPILER),
("os", Protocol.FE_CMD_OSNAME),
("build_by", Protocol.FE_CMD_USER),
("email", Protocol.FE_CMD_EMAIL)
]
meta = {}
location_ids = None
for _, cmd in meta_cmds:
self.queue_out.put(Protocol.create_packet(cmd))
self.queue_out.put(Protocol.create_packet(Protocol.FE_CMD_LOCATION_ID_LIST, data=bytearray(b'\x00\x00\x00'), use_length=True))
while True:
if all(name in meta for name, _ in meta_cmds) and location_ids is not None:
break
try:
if not self.queue_out.empty():
packet = self.queue_out.get(False)
LOG.debug("--> %s" % binascii.hexlify(packet[1:-2]))
self.ser.write(packet)
self.ser.flush()
resp = self.queue_in.get()
LOG.debug("<-- %s" % binascii.hexlify(resp))
data = Protocol.decode_packet(resp)
# FIXME: hax, make more elegant
meta_info = [(name, data[1].decode("ascii").rstrip('\0')) for name, cmd_id in meta_cmds if cmd_id + 1 == data[0]]
if meta_info:
m = meta_info[0]
LOG.debug("Received meta: %s" % m[0])
meta[m[0]] = m[1]
elif data[0] == Protocol.FE_CMD_LOCATION_ID_LIST + 1:
ids = len(data[1]) / 2
LOG.debug("Received %d location IDs" % ids)
location_ids = struct.unpack_from(">%dH" % ids, buffer(data[1]))
# TODO: error message handling
except Queue.Empty:
pass
return meta, location_ids
示例2: get_ram_data
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import decode_packet [as 别名]
def get_ram_data(self, location, size):
LOG.debug("Get RAM location: 0x%02x, offset: %d, size: %d" % (location[0], location[1], size))
packet = Protocol.create_packet(Protocol.FE_CMD_RAM_READ, location, size)
LOG.debug("--> %s" % binascii.hexlify(packet[1:-2]))
self.ser.write(packet)
self.ser.flush()
resp = self.queue_in.get(5)
if resp:
LOG.debug("<-- %s" % binascii.hexlify(resp))
data = Protocol.decode_packet(resp)
if data[0] == Protocol.FE_CMD_RAM_READ + 1:
return data[1]
else:
LOG.warn("Failed to load location...")
示例3: get_location_info
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import decode_packet [as 别名]
def get_location_info(self, location_id):
LOG.debug("Get location info: 0x%02x" % location_id)
packet = Protocol.create_packet(Protocol.FE_CMD_LOCATION_ID_INFO, data=struct.pack(">H", location_id))
LOG.debug("--> %s" % binascii.hexlify(packet[1:-2]))
self.ser.write(packet)
self.ser.flush()
locinfo = namedtuple('LocationInfo', ['flags', 'parent', 'ram_page', 'flash_page', 'ram_addr', 'flash_addr', 'size'])
resp = self.queue_in.get(5)
if resp:
LOG.debug("<-- %s" % binascii.hexlify(resp))
data = Protocol.decode_packet(resp)
if data[0] == Protocol.FE_CMD_LOCATION_ID_INFO + 1:
return locinfo(*struct.unpack_from(">HHBBHHH", buffer(data[1])))
else:
LOG.warn("Failed to load location...")