13/09/2016

Reverse engineering the Puxing PX888K programming format (2: Making sense of the data)

I have found out that the reverse engineering was the easy part. It should however come as no surprise, since if communications protocol and data format are simple, and they are, the whole thing becomes a iterative process of changing a single setting to a new value, and diff the old communications dump against the new, to see what bits have changed.

Using jpnevulator to listen in on the data transfer between the stock software and the radio, the program can listen to multiple serial ports at the same time, and neatly display which port sends what when. This way the back and forth between the stock software and the radio can be easily viewed and the protocol is quickly figured out. There is a short initial handshake in the beginning, followed by either reading or writing the whole image in chunks of 64 bytes.
The protocol, but just as much an image to break the text
The next step was to implement a few scripts that could play the part of the radio, but dump the memory written to an image file, instead of writing to the radio each time, and reverse engineer from the snooped data which contains the communications commands which, we are no longer interested in. The script can also read from an image file, making it possible to poke at the bits and see what changes in the stock software. Functions for reading and writing to the radio are also implemented, which is useful since the stock software does not cover all settings available on the radio. The scripts are available on github.

After a data communications failure, it also became apparent that there are features not available in the stock software I had, as well as the radio: Something went wrong and I found myself with a radio with a locked keypad. It turns out that this is a feature rather than a bug, and a newer version of the stock software includes the possibility of changing this setting. The new software version also makes the feature Relay without disable tail available, which I have no idea what it does, and I can't find it documented anywhere. The closest thing I have found when searching is that it may enable or disable Squelch tail elimination, but I don't have the equipment to test this feature currently.

Another setting that is poorly documented is Wait time which can be set to 0.3, 0.5 or any integer in the range 1-12. I do not know what it is waiting for. It does not seem to be any of backlight timeout, keypad lock timeout, or any delay regarding when PTT ID or other data signals are sent. Possibly it could have something to do with when the battery save functionality sets in, but I don't know how to test this reliably. A bit of keyword searching lead me to a French forum which hinted at, and is corroborated with my own following tests, that it is how long it waits in before it resumes scanning, when using carrier based scanning.

A bigger challenge, the "but" continuation of the "easy" in the beginning of this text is writing a CHIRP plugin. It would be easy enough to pour data between a csv file tailored for this radio, and this radio only, and the binary image would be easy. It is a different matter entirely to fit this into a system that also needs to cover how other radios work, and what their features are. But the point of doing this is to make it possible to copy settings between radios that would otherwise be each programmed by their own software platform, all incompatible with each other. I can certainly get behind that kind of endeavor. Another part is that doing this project with the goal of writing a CHIRP plugin is probably the best way to have it reach other users of this particular model and have them benefit.

10/09/2016

Reverse engineering the Puxing PX888K programming format (1: The joy of soldering)

A while ago I bought a Puxing PX888K VHF+UHF radio HT. Like for many other radios, it's possible to change the configuration from a computer. Like for many others, the program is severely lacking in polish and only available for windows. To its defense though, it works more or less as good (or bad) running it through wine on Linux, as it does on windows. But it offers nothing like export/import CSV, or even though the channel list looks like an Excel sheet, it is not possible to copy or paste rows.

The perhaps default open-source radio programming software distribution CHIRP does not at this time support this radio model. Maybe, if I'm successful in my work, that can be changed.

First things first. To decode the data, I need to get the data. To get the data I need to listen on the communication wires, so a junction box was built. Given that I'm building with what I find in my parts bins, rather than routing a proper board and ordering parts, the final result does perhaps look more grown than designed. ...And that's not really false marketing.

junction box and schematic junction box back
The amount of switches comes from the fact that one of the serial cables I use for snooping is straight, while the other is a null modem cable, as I wrote, I'm working with what I have here.
Also, I want to keep my options open.

Since the radio is programmed with 5V signals, and the snooping ports work at RS232 levels, a level converter is needed. Again, lots of switches for connectivity options, and mixing SMT and through-hole devices oh my.

level converter and
simplified schematic
level converter back
A quick gander with the logic analyzer and a few attempts to read shows that the data is transmitted as regular serial 9600,8,N,1

action shot
To be continued...

06/07/2016

More DMX512 Protocol Interfacing

This spring gave me opportunity to revisit a few old projects, the led bars previously documented, and the hardware I designed earlier for interfacing with DMX512 equipment.


09/06/2014

Interactive Shell Achieved

Success! On the /etc/inittab line normally starting an ash shell instance with the serial port as stdin/out, I have substituted my own binary (gritty, a hack, not complete, caveat emptor and so on) which identifies which /dev/input/event* is a keyboard and starts reading from it. Gritty then starts a pseudoterminal, and runs ash, feeding it the keypresses it detects, and putting returned outputting returned data (on the serial port as it were)
main screen turn on

The latter part could possibly be automated by some extra dup2() calls, but if that is a good idea would also depend on wether I want to do some translation first, e.g. as of now I have no handling of escape codes, so any terminal output with colour, or worse yet, curses apps makes everything go bananas. Another thing that remains to be done is the correct interpretation of modifier/special keys.

04/06/2014

An Arduino Yún and an ATM12864D Display

In the beginning of the year I received an Arduino Yún from good friends as a birthday gift. Fitted with both an Atmel Atmega32u4 as well as a small Linux module running some spin of OpenWRT. I'm not sure what it's final use will be, or if it will move from project to project as an intermediary solution until I get boards fabbed for the real deal. After all that is part of what the selling point of the Arduino platform is. I'm crunching down basic C on the AVR though, ditching the Arduino software/firmware platform, I can not stand it. I want to be able to flip bits on the metal. And somebody will say "oh, C, he uses a high-level language…" and another will chime in with "oh, digital electronics…" and so on. Everybody has their level of comfort. In the microcontroller world mine is C, and occasionally ASM.

Years ago I bought a graphical LCD display, way before oleds and whatnot were starting to become common in the hobbyist crowd. 128x64 pixels, monochrome white foreground on blue background. KS0107+KS0108 drivers. I never got it to work very good, I—with relative little experience at the time—were bound to bodge the connection of at least some of the 20 pins it needed power and signals on. Or get the timing wrong. Or both. Then there was the fact that not many of my few projects actually needed or could take advantage of a graphical display. A button and/or a RS232 connection to a computer usually were enough.

Now with the Arduino+Linux module, and for that matter, more experience, what if I tried to tackle the display again? I set out with the goal of reading the serial output from the Linux module and pushing it onto the LCD, effectively making the AVR+LCD a serial console for the Linux module.
After a very brief search it seemed that the Arduino was not made with writing a whole byte to a range of pins in paralell (like PORTD=0x2a) in mind, and at that time I decided that enough is enough, and purged the Arduino stack and switched to C. When writing this post I did some searching again, and of course it seems to be the case that one can use e.g. PORTD=0x2a in the Arduino stack. Oh well, switching to C is something I wanted to do in the first place, so it does not really matter.

Then came the second and third setback, the Arduino headers I wanted to use do not map to consecutive bits of the various AVR ports, mitigating the benefit of being able to write a byte to a port in one go. And for that matter, some of the pins I wanted to use were tied up in special nets connecting the AVR to the Linux module. This is the reason I dead-bugged the 74LS164 shift register in the previous post.

It's so pretty! And neat! Hm, actually, for a random wiring job I think it's not that bad…
The datasheet of the display (ATM12864D) is pretty helpful, apart from one single point that had me quite confused. The pinout lists a D/I signal, and the longer description had me believe that it was an internal signal (e.g. between the KS0107-KS0108 chips or whatever) that for some reason was routed to the external interface as well. The command table on the other hand, lists an RS signal, absent from the pinout, and used to differentiate between display pixel data, and instructions (hmm… D/I…). I've seen no comment about this elsewhere on the net, so in the case anyone is as confused as I was, and happens to stumble upon this post I'll state it explicitly: For this particular display, the RS signal listed in the command table is the D/I signal listed in the pinout.

Pair programming, now it's the cat's turn at the keyboard.
I also have the chance of getting my projects ESD tested. For free.
After a while of still not getting any consistent behaviour from the display notice that I have soldered the data bus cable the wrong way. After a while of putting off having to resolder the cable, by mirroring every byte written, in software, the thought strikes me. Hey! I can clock out the data to the 164 LSB first instead of MSB first!

It seems that the stereotypes are true…
Now with the ability to get arbitrary grahics data to the display I notice that a column is dead, constant off, unless I hold a finger on the unpopulated C12/13 pads on the back of the display, in which case it turns constant on.
Very irritating, but if I tailor the font routine and offsets etc. I can make so it is at the part of the text matrix that is the space between letters and always off.

After a while of fiddling around with trying to find out the correct baud rate for communicating with the Linux module (it's 250k by the way) I figured that maybe the display updating routine was too slow to run each time a byte is received, and moved reception to an interrupt routine, left updating the display to the main loop. Success!

Boot messages!

01/06/2014

Dead Bug Soldering

Only stock up on SMT parts he thought… It's the future he thought…
In litterature, movies, …culture at large, when they want to emphasize how mean and sadistic the bully is, it is not that uncommon to mention how he likes to pull the legs off of spiders and insects. But what about those who try to add legs to the poor critters?

31/05/2014

Moved

Most of the project pages have been moved, partially rewritten, and published. Given that I can publish not only blog posts, but also maintain pages, is very convenient and I don't miss much from my old CMS to be honest. There is one thing though, and it is a bit of a thorn in my side. Images.

On my old setup I could have images of any aspect ratio side by side without it looking horrible, because the image displayed on the page would be resized to a predefined size, and cropped to a square with a link to the uncropped, unresized image. No such thing here—as far as I can tell—unless one wants to do it manually, which would be of little benefit anyway, since the editor does not really want to place images beside each other, only images on their own, or, images beside text. But then again, I have only used the wysiwyg editor so far, and not tried to do any raw HTML editing. Not that I like writing raw HTML.

I don't.

I dislike it enough that I wrote a CMS to get out of it.