forked from km4ack/pi-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtflrig
More file actions
220 lines (190 loc) · 6.15 KB
/
btflrig
File metadata and controls
220 lines (190 loc) · 6.15 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
#script connects to bluetooth CAT device
#and starts FLRIG
#Special thanks to Brian, AB6D for sharing the bluetooth device me
#and contribution to the script!
#06FEB2021
#31MARCH2021 edit.
#===============================================
#To use this script, be sure it is placed in
#the ~/bin directory on your build a pi system.
#Make it executable with chmod +x btflrig
#and run it with btflrig help
#===============================================
##################################################################
# #
# # # # # # # ##### # # #
# # # # # # # ## # # # # # #
# # # # # # # # # # # # # #
# ## # # ##### ####### # ## #
# # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # ##### # # #
# #
#################################################################
CHANGELOG(){
31MARCH2021
update script to ask user for name
add version number
bump version number to 2
}
VERSION=2
CONFIG=/home/pi/bin/.btflrig.mac
touch $CONFIG
source $CONFIG
#######################################
# Generate Help File #
#######################################
HELP(){
clear
cat <<EOF>/run/user/$UID/btflrig.help
You can return to this help file at any time by running
"btflrig help" at the terminal.
NAVIGATING THIS HELP FILE:
Press "q" to exit this help file
Press the space bar for the next screen of the help file.
SETUP:
Use the GUI bluetooth interface found next to the clock
to connect with the CAT bluetooth device (SPP-CA).
The passcode is "1234". You will get an error that indicates
no usable services are found on the device. This is
expected.
Once the above is complete, run "btflrig scan" from the
terminal window. This will scan for the new CAT device
and obtain the MAC address which is needed so we can
connect to the new device. Occasionally the first scan
will fail to obtain the MAC address of the new device and
you will receive an error alert. Should this occur, run
the "btflrig scan" command again.
Finally, run "btflrig menu" from the terminal window
and this script will create a menu shortcut that can
be used to start the bluetooth service and open FLRIG.
FLRIG SETUP:
In FLRIG, navigate to Config>Setup>transceiver.
On the configuration page choose your Yaesu rig from
the top drop down box labeled rig. In the next box, choose
"/dev/rfcomm7" which will be near the bottom of the list.
If /dev/rfcomm7 isn't found in the list, you can enter it
manually in the box. Now set the baud rate to 9600. Make sure
your the baud rate on your radio is also set to 9600. This
is labeled CAT rate in your radio menu. All other
settings in FLRIG should be left at default. Now press
the "Init" button in the bottom right corner of the
configuration window in FLRIG.
PAT MENU SETUP:
Open Pat Menu and click on Settings/Config. Now click
Create New Config File. Verify your call is correct.
Change rig control to equal yes.
In the KISS Command box enter
sudo /usr/sbin/kissattach /dev/rfcomm7
In the RIG Command box enter
/usr/local/bin/rigctl -m 4
For the Yaesu 817 I set HF Mode to RTTY and 2M mode
to PKTFM. Others are probably ok left at default.
Now click the "Create" button at the bottom and name
the new config file. I use "BT-RIG#" for my names.
Now use Pat Menu to load the new config file that
you just created.
EOF
cat /run/user/$UID/btflrig.help | less
clear;echo;echo
echo "You can open the help file again by running"
echo "\"btflrig help\" at anytime or you can place"
echo "the help document on your desktop."
read -p "Place on your desktop y/n ? " ANS
if [ $ANS = 'y' ] || [ $ANS = 'Y' ]; then
cat /run/user/$UID/btflrig.help | tail -n +8 > $HOME/Desktop/btflrig-help.txt
fi
}
#######################################
# Create Menu Shortcut #
#######################################
MENUITEM(){
cat <<EOF>/run/user/$UID/btflrig.desktop
[Desktop Entry]
Name=BT-Flrig
GenericName=Amateur Radio Rig Control
Comment=Amateur Radio Communications
Exec=/home/pi/bin/btflrig
Icon=flrig
Terminal=false
Type=Application
Categories=Network;HamRadio;
NoDisplay=false
EOF
sudo mv /run/user/$UID/btflrig.desktop /usr/share/applications/
}
#######################################
# Scan for Mac Addr #
#######################################
SCAN(){
FILE=/run/user/$UID/bt.txt
clear;echo;echo
echo "scanning for device......please wait"
hcitool scan > $FILE
sed -i '1d' $FILE
CHK=$(grep : $FILE)
if [ -z "$CHK" ]; then
clear;echo;echo
echo "Device not found. Check that the device"
echo "is firmly seated and the radio is on."
echo "Then run \"btflrig scan\" again"
exit 1
fi
clear;echo;echo
echo " MAC ADDRESS NAME"
echo " ================= ======"
cat $FILE
echo
echo "Find your device in the line/list above"
read -p "and enter the name of the device. " ANS
MAC=$(grep -i "$ANS" /run/user/$UID/bt.txt | awk '{print $1}')
echo "MAC=$MAC" > $CONFIG
}
#######################################
# Check for user input #
#######################################
if [ $1 = 'scan' ]; then
SCAN
source $CONFIG
if [ -z $MAC ] || [ "$MAC" = '...' ]; then
echo "Scan failed. Please try again"
exit 1
else
echo "Scan complete. Next run \"btflrig menu\" to create a menu shortcut"
exit
fi
elif [ $1 = 'menu' ]; then
MENUITEM
echo "Menu shortcut created"
echo "Use menu item \"BT-Flrig\" found in the"
echo "ham radio category of the pi menu to start"
echo "FLRIG"
exit 0
elif [ $1 = 'help' ]; then
HELP
exit 0
fi
#######################################
# Main Connect Script #
#######################################
#sudo rfcomm connect /dev/rfcomm0 $MAC &
#sleep 3
#/usr/local/bin/flrig
#release rfcomm once FLRIG is closed
#sudo rfcomm release /dev/rfcomm0
while :
do
rfcomm show 7
connection_state=$?
while [ $connection_state -ne 0 ]
do
sudo rfcomm connect 7 $MAC &
sleep 2
rfcomm show 7
connection_state=$?
done
/usr/local/bin/flrig --config-dir $HOME/.btflrig
sudo rfcomm release 7
exit 0
done