當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。