firmware/general/package/wifibroadcast-ng/files/wifibroadcast

154 lines
3.1 KiB
Bash
Executable File

#!/bin/sh
wfb_soc=$(ipcinfo -c)
wfb_key=/etc/drone.key
wfb_cfg=/etc/wfb.conf
# Default broadcast
wlan=wlan0
txpower=1
region=00
channel=161
bandwidth=20
mcs_index=1
telemetry_mcs_index=1
stream=0
stbc=0
ldpc=0
fec_k=8
fec_n=12
link_id=7669206
bandwidth_iw_mode_20=HT20
bandwidth_iw_mode_40=HT40+
bandwidth_iw_mode_80=80Mhz
# Default telemetry
router=msposd
serial=/dev/ttyS2
baud=115200
mav_chn=8
osd_fps=20
port_rx=14551
port_tx=14555
# Custom configuration
if [ -e "$wfb_cfg" ]; then
. "$wfb_cfg"
fi
load_modules() {
for card in $(lsusb | awk '{print $6}' | sort | uniq); do
case "$card" in
"0bda:8812" | "0bda:881a" | "0b05:17d2" | "2357:0101" | "2604:0012")
driver=88XXau
modprobe "$driver" rtw_tx_pwr_idx_override="$txpower"
;;
"0bda:a81a")
driver=8812eu
modprobe "$driver" rtw_regd_src=1 rtw_tx_pwr_by_rate=0 rtw_tx_pwr_lmt_enable=0
;;
"0bda:f72b" | "0bda:b733")
driver=8733bu
modprobe "$driver" rtw_regd_src=1 rtw_tx_pwr_by_rate=0 rtw_tx_pwr_lmt_enable=0
;;
esac
done
if [ -z "$driver" ]; then
echo "Wireless module not detected, check the usb connection"
exit 1
else
echo "Detected driver: $driver"
fi
}
load_interface() {
iw dev "$wlan" set monitor none
iwconfig "$wlan" mode monitor
ifconfig "$wlan" up
#iw "$wlan" set type monitor
case "$bandwidth" in
"20")
iw_mode="$bandwidth_iw_mode_20"
;;
"40")
iw_mode="$bandwidth_iw_mode_40"
;;
"80")
iw_mode="$bandwidth_iw_mode_80"
;;
esac
iw "$wlan" set channel "$channel" "$iw_mode"
iw reg set "$region"
if [ "$driver" = "8812eu" ] || [ "$driver" = "8733bu" ]; then
iw "$wlan" set txpower fixed $((txpower * 50))
fi
}
start_wfb() {
echo "Starting wfb_tx"
wfb_tx -K "$wfb_key" -M "$mcs_index" -p "$stream" -B "$bandwidth" -C 8000 \
-S "$stbc" -L "$ldpc" -k "$fec_k" -n "$fec_n" -i "$link_id" "$wlan" &> /dev/null &
}
start_tunnel() {
echo "Starting wfb_tun"
wfb_rx -p 160 -u 5800 -K "$wfb_key" -i "$link_id" "$wlan" &> /dev/null &
wfb_tx -p 32 -u 5801 -K "$wfb_key" -M "$telemetry_mcs_index" -S "$stbc" -L "$ldpc" \
-k "$fec_k" -n "$fec_n" -i "$link_id" "$wlan" &> /dev/null &
wfb_tun -a 10.5.0.10/24 > /dev/null &
}
start_telemetry() {
if [ "$wfb_soc" = "gk7205v200" ]; then
devmem 0x120C0010 32 0x1E04
elif [ "$wfb_soc" = "ssc33x" ]; then
devmem 0x1F207890 16 0x8
fi
if [ "$router" = "msposd" ]; then
echo "Starting $router"
msposd --master "$serial" --baudrate "$baud" -osd --ahi 0 -r "$osd_fps" \
--channels "$mav_chn" --out 10.5.0.1:"$port_tx" > /dev/null &
elif [ "$router" = "mavfwd" ]; then
echo "Starting $router"
mavfwd --master "$serial" --baudrate "$baud" -p 100 -a 15 -t \
--channels "$mav_chn" --in 0.0.0.0:"$port_rx" --out 10.5.0.1:"$port_tx" > /dev/null &
fi
}
case "$1" in
start)
if [ ! -e /etc/system.ok ]; then
echo "Preparing system tweaks for $wfb_soc..."
tweaksys "$wfb_soc"
exit 0
fi
load_modules
load_interface
start_wfb
start_tunnel
start_telemetry
;;
stop)
killall -q wfb_rx
killall -q wfb_tx
killall -q wfb_tun
killall -q msposd
killall -q mavfwd
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac