1
0
Fork 0
mirror of https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git synced 2024-11-27 16:20:10 +00:00
docker-adsb-ultrafeeder/rootfs/etc/s6-overlay/scripts/gpsd_mlat_restart

54 lines
2.3 KiB
Text
Raw Normal View History

2024-05-18 20:39:49 +00:00
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC2015,SC2016,SC1091,SC2001,SC2154
#---------------------------------------------------------------------------------------------
# Copyright (C) 2023-2024, Ramon F. Kolb (kx1t) and contributors
#
# This program 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.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------------
source /scripts/common
2024-05-24 13:29:36 +00:00
# Wait until all mlat-client instances have started
2024-05-23 21:46:21 +00:00
while [[ ! -f /run/.all_mlatclient_instances_have_started ]]; do
sleep 5 & wait $!
2024-05-18 20:39:49 +00:00
done
2024-05-23 21:46:21 +00:00
rm -f /run/.all_mlatclient_instances_have_started
2024-05-24 13:29:36 +00:00
# Check every 60 secs if GPSD has been enabled
while [[ ! -f /run/readsb/gpsd.json ]] || [[ "$(jq -r .lat /run/readsb/gpsd.json)" == "null" ]]; do
sleep 60 & wait $!
done
2024-05-23 21:46:21 +00:00
# Now wait a bit to allow GPS to establish itself
sleep "${GPSD_INITIAL_WAIT:-60}"
2024-05-18 20:39:49 +00:00
# Get initial lat/lon/alt
2024-05-23 21:46:21 +00:00
lat="${LAT:-${READSB_LAT:-$(jq -r .lat /run/readsb/gpsd.json)}}"
lon="${LONG:-${READSB_LON:-$(jq -r .lon /run/readsb/gpsd.json)}}"
2024-05-18 20:39:49 +00:00
2024-05-23 22:03:48 +00:00
"${s6wrap[@]}" echo "GPSD is active. Your mlat-client(s) will restart with new coordinates if you move more than ${GPSD_MIN_DISTANCE:-20} meters"
2024-05-23 22:00:47 +00:00
2024-05-18 20:39:49 +00:00
while :; do
2024-05-23 21:46:21 +00:00
new_lat="$(jq -r .lat /run/readsb/gpsd.json)"
new_lon="$(jq -r .lon /run/readsb/gpsd.json)"
2024-05-18 20:39:49 +00:00
distance="$(nice -n 20 distance "$lat" "$lon" "$new_lat" "$new_lon")"
2024-05-23 21:47:57 +00:00
if (( ${distance%%.*} > ${GPSD_MIN_DISTANCE:-20} )); then
2024-05-18 20:39:49 +00:00
"${s6wrap[@]}" echo "Receiver moved ${distance%%.*} meters - restarting all mlat-clients"
2024-05-23 21:46:21 +00:00
# kill the mlat-client instances so they get restarted with the new GPS coords
pkill -f "/usr/bin/python3 /usr/bin/mlat-client" >/dev/null 2>&1
2024-05-23 22:05:29 +00:00
lat="$new_lat"
lon="$new_lon"
2024-05-18 20:39:49 +00:00
fi
2024-05-23 21:58:07 +00:00
sleep "${GPSD_CHECK_INTERVAL:-30}" & wait $!
2024-05-18 20:39:49 +00:00
done