-
Notifications
You must be signed in to change notification settings - Fork 1
/
spr.sh
executable file
·50 lines (39 loc) · 1.11 KB
/
spr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Thanks to Gil Kloepfer (KI5BPK) for the hard work mapping the
# FT-991/A address space - and troubleshooting my code!
# For more information, visit https://www.kloepfer.org/ft991a/memory-map.txt
# Change these to meet your transceiver's config
SERIAL=/dev/ttyUSB0
SPEED=38400
if [ -z $1 ] ; then
echo Inform address range
exit 1
fi
if ! stty -ixon -F $SERIAL $SPEED; then
echo "Failed to configure port"
exit 1
fi
# Function to encode hex to binary
encode() {
echo -n "$1" | xxd -r -p
}
# Function to create the CAT SPR command to the radio
catstring() {
printf "SPR"
encode $ADL
encode $ADH
echo -n "$CHECK;"
}
# High and low address parts
ADL=0x${1:0:2}
ADH=0x${1:2:2}
# Encode the checksum - And strip out the exceeding character in checksum sum
# Avoided the bitwise AND operation because Shell endinanness is not compatible.
# Sum High, Low and Magic
CHECK=$(( $ADH + $ADL + 0xf5 ))
# Convert the Decimal value to Hexadecimal
CHECK=$(printf "%X" $CHECK)
# Encode the Checksum to binary, use only two least significant bytes
CHECK=$(encode ${CHECK:1})
catstring | hexdump -C
catstring > $SERIAL;