-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsdr-bookmarks
90 lines (82 loc) · 2.76 KB
/
sdr-bookmarks
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
#!/bin/bash
# Copyright (c) 2021 by Philip Collier, radio AB9IL
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version. There is NO warranty; not even for
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
BOOKMARKS_FILE="~/.config/sdrbookmarks"
UNIT="e6" # Freq units. e6 for MHz, empty for Hz
AM_SAMP="16000" # am sampling rate
FM_SAMP="16000" # fm sampling rate
SQUELCH="170" # squelch level
#------------------------------------------------------------------------------
#-----EDIT BELOW ONLY IF NECESSARY---WATCH FOR DRAGONS-------------------------
#------------------------------------------------------------------------------
OPTION1="Tune SDR Bookmarks"
OPTION2="Stop SDR Bookmarks"
OPTION3="Reset the USB Device"
OPTION4="Edit Bookmarks"
OPTIONS="$OPTION1\n$OPTION2\n$OPTION3\n$OPTION4"
FZF_COMMAND1='fzf --layout=reverse --header=Select:'
ROFI_COMMAND1='rofi -lines 4 -dmenu -p Select'
FZF_COMMAND2='fzf --layout=reverse --header=Select:'
ROFI_COMMAND2='rofi -dmenu -p Select'
FZF_COMMAND3='usbreset-helper'
ROFI_COMMAND3='x-terminal-emulator -e usbreset-helper'
FZF_COMMAND4="vim $BOOKMARKS_FILE"
ROFI_COMMAND4="x-terminal-emulator -e vim $BOOKMARKS_FILE"
#Get the SDR frequency offset (ppm)
CORR=$(cat /usr/local/etc/sdr_offset)
#Get the SDR gain (gain)
GAIN=$(cat /usr/local/etc/sdr_gain)
stop_sdr(){
killall -9 rtl_fm
}
# interface based on commandline arguments
case "$1" in
gui)
COMMAND1=$ROFI_COMMAND1
COMMAND2=$ROFI_COMMAND2
COMMAND3=$ROFI_COMMAND3
COMMAND4=$ROFI_COMMAND4
;;
*)
COMMAND1=$FZF_COMMAND1
COMMAND2=$FZF_COMMAND2
COMMAND3=$FZF_COMMAND3
COMMAND4=$FZF_COMMAND4
;;
esac
# select option from first menu instance
SELECTED="$(echo -e "$OPTIONS" | $COMMAND1 )"
case $SELECTED in
$OPTION1)
readarray STREAMS < $BOOKMARKS_FILE
CHOICE="$(echo "${STREAMS[@]}" | awk -F \" '{print $1, $2}' | sed 's/^ //g' | $COMMAND2 )"
# start the SDR stream
stop_sdr
sleep 0.5
SAMP=""
SQ=""
RATE=48000
FREQ="$(echo "$CHOICE" | awk '{print $1}')"
MODE="$(echo "$CHOICE" | awk '{print $2}')"
[[ "$MODE" == "fm" ]] && SAMP="-s $FM_SAMP" && RATE=$FM_SAMP && SQ="-l $SQUELCH"
[[ "$MODE" == "am" ]] && SAMP="-s $AM_SAMP" && RATE=$AM_SAMP && SQ="-l $SQUELCH"
rtl_fm -M $MODE -f $FREQ$UNIT -p $CORR $SAMP -g $GAIN $SQ -r $RATE | \
aplay -r $RATE -t raw -c 1 -f S16_LE 2>&1 &
;;
$OPTION2)
# cleanly stop the player
stop_sdr
;;
$OPTION3)
# reset a USB Device
$COMMAND3
;;
$OPTION4)
# edit the bookmarks
$COMMAND4
;;
esac