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 low ASCII decimal value
SUMH="" # Checksum as two digit Hex
# Example: "Set ATC radio to 119.100 MHz Normal"
# '$PMRRC00G4N29\r\n'
if [ -n "$1" ]; then
MHZ=$(echo "$1" | cut -d "." -f 1)
KHZ=$(echo "$1" | cut -d "." -f 2)
echo "Frequency=$MHZ.$KHZ"
echo
echo "Set serial port USB0 to 9600N81"
stty -F /dev/ttyUSB0 raw
stty -F /dev/ttyUSB0 9600
echo
echo Calculate frequency characters
MD=$(echo "$MHZ - 48" | bc)
MA=$(printf \\$(printf "%o" $MD))
KD=$(echo "$KHZ - 48" | bc)
KA=$(printf \\$(printf "%o" $KD))
echo m=$MA
echo k=$KA
echo
echo Calculate checksum
IDHD=$(printf "%d" "'$IDH")
IDLD=$(printf "%d" "'$IDL")
MODD=$(printf "%d" "'$MOD")
SUM=$(echo "$IDHD + $IDLD + $MD + $KD + $MODD" | bc)
SUM=$(echo "$SUM % 256" | bc)
SUMH=$(printf "%02x" "$SUM")
echo SUMH=$SUMH
echo
echo "Frequency Message = $HDR$IDH$IDL$MA$KA$MOD$SUMH"
echo "$HDR$IDH$IDL$MA$KA$MOD$SUMH" > /dev/ttyUSB0
echo
echo "La Voila!"
exit 1
fi
echo Example: atcfreq 123.450
exit 0
The above script will take 119.100 MHz and output the message '$PMRRC00G4N29' to the screen and to the serial port.
Why on earth do I use Bash for this? Because I'm a masochist and love to fight the Bash automatic type conversions...
All Linux/UNIX machines have Bash (and Windows has Cygwin), therefore this is an easy way to debug and test any and all black boxes in a lab setting.
Modify at your peril!
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 low ASCII decimal value
SUMH="" # Checksum as two digit Hex
# Example: "Set ATC radio to 119.100 MHz Normal"
# '$PMRRC00G4N29\r\n'
if [ -n "$1" ]; then
MHZ=$(echo "$1" | cut -d "." -f 1)
KHZ=$(echo "$1" | cut -d "." -f 2)
echo "Frequency=$MHZ.$KHZ"
echo
echo "Set serial port USB0 to 9600N81"
stty -F /dev/ttyUSB0 raw
stty -F /dev/ttyUSB0 9600
echo
echo Calculate frequency characters
MD=$(echo "$MHZ - 48" | bc)
MA=$(printf \\$(printf "%o" $MD))
KD=$(echo "$KHZ - 48" | bc)
KA=$(printf \\$(printf "%o" $KD))
echo m=$MA
echo k=$KA
echo
echo Calculate checksum
IDHD=$(printf "%d" "'$IDH")
IDLD=$(printf "%d" "'$IDL")
MODD=$(printf "%d" "'$MOD")
SUM=$(echo "$IDHD + $IDLD + $MD + $KD + $MODD" | bc)
SUM=$(echo "$SUM % 256" | bc)
SUMH=$(printf "%02x" "$SUM")
echo SUMH=$SUMH
echo
echo "Frequency Message = $HDR$IDH$IDL$MA$KA$MOD$SUMH"
echo "$HDR$IDH$IDL$MA$KA$MOD$SUMH" > /dev/ttyUSB0
echo
echo "La Voila!"
exit 1
fi
echo Example: atcfreq 123.450
exit 0
The above script will take 119.100 MHz and output the message '$PMRRC00G4N29' to the screen and to the serial port.
Why on earth do I use Bash for this? Because I'm a masochist and love to fight the Bash automatic type conversions...
All Linux/UNIX machines have Bash (and Windows has Cygwin), therefore this is an easy way to debug and test any and all black boxes in a lab setting.
Modify at your peril!
Dear Sir, could you please unveil a source for the complete protocol, or at least hint a little, how to read, rather than write the active/standby frequencies?
ReplyDeleteHi, me again. Isn't there a mistake?? KD=$(echo "$KHZ - 48" | bc) What is the script doing w/ Khz=0? e.g. 119.000 MHz?? And multiple of 25KHz is 4, yes, but that's not the way the script calulates it?? or did I miss something?
ReplyDeleteThis is long ago!
ReplyDeleteThe minus 48 converts the character from ASCII to a numerical value.
See this table https://www.asciitable.com/
Note that "0" == 48 decimal
So there is an offset of 48 for the numbers in the ASCII table.
Some googling will find a manual with the serial protocol description, for example this one: http://www.aeroelectric.com/Installation_Data/Garmin/SL30_IM.pdf
ReplyDelete