Function added to write a radio eeprom hexdump file.

This commit is contained in:
Kai Lauterbach 2024-04-19 18:54:13 +02:00
parent a2a7d18fcd
commit 75ee72e1b9

View file

@ -58,6 +58,8 @@ DEBUG_SHOW_OBFUSCATED_COMMANDS = False
# might be useful for someone debugging some obscure memory issue
DEBUG_SHOW_MEMORY_ACTIONS = False
DEBUG_WRITE_RADIO_HEXDUMP = True
MEM_FORMAT = """
#seekto 0x0000;
struct {
@ -626,9 +628,37 @@ def do_download(radio):
else:
raise errors.RadioError("Memory download incomplete")
if DEBUG_WRITE_RADIO_HEXDUMP:
hex_data = _convert_to_intel_hex(eeprom)
_save_to_hex_file(hex_data, "radio_dump.hex")
return memmap.MemoryMapBytes(eeprom)
def _convert_to_intel_hex(data):
hex_data = ""
for i in range(0, len(data), 16):
chunk = data[i:i+16]
hex_data += ":"
hex_data += format(len(chunk), "02X")
hex_data += format(i >> 8, "04X")
hex_data += format(i & 0xFF, "02X")
hex_data += "00"
for byte in chunk:
hex_data += format(byte, "02X")
checksum = (len(chunk) + (i >> 8) + (i & 0xFF)) & 0xFF
checksum = ((~checksum) + 1) & 0xFF
hex_data += format(checksum, "02X")
hex_data += "\n"
hex_data += ":00000001FF" # End of file record
return hex_data
def _save_to_hex_file(data, filename):
with open(filename, "w") as f:
f.write(data)
def do_upload(radio):
serport = radio.pipe
serport.timeout = 0.5