mirror of
https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git
synced 2024-11-23 22:30:09 +00:00
don't immediately start mlat clients when GPSD is configured
This commit is contained in:
parent
372600dfb5
commit
0b10463093
1 changed files with 31 additions and 15 deletions
|
@ -77,20 +77,20 @@ GPSD=0
|
|||
if grep -qs "gpsd" <<< "$ULTRAFEEDER_CONFIG" || grep -qs "gpsd" <<< "$ULTRAFEEDER_NET_CONNECTOR"; then
|
||||
GPSD=1
|
||||
LOCATION_PERSIST=/var/globe_history/gpsd_last_location
|
||||
if [[ -f "$LOCATION_PERSIST" ]] && { grep -qs "gpsd" <<< "$ULTRAFEEDER_CONFIG" || grep -qs "gpsd" <<< "$ULTRAFEEDER_NET_CONNECTOR"; }; then
|
||||
if [[ -f "$LOCATION_PERSIST" ]]; then
|
||||
read new_lat new_lon new_alt < "$LOCATION_PERSIST"
|
||||
"${s6wrap[@]}" --args echo "Using last known GPSD location for startup: $new_lat,$new_lon (alt: $new_alt)"
|
||||
else
|
||||
fi
|
||||
# initialize "old" location for gpsd movement detection
|
||||
# use zero island as starting point if location persist does not exit
|
||||
old_lat=${new_lat:-0}
|
||||
old_lon=${new_lon:-0}
|
||||
|
||||
# wait for gpsd to continue with startup
|
||||
"${s6wrap[@]}" --args echo "GPSD configured, no location set, no persistent location found, waiting for gpsd to provide location data"
|
||||
"${s6wrap[@]}" --args echo "GPSD configured, waiting for gpsd to provide location data"
|
||||
while ! check_gpsd; do
|
||||
sleep "${GPSD_CHECK_INTERVAL:-30}" & wait $!
|
||||
done
|
||||
"${s6wrap[@]}" --args echo "GPSD has provided location data"
|
||||
fi
|
||||
# initialize "old" location for gpsd movement detection
|
||||
old_lat="$new_lat"
|
||||
old_lon="$new_lon"
|
||||
|
||||
GPSD_MIN_DISTANCE="${GPSD_MIN_DISTANCE:-20}"
|
||||
# enforce gpsd min distance is no larger than 40m
|
||||
|
@ -284,6 +284,12 @@ do
|
|||
# shellcheck disable=SC2048,SC2086
|
||||
execstring="$(echo ${MLAT_CMD} ${MLAT_PARAM[*]} | xargs)"
|
||||
|
||||
if (( GPSD == 1 )); then
|
||||
# when GPSD is active, just write the pid array, mlat-client will be started by the gpsd checking logic later
|
||||
# use a long random PID so that it's detected as "not running"
|
||||
pid_array["${RANDOM}${RANDOM}${RANDOM}"]="${MLAT_PARAM[*]}"
|
||||
continue
|
||||
fi
|
||||
|
||||
# stagger by 15 second so they don't all start at the same time
|
||||
sleep "${MLAT_STARTUP_STAGGER:-15}" & wait $!
|
||||
|
@ -311,20 +317,28 @@ sleep 5 & wait $!
|
|||
# Now iterate over all MLAT-client instances and check if they are still running:
|
||||
while true
|
||||
do
|
||||
if check_gpsd; then
|
||||
if (( GPSD == 1 )); then
|
||||
if ! check_gpsd; then
|
||||
# don't do mlat client restarts if GPSD is configured but not providing a position
|
||||
sleep "${GPSD_CHECK_INTERVAL}" & wait $!
|
||||
continue
|
||||
fi
|
||||
|
||||
distance="$(distance "$old_lat" "$old_lon" "$new_lat" "$new_lon")"
|
||||
if ! [[ -f "$LOCATION_PERSIST" ]]; then
|
||||
echo "$new_lat" "$new_lon" "$new_alt" > "$LOCATION_PERSIST"
|
||||
fi
|
||||
if (( ${distance%%.*} > ${GPSD_MIN_DISTANCE:-20} )); then
|
||||
|
||||
msg="Receiver moved ${distance%%.*} meters"
|
||||
|
||||
# kill the mlat-client instances so they get restarted with the new GPS coords
|
||||
if pkill -f "/usr/bin/python3 /usr/bin/mlat-client" >/dev/null 2>&1; then
|
||||
"${s6wrap[@]}" --args echo "Receiver moved ${distance%%.*} meters - Stopping all mlat-clients"
|
||||
else
|
||||
"${s6wrap[@]}" --args echo "Receiver moved ${distance%%.*} meters"
|
||||
msg+=" - Stopping all mlat-clients"
|
||||
fi
|
||||
|
||||
"${s6wrap[@]}" --args echo "${msg}"
|
||||
|
||||
old_lat="$new_lat"
|
||||
old_lon="$new_lon"
|
||||
|
||||
|
@ -338,6 +352,8 @@ do
|
|||
# no movement during the checking interval, allow mlat-clients to be restarted
|
||||
(( no_movement += ${GPSD_CHECK_INTERVAL:-30} )) || true
|
||||
if (( no_movement < no_movement_required )); then
|
||||
msg="Receiver moved less than ${GPSD_MIN_DISTANCE} meters, $(( no_movement_required - no_movement )) seconds remaining before starting mlat-clients"
|
||||
"${s6wrap[@]}" --args echo "${msg}"
|
||||
sleep "${GPSD_CHECK_INTERVAL:-30}" & wait $!
|
||||
continue
|
||||
elif (( no_movement / ${GPSD_CHECK_INTERVAL:-30} == no_movement_required / ${GPSD_CHECK_INTERVAL:-30} )); then
|
||||
|
|
Loading…
Reference in a new issue