davidmpye / RT73-utils

GNU General Public License v3.0
3 stars 2 forks source link

Support latest Radioddity DB25-D firmware #11

Open clewisit opened 1 year ago

clewisit commented 1 year ago

Any chance this can be updated to support the new versions of Radioddity firmware? It currently crashes when reading the codeplug from the radio.

DavidB445 commented 1 year ago

More info on how it crashed would help.

However.. In recent firmware, the Firmware ID has changed so that it is longer than it was originally. Meaning that reading 103 bytes is now not enough, so it's leaving bytes in the buffer that are then being added to the start of the codeplug bytearray. Which shifts all the bytes by however many bytes were left in the buffer, resulting in a 'corrupt' codeplug_bin and none of the addresses being correct.

response = port.read(103)

You could update the port.read with the correct number of bytes but it may change again so a quick fix without much code changes would be to add the following lines to the download/upload functions. After checking the response, but before reading any codeplug bytes from the radio.

port.reset_input_buffer()
port.reset_output_buffer()

Doing so will clear any unread bytes from the buffers before reading the codeplug bytes. Adding just those 2 lines to the functions means you don't really have to worry about the length of the response, since all you really need to know is that the radio responded.

e.g in 'downloadCodeplug' add them before getting the num_pages value.

        .....
        response = port.read(103)
        if len(response) <= 1:
            print("Timeout: No Response...")
            sys.exit(1)
        else:
            print("Success: Begin Download...")

        if debug_level == 4:
            print("Message rx from plug download handshake:")
            print(response)
            for i in range(len(response)):
                print(hex(response[i]) + " ",end='')

        port.reset_input_buffer()
        port.reset_output_buffer()

        num_pages = response[18] + response[20]
        .....

You'd need to add the lines to the uploadCodeplug function and the others. Since when uploading a codeplug you need to read 5 bytes which will either be "Write" or "Check".. so if there is unread bytes in the buffer from the initial read, it would fail after writing the first block as the 5 byte response would not be "Write".

clewisit commented 1 year ago

Sorry, I meant to get this back to you earlier. reading from the radio works, but it looks like decompiling fails.

Reading Block 67 of 67 Download Complete... Traceback (most recent call last): File "/usr/local/bin/rt73", line 1244, in json = decompileCodeplug(data) File "/usr/local/bin/rt73", line 602, in decompileCodeplug if msg_str != "": UnboundLocalError: local variable 'msg_str' referenced before assignment