-
Notifications
You must be signed in to change notification settings - Fork 9
/
autopat
executable file
·262 lines (214 loc) · 5.13 KB
/
autopat
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
#script to perform auto connects to gateways
#using pat winlink
#20191015 KM4ACK
MYPATH=$HOME/patmenu2
LOGO=$MYPATH/pmlogo.png
MAIN=$MYPATH/patmenu
source $MYPATH/config
if [ $RIGCONTROL == 'no' ]
then
yad --title="NO RIG CONTROL" --width=400 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
--center --form --text="\r\r\r\rRig Control is needed for auto pat.\rPlease configure rig control and try again." \
--button=gtk-ok
exit
fi
#Check if FLRIG is running if user has it set in config file
if [ "$RIGCONTROL" = 'yes' ]; then
echo "rig control is on"
FLRIG=$(echo $RIG | grep "\-m 4")
if [ -z "$FLRIG" ]; then
echo
else
FLRIG=$(pidof flrig)
if [ -z "$FLRIG" ]; then
yad --title="FAILED" --width=400 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
--center --form --text="Please start FLRIG and try again" \
--button=gtk-ok
exit
fi
fi
fi
if [ $AMRRON = "no" ]
then
DIRE=$(pidof direwolf)
if [ -z "$DIRE" ]
then
echo
else
sudo killall direwolf kissattach
fi
PIARDOPC=$(pidof piardopc)
if [ -z "$PIARDOPC" ]
then
echo
else
sudo killall piardopc ardop-GUI
fi
fi
#clear any temp files from previous runs that might exist
rm -rf $HOME/tempardop > /dev/null
ARDOPLIST=$MYPATH/ardop-list/
touch $LOG
DATE=$(date)
STARTRIG () {
#start rigctld if not already
PIDCTL=$(pidof rigctld)
WHO=$(whoami)
if [ -z "$PIDCTL" ]
then
CONTROL=$(echo $RIG | sed 's/rigctl/rigctld/')
$CONTROL &
sudo systemctl restart pat@$WHO
fi
}
STARTRIG
if [ -z "$PIDCTL" ]
then
STARTRIG
fi
SETRIG () {
#Set USB Mode
RIGUSB=$RIG" M $MODEHF 0"
#check rig is in USB
MODE=$($RIG m | grep $MODEHF)
sleep 1
MODECHECK() {
#check rig is in correct mode
MODE=$($RIG m | grep $MODEHF)
}
sleep 1
if [ -z $MODE ]
then
$RIGUSB
MODECHECK
fi
}
SETRIG
#Directions Function
directions () {
echo "The script needs two arguments to run."
echo "It needs the distance that you want to try to connect"
echo "and it needs the band you wish to use"
echo "Bands available are 20, 30, 40, & 80"
echo "The first argument is the distance"
echo "and the second is the band. So to try all 40M"
echo "stations in a 300km radius, you would enter"
echo "autopat 300 40"
exit 0
}
#check if distance is empty and give direction
if [ -z "$1" ]
then
directions
fi
#check if band is empty and give direction
if [ -z "$2" ]
then
directions
fi
#Check for min distance
if [ -z "$3" ]
then
MIN=0
else
MIN=$3
fi
#take $2 as band to use
if [ $2 = "20" ]
then
FILE=$ARDOPLIST"20mardoplist.txt"
elif [ $2 = "30" ]
then
FILE=$ARDOPLIST"30mardoplist.txt"
elif [ $2 = "40" ]
then
FILE=$ARDOPLIST"40mardoplist.txt"
elif [ $2 = "80" ]
then
FILE=$ARDOPLIST"80mardoplist.txt"
fi
#Verify we have a list to work with
test -f $FILE
FILERESULT=$(echo $?)
if [ $FILERESULT = "1" ]
then
echo "FILE DOESN'T EXIST."
yad --title="NO LIST" --width=400 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
--center --form --text="\r\r\rNo list has been downloaded. Auto Pat has no data to work with. Please download the gateway list \
and try again" \
--button="Download List":2 \
--button="Cancel":1
BUT=$?
if [ $BUT = 1 ]; then
exit
elif [ $BUT = 2 ]; then
$MYPATH/getardoplist
$MAIN &
exit
fi
fi
if [ $AMRRON = "no" ]
then
#start ardop-gui & piardopc
$ARDOPGUI &
$ARDOP &
sleep 10
fi
#Pat Connection Function
connect () {
pat connect $CALL
#Check if connection was successful
RESULTS=$(echo $?)
if [ $RESULTS = "0" ]
then
echo "A connection was made"
echo $DATE" "$CALL" Success with autopat" >> $LOG
yad --title="SUCCESS" --width=300 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top \
--center --form --text="Successfully connected with $CALL" \
--button=gtk-ok
if [ $AMRRON = "no" ]
then
sudo killall piardopc piARDOP_GUI
fi
exit 0
fi
}
#create temp dir & manipulate file
mkdir -p $HOME/tempardop/
#cat file, remove first few lines, remove blanks > NEWFILE NAME
cat $FILE | tail -n +5 | grep '[^[:blank:]]' > $HOME/tempardop/tempardop.txt
#pad with zeros
while read LINE
do DISTANCE=$(echo $LINE | awk '{ print $3 }' | sed -e :a -e 's/^.\{1,4\}$/0&/;ta')
CALL=$(echo $LINE | awk '{ print $11 }')
echo $DISTANCE" "$CALL >> $HOME/tempardop/tempardop1.txt
done < $HOME/tempardop/tempardop.txt
cat $HOME/tempardop/tempardop1.txt | sort >> $HOME/tempardop/sorted.txt
echo "Will Attempt to Connect to This Station"
#loop through file and find needed station info
while read LINE
do DISTANCE=$(echo $LINE | awk '{ print $1 }')
CALL=$(echo $LINE | awk '{ print $2 }')
if [ $DISTANCE -lt "$1" ] && [ $DISTANCE -gt "$MIN" ]
then
echo "Distance="$DISTANCE " Call="$CALL
#call the connect funtion
connect
fi
done < $HOME/tempardop/sorted.txt
#remove temp directory & files
rm -rf $HOME/tempardop
if [ $AMRRON = "no" ]
then
#Stop ARDOP modem and gui
sudo killall piardopc piARDOP_GUI
fi
yad --title="NO Connection" --width=400 --height=100 \
--image $LOGO --window-icon=$LOGO --image-on-top --text-align=center \
--center --form --text="\r\r\r\rNo Winlink connection was made using the criteria you entered." \
--button=gtk-ok