This repository was archived by the owner on Jun 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathautopat
More file actions
213 lines (174 loc) · 3.61 KB
/
autopat
File metadata and controls
213 lines (174 loc) · 3.61 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
#!/bin/bash
#script to perform auto connects to gateways
#using pat winlink
#20191015 KM4ACK
source $HOME/patmenu/config
if [ $RIGCONTROL == 'no' ]
then
echo;echo
echo "Rig contol needed for this script to work"
echo "Please configure rig control and try again"
sleep 5
exit 0
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=$HOME/patmenu/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."
#Ask user to install findardop??
exit 0
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
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