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 srecord(self, record_type, length, address, data = None): if data is None: data = [] length += self.offset address_bytes = utils.int_to_array(address) checksum = self.checksum(make_list(address_bytes, length, data)) mask = "S%u%02X{0!s}%s%02X".format(self.address_mask) return mask % (record_type, length, address, Writer.hex_bytes(data), checksum)
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
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 compose_row(self, address, length, row): address_checksum = checksums.rotatedXOR( utils.make_list(utils.int_to_array(address), length), 8, checksums.ROTATE_LEFT) data_checksum = checksums.rotatedXOR(row, 8, checksums.ROTATE_LEFT) line = ":{0:04X}{1:02X}{2:02X}{3}{4:02X}".format( address, length, address_checksum, Writer.hex_bytes(row), data_checksum) self.last_address = address + length return line
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
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 == 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): if format_type == DATA: if line.length != len(line.chunk): raise hexfile.InvalidRecordLengthError( "Byte count doesn't match length of actual data.") address_checksum = checksums.rotatedXOR( utils.make_list(utils.int_to_array(line.address), line.length), 8, checksums.ROTATE_LEFT) if line.addrChecksum != address_checksum: raise hexfile.InvalidRecordChecksumError() data_checksum = checksums.rotatedXOR(line.chunk, 8, checksums.ROTATE_LEFT) if line.checksum != data_checksum: raise hexfile.InvalidRecordChecksumError()
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 compose_row(self, address, length, row): checksum = checksums.lrc(utils.make_list(utils.int_to_array(address), length, row), 16, checksums.COMPLEMENT_NONE) line = ";{0:02X}{1:04X}{2!s}{3:04X}".format(length, address, Writer.hex_bytes(row), checksum) return line