Skip to main content

Posts

Showing posts from January, 2015

Makefiles Made Easy

The bane of computer programming is the Makefile . As soon as there are more than one source file and a library, a Makefile becomes essential and generating one can be painful.  The Makefile syntax reminds me of a sendmail configuration file, which looks like someone banged his head on a keyboard: # This rule ensures that all local mail is delivered using the  # smtp transport, everything else will go via the smart host.  R$* < @ $* .$m. > $* $#smtp $@ $2.$m. $: $1 < @ $2.$m. > $3 dnl Way back in the dark ages, before there was m4 , I actually edited a few sendmail files by hand - that was how I earned my UNIX beard - but good grief... Same as with sendmail , you should never edit a Makefile manually these days.  It is a total waste of time.  There now are nice and simple utilities to do it for you! GCC -MM If you have a very simple project, then gcc can generate the Makefile for you: $ gcc -MM *.c > Makefile $ make Error: cc1plus If you get th

Serial Port I/O

Until about 20 years ago, most desktop and portable computers had serial and parallel ports built in.  Those ports were great for controlling and testing home brew gadgets.  Modern machines are blessed/cursed with USB ports, which are just getting more and more complex. The result is that if you want to do anything at all in your Underground Lab or Rooftop Radio Shack, you need an Arduino,  a Raspberry or a Beaglebone embedded computer. However, every respectable engineer has two or three FTDI USB to RS232 serial adaptors lying in a drawer (to control his Raspberry or Beaglebone).  These adaptors are great, since they effectively insulate your target system from your expensive computer, therefore whatever goes wrong on the far end, is unlikely to fry your machine and they are delightfully hackable. I prefer the dongles made by SerialComm .  They are cheap and both RS232 and RS422/485 are available. You can also get ones from Sparkfun that are even more hackable, or you can cr

MGL V6R ATC VHF Radio Control Protocol in Bash

The MGL V6R and V10, ATC VHF radios have a binary protocol (described in the V10 manual), in addition to the ubiquitous Garmin SL40 protocol. The Emergency/Setup channel is 121.5 MHz.  Don't use it for testing... In this example, I used the Bash let operator to do the calculations and printf is treated as a built-in function - TIMTOWTDI. Frequency Here is a simple Bash script that computes the frequency message (It doesn't check for out of range values!): #! /bin/bash echo MGL V6R ATC VHF Radio Protocol echo STX="02"        # Message header DLE="05"        # Message header CC="00"            # Active Frequency message ID = 00H, Standby Frequency message ID = 01H KHZ="000000"    # Frequency in Kilohertz, decimal string (6 digits) KHZH="000000"    # Frequency in Kilohertz, hexadecimal string (3 bytes)        KHZ0="00"        # Frequency in Kilohertz, B0, LSB first KHZ1="00"        # Frequency in Ki

Garmin SL40 ATC VHF Radio Serial Protocol in Bash

The Garmin SL30 and SL40 protocols are used by most aircraft and marine VHF radios.  These radios are very simple AM devices and basically one only needs to set the frequency. The Emergency/Setup channel is 121.5 MHz.  Don't use it for testing... Here is a Bash script that will compute a SL40 frequency message complete with its arithmetic checksum, using the bc calculator: #! /bin/bash echo Garmin SL40 ATC Radio Protocol echo # Set Active Frequency Message HDR='$PMRRC'    # Header IDH='0'        # ID IDL='0'        MHZ='119'    # 118 to 136 MHz KHZ='100'    # multiples of 25 kHz MOD='N'        # N=normal SUM=0    # Arithmetic Checksum MD=0    # MHZ scaled to ASCII decimal value MA=""    # MHZ in ASCII character KD=0    # KHZ scaled to ASCII decimal value KA=""    # KHZ in ASCII character MODD="" # MOD in ASCII decimal value IDHD="" # ID high ASCII decimal value IDLD="" # ID l