Ejemplo n.º 1
0
 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()
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
 def testLRCCase5(self):
     self.assertEqual(lrc(range(10), 8, COMPLEMENT_TWOS), 211)
Ejemplo n.º 7
0
 def testLRCCase6(self):
     self.assertEqual(lrc(range(100), 8, COMPLEMENT_TWOS), 170)
Ejemplo n.º 8
0
def testLRCCase9():
    assert lrc(range(10), 16, COMPLEMENT_ONES) == 65490
Ejemplo n.º 9
0
 def testLRCCase4(self):
     self.assertEqual(lrc(range(100), 8, COMPLEMENT_ONES), 169)
Ejemplo n.º 10
0
def testLRCCase11():
    assert lrc(range(10), 16, COMPLEMENT_TWOS) == 65491
Ejemplo n.º 11
0
 def testLRCCase17(self):
     self.assertEqual(lrc(range(10), 32, COMPLEMENT_TWOS), 4294967251)
Ejemplo n.º 12
0
def testLRCCase18():
    assert lrc(range(100), 32, COMPLEMENT_TWOS) == 4294962346
Ejemplo n.º 13
0
 def testLRCCase10(self):
     self.assertEqual(lrc(range(100), 16, COMPLEMENT_ONES), 60585)
Ejemplo n.º 14
0
def testLRCCase16():
    assert lrc(range(100), 32, COMPLEMENT_ONES) == 4294962345
Ejemplo n.º 15
0
def testLRCCase17():
    assert lrc(range(10), 32, COMPLEMENT_TWOS) == 4294967251
Ejemplo n.º 16
0
def testLRCCase15():
    assert lrc(range(10), 32, COMPLEMENT_ONES) == 4294967250
Ejemplo n.º 17
0
def testLRCCase14():
    assert lrc(range(100), 32, COMPLEMENT_NONE) == 4950
Ejemplo n.º 18
0
def testLRCCase12():
    assert lrc(range(100), 16, COMPLEMENT_TWOS) == 60586
Ejemplo n.º 19
0
 def testLRCCase7(self):
     self.assertEqual(lrc(range(10), 16, COMPLEMENT_NONE), 45)
Ejemplo n.º 20
0
 def testLRCCase12(self):
     self.assertEqual(lrc(range(100), 16, COMPLEMENT_TWOS), 60586)
Ejemplo n.º 21
0
 def testLRCCase9(self):
     self.assertEqual(lrc(range(10), 16, COMPLEMENT_ONES), 65490)
Ejemplo n.º 22
0
 def testLRCCase15(self):
     self.assertEqual(lrc(range(10), 32, COMPLEMENT_ONES), 4294967250)
Ejemplo n.º 23
0
 def testLRCCase11(self):
     self.assertEqual(lrc(range(10), 16, COMPLEMENT_TWOS), 65491)
Ejemplo n.º 24
0
def testLRCCase10():
    assert lrc(range(100), 16, COMPLEMENT_ONES) == 60585
Ejemplo n.º 25
0
 def testLRCCase14(self):
     self.assertEqual(lrc(range(100), 32, COMPLEMENT_NONE), 4950)
Ejemplo n.º 26
0
def testLRCCase6():
    assert lrc(range(100), 8, COMPLEMENT_TWOS) == 170
Ejemplo n.º 27
0
 def testLRCCase16(self):
     self.assertEqual(lrc(range(100), 32, COMPLEMENT_ONES), 4294962345)
Ejemplo n.º 28
0
 def testLRCCase2(self):
     self.assertEqual(lrc(range(100), 8, COMPLEMENT_NONE), 86)
Ejemplo n.º 29
0
 def testLRCCase18(self):
     self.assertEqual(lrc(range(100), 32, COMPLEMENT_TWOS), 4294962346)
Ejemplo n.º 30
0
def testLRCCase8():
    assert lrc(range(100), 16, COMPLEMENT_NONE) == 4950