-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspw.sh
executable file
·68 lines (55 loc) · 1.5 KB
/
spw.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/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
if [ -z $IKNOWRIGHT ] ; then
echo
echo "THIS CAN ==AND WILL== BRICK YOUR RADIO BEYOND REPAIR"
echo
echo "If you *really really* know what you are doing, move ahead"
echo
exit 1
fi
if [ -z $1 ] ; then
echo "Inform address range (4-byte, cleartext hex)"
exit 1
elif [ -z $2 ] ; then
echo "Inform the data to be written (4-byte, cleartext hex)"
echo "For more information visit:"
echo "https://www.kloepfer.org/ft991a/memory-map.txt"
exit 1
fi
SERIAL=/dev/ttyUSB0
SPEED=38400
if ! stty -ixon -F $SERIAL $SPEED; then
echo "Failed to configure port"
exit 1
fi
# Function to encode hex to binary
encode() {
printf "$1" | xxd -r -p
}
# High and low address parts
ADL=0x${1:0:2}
ADH=0x${1:2:2}
VALL=0x${2:0:2}
VALH=0x${2: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=$(( 0xfb + $ADH + $ADL + $VALH + $VALL + 0xff ))
# 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})
# The final stream
catstring() {
printf "SPW"
encode $ADL
encode $ADH
encode $VALL
encode $VALH
printf "$CHECK;"
}
catstring | hexdump -C
catstring > $SERIAL;