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-23 21:46:21 +00:00
|
|
|
# Check every 60 secs if GPSD has been enabled
|
|
|
|
if [[ ! -f /run/readsb/gpsd.json ]] || [[ "$(jq -r .lat /run/readsb/gpsd.json)" == "null" ]]; then
|
|
|
|
sleep 60 & wait $!
|
2024-05-18 20:39:49 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-23 21:46:21 +00:00
|
|
|
# Then wait until all mlat-client instances have started
|
|
|
|
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
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
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:46:21 +00:00
|
|
|
if (( ${distance%%.*} > GPSD_MIN_DISTANCE )); 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
|
|
|
# flag to the mlat-client script that it should try to use GPS coords instead of the predefined LAT/LON
|
|
|
|
touch /run/.gpsd_is_active
|
|
|
|
# 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-18 20:39:49 +00:00
|
|
|
fi
|
2024-05-23 21:46:21 +00:00
|
|
|
sleep "${GPSD_CHECK_INTERVAL:30}" & wait $!
|
2024-05-18 20:39:49 +00:00
|
|
|
done
|