1
0
Fork 0
mirror of https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git synced 2024-12-28 15:22:00 +00:00
docker-adsb-ultrafeeder/rootfs/etc/services.d/autogain/run
2023-03-24 15:36:56 +01:00

43 lines
No EOL
2 KiB
Text

#!/usr/bin/with-contenv bash
# shellcheck shell=bash disable=SC2076
# Autogain routine
#
# Relevant env variables:
# READSB_GAIN: set to "autogain" to enable autogain
# READSB_AUTOGAIN_INITIAL_INTERVAL: time in seconds to run autogain during initial assessment period; 300 if omitted
# READSB_AUTOGAIN_SUBSEQUENT_INTERVAL: time in seconds to run autogain during initial assessment period; 86400 (=1 day) if omitted
# Command to restart autogain: docker exec -it tar1090 /usr/local/bin/autogain1090 reset
READSB_AUTOGAIN_INITIAL_INTERVAL="${READSB_AUTOGAIN_INITIAL_INTERVAL:-300}"
READSB_AUTOGAIN_SUBSEQUENT_INTERVAL="${READSB_AUTOGAIN_SUBSEQUENT_INTERVAL:-86400}"
READSB_AUTOGAIN_INITIAL_TIMEPERIOD="${READSB_AUTOGAIN_INITIAL_TIMEPERIOD:-7200}"
if [[ "${READSB_GAIN,,}" != "autogain" ]]; then
# Autogain is not enabled, so let's do nothing forever
sleep infinity
fi
if [[ "${READSB_DEVICE_TYPE,,}" != "rtlsdr" ]] || [[ -z "${READSB_RTLSDR_DEVICE}" ]]; then
echo "[autogain] ERROR: AUTOGAIN enabled but READSB_DEVICE_TYPE is not \"rtlsdr\" or READSB_RTLSDR_DEVICE serial number not defined. Autogain disabled."
sleep infinity
fi
mkdir -p /var/globe_history/autogain
# Do special things if it's the first time AUTOGAIN is running
if [[ ! -f /var/globe_history/autogain/autogain_initialized ]]; then
# run autogain every $READSB_AUTOGAIN_INITIAL_INTERVAL secs (default 5 mins) for $READSB_AUTOGAIN_INITIAL_TIMEPERIOD secs (default 2 hours)
for (( i=0; i<$(( READSB_AUTOGAIN_INITIAL_TIMEPERIOD / READSB_AUTOGAIN_INITIAL_INTERVAL )); i++ ))
do
sleep "$READSB_AUTOGAIN_INITIAL_INTERVAL" # sleep first to give readsb the opportunity to collect some initial data
/usr/local/bin/autogain1090 2>&1 | mawk -W Interactive '{print "[autogain] " $0}'
done
touch /var/globe_history/autogain/autogain_initialized
fi
while true
do
sleep "$READSB_AUTOGAIN_SUBSEQUENT_INTERVAL"
/usr/local/bin/autogain1090 2>&1 | mawk -W Interactive '{print "[autogain] " $0}'
done