#!/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 . #--------------------------------------------------------------------------------------------- source /scripts/common # 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 $! fi # Then wait until all mlat-client instances have started while [[ ! -f /run/.all_mlatclient_instances_have_started ]]; do sleep 5 & wait $! done rm -f /run/.all_mlatclient_instances_have_started # Now wait a bit to allow GPS to establish itself sleep "${GPSD_INITIAL_WAIT:-60}" # Get initial lat/lon/alt lat="${LAT:-${READSB_LAT:-$(jq -r .lat /run/readsb/gpsd.json)}}" lon="${LONG:-${READSB_LON:-$(jq -r .lon /run/readsb/gpsd.json)}}" "${s6wrap[@]}" echo "GPSD is active. Your mlat-client(s) will restart with new coordinates if you move more than ${GPSD_MIN_DISTANCE:-20} meters" while :; do new_lat="$(jq -r .lat /run/readsb/gpsd.json)" new_lon="$(jq -r .lon /run/readsb/gpsd.json)" distance="$(nice -n 20 distance "$lat" "$lon" "$new_lat" "$new_lon")" if (( ${distance%%.*} > ${GPSD_MIN_DISTANCE:-20} )); then "${s6wrap[@]}" echo "Receiver moved ${distance%%.*} meters - restarting all mlat-clients" # 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 lat="$new_lat" lon="$new_lon" fi sleep "${GPSD_CHECK_INTERVAL:-30}" & wait $! done