예제 #1
0
    def compose_row(self, address, length, row):
        address_checksum = checksums.nibble_sum(
            utils.make_list(utils.int_to_array(address), length))

        data_checksum = checksums.nibble_sum(row)
        line = "/{0:04X}{1:02X}{2:02X}{3!s}{4:02X}".format(
            address, length, address_checksum, Writer.hex_bytes(row),
            data_checksum)
        self.last_address = address + length
        return line
예제 #2
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.")
         addrChecksum = 0
         address_checksum = checksums.nibble_sum(
             utils.make_list(utils.int_to_array(line.address), line.length))
         if line.addrChecksum != address_checksum:
             raise hexfile.InvalidRecordChecksumError()
         checksum = checksums.nibble_sum(line.chunk)
         if line.checksum != checksum:
             raise hexfile.InvalidRecordChecksumError()
예제 #3
0
    def compose_row(self, address, length, row):
        checksum = checksums.nibble_sum(
            utils.make_list(utils.int_to_array(address), 6, ((length + 5) * 2),
                            row))

        line = "%{0:02X}6{1:02X}{2:04X}{3!s}".format((length + 5) * 2,
                                                     checksum, address,
                                                     Writer.hex_bytes(row))
        return line
예제 #4
0
 def check_line(self, line, format_type):
     if format_type == DATA:
         line.length = (line.length / 2) - 5
         checksum = checksums.nibble_sum(
             utils.make_list(utils.int_to_array(line.address), 6,
                             ((line.length + 5) * 2), line.chunk))
         if line.length != len(line.chunk):
             raise hexfile.InvalidRecordLengthError(
                 "Byte count doesn't match length of actual data.")
         if line.checksum != checksum:
             raise hexfile.InvalidRecordChecksumError()
     elif format_type == SYMBOL:
         checksum = checksums.nibble_sum(
             utils.make_list(3, ((line.length + 5) * 2),
                             [ord(b) for b in line.chunk]))
         chunk = line.chunk.strip()
         address = int(chunk[-4:], 16)
         line.address = address
예제 #5
0
def testNibbleSumCase1():
    assert nibble_sum(range(10)) == 45
예제 #6
0
def testNibbleSumCase2():
    assert nibble_sum(range(100)) == 222
예제 #7
0
 def compose_footer(self, meta):
     return "/{0:04X}00{1:02X}".format(
         self.last_address,
         checksums.nibble_sum(utils.int_to_array(self.last_address)))
 def testNibbleSumCase1(self):
     self.assertEqual(nibble_sum(range(10)), 45)
 def testNibbleSumCase2(self):
     self.assertEqual(nibble_sum(range(100)), 222)