def _read(self, block, blocknum, lastblock): # be very patient at first block if blocknum == 0: attempts = 60 else: attempts = 5 for _i in range(0, attempts): data = self.pipe.read(block + 2) if data: break time.sleep(0.5) if len(data) == block + 2 and data[0] == chr(blocknum): checksum = yaesu_clone.YaesuChecksum(1, block) if checksum.get_existing(data) != \ checksum.get_calculated(data): raise Exception("Checksum Failed [%02X<>%02X] block %02X" % (checksum.get_existing(data), checksum.get_calculated(data), blocknum)) # Chew away the block number and the checksum data = data[1:block + 1] else: if lastblock and self._US_model: raise Exception( _("Unable to read last block. " "This often happens when the selected model " "is US but the radio is a non-US one (or " "widebanded). Please choose the correct " "model and try again.")) else: raise Exception( "Unable to read block %02X expected %i got %i" % (blocknum, block + 2, len(data))) LOG.debug("Read %i" % len(data)) return data
def _test_checksum(self, mmap): cs = yaesu_clone.YaesuChecksum(0, 2, 3) self.assertEqual(42, cs.get_existing(mmap)) self.assertEqual(0x8A, cs.get_calculated(mmap)) try: mmap = mmap.get_byte_compatible() mmap[0] = 3 except AttributeError: # str or bytes try: # str mmap = memmap.MemoryMap('\x03' + mmap[1:]) except TypeError: # bytes mmap = memmap.MemoryMapBytes(b'\x03' + mmap[1:]) cs.update(mmap) self.assertEqual(95, cs.get_calculated(mmap))
def _clone_out(self): looppredelay = 0.4 looppostdelay = 1.9 start = time.time() blocknum = 0 pos = 0 status = chirp_common.Status() status.msg = "Cloning to radio..." self.status_fn(status) status.max = len(self._block_lengths) for blocksize in self._block_lengths: checksum = yaesu_clone.YaesuChecksum(pos, pos+blocksize-1) blocknumbyte = chr(blocknum) payloadbytes = self.get_mmap()[pos:pos+blocksize] checksumbyte = chr(checksum.get_calculated(self.get_mmap())) LOG.debug("Block %i - will send from %i to %i byte " % (blocknum, pos, pos + blocksize)) LOG.debug(util.hexprint(blocknumbyte)) LOG.debug(util.hexprint(payloadbytes)) LOG.debug(util.hexprint(checksumbyte)) # send wrapped bytes time.sleep(looppredelay) self.pipe.write(blocknumbyte) self.pipe.write(payloadbytes) self.pipe.write(checksumbyte) tmp = self.pipe.read(blocksize + 2) # chew echo LOG.debug("bytes echoed: ") LOG.debug(util.hexprint(tmp)) # radio is slow to write/ack: time.sleep(looppostdelay) buf = self.pipe.read(1) LOG.debug("ack recd:") LOG.debug(util.hexprint(buf)) if buf != CMD_ACK: raise Exception("Radio did not ack block %i" % blocknum) pos += blocksize blocknum += 1 status.cur = blocknum self.status_fn(status) LOG.info("Clone completed in %i seconds" % (time.time() - start))
def _clone_out(self): delay = 0.5 start = time.time() blocks = 0 pos = 0 status = chirp_common.Status() status.msg = _("Cloning to radio") status.max = len(self._block_lengths) + 39 for block in self._block_lengths: if blocks == 8: # repeated read of 40 block same size (memory area) repeat = 40 else: repeat = 1 for _i in range(0, repeat): time.sleep(0.01) checksum = yaesu_clone.YaesuChecksum(pos, pos + block - 1) LOG.debug("Block %i - will send from %i to %i byte " % (blocks, pos, pos + block)) LOG.debug(util.hexprint(chr(blocks))) LOG.debug(util.hexprint(self.get_mmap()[pos:pos + block])) LOG.debug( util.hexprint(chr(checksum.get_calculated( self.get_mmap())))) self.pipe.write(chr(blocks)) self.pipe.write(self.get_mmap()[pos:pos + block]) self.pipe.write(chr(checksum.get_calculated(self.get_mmap()))) buf = self.pipe.read(1) if not buf or buf[0] != chr(CMD_ACK): time.sleep(delay) buf = self.pipe.read(1) if not buf or buf[0] != chr(CMD_ACK): LOG.debug(util.hexprint(buf)) raise Exception(_("Radio did not ack block %i") % blocks) pos += block blocks += 1 status.cur = blocks self.status_fn(status) LOG.info("Clone completed in %i seconds" % (time.time() - start))
def _read(self, blocksize, blocknum): data = self.pipe.read(blocksize+2) # chew echo'd ack self.pipe.write(CMD_ACK) time.sleep(0.02) self.pipe.read(1) # chew echoed ACK from 1-wire serial if len(data) == blocksize + 2 and data[0] == chr(blocknum): checksum = yaesu_clone.YaesuChecksum(1, blocksize) if checksum.get_existing(data) != checksum.get_calculated(data): raise Exception("Checksum Failed [%02X<>%02X] block %02X, " "data len: %i" % (checksum.get_existing(data), checksum.get_calculated(data), blocknum, len(data))) data = data[1:blocksize + 1] # Chew blocknum and checksum else: raise Exception("Unable to read blocknum %02X " "expected blocksize %i got %i." % (blocknum, blocksize+2, len(data))) return data
def _checksums(self): return [yaesu_clone.YaesuChecksum(0x064A, 0x06C8), yaesu_clone.YaesuChecksum(0x06CA, 0x0748), yaesu_clone.YaesuChecksum(0x074A, 0x07C8), yaesu_clone.YaesuChecksum(0x07CA, 0x0848), yaesu_clone.YaesuChecksum(0x0000, 0xFEC9)]
def _checksums(self): return [yaesu_clone.YaesuChecksum(0x0000, 0x7F49)]
def _checksums(self): return [ yaesu_clone.YaesuChecksum(0x0592, 0x0610), yaesu_clone.YaesuChecksum(0x0612, 0x0690), yaesu_clone.YaesuChecksum(0x0000, 0x3F51), ]
def _checksums(self): return [yaesu_clone.YaesuChecksum(0x0000, 0x1FB9, 0x1FBA)]
def _checksums(self): return [yaesu_clone.YaesuChecksum(0, self._memsize - 1)]
def _checksums(self): return [yaesu_clone.YaesuChecksum(0x0000, 0xFEC9)] # The whole file -2 bytes