I want to convert the integer 259 to an IntelHex formatted file using Python3. I found the IntelHex python package and tried getting it to do the job but I failed miserably when it comes to the correct byte count.
This is my integer in bytes, already with an CRC16 checksum behind it:
temp = b'\x03\x01\x00\x00\x99\xc5
(short version, but: type(temp) -> bytes
Now I added 128 - 6 = 122 Bytes to it and I used the IntelHex Python package on it:
ih = IntelHex()
ih.frombytes(temp)
ih.tofile('EEPROM.hex', format='hex')
My EEPROM.hex file looks correct formatted (correct checksum and so on), but it has wrong entries on the bytes count for example. Here is what it should look like:
:204000000300000099C500000000000000000000000000000000000000000000000000003F
:20402000000000000000000000000000000000000000000000000000000000000000000080
:20404000000000000000000000000000000000000000000000000000000000000000000060
:20406000000000000000000000000000000000000000000000000000000000000000000040
:00000001FF
and here is what I got:
:100000000301000099C5000000000000000000008E
:1000100000000000000000000000000000000000E0
:1000200000000000000000000000000000000000D0
:1000300000000000000000000000000000000000C0
:1000400000000000000000000000000000000000B0
:1000500000000000000000000000000000000000A0
:100060000000000000000000000000000000000090
:100070000000000000000000000000000000000080
:00000001FF
The problem is, I did not find any options in the IntelHex package to take care of these leading bytes. Anyone else got an idea?
Edit: I also need a hint on how to set it to inthex 32 as my code right now produces a 16Bit aligned output.