當前位置: 首頁>>代碼示例>>Python>>正文


Python Protocol.hasCmd方法代碼示例

本文整理匯總了Python中protocol.Protocol.hasCmd方法的典型用法代碼示例。如果您正苦於以下問題:Python Protocol.hasCmd方法的具體用法?Python Protocol.hasCmd怎麽用?Python Protocol.hasCmd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在protocol.Protocol的用法示例。


在下文中一共展示了Protocol.hasCmd方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from protocol import Protocol [as 別名]
# 或者: from protocol.Protocol import hasCmd [as 別名]

#.........這裏部分代碼省略.........
        self._memory_name = name
        operation = 'select_memory_' + name.lower()
        self._opDotOperation(operation)

    def opProgram(self, data, addr_start=0):
        addr_hi_prev = None
        addr = addr_start
        while data:
            addr_hi, addr_lo = divmod(addr, 0x10000)
            if addr_hi != addr_hi_prev:
                addr_hi_prev = addr_hi
                cmd = self._protocol.getCmd('select_memory_page', PPPP=addr_hi)
                self._opDotCmd(cmd)

            addr_end = addr_lo + len(data)
            if addr_end >= 0x10000:
                addr_end = 0xffff
            size = addr_end + 1 - addr_lo
            buf, data = data[:size], data[size:]
            cmd = self._protocol.getCmd('program_start', PPPP=addr_lo, QQQQ=addr_end)
            self._opDotCmd(cmd)
            self._wdelayHack()
            addr = addr + size

            # send data
            ihex = IHex()
            ihex.insert_data(addr_lo, buf)
            ihex.set_row_bytes(255)
            buf = ihex.write()
            # split to lines, remove, empty strings
            buf = [b for b in buf.splitlines() if b]
            # remove hex end if file
            buf = buf[:-1]
            for d in buf:
                self._opDotCmd(str(d, 'ascii').upper())
                self._wdelayHack()

    def opRead(self, addr_start, size=None):
        if size is None:
            addr_stop = self._part.getMemory(self._memory_name).getSize()
        else:
            addr_stop = addr_start + size
        page_size = self._part.getPageSize()

        data = ''
        addr = addr_start
        addr_hi_prev = None

        while addr < addr_stop:
            addr_hi, addr_lo = divmod(addr, 0x10000)
            if addr_hi != addr_hi_prev:
                addr_hi_prev = addr_hi
                cmd = self._protocol.getCmd('select_memory_page', PPPP=addr_hi)
                self._opDotCmd(cmd)
            addr_end = addr_lo + page_size - 1
            if addr_end > addr_stop:
                addr_end = addr_stop - 1
            if addr_end >= 0x10000:
                addr_end = 0x10000 - 1
            cmd = self._protocol.getCmd('read_memory', PPPP=addr_lo, QQQQ=addr_end)
            self._io.send(cmd)

            r_addr = addr
            while addr_lo <= addr_end:
                buf = self._io.recv()
                # AAAA=ddddddd....
                r_addr, r_eq, r_data = buf[:4], buf[4:5], buf[5:]
                if r_eq != '=':
                    raise PgmError("Expected 'xxxx=...' in :%s" % buf)
                if r_addr != ("%.4X" % addr_lo):
                    raise PgmError("Invalid address in response got: %s exp: %s data: %s" %
                            (r_addr, addr_lo, bug))
                addr_lo = addr_lo + len(r_data) / 2
                data = data + r_data

            addr = addr_hi * 0x10000 + addr_end + 1

        return binascii.unhexlify(data)

    def opStartAppl(self, reset):
        if reset:
            cmd = self._protocol.getCmd('startAppliWithReset')
        else:
            cmd = self._protocol.getCmd('startAppliWithoutReset')
        self._io.send(cmd)
        # read \x00 if follows by reset, or timeout
        self._io.readRaw(1)

    def opSync(self):
        """Called only once to synchronize bytestream."""
        if self._protocol.hasCmd('sync'):
            sync = self._protocol.getCmd('sync')
            sync = bytes(sync, 'ascii')
            self._io.writeRaw(sync)
            r = self._io.readRaw(len(sync))
            if r != sync:
                raise PgmError('Synchronization failed, invalid response: %s' % r)

    def _wdelayHack(self):
        time.sleep(self._wdelay)
開發者ID:pinkavaj,項目名稱:batch_isp,代碼行數:104,代碼來源:operations.py


注:本文中的protocol.Protocol.hasCmd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。