def ping(self): logging.debug('Ping') pkt = Packet.pack32(0x64) + Packet.pack32(1) self.write_pkt(pkt) if not self.read_nofail(8): logging.warning('Ping failed!') return False return True
def read_buf(self, part): self.set_isdump(1) logging.debug('Reading buf part {}'.format(part)) pkt = Packet.pack32(0x65) + Packet.pack32(2) + \ Packet.pack32(part & 0xffffffff) self.write_pkt(pkt) buf = self.read_nofail(500) return buf
def filetransfer_write(self, buf): self.set_isdump(0) self.set_packet_data_size(len(buf)) logging.debug('Writing filetransfer ({} bytes)'.format(len(buf))) pkt = Packet.pack32(0x66) + Packet.pack32(2) + Packet.pack32(len(buf)) self.write_pkt(pkt) self.read_nofail(8) for i in range(0, len(buf), self._packet_data_size): self.write(buf[i:i+self._packet_data_size]) self.read_nofail(8)
def write_buf(self, data): self.set_isdump(0) logging.debug('Writing buf ({} bytes)'.format(len(data))) pkt = Packet.pack32(0x65) + Packet.pack32(2) + Packet.pack32(len(data)) self.write_pkt(pkt) if not self.read_nofail(8): logging.warning('Cannot set write buffer length') self.write(data) ret = self.read_nofail(8) if not ret: logging.warning('Cannot write buffer') return ret
def set_filetransfer_offset(self, val): self.set_isdump(0) logging.debug('Setting g_filetransfer_offset=0x{:08x}'.format(val)) pkt = Packet.pack32(0x66) + Packet.pack32(3) + Packet.pack32(0) + \ Packet.pack32(val) + Packet.pack32(0) + Packet.pack32(0) self.write_pkt(pkt) self.read_nofail(8)
def set_tflash(self): logging.debug('Setting g_tflash=1') pkt = Packet.pack32(0x64) + Packet.pack32(8) self.write_pkt(pkt) self.read_nofail(8)
def set_packet_data_size(self, sz): logging.debug('Setting g_packet_data_size=0x{:08x}'.format(sz)) pkt = Packet.pack32(0x64) + Packet.pack32(5) + Packet.pack32(sz) self.write_pkt(pkt) if self.read_nofail(8): self._packet_data_size = sz
def set_total_bytes(self, totbytes): logging.debug('Setting g_total_bytes=0x{:08x}'.format(totbytes)) pkt = Packet.pack32(0x64) + Packet.pack32(2) + Packet.pack32(totbytes) self.write_pkt(pkt) self.read_nofail(8)
def close_session(self, reboot=0): logging.debug('Closing session (reboot={})'.format(reboot)) pkt = Packet.pack32(0x67) + Packet.pack32(reboot) self.write_pkt(pkt) self.read_nofail(8)
def set_isdump(self, isdump): isdump = 1 if isdump else 0 logging.debug('Setting isdump={}'.format(isdump)) pkt = Packet.pack32(0x66) + Packet.pack32(isdump) self.write_pkt(pkt) return self.read_nofail(8)