Read/write GD-77 codeplug in Linux in Python 3 (experimental)

OpenGD77CPS
larsks
Posts: 5
Joined: Mon Oct 26, 2020 12:22 pm

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by larsks » Wed Oct 28, 2020 11:35 am

Hey folks,

I was starting down the same path (writing a Linux utility for interacting with the GD77), and it's great to find that other people have already done some development work!

I have a question about the serial port protocol. Looking at the source for the CPS, the sendCommand method (in Extras/OpenGD77/OpenGD77Form.cs) appears to validate commands by checking the response from the radio for:

Code: Select all

((readbuffer[0] == sendbuffer[0]) && (readbuffer[1] == sendbuffer[1]))
I see the same check in the GD77transfer.py script posted in this thread. However, even though the code in GD77transfer.py works (it displays text on the screen and downloads the codeplug), it looks like it only works because it ignores the return value of the sendCommand method. The radio always returns "-", so sendCommand always returns False.

The code in https://github.com/kzyapkov/opengd77xfer solves the problem by just explicitly checking for "-" as a response.

The radio must produce a valid response for CPS, because CPS includes this check:

Code: Select all

if (!sendCommand(0))
{
        displayMessage("Error connecting to the OpenGD77");
        dataObj.responseCode = 1;
        break;
}
...which would only succeed if that validation at the end of sendCommand returns true, but I can't produce this behavior working with the serial communication code in either GD77transfer.py or in https://github.com/kzyapkov/opengd77xfer.

What's going on here?

oh1fss
Posts: 74
Joined: Mon May 04, 2020 11:53 am

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by oh1fss » Wed Nov 18, 2020 4:58 pm

I have extended the program to read/write codeplugs to OpenGD77 radios. Now you can backup the calibration, flash, EEPROM and MCU ROM using the program. I have tested the program in Linux (Fedora 33) using Python 3.9 with Baofeng DM 5R Plus running OpenRD5R.

The old functionality of the previous version (dated 24 May 2020) is intact. All old options work the same.

So to read codeplug from OpenGD77 radios:

./GD77transfer.py -r -f MyCodePlug.g77

and write it back to radio:

./GD77transfer.py -w -f MyCodePlug.g77

The memory segments can be backed up with the following commands:

./GD77transfer.py -o calibration -r -f calibration.bin
./GD77transfer.py -o flash -r -f flash.bin
./GD77transfer.py -o eeprom -r -f eeprom.bin
./GD77transfer.py -o mcurom -r -f mcurom.bin

To restore those files back to radio use the CPS. I have not tested that...

Also I fixed a bug in function initEmptyCodeplug(). The program worked correctly despite of the bug.
Attachments

[The extension tgz has been deactivated and can no longer be displayed.]


W9YA
Posts: 56
Joined: Sun Sep 06, 2020 4:16 am
Location: DM65pd38
Contact:

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by W9YA » Thu Feb 11, 2021 8:48 pm

Great stuff OM...mny tnxs agn !!

es vy 73 de "baab" w9ya

VK3KYY
Posts: 7483
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by VK3KYY » Thu Feb 11, 2021 9:55 pm

oh1fss wrote:
Sun May 24, 2020 9:31 am
CPS (MainForm.cs, function openCodeplugFile()) checks the first 8 bytes of the codeplug file that it opens. Those 8 bytes must be FF or contain the current radio model. Otherwise you get error "Model does not match".

So I should set all gaps that are not read from the radio as FF - is that enough?

Those gaps are not written to the radio.
I don't know.

I reverse engineers the CPS from the official CPS Exe.

You'll need to do whatever makes your code compatible with whatever the CPS code currently does.

The firmware does not check the codeplug in any way.

ok3js
Posts: 9
Joined: Wed Apr 22, 2020 3:15 pm

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by ok3js » Mon Mar 22, 2021 11:00 am

on openGD77 in DM1801 (openSuse Tumbeweeld) GD77TRANSFER-201118

ok3js@install:~/DMR> python3 GD77transfer.py -r -o mcurom -f test.gd77
- reading 0x80000 bytes: 100%
Traceback (most recent call last):
File "GD77transfer.py", line 476, in <module>
main()
File "GD77transfer.py", line 458, in main
getBackup(ser,filename,MODE_READ_MCUROM,0,512*1024,"MCU ROM")
File "GD77transfer.py", line 382, in getBackup
with open(filename,'wb') as f:
PermissionError: [Errno 13] Permission denied: 'test.gd77'


edit:
partially resolved, problem with rights, under root (su) it runs,

edit
error with me, I created a directory under root and the application did not have the right to save to this directory.

W9YA
Posts: 56
Joined: Sun Sep 06, 2020 4:16 am
Location: DM65pd38
Contact:

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by W9YA » Mon Mar 22, 2021 12:45 pm

Um.....it's a bad idea to run as root user. Using sudo is preferred. I do not reqiire either to run GD77transfer.py ! ...... I use my stock archlinux machine for such chores. (Been using it since 2013, with updates to the latest software.)

OE1MWW
Posts: 106
Joined: Sat Oct 17, 2020 2:20 pm
Location: JN88EG
Contact:

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by OE1MWW » Wed Apr 05, 2023 3:53 pm

LZ1CK wrote:
Thu Sep 03, 2020 9:31 pm
The intended usage of the tool looks like this:

Code: Select all

# read from radio into a file
gd77xfer read myradio.gd77 # in the original binary format, or straight
gd77xfer read --format yaml myradio.yml

# export binary into yaml
gd77xfer export input.gd77 output.yaml

## not yet implemented
gd77xfer import edited-codeplug.yaml existing-binary.gd77 

Hi Kiril,

did you have the time & chance to implement the 'import' function ?

73's de OE1MWW
Wolfgang

AF6MQ
Posts: 20
Joined: Thu Jan 09, 2020 4:04 am
Location: CM88DV
Contact:

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by AF6MQ » Wed Jun 07, 2023 11:29 pm

thank you so much for trying to make linux way to read/write CPS.
i am having very strange error when i try to use your script.
first time after i plug in USB cable it goes almost all the way.
subsequent times the error pops up sooner and sooner.
every time after that it crashes sooner and sooner.

Code: Select all

gaspo@mbp13:~/Downloads$ python3 ./GD77transfer.py -r -f t1.g77
 - reading 0x5F20 bytes: 100%
 - reading 0x3B00 bytes: 100%
 - reading 0x13E60 bytes: 51%Traceback (most recent call last):
  File "./GD77transfer.py", line 476, in <module>
    main()
  File "./GD77transfer.py", line 450, in main
    getConfig(ser,filename)
  File "./GD77transfer.py", line 346, in getConfig
    getMemoryArea(ser,buf,MODE_READ_FLASH,  0xB000,0x7b000,0x13E60)
  File "./GD77transfer.py", line 128, in getMemoryArea
    while (ser.in_waiting == 0):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 467, in in_waiting
    s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
OSError: [Errno 5] Input/output error
can you help me understand please?

thanks,

--gaspo.

AF6MQ
Posts: 20
Joined: Thu Jan 09, 2020 4:04 am
Location: CM88DV
Contact:

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by AF6MQ » Wed Jun 07, 2023 11:34 pm

so for grins i changed "SERIAL_WAIT_SLEEP" from 0.0 to 0.001 and now i get 4x 100% and i can open the saved file in CPS ok. however, the radio is stuck on "CPS reading codeplug" ???

i had to remove battery to reset radio as i had suspend=on.

i would like to understand before i try to write the codeplug back.



--gaspo.

KD0RK
Posts: 14
Joined: Mon Nov 13, 2023 5:46 pm

Re: Read/write GD-77 codeplug in Linux in Python 3 (experimental)

Post by KD0RK » Tue Nov 14, 2023 2:39 pm

oh1fss wrote:
Wed Nov 18, 2020 4:58 pm
I have extended the program to read/write codeplugs to OpenGD77 radios. Now you can backup the calibration, flash, EEPROM and MCU ROM using the program. I have tested the program in Linux (Fedora 33) using Python 3.9 with Baofeng DM 5R Plus running OpenRD5R.
Any chance I can get a copy of this program? It's no longer available on the forum.

Thanks!

Post Reply