def check_line(self, line, format_type): if format_type == DATA: if line.length != len(line.chunk): raise hexfile.InvalidRecordLengthError("Byte count doesn't match length of actual data.") checksum = checksums.lrc(utils.make_list(utils.int_to_array(line.address), line.length, line.chunk), 16, checksums.COMPLEMENT_NONE) if line.checksum != checksum: raise hexfile.InvalidRecordChecksumError()
def composeRow(self, address, length, row): checksum = checksums.lrc( utils.makeList(utils.intToArray(address), length, row), 16, checksums.COMPLEMENT_NONE) line = ";{0:02X}{1:04X}{2!s}{3:04X}".format(length, address, Writer.hexBytes(row), checksum) return line
def checkLine(self, line, formatType): if line.length != len(line.chunk): raise hexfile.InvalidRecordLengthError( "Byte count doesn't match length of actual data.") checksum = checksums.lrc( utils.makeList(line.type, line.length, utils.intToArray(line.address), line.chunk), 8, checksums.COMPLEMENT_TWOS) if line.checksum != checksum: raise hexfile.InvalidRecordChecksumError()
def compose_row(self, address, length, row): tmp = 0 # TODO: format type!? checksum = checksums.lrc( utils.make_list(tmp, length + 4, utils.int_to_array(address), row), 8, checksums.COMPLEMENT_TWOS) if length < self.row_length: lengthToPad = self.row_length - length padding = [0] * (lengthToPad) row.extend(padding) line = "{0:02X}{1}0000{2:08X}{3}".format(checksum, length - 2, address, Writer.hex_bytes(row)) return line
def check_line(self, line, format_type): if format_type == EOF: return True line.length -= 4 if line.length != len(line.chunk): line.chunk = line.chunk[:line.length] # Cut padding. if format_type == DATA_ABS: tmp = 0 self.last_address = line.address + line.length elif format_type == DATA_INC: tmp = 1 line.address = self.last_address elif format_type == DATA_REL: self.error("relative adressing not supported.") tmp = 2 else: self.error("Invalid format type: '{0}'".format(format_type)) tmp = 0 checksum = checksums.lrc( utils.make_list(tmp, line.length + 4, utils.int_to_array(line.address), line.chunk), 8, checksums.COMPLEMENT_TWOS) if line.checksum != checksum: raise hexfile.InvalidRecordChecksumError()
def testLRCCase5(self): self.assertEqual(lrc(range(10), 8, COMPLEMENT_TWOS), 211)
def testLRCCase6(self): self.assertEqual(lrc(range(100), 8, COMPLEMENT_TWOS), 170)
def testLRCCase9(): assert lrc(range(10), 16, COMPLEMENT_ONES) == 65490
def testLRCCase4(self): self.assertEqual(lrc(range(100), 8, COMPLEMENT_ONES), 169)
def testLRCCase11(): assert lrc(range(10), 16, COMPLEMENT_TWOS) == 65491
def testLRCCase17(self): self.assertEqual(lrc(range(10), 32, COMPLEMENT_TWOS), 4294967251)
def testLRCCase18(): assert lrc(range(100), 32, COMPLEMENT_TWOS) == 4294962346
def testLRCCase10(self): self.assertEqual(lrc(range(100), 16, COMPLEMENT_ONES), 60585)
def testLRCCase16(): assert lrc(range(100), 32, COMPLEMENT_ONES) == 4294962345
def testLRCCase17(): assert lrc(range(10), 32, COMPLEMENT_TWOS) == 4294967251
def testLRCCase15(): assert lrc(range(10), 32, COMPLEMENT_ONES) == 4294967250
def testLRCCase14(): assert lrc(range(100), 32, COMPLEMENT_NONE) == 4950
def testLRCCase12(): assert lrc(range(100), 16, COMPLEMENT_TWOS) == 60586
def testLRCCase7(self): self.assertEqual(lrc(range(10), 16, COMPLEMENT_NONE), 45)
def testLRCCase12(self): self.assertEqual(lrc(range(100), 16, COMPLEMENT_TWOS), 60586)
def testLRCCase9(self): self.assertEqual(lrc(range(10), 16, COMPLEMENT_ONES), 65490)
def testLRCCase15(self): self.assertEqual(lrc(range(10), 32, COMPLEMENT_ONES), 4294967250)
def testLRCCase11(self): self.assertEqual(lrc(range(10), 16, COMPLEMENT_TWOS), 65491)
def testLRCCase10(): assert lrc(range(100), 16, COMPLEMENT_ONES) == 60585
def testLRCCase14(self): self.assertEqual(lrc(range(100), 32, COMPLEMENT_NONE), 4950)
def testLRCCase6(): assert lrc(range(100), 8, COMPLEMENT_TWOS) == 170
def testLRCCase16(self): self.assertEqual(lrc(range(100), 32, COMPLEMENT_ONES), 4294962345)
def testLRCCase2(self): self.assertEqual(lrc(range(100), 8, COMPLEMENT_NONE), 86)
def testLRCCase18(self): self.assertEqual(lrc(range(100), 32, COMPLEMENT_TWOS), 4294962346)
def testLRCCase8(): assert lrc(range(100), 16, COMPLEMENT_NONE) == 4950