本文整理汇总了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)