3 minute read

I’ve been writing firmware for an RFID reader that connects over USB to an Android device.  Our installers will need to upgrade the readers out in the field and they have no way of knowing which firmware has been installed.  The reader, an Elatec TWN4, has a pretty decent API that you write code for, using the C language.  Their API includes a wonderful function called “Beep”.  You pass in the volume, frequency, how to play the tone (in ms), and finally, how long to be quiet after the tone has been played.  So I have been setting the readers to play a few notes on power up.  This allows the installers to know which firmware has been installed.

The original firmware plays the opening notes to “Smoke On The Water”.  Because anything that can produce at least 4 notes can play it.  The following C code will beep it’s way through some vintage Deep Purple

We added some code to the firmware to allow our app to put the reader is a sleep mode. Our installers will need to upgrade a few devices out in the field, so it was time to change that tune. By checking a few different sites, we found simplified chord progressions for some recognizable songs. My choices were restricted to simple note changes, you can’t generated complicated chords from a device that only knows how to beep. It does that beep very well, but at the end of the day it’s only a beep.

I needed to play something else to let the installers know that the firmware had been updated.  Something short, something simple, something simple.  One of my musically inclined co-workers worked out the opening notes of “The Final Countdown” by Europe.  That song has a distinctive opening riff.  And many cover versions.  Some might say too many.

I found a note to frequency conversion table and used that to create a set of constants for the notes I needed.  That allowed me to specify the beeps with readable note constants, instead of the frequency values. You can get those constants here.  With the use of those constants, you can play the opening notes of “The Final Countdown” with the following code:

When using the constants, the code is much easier to read. And it becomes much easier to create new song intros. With that in place, the installers can quickly check the firmware version by powering up the RFID reader. At some point I’ll refactor the code to just read the values from an array. The current design is easy to setup and read, I may just stay with what works.

Right now, I need to use Elatec’s development tools to push the firrmware out via a simple GUI. If I could get a command line tool for pushing the firmware out, I could add code to the firmware to return the version number from a query sent over USB. That would allow me to write a simple app or Powershell script to identify a connected reader, query the version, and then push the update out. If anyone from Elatec ever reads this, a command line firmware updater would be very helpful.

Decades of using development tools like Visual Studio has accustomed me to being able to use a debugger to step through the code. Writing code where you can’t visually debug it, requires thinking out side the box. I can test much of the code by having the reader send back text, but when testing with the device that it will be hooked up to, that would interfere with how they work. Sometimes you just have to use a different path out of the machine to see what it’s doing.

Comments