当前位置: 首页>>代码示例>>Python>>正文


Python Protocol.create_packet方法代码示例

本文整理汇总了Python中protocol.Protocol.create_packet方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.create_packet方法的具体用法?Python Protocol.create_packet怎么用?Python Protocol.create_packet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在protocol.Protocol的用法示例。


在下文中一共展示了Protocol.create_packet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_metadata

# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import create_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
开发者ID:MrOnion,项目名称:fuct,代码行数:53,代码来源:interrogator.py

示例2: get_ram_data

# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import create_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...")
开发者ID:MrOnion,项目名称:fuct,代码行数:17,代码来源:interrogator.py

示例3: get_location_info

# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import create_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...")
开发者ID:MrOnion,项目名称:fuct,代码行数:18,代码来源:interrogator.py


注:本文中的protocol.Protocol.create_packet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。