forked from cyoung/stratux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdr-tool.sh
295 lines (264 loc) · 9.52 KB
/
sdr-tool.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
######################################################################
# STRATUX SDR MANAGER #
######################################################################
#Set Script Name variable
SCRIPT=`basename ${BASH_SOURCE[0]}`
# rtl_eeprom -d 0 -s <String>:<Freq>:<PPM>
#Initialize variables to default values.
SERVICE=stratux.service
WhichSDR=1090
FallBack=true
PPMValue=0
parm="*"
err="####"
att="+++"
#Set fonts for Help.
BOLD=$(tput bold)
STOT=$(tput smso)
DIM=$(tput dim)
UNDR=$(tput smul)
REV=$(tput rev)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
MAGENTA=$(tput setaf 5)
WHITE=$(tput setaf 7)
NORM=$(tput sgr0)
NORMAL=$(tput sgr0)
#This is the Title
function HEAD {
clear
echo "######################################################################"
echo "# STRATUX SDR SERIAL TOOL #"
echo "######################################################################"
echo " "
}
function STOPSTRATUX {
HEAD
echo "Give me a few seconds to check if STRATUX is running..."
# The service we want to check (according to systemctl)
if [ "`systemctl is-active $SERVICE`" = "active" ]
then
echo "$SERVICE is currently running"
echo "Stopping..."
SDRs=`systemctl stop stratux.service`
fi
sleep 3
}
#Function to set the serial function
function SETSDRSERIAL {
HEAD
echo "# Setting ${WhichSDR}mhz SDR Serial Data #"
#Build this string
# rtl_eeprom -d 0 -s <String>:<Freq>:<PPM>
echo " SETTING SERIAL: "
echo " rtl_eeprom -d 0 -s stx:${WhichSDR}:${PPMValue} "
echo " "
echo "${REV}Answer 'y' to the qustion: 'Write new configuration to device [y/n]?'${NORM}"
echo " "
SDRs=`rtl_eeprom -d 0 -s stx:${WhichSDR}:${PPMValue}`
sleep 2
echo " "
echo "Do you have another SDR to program?"
echo " 'Yes' will shutdown your STRATUX and allow you to swap SDRs."
echo " 'No' will reboot your STRATUX and return your STRATUX to normal operation."
echo " 'exit' will exit the script and return you to your shell prompt"
choices=( 'Yes' 'No' 'exit' )
# Present the choices.
# The user chooses by entering the *number* before the desired choice.
select choice in "${choices[@]}"; do
# If an invalid number was chosen, $choice will be empty.
# Report an error and prompt again.
[[ -n $choice ]] || { echo "Invalid choice." >&2; continue; }
case $choice in
'Yes')
echo "Shutting down..."
SDRs=`shutdown -h now`
;;
'No')
echo "Rebooting..."
SDRs=`reboot`
;;
exit)
echo "Exiting. "
exit 0
esac
break
done
}
function SDRInfo {
HEAD
echo "# Building ${WhichSDR}mhz SDR Serial #"
echo " "
echo "Do you have a PPM value to enter?"
echo "If not, its ok... Just choose 'No'"
choices=( 'Yes' 'No' 'exit' )
# Present the choices.
# The user chooses by entering the *number* before the desired choice.
select choice in "${choices[@]}"; do
# If an invalid number was chosen, $choice will be empty.
# Report an error and prompt again.
[[ -n $choice ]] || { echo "Invalid choice." >&2; continue; }
case $choice in
'Yes')
echo "Please enter your PPM value for your 978mhz SDR:"
read PPMValue
;;
'No')
echo " "
;;
exit)
echo "Exiting. "
exit 0
esac
break
done
SETSDRSERIAL
}
function PICKFALLBACK {
HEAD
echo "# Gathering ${WhichSDR}mhz SDR Serial #"
echo " "
echo "${RED}${BOLD}IMPORTANT INFORMATION: READ CAREFULLY${NORM}"
echo "${BOLD}DO you want to set the 1090mhz SDR to Fall Back to 978mhz in the event of the 978mhx SDR failing inflight?${NORM}"
echo "If no serials are set on any of the attached SDRs then STRATUX will assign 978mhz to the first SDR found and 1090mhz to the remaining SDR. This is a safety featre of STRATUX to always allow users to always have access to WEATHER and METAR data in the event of one SDR failing in flight. "
echo " "
echo "When a user assigns a frequency to an SDR, via setting serials, STRATUX will always assign that frequency. NO MATTER WHAT."
echo "This could cause issues if an SDR fails in flight. If the 978mhz SDR fails in flight and the other SDR is assigned the 1090 serial this SDR will never be set to 978mhz and the user will not have access to WEATHER and METAR data"
echo " "
echo "Choosing the Fall Back mode will allow the remaining SDR to be assigned to 978mhz while keeping the PPM value, allowing the user to continue to receive WEATHER and METAR data."
echo "Fall Back mode is reccomended!"
choices=( 'FallBack' '1090mhz' 'exit' )
# Present the choices.
# The user chooses by entering the *number* before the desired choice.
select choice in "${choices[@]}"; do
# If an invalid number was chosen, $choice will be empty.
# Report an error and prompt again.
[[ -n $choice ]] || { echo "Invalid choice." >&2; continue; }
case $choice in
'FallBack')
WhichSDR=0
;;
'1090mhz')
echo " "
;;
exit)
echo "Exiting. "
exit 0
esac
break
done
}
function PICKFREQ {
HEAD
echo "# Selecting Radio to set Serial #"
echo " "
echo "${BOLD}Which SDR are you setting up?${NORM}"
echo "${DIM}If you have tuned antennas make sure you have the correct SDR and antenna combination hooked up at this time and remember which antenna connection is for which antenna.${NORM}"
choices=( '978mhz' '1090mhz' 'exit' )
# Present the choices.
# The user chooses by entering the *number* before the desired choice.
select choice in "${choices[@]}"; do
# If an invalid number was chosen, $choice will be empty.
# Report an error and prompt again.
[[ -n $choice ]] || { echo "Invalid choice." >&2; continue; }
case $choice in
'978mhz')
WhichSDR=978
SDRInfo
;;
'1090mhz')
PICKFALLBACK
SDRInfo
;;
exit)
echo "Exiting. "
exit 0
esac
break
done
}
function MAINMENU {
HEAD
echo "Loading SDR info..."
sleep 2
HEAD
echo "-----------------------------------------------------------"
SDRs=`rtl_eeprom`
echo "-----------------------------------------------------------"
echo " "
echo "${BOLD}${RED}Read the lines above.${NORM}"
echo "${BOLD}How many SDRs were found?${NORM}"
# Define the choices to present to the user, which will be
# presented line by line, prefixed by a sequential number
# (E.g., '1) copy', ...)
choices=( 'Only 1' '2 or more' 'exit' )
# Present the choices.
# The user chooses by entering the *number* before the desired choice.
select choice in "${choices[@]}"; do
# If an invalid number was chosen, $choice will be empty.
# Report an error and prompt again.
[[ -n $choice ]] || { echo "Invalid choice." >&2; continue; }
case $choice in
'Only 1')
PICKFREQ
;;
'2 or more')
echo "#####################################################################################"
echo "# ${RED}Too Many SDRs Plugged in. Unplug all SDRs except one and try again!!${NORM} #"
echo "#####################################################################################"
exit 0
;;
exit)
echo "Exiting. "
exit 0
esac
# Getting here means that a valid choice was made,
# so break out of the select statement and continue below,
# if desired.
# Note that without an explicit break (or exit) statement,
# bash will continue to prompt.
break
done
}
function START {
echo "Help documentation for ${BOLD}${SCRIPT}.${NORM}"
echo " "
echo "This script will help you in setting your SDR serials. Please read carefully before continuing. There are many options in settings the SDR serials. Programming the SDR serials does 2 things. "
echo " "
echo "${BOLD}First:${NORM}"
echo "Setting the serials will tell your STRATUX which SDR is attached to which tuned antenna."
echo " "
echo "${BOLD}Second:${NORM}"
echo "Setting the PPM value will enhance the reception of your SDR by correcting the Frequency Error in each SDR. Each PPM value is unique to each SDR. For more info on this please refer to the Settings page in the WebUI and click on the Help in the top right."
echo " "
echo "Steps we will take:"
echo "1) Make sure you have ${BOLD}${REV}ONLY ONE${NORM} SDR plugged in at a time. Plugging in one SDR at a time will ensure they are not mixed up."
echo "2) Select which SDR we are setting the serial for."
echo "3) Add a PPM value. If you do not know or do not want to set this value this will be set to 0. "
echo "4) Write the serial to the SDR."
echo " "
echo "If you are ready to begin choose ${BOLD}Continue${NORM} to begin."
echo " Continuing will stop the STRATUX service to release the SDRs for setting the serials"
choices=( 'Continue' 'Exit' )
# Present the choices.
# The user chooses by entering the *number* before the desired choice.
select choice in "${choices[@]}"; do
# If an invalid number was chosen, $choice will be empty.
# Report an error and prompt again.
[[ -n $choice ]] || { echo "Invalid choice." >&2; continue; }
case $choice in
'Continue')
STOPSTRATUX
MAINMENU
;;
exit)
echo "Exiting. "
exit 0
esac
break
done
}
HEAD
START