本文整理汇总了Python中protocol.Protocol.getCmd方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.getCmd方法的具体用法?Python Protocol.getCmd怎么用?Python Protocol.getCmd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.getCmd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import getCmd [as 别名]
class Operations:
def __init__(self, part, io, sync=True):
"""part - Part object, io - *IO object. If sync is True do protocol
synchronization (if supported by device."""
self._part = part
self._io = io
protocolPath = self._part.getProtocolFileName(self._io.getHardware())
protocolPath = os.path.join('ProtocolDescriptionFiles', protocolPath)
self._protocol = Protocol(protocolPath)
self._wdelay = 1
"""Write delay hack"""
if sync:
self.opSync()
def _opDotOperation(self, operation, **argv):
"""Common function for operation with no result."""
cmd = self._protocol.getCmd(operation, **argv)
self._opDotCmd(cmd)
def _opDotCmd(self, cmd):
"""Common function for operation with no result."""
self._io.send(cmd)
data = self._io.recv()
if data != '.':
raise PgmError("Invalid response, expected '.' got: %s" % data)
def opBlankCheck(self, addr_start, size=None):
if size is None:
size = self._part.getMemory('FLASH').getSize() - addr_start
addr = addr_start
addr_hi_prev = None
while size > 0:
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 + size - 1
if addr_end >= 0x10000:
addr_end = 0xffff
cmd = self._protocol.getCmd('blank_check', PPPP=addr_lo, QQQQ=addr_end)
self._opDotCmd(cmd)
addr = addr_hi * 0x10000 + addr_end + 1
size = size - (addr_end - addr_lo + 1)
def opErase(self):
self._opDotOperation('erase')
self._wdelayHack()
def opMemory(self, name):
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:
#.........这里部分代码省略.........