Exemplo n.º 1
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
Exemplo n.º 2
0
 def srecord(self, recordType, length, address, data=None):
     if data is None:
         data = []
     length += self.offset
     addressBytes = utils.intToArray(address)
     checksum = self.checksum(makeList(addressBytes, length, data))
     mask = "S%u%02X{0!s}%s%02X".format(self.addressMask)
     return mask % (recordType, length, address, Writer.hexBytes(data),
                    checksum)
Exemplo n.º 3
0
    def composeRow(self, address, length, row):
        checksum = checksums.nibbleSum(
            utils.makeList(utils.intToArray(address), 6, ((length + 5) * 2),
                           row))

        line = "%{0:02X}6{1:02X}{2:04X}{3!s}".format((length + 5) * 2,
                                                     checksum, address,
                                                     Writer.hexBytes(row))
        return line
Exemplo n.º 4
0
 def checkLine(self, line, formatType):
     if formatType == DATA:
         if line.length != len(line.chunk):
             raise hexfile.InvalidRecordLengthError(
                 "Byte count doesn't match length of actual data.")
         checksum = checksums.lrc(
             utils.makeList(utils.intToArray(line.address), line.length,
                            line.chunk), 16, checksums.COMPLEMENT_NONE)
         if line.checksum != checksum:
             raise hexfile.InvalidRecordChecksumError()
Exemplo n.º 5
0
 def checkLine(self, line, formatType):
     if formatType == DATA:
         if line.length != len(line.chunk):
             raise hexfile.InvalidRecordLengthError("Byte count doesn't match length of actual data.")
         addressChecksum = checksums.rotatedXOR(utils.makeList(utils.intToArray(line.address), line.length), 8, checksums.ROTATE_LEFT)
         if line.addrChecksum != addressChecksum:
             raise hexfile.InvalidRecordChecksumError()
         dataChecksum = checksums.rotatedXOR(line.chunk, 8, checksums.ROTATE_LEFT)
         if line.checksum != dataChecksum:
             raise hexfile.InvalidRecordChecksumError()
Exemplo n.º 6
0
 def composeRow(self, address, length, row):
     tmp = 0  # TODO: format type!?
     checksum = checksums.lrc(
         utils.makeList(tmp, length + 4, utils.intToArray(address), row), 8,
         checksums.COMPLEMENT_TWOS)
     if length < self.rowLength:
         lengthToPad = self.rowLength - length
         padding = [0] * (lengthToPad)
         row.extend(padding)
     line = "{0:02X}{1}0000{2:08X}{3}".format(checksum, length - 2, address,
                                              Writer.hexBytes(row))
     return line
Exemplo n.º 7
0
 def checkLine(self, line, formatType):
     if formatType == DATA:
         line.length = (line.length / 2) - 5
         checksum = checksums.nibbleSum(
             utils.makeList(utils.intToArray(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 formatType == SYMBOL:
         checksum = checksums.nibbleSum(
             utils.makeList(3, ((line.length + 5) * 2),
                            [ord(b) for b in line.chunk]))
         chunk = line.chunk.strip()
         address = int(chunk[-4:], 16)
         line.address = address
Exemplo n.º 8
0
 def checkLine(self, line, formatType):
     if formatType == EOF:
         return True
     line.length -= 4
     if line.length != len(line.chunk):
         line.chunk = line.chunk[:line.length]  # Cut padding.
     if formatType == DATA_ABS:
         tmp = 0
         self.lastAddress = line.address + line.length
     elif formatType == DATA_INC:
         tmp = 1
         line.address = self.lastAddress
     elif formatType == DATA_REL:
         self.error("relative adressing not supported.")
         tmp = 2
     else:
         self.error("Invalid format type: '{0}'".format(formatType))
         tmp = 0
     checksum = checksums.lrc(
         utils.makeList(tmp, line.length + 4,
                        utils.intToArray(line.address), line.chunk), 8,
         checksums.COMPLEMENT_TWOS)
     if line.checksum != checksum:
         raise hexfile.InvalidRecordChecksumError()
Exemplo n.º 9
0
 def composeRow(self, address, length, row):
     addressChecksum = checksums.rotatedXOR(utils.makeList(utils.intToArray(address), length), 8, checksums.ROTATE_LEFT)
     dataChecksum = checksums.rotatedXOR(row, 8, checksums.ROTATE_LEFT)
     line = ":{0:04X}{1:02X}{2:02X}{3}{4:02X}".format(address, length, addressChecksum, Writer.hexBytes(row), dataChecksum)
     self.lastAddress = address + length
     return line