Page 1 of 2

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

Posted: Thu May 21, 2020 3:07 pm
by oh1fss
I have written a program in Python 3 to read and write GD-77 codeplug in Linux.

I have tested this program only with my own GD-77. Before trying this make backups!

Usage:

$ ./GD77transfer.py -h
GD-77 Data Transfer v0.0.4
Usage: GD77transfer.py [OPTION]

-h, --help : Display this help text,
-r, --read : Read config (codeplug) from radio,
-w, --write : Write config (codeplug) to radio,
-d, --device=<device> : Use the specified device as serial port,
-f, --filename=<filename> : Config (codeplug) file name,

To read a codeplug:

$ ./GD77transfer.py -r -f turha.g77
- reading 0x5F20 bytes: 100%
- reading 0x3B00 bytes: 100%
- reading 0x13E60 bytes: 100%
- reading 0x11A0 bytes: 100%

To write a codeplug:

$ ./GD77transfer.py -w -f Gd77Plug_OH1FSS_v1_33.g77
- eepromming 0x5F20 bytes: 100%
- eepromming 0x3B00 bytes: 100%
- flashing 0x13E60 bytes: 100%
- flashing 0x11A0 bytes: 100%

73 OH1FSS

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

Posted: Thu May 21, 2020 9:25 pm
by VK3KYY
Thanks

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

Posted: Sun May 24, 2020 6:14 am
by VK3KYY
I think there are some bugs.

I tried to read the codeplug from my radio, and it took a very long time, and the file could not be opened by the CPS because its not in the correct format.

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

Posted: Sun May 24, 2020 6:29 am
by VK3KYY
I found the reason its slow

Change the sleep time to zero while waiting for a response from the radio, otherwise all the sleeps of 0.2S adds up to a lot of sleeping

BTW. I tried also to increase the baud rate, but this value makes no difference at all, because its ignored by the OpenGD77 as its a virtual serial device not a real one.

I still don't know what the data in the codeplug is file that I read from the radio is incorrect

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

Posted: Sun May 24, 2020 6:53 am
by Riku
heya,
i suggest change serial module to HID device, as serial don't work on darwin.
Something like firmware upgrade tool here on this topic viewtopic.php?f=16&t=826
it works now on multiple operating system (also on OSX) after changing the module to hid.
more info about hid here: https://github.com/apmorton/pyhidapi

Code: Select all

% python3 GD77transfer.py -r -d /dev/tty.usbmodem14101 -f test.g77
Traceback (most recent call last):
  File "GD77transfer.py", line 405, in <module>
    main()
  File "GD77transfer.py", line 391, in main
    ser = serialInit(serialDev)
  File "GD77transfer.py", line 63, in serialInit
    ser = serial.Serial()
AttributeError: module 'serial' has no attribute 'Serial'
riku

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

Posted: Sun May 24, 2020 7:12 am
by F1RMB
Hi,
Riku wrote:
Sun May 24, 2020 6:53 am
heya,
i suggest change serial module to HID device, as serial don't work on darwin.
Something like firmware upgrade tool here on this topic viewtopic.php?f=16&t=826
it works now on multiple operating system (also on OSX) after changing the module to hid.
more info about hid here: https://github.com/apmorton/pyhidapi

Code: Select all

% python3 GD77transfer.py -r -d /dev/tty.usbmodem14101 -f test.g77
Traceback (most recent call last):
  File "GD77transfer.py", line 405, in <module>
    main()
  File "GD77transfer.py", line 391, in main
    ser = serialInit(serialDev)
  File "GD77transfer.py", line 63, in serialInit
    ser = serial.Serial()
AttributeError: module 'serial' has no attribute 'Serial'
riku
I highly doubt Serial communication doesn't work on Darwin, or any *nix. I would trust that there are some specific things needed, because Apple loves to break things, but nothing more.
Also, the firmware uses CDC universal class, while in non bootloader mode, for good reasons. Changing everything back to USB HID will breaks CPS and Hotspot.
After 2 minutes of googling, using something like pyserial might enables multiplatform support.

Cheers.
---
Daniel

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

Posted: Sun May 24, 2020 8:00 am
by Riku
serial works on darwin, sorry my bad, needed module was pyserial instead "serial"
resolved this with juhani, talked with him :)
read works now.

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

Posted: Sun May 24, 2020 8:48 am
by oh1fss
VK3KYY wrote:
Sun May 24, 2020 6:29 am
I still don't know what the data in the codeplug is file that I read from the radio is incorrect
I copied the logic for reading the codeplug from GD-77 from function worker_DoWork(), case READ_CODEPLUG in file OpenGD77Form.cs. That piece of code leaves gaps in the codeplug file:

Code: Select all

def getMemoryArea(ser,buf,mode,bufStart,radioStart,length):
    getMemoryArea(ser,buf,MODE_READ_EEPROM, 0x00E0, 0x00E0, 0x5f20)
    getMemoryArea(ser,buf,MODE_READ_EEPROM, 0x7500, 0x7500, 0x3B00)
    getMemoryArea(ser,buf,MODE_READ_FLASH,  0xB000,0x7b000,0x13E60)
    getMemoryArea(ser,buf,MODE_READ_FLASH, 0x1EE60,0x00000, 0x11A0)
My program leaves those gaps zeroed, maybe that's why CPS complains about it.

So I have to hunt *.cs to find out how to invent something valid into those gaps...

73, OH1FSS

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

Posted: Sun May 24, 2020 9:04 am
by F1RMB
Hi,
oh1fss wrote:
Sun May 24, 2020 8:48 am
VK3KYY wrote:
Sun May 24, 2020 6:29 am
I still don't know what the data in the codeplug is file that I read from the radio is incorrect
I copied the logic for reading the codeplug from GD-77 from function worker_DoWork(), case READ_CODEPLUG in file OpenGD77Form.cs. That piece of code leaves gaps in the codeplug file:

Code: Select all

def getMemoryArea(ser,buf,mode,bufStart,radioStart,length):
    getMemoryArea(ser,buf,MODE_READ_EEPROM, 0x00E0, 0x00E0, 0x5f20)
    getMemoryArea(ser,buf,MODE_READ_EEPROM, 0x7500, 0x7500, 0x3B00)
    getMemoryArea(ser,buf,MODE_READ_FLASH,  0xB000,0x7b000,0x13E60)
    getMemoryArea(ser,buf,MODE_READ_FLASH, 0x1EE60,0x00000, 0x11A0)
My program leaves those gaps zeroed, maybe that's why CPS complains about it.

So I have to hunt *.cs to find out how to invent something valid into those gaps...

73, OH1FSS
I didn't checked your Python script, but maybe that's the problem, as unused bytes should be 0xFF and not 0x0.


Cheers.
---
Daniel

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

Posted: Sun May 24, 2020 9:31 am
by oh1fss
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.