-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.sh
executable file
·189 lines (168 loc) · 5.89 KB
/
main.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
###############################################################################
# The main entrypoint for the Wifibroadcast system.
# Based heavily on the EZ-Wifibroadcast .profile script.
###############################################################################
###############################################################################
# Setup global variables
###############################################################################
source global_functions.sh
TTY=`tty`
#TTY="/dev/tty1"
# GPIO variable
CONFIGFILE=`/root/wifibroadcast_misc/gpio-config.py`
# Check for the camera
check_camera_attached
# Set the approperiate display font size
set_font_for_resolution
# Read the config file
read_config_file
# Set the wifi parameters based on the selected datarate
datarate_to_wifi_settings
# Set the specififc video player based on the fps
set_video_player_based_fps
# Fixed video values
VIDEO_UDP_BLOCKSIZE=1024
TELEMETRY_UDP_BLOCKSIZE=128
RELAY_VIDEO_BLOCKS=8
RELAY_VIDEO_FECS=4
RELAY_VIDEO_BLOCKLENGTH=1024
RSSI_UDP_PORT=5003
# Set telemetry settings based on telemetry type
get_telemetry_settings
# cts protection
set_cts_protection
### FLIGHT CONTROLLER AND TELEMETRY SETTINGS
FC_TELEMETRY_STTY_OPTIONS="-icrnl -ocrnl -imaxbel -opost -isig -icanon -echo -echoe -ixoff -ixon"
EXTERNAL_TELEMETRY_SERIALPORT_GROUND_STTY_OPTIONS="-icrnl -ocrnl -imaxbel -opost -isig -icanon -echo -echoe -ixoff -ixon"
TELEMETRY_OUTPUT_SERIALPORT_GROUND_STTY_OPTIONS="-icrnl -ocrnl -imaxbel -opost -isig -icanon -echo -echoe -ixoff -ixon"
###############################################################################
# Include sub sources
###############################################################################
source tx_rx_functions.sh
source osd_tx_rx_functions.sh
source rc_tx_rx_functions.sh
source rssi_rx_functions.sh
source screenshot_functions.sh
source video_save_functions.sh
source tether_functions.sh
source hotspot_functions.sh
source alive_functions.sh
source uplink_functions.sh
###############################################################################
# Execute the different segments of the system on different TTY consoles
###############################################################################
case $TTY in
/dev/tty1) # TX/RX
MAIN_TX_RX_FUNCTION
;;
/dev/tty2) # OSD
MAIN_OSD_TX_RX_FUNCTION
;;
/dev/tty3) # RC Control
MAIN_RC_TX_RX_FUNCTION
;;
/dev/tty4) # unused
MAIN_RSSI_RX_FUNCTION
;;
/dev/tty5) # screenshot stuff
MAIN_SCREENSHOT_FUNCTION
;;
/dev/tty6) # Save of video after flight
MAIN_VIDEO_SAVE_FUNCTION
;;
/dev/tty7) # check tether
MAIN_TETHER_FUNCTION
;;
/dev/tty8) # check hotspot
MAIN_HOTSPOT_FUNCTION
;;
/dev/tty9) # check alive
MAIN_ALIVE_FUNCTION
;;
/dev/tty10) # uplink
MAIN_UPLINK_FUNCTION
;;
/dev/tty11) # tty for dhcp and login
echo "================== eth0 DHCP client (tty11) ==========================="
# sleep until everything else is loaded (atheros cards and usb flakyness ...)
sleep 6
if [ "$CAM" == "0" ]; then
EZHOSTNAME="wifibrdcast-rx"
else
EZHOSTNAME="wifibrdcast-tx"
fi
# only configure ethernet network interface via DHCP if ethernet hotspot is disabled
if [ "$ETHERNET_HOTSPOT" == "N" ]; then
# disabled loop, as usual, everything is flaky on the Pi, gives kernel stall messages ...
nice ifconfig eth0 up
sleep 5
if cat /sys/class/net/eth0/carrier | nice grep -q 1; then
echo "Ethernet connection detected"
CARRIER=1
if nice pump -i eth0 --no-ntp -h $EZHOSTNAME; then
#ETHCLIENTIP=`ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1`
ETHCLIENTIP=`ip addr show eth0 | grep -Po 'inet \K[\d.]+'`
# kill and pause OSD so we can safeley start wbc_status
ps -ef | nice grep "osd" | nice grep -v grep | awk '{print $2}' | xargs kill -9
killall wbc_status > /dev/null 2>&1
nice /home/pi/wifibroadcast-status/wbc_status "Ethernet connected. IP: $ETHCLIENTIP" 7 55 0
pause_while # make sure we don't restart osd while in pause state
OSDRUNNING=`pidof /tmp/osd | wc -w`
if [ $OSDRUNNING -ge 1 ]; then
echo "OSD already running!"
else
killall wbc_status > /dev/null 2>&1
if [ "$CAM" == "0" ]; then # only (re-)start OSD if we are RX
/tmp/osd >> /wbc_tmp/telemetrydowntmp.txt &
fi
fi
ping -n -q -c 1 1.1.1.1
else
ps -ef | nice grep "pump -i eth0" | nice grep -v grep | awk '{print $2}' | xargs kill -9
nice ifconfig eth0 down
echo "DHCP failed"
ps -ef | nice grep "osd" | nice grep -v grep | awk '{print $2}' | xargs kill -9
killall wbc_status > /dev/null 2>&1
nice /home/pi/wifibroadcast-status/wbc_status "ERROR: Could not acquire IP via DHCP!" 7 55 0
pause_while # make sure we don't restart osd while in pause state
OSDRUNNING=`pidof /tmp/osd | wc -w`
if [ $OSDRUNNING -ge 1 ]; then
echo "OSD already running!"
else
killall wbc_status > /dev/null 2>&1
if [ "$CAM" == "0" ]; then # only (re-)start OSD if we are RX
/tmp/osd >> /wbc_tmp/telemetrydowntmp.txt &
fi
fi
fi
else
echo "No ethernet connection detected"
fi
else
echo "Ethernet Hotspot enabled, doing nothing"
fi
sleep 365d
;;
/dev/tty12) # tty for local interactive login
echo
if [ "$CAM" == "0" ]; then
echo -n "Welcome to EZ-Wifibroadcast 1.6 (RX) - "
read -p "Press <enter> to login"
killall osd
rw
else
echo -n "Welcome to EZ-Wifibroadcast 1.6 (TX) - "
read -p "Press <enter> to login"
rw
fi
;;
*) # all other ttys used for interactive login
if [ "$CAM" == "0" ]; then
echo "Welcome to EZ-Wifibroadcast 1.6 (RX) - type 'ro' to switch filesystems back to read-only"
rw
else
echo "Welcome to EZ-Wifibroadcast 1.6 (TX) - type 'ro' to switch filesystems back to read-only"
rw
fi
;;
esac