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()
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()
def check_line(self, line, format_type): # todo: Fkt.!!! if format_type in (S0, S1, S5, S9): checksum_of_address = ( (line.address & 0xff00) >> 8) + (line.address & 0xff) elif format_type in (S2, S8): checksum_of_address = ((line.address & 0xff0000) >> 16) + ( (line.address & 0xff00) >> 8) + (line.address & 0xff) elif format_type in (S3, S7): checksum_of_address = (((line.address & 0xff000000) >> 24) + ((line.address & 0xff0000) >> 16) + ((line.address & 0xff00) >> 8) + (line.address & 0xff)) else: raise TypeError("Invalid format type '{0!s}'.".format(format_type)) if hasattr(line, 'chunk'): checksum = (~(sum([line.length, checksum_of_address]) + sum(line.chunk))) & 0xff else: checksum = (~(sum([line.length, checksum_of_address]))) & 0xff if line.checksum != checksum: raise hexfile.InvalidRecordChecksumError() line.length -= BIAS[format_type] # calculate actual data length. if hasattr( line, 'chunk') and line.length and (line.length != len(line.chunk)): raise hexfile.InvalidRecordLengthError( "Byte count doesn't match length of actual data.")
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 check_line(self, line, format_type): if line.length != len(line.chunk): raise hexfile.InvalidRecordLengthError("Byte count doesn't match length of actual data.") # todo: factor out checksum calculation from line!!! checksum = (sum(line.chunk) & 0xffff) if line.checksum != checksum: raise hexfile.InvalidRecordChecksumError()
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 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
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()