-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlora.sh
150 lines (117 loc) · 2.95 KB
/
lora.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
#!/bin/bash
workingdir="$( cd "$(dirname "$0")" ; pwd -P )"
source ${workingdir}/lora-options.conf
piddir=${workingdir}/pidfiles
bindir=${workingdir}/bin
fifopath=${workingdir}/fifos
beaconfile=${workingdir}/beacon.txt
LORARX=${bindir}/lorarx
LORAUDPGATE=${bindir}/udpgate4
LORASDRTST=${bindir}/sdrtst
command -v ${LORARX} >/dev/null 2>&1 || { echo "Ich vermisse " ${LORARX} >&2; exit 1; }
command -v ${LORAUDPGATE} >/dev/null 2>&1 || { echo "Ich vermisse " ${LORAUDPGATE} >&2; exit 1; }
command -v ${LORASDRTST} >/dev/null 2>&1 || { echo "Ich vermisse " ${LORASDRTST} >&2; exit 1; }
function startrtltcp {
echo "Starte rtl_tcp"
rtl_tcp -a 127.0.0.1 -d ${device} -g ${gain} -p ${rtltcp_port} 2>&1 > /dev/null &
rtltcp_pid=$!
echo $rtltcp_pid > $PIDFILE
sleep 5
}
function startsdrtst {
echo "Starte sdrtst"
mknod ${fifopath}/lorapipe p 2> /dev/null
${LORASDRTST} -t 127.0.0.1:${rtltcp_port} -i 1024000 -c ${workingdir}/qrg.txt -r 250000 -L 127.0.0.1:18051 -s ${fifopath}/lorapipe -v >&1 >> ${LOGFILE} &
sdrtst_pid=$!
echo $sdrtst_pid > $PIDFILE
}
function startlorarx {
echo "Starte lorarx"
${LORARX} -i ${fifopath}/lorapipe -f i16 -b 7 -v -s 12 -L 127.0.0.1:9702 -s 10 -v 2>&1 >> ${LOGFILE} &
lorarx_pid=$!
echo $lorarx_pid > $PIDFILE
}
function startudpgate {
echo "Starte udpgate"
${LORAUDPGATE} -s ${gatewaycall} -R 127.0.0.1:9071:9702 -n 10:${beaconfile} -g ${aprsserver}:${aprsport} -p ${aprspass} -v 2>&1 >> ${LOGFILE} &
udpgate_pid=$!
echo $udpgate_pid > $PIDFILE
}
function sanitycheck {
# check pidfiles in piddir
shopt -s nullglob # no error if no PIDFILE
for f in ${piddir}/*.pid; do
pid=`cat $f`
if [ -f /proc/$pid/exe ]; then ## pid is running?
echo "$(basename $f) ok pid: $pid"
else ## pid not running
echo "$(basename $f) died"
rm $f
fi
done
}
function checkproc {
#checks if prog is running or not
if [ -s $PIDFILE ];then ##have PIDFILE
pid=`cat $PIDFILE`
if [ -f /proc/$pid/exe ]; then ## pid is running?
return 0
else ## pid not running
return 1
fi
else ## no PIDFILE
return 1
fi
}
tnow=`date "+%x_%X"`
echo $tnow
### kill procs
if [ "x$1" == "xstop" ];then
killall rtl_tcp
killall lorarx
killall udpgate4
killall sdrtst
sanitycheck
exit 0
fi
# check for rtl_tcp
LOGFILE=/tmp/rtl_tcp.log
PIDFILE=${piddir}/rtl_tcp.pid
checkproc
returnval=$?
if [ $returnval -eq 1 ];then
: > ${LOGFILE}
startrtltcp
fi
sleep 2
# check for sdrtst
LOGFILE=/tmp/sdrtst.log
PIDFILE=${piddir}/sdrtst.pid
checkproc
returnval=$?
if [ $returnval -eq 1 ];then
: > ${LOGFILE}
startsdrtst
fi
# check for udpgate
cd ${caldir}
LOGFILE=/tmp/udpgate4.log
PIDFILE=${piddir}/udpgate4.pid
checkproc
returnval=$?
if [ $returnval -eq 1 ];then
: > ${LOGFILE}
startudpgate
fi
# check for lorarx
cd ${caldir}
LOGFILE=/tmp/lorarx.log
PIDFILE=${piddir}/lorarx.pid
checkproc
returnval=$?
if [ $returnval -eq 1 ];then
: > ${LOGFILE}
startlorarx
fi
sanitycheck
exit 0