Project

General

Profile

DevelopersAdd a Radio » History » Version 8

Daniel Clemmensen, 03/18/2019 08:31 AM
Note that the template is for clone mode and is less applicable to live mode.

1 1 Tom Hayward
h1. Add a Radio
2
3
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:
4
5
* a subscription to the "chirp_devel mailing list":http://intrepid.danplanet.com/mailman/listinfo/chirp_devel
6
* a Python + PyGTK development environment
7
* radio
8
* programming cable
9
10
h2. Setting up the development environment
11
12
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.
13
14
To install Mercurial:
15
16
  sudo apt-get install mercurial
17
18
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.
19
20
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]].
21
22
h2. Look over some existing code
23
24 3 Aaron P
Read source:chirp/drivers/template.py. The whole thing.
25 1 Tom Hayward
26 8 Daniel Clemmensen
This serves as a starting point for understanding the structure of a driver for a radio that operates in "clone mode", which is by far the most common type of radio and CHIRP driver. If your radio will operate in "live mode", and especially if your radio uses the CAT protocol, you should probably start by reading source:chirp/drivers/kenwood_live.py.
27
28 1 Tom Hayward
h2. Write the download/upload routines
29
30
h3. Sniffing the protocol used by existing software
31
32 4 Aaron P
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.
33
34
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.
35 1 Tom Hayward
36
Start with a read.
37
38
# Click Read in the official software
39
# Watch the output of Portmon after you click Read
40
# Look for a line that sets the BAUD RATE. Sometimes there are a few of them.
41
# Look for a WRITE line with a few data bytes. This is probably the command to tell the radio to start sending data.
42
# Look for READ lines with lots of data bytes after them. This is probably the memory contents of the radio being downloaded
43
# You're a smart developer. You should be able to figure out the protocol from here!
44
45 5 Daniel Clemmensen
You can also sniff a many Windows programs by running them in the Wine environment under Linux. Manufacturers' radio programming software is likely to run in this environment. See [[DevelopersUSB Sniffing in Linux]].
46
47 1 Tom Hayward
h3. Using existing Chirp code
48
49 6 Daniel Clemmensen
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 radios (other than the FT-4/FT-65 family), 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).
50 1 Tom Hayward
51
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:
52
53
 cd chirp.hg/chirp
54
sed s/VX8/VX9/g vx8.py > vx9.py
55
56
Increase the @_memsize@ variable significantly. The goal is to read more data than the radio sends.
57
58
Launch Chirp and start a download with your new radio driver. Did it work, sort of? Save the .img.
59
60
Now we're going to determine the @_memsize@. Open the .img in a hex editor:
61
62
 hexdump -C VX9_oversize.img | less
63
64
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.
65
66
h2. Map the memory blob
67
68
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.
69
70
Here's a little helper script I use for the comparisons:
71
72
@hexdiff.sh:@
73
<pre>
74
#!/bin/sh
75
76
A=`mktemp`
77
B=`mktemp`
78
79
hexdump -C $1 > $A
80
hexdump -C $2 > $B
81
diff $A $B | less
82
rm $A $B
83
</pre>
84
85
# Find the first channel
86
# Find the second channel
87
# The offset between the two is your memory channel struct size
88
# Find the last channel. Hopefully its offset is struct size * advertised number of channels away from the first channel!
89
90
You'll probably start off with something like this:
91
<pre>
92
MEM_FORMAT = """
93
#seekto 0xb00;
94
struct {
95
  u32 freq;
96
  u8 unknown1;
97
  u8 unknown2;
98
  u8 unknown3;
99
  char name[8];
100
} memory[200];
101
"""
102
</pre>
103
@0xb00@ is the location of the first memory channel.
104
@200@ is the number of channels the radio supports.
105
@unknown1@, @unknown2@, and @unknown3@ are for memory-specific settings (e.g., tone) that you haven't sussed out yet.
106
107
h2. Write @get_memory()@
108
109
h2. Write @set_memory()@
110
111
h2. Submit code to chirp_devel
112
113
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.
114 2 Brian Dickman
115
h2. Pass testing
116
117
More detail on this in [[DevelopersProcess#Testing]]. 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.
118 7 Daniel Clemmensen
119
While a test image may be any valid image file for your radio, be aware that this image file becomes part of the CHIRP test suite and will be distributed to anyone who downloads the CHIRP repository. Do not include an image with passwords, callsigns, or frequency lists that you do not wish to make public. A "factory reset" image is acceptable.