-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrx_functions.sh
executable file
·194 lines (162 loc) · 6.74 KB
/
rx_functions.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
function rx_function {
/home/pi/wifibroadcast-base/sharedmem_init_rx
# start virtual serial port for cmavnode and ser2net
ionice -c 3 nice socat -lf /wbc_tmp/socat1.log -d -d pty,raw,echo=0 pty,raw,echo=0 & > /dev/null 2>&1
sleep 1
ionice -c 3 nice socat -lf /wbc_tmp/socat2.log -d -d pty,raw,echo=0 pty,raw,echo=0 & > /dev/null 2>&1
sleep 1
# setup virtual serial ports
stty -F /dev/pts/0 -icrnl -ocrnl -imaxbel -opost -isig -icanon -echo -echoe -ixoff -ixon 57600
stty -F /dev/pts/1 -icrnl -ocrnl -imaxbel -opost -isig -icanon -echo -echoe -ixoff -ixon 115200
echo
# if USB memory stick is already connected during startup, notify user
# and pause as long as stick is not removed
# some sticks show up as sda1, others as sda, check for both
if [ -e "/dev/sda1" ]; then
STARTUSBDEV="/dev/sda1"
else
STARTUSBDEV="/dev/sda"
fi
if [ -e $STARTUSBDEV ]; then
touch /tmp/donotsave
STICKGONE=0
while [ $STICKGONE -ne 1 ]; do
killall wbc_status > /dev/null 2>&1
nice /home/pi/wifibroadcast-status/wbc_status "USB memory stick detected - please remove and re-plug after flight" 7 65 0 &
sleep 4
if [ ! -e $STARTUSBDEV ]; then
STICKGONE=1
rm /tmp/donotsave
fi
done
fi
killall wbc_status > /dev/null 2>&1
sleep 1
detect_nics
echo
sleep 0.5
# videofifo1: local display, hello_video.bin
# videofifo2: secondary display, hotspot/usb-tethering
# videofifo3: recording
# videofifo4: wbc relay
if [ "$VIDEO_TMP" == "sdcard" ]; then
touch /tmp/pausewhile # make sure check_alive doesn't do it's stuff ...
tmessage "Saving to SDCARD enabled, preparing video storage ..."
if cat /proc/partitions | nice grep -q mmcblk0p3; then # partition has not been created yet
echo
else
echo
echo -e "n\np\n3\n3674112\n\nw" | fdisk /dev/mmcblk0 > /dev/null 2>&1
partprobe > /dev/null 2>&1
mkfs.ext4 /dev/mmcblk0p3 -F > /dev/null 2>&1 || {
tmessage "ERROR: Could not format video storage on SDCARD!"
collect_errorlog
sleep 365d
}
fi
e2fsck -p /dev/mmcblk0p3 > /dev/null 2>&1
mount -t ext4 -o noatime /dev/mmcblk0p3 /video_tmp > /dev/null 2>&1 || {
tmessage "ERROR: Could not mount video storage on SDCARD!"
collect_errorlog
sleep 365d
}
VIDEOFILE=/video_tmp/videotmp.raw
echo "VIDEOFILE=/video_tmp/videotmp.raw" > /tmp/videofile
rm $VIDEOFILE > /dev/null 2>&1
else
VIDEOFILE=/wbc_tmp/videotmp.raw
echo "VIDEOFILE=/wbc_tmp/videotmp.raw" > /tmp/videofile
fi
# tracker disabled
#/home/pi/wifibroadcast-base/tracker /wifibroadcast_rx_status_0 >> /wbc_tmp/tracker.txt &
#sleep 1
killall wbc_status > /dev/null 2>&1
if [ "$AIRODUMP" == "Y" ]; then
touch /tmp/pausewhile # make sure check_alive doesn't do it's stuff ...
echo "AiroDump is enabled, running airodump-ng for $AIRODUMP_SECONDS seconds ..."
sleep 3
# strip newlines
NICS_COMMA=`echo $NICS | tr '\n' ' '`
# strip space at end
NICS_COMMA=`echo $NICS_COMMA | sed 's/ *$//g'`
# replace spaces by comma
NICS_COMMA=${NICS_COMMA// /,}
if [ "$FREQ" -gt 3000 ]; then
AIRODUMP_CHANNELS="5180,5200,5220,5240,5260,5280,5300,5320,5500,5520,5540,5560,5580,5600,5620,5640,5660,5680,5700,5745,5765,5785,5805,5825"
else
AIRODUMP_CHANNELS="2412,2417,2422,2427,2432,2437,2442,2447,2452,2457,2462,2467,2472"
fi
airodump-ng --showack -h --berlin 60 --ignore-negative-one --manufacturer --output-format pcap --write /wbc_tmp/wifiscan --write-interval 2 -C $AIRODUMP_CHANNELS $NICS_COMMA &
sleep $AIRODUMP_SECONDS
sleep 2
ionice -c 3 nice -n 19 /home/pi/wifibroadcast-misc/raspi2png -p /wbc_tmp/airodump.png >> /dev/null
killall airodump-ng
sleep 1
printf "\033c"
for NIC in $NICS
do
iw dev $NIC set freq $FREQ
done
sleep 1
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
fi
if [ "$DEBUG" == "Y" ]; then
collect_debug /wbc_tmp &
fi
wbclogger_function &
if vcgencmd get_throttled | nice grep -q -v "0x0"; then
TEMP=`cat /sys/class/thermal/thermal_zone0/temp`
TEMP_C=$(($TEMP/1000))
if [ "$TEMP_C" -lt 75 ]; then
echo " ---------------------------------------------------------------------------------------------------"
echo " | ERROR: Under-Voltage detected on the RX Pi. Your Pi is not supplied with stable 5 Volts. |"
echo " | |"
echo " | Either your power-supply or wiring is not sufficent, check the wiring instructions in the Wiki! |"
echo " ---------------------------------------------------------------------------------------------------"
echo "1" >> /tmp/undervolt
sleep 5
fi
echo "0" >> /tmp/undervolt
else
echo "0" >> /tmp/undervolt
fi
if [ -e "/tmp/pausewhile" ]; then
rm /tmp/pausewhile # remove pausewhile file to make sure check_alive and everything runs again
fi
while true; do
pause_while
ionice -c 1 -n 4 nice -n -10 cat /root/videofifo1 | ionice -c 1 -n 4 nice -n -10 $DISPLAY_PROGRAM > /dev/null 2>&1 &
ionice -c 3 nice cat /root/videofifo3 >> $VIDEOFILE &
if [ "$RELAY" == "Y" ]; then
ionice -c 1 -n 4 nice -n -10 cat /root/videofifo4 | /home/pi/wifibroadcast-base/tx_rawsock -p 0 -b $RELAY_VIDEO_BLOCKS -r $RELAY_VIDEO_FECS -f $RELAY_VIDEO_BLOCKLENGTH -t $VIDEO_FRAMETYPE -d 24 -y 0 relay0 > /dev/null 2>&1 &
fi
# update NICS variable in case a NIC has been removed (exclude devices with wlanx)
NICS=`ls /sys/class/net/ | nice grep -v eth0 | nice grep -v lo | nice grep -v usb | nice grep -v intwifi | nice grep -v wlan | nice grep -v relay | nice grep -v wifihotspot`
tmessage "Starting RX ... (FEC: $VIDEO_BLOCKS/$VIDEO_FECS/$VIDEO_BLOCKLENGTH)"
ionice -c 1 -n 3 /home/pi/wifibroadcast-base/rx -p 0 -d 1 -b $VIDEO_BLOCKS -r $VIDEO_FECS -f $VIDEO_BLOCKLENGTH $NICS | ionice -c 1 -n 4 nice -n -10 tee >(ionice -c 1 -n 4 nice -n -10 /home/pi/wifibroadcast-misc/ftee /root/videofifo2 > /dev/null 2>&1) >(ionice -c 1 nice -n -10 /home/pi/wifibroadcast-misc/ftee /root/videofifo4 > /dev/null 2>&1) >(ionice -c 3 nice /home/pi/wifibroadcast-misc/ftee /root/videofifo3 > /dev/null 2>&1) | ionice -c 1 -n 4 nice -n -10 /home/pi/wifibroadcast-misc/ftee /root/videofifo1 > /dev/null 2>&1
RX_EXITSTATUS=${PIPESTATUS[0]}
check_exitstatus $RX_EXITSTATUS
ps -ef | nice grep "$DISPLAY_PROGRAM" | nice grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | nice grep "rx -p 0" | nice grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | nice grep "ftee /root/videofifo" | nice grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | nice grep "cat /root/videofifo" | nice grep -v grep | awk '{print $2}' | xargs kill -9
done
}