1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
7 f = io.open(filename, "r")
11 raise Exception("Hex file has a line not starting with ':'")
12 recLen = int(line[1:3], 16)
13 addr = int(line[3:7], 16) + extraAddr
14 recType = int(line[7:9], 16)
15 if len(line) != recLen * 2 + 11:
16 raise Exception("Error in hex file: " + line)
18 for i in xrange(0, recLen + 5):
19 checkSum += int(line[i*2+1:i*2+3], 16)
22 raise Exception("Checksum error in hex file: " + line)
24 if recType == 0:#Data record
25 while len(data) < addr + recLen:
27 for i in xrange(0, recLen):
28 data[addr + i] = int(line[i*2+9:i*2+11], 16)
29 elif recType == 1: #End Of File record
31 elif recType == 2: #Extended Segment Address Record
32 extraAddr = int(line[9:13], 16) * 16
34 print(recType, recLen, addr, checkSum, line)