Project

General

Profile

Actions

DevelopersAdd a Radio » History » Revision 4

« Previous | Revision 4/23 (diff) | Next »
Aaron P, 01/23/2017 06:36 PM
Add links for Wireshark and USBPcap


h1. Add a Radio

You've got a radio that's not in Chirp, a little bit of software development experience, and you want to add that radio to Chirp. Here's what you'll need:

h2. Setting up the development environment

Most Chirp contributors develop in Ubuntu Linux. Mainly, because we're lazy. Ubuntu comes with almost everything needed to develop for Chirp: Python, PyGTK, and a text editor. The one missing piece is Mercurial, for source code management.

To install Mercurial:

sudo apt-get install mercurial

If you've never used Mercurial before, please read DevelopersProcess. Actually, even if you have used Mercurial, that's a good document to read. It describes how to get the Chirp source code and generate a patch in the required format for inclusion in Chirp.

If you want to develop in another operating system, you're on your own. This guide isn't going to cover it. Here's a guide for Windows: DevelopersWin32Environment.

h2. Look over some existing code

Read source:chirp/drivers/template.py. The whole thing.

h2. Write the download/upload routines

h3. Sniffing the protocol used by existing software

If you have other programming software for your radio, such as the software from the manufacturer, you can sniff the serial programming protocol with "Portmon":http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx. Typically, radio programming software is written for Windows, and Portmon is a Windows utility.

For recent versions of Windows, you might try sniffing USB with "USBPcap":http://desowin.org/usbpcap/. The captured data is analysed with any recent version of "Wireshark":http://www.wireshark.org.

Start with a read.

Click Read in the official software

Watch the output of Portmon after you click Read

Look for a line that sets the BAUD RATE. Sometimes there are a few of them.

Look for a WRITE line with a few data bytes. This is probably the command to tell the radio to start sending data.

Look for READ lines with lots of data bytes after them. This is probably the memory contents of the radio being downloaded

You're a smart developer. You should be able to figure out the protocol from here!

h3. Using existing Chirp code

If the radio you're developing for doesn't have existing programming software, you won't be able to use the above reverse engineering technique. Most radio manufacturers use a common protocol across most of their radios. Because Chirp supports so many manufacturers, there's a chance an existing radio driver has a download routine that will work with your new radio. This is especially true with Yaesu, which don't really even have a protocol. They just dump their memory. All you need to figure out is the baud rate and the memory size (and baud rate is usually 9600).

Choose a radio driver that you think might be similar. If you were going to add the VX9, you might start with the VX8 driver:

cd chirp.hg/chirp
sed s/VX8/VX9/g vx8.py > vx9.py

Increase the @_memsize@ variable significantly. The goal is to read more data than the radio sends.

Launch Chirp and start a download with your new radio driver. Did it work, sort of? Save the .img.

Now we're going to determine the @_memsize@. Open the .img in a hex editor:

hexdump -C VX9_oversize.img | less

Look towards the end of the file for the offset where the data becomes all zeros. This is your @_memsize@. The radio has stopped sending data, but Chirp was still "reading". Change @_memsize@ in your driver so that Chirp reads the same number of bytes the radio is sending.

h2. Map the memory blob

To map the memory layout, you're going to make a small change on the radio, do a download, then look for differences. Do this over and over until you have the whole memory layout mapped.

Here's a little helper script I use for the comparisons:

@hexdiff.sh:@

#!/bin/sh

A=`mktemp`
B=`mktemp`

hexdump -C $1 > $A
hexdump -C $2 > $B
diff $A $B | less
rm $A $B

Find the first channel

Find the second channel

The offset between the two is your memory channel struct size

Find the last channel. Hopefully its offset is struct size * advertised number of channels away from the first channel!

You'll probably start off with something like this:

MEM_FORMAT = """
#seekto 0xb00;
struct {
  u32 freq;
  u8 unknown1;
  u8 unknown2;
  u8 unknown3;
  char name[8];
} memory[200];
"""

@0xb00@ is the location of the first memory channel.
@200@ is the number of channels the radio supports.
@unknown1@, @unknown2@, and @unknown3@ are for memory-specific settings (e.g., tone) that you haven't sussed out yet.

h2. Write @get_memory()@

h2. Write @set_memory()@

h2. Submit code to chirp_devel

Send a hg patch to the developer mailing list for review. We'll pick it apart and give you a list of things that can be improved before inclusion in Chirp. Don't take it personally! Our goal is to produce high quality software through peer review.

h2. Pass testing

More detail on this in DevelopersProcess. In summary, create a test image in tests/images, make sure all tests pass, and attach the test image to your tracker issue for the new model.

Updated by Aaron P about 7 years ago · 4 revisions