Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def addArea(self, startaddress, data, insertFirst=False):
#self.areas.append(IntelHexArea(startaddress, data))
if (insertFirst):
self.areas = [IntelHexArea(startaddress, data)] + self.areas
else:
#order by start address
self.areas = insertAreaSorted(self.areas, IntelHexArea(startaddress, data))
if len(data) == 0:
continue
if data[0] != ':':
raise Exception("Invalid data at line %d" % lineNumber)
data = bytearray.fromhex(data[1:])
count = data[0]
address = (data[1] << 8) + data[2]
recordType = data[3]
if recordType == 0x00:
if startZone == None:
raise Exception("Data record but no zone defined at line " + str(lineNumber))
if startFirst == None:
startFirst = address
current = startFirst
if address != current:
self._addArea(IntelHexArea((startZone << 16) + startFirst, zoneData))
zoneData = b''
startFirst = address
current = address
zoneData += data[4:4 + count]
current += count
if recordType == 0x01:
if len(zoneData) != 0:
self._addArea(IntelHexArea((startZone << 16) + startFirst, zoneData))
zoneData = b''
startZone = None
startFirst = None
current = None
if recordType == 0x02:
raise Exception("Unsupported record 02")
if recordType == 0x03:
raise Exception("Unsupported record 03")
def addArea(self, startaddress, data, insertFirst=False):
#self.areas.append(IntelHexArea(startaddress, data))
if (insertFirst):
self.areas = [IntelHexArea(startaddress, data)] + self.areas
else:
#order by start address
self.areas = insertAreaSorted(self.areas, IntelHexArea(startaddress, data))
raise Exception("Unsupported record 02")
if recordType == 0x03:
raise Exception("Unsupported record 03")
if recordType == 0x04:
if len(zoneData) != 0:
self._addArea(IntelHexArea((startZone << 16) + startFirst, zoneData))
zoneData = b''
startZone = None
startFirst = None
current = None
startZone = (data[4] << 8) + data[5]
if recordType == 0x05:
self.bootAddr = ((data[4]&0xFF) << 24) + ((data[5]&0xFF) << 16) + ((data[6]&0xFF) << 8) + (data[7]&0xFF)
#tail add of the last zone
if len(zoneData) != 0:
self._addArea(IntelHexArea((startZone << 16) + startFirst, zoneData))
zoneData = b''
startZone = None
startFirst = None
current = None
file.close()