diff --git a/rootfs/etc/services.d/autogain/run b/rootfs/etc/services.d/autogain/run deleted file mode 100644 index d0ef46a..0000000 --- a/rootfs/etc/services.d/autogain/run +++ /dev/null @@ -1,43 +0,0 @@ -#!/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 \ No newline at end of file diff --git a/rootfs/usr/local/bin/autogain1090 b/rootfs/usr/local/bin/autogain1090 deleted file mode 100755 index 1eee71e..0000000 --- a/rootfs/usr/local/bin/autogain1090 +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash - -low="${READSB_AUTOGAIN_LOW_PCT:-2.5}" -high="${READSB_AUTOGAIN_HIGH_PCT:-6.0}" -ga=(0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 -10) -tmp=/var/globe_history/autogain -mkdir -p $tmp -mkdir -p /var/globe_history/autogain - -#work around stupid locale stuff -export LC_ALL=C - -APP=dump1090-fa -if [[ -f /run/dump1090-fa/stats.json ]]; then - APP=dump1090-fa -elif [[ -f /run/readsb/stats.json ]]; then - APP=readsb -fi - -stats=/run/$APP/stats.json - -if [[ "$1" == "reset" ]]; then - echo "Reset AutoGain - restarting with initial values and initialization process" - rm -f /var/globe_history/autogain/* >/dev/null 2>&1 - pkill -f "s6-supervise autogain" - exit 0 -fi - -if ! [[ -f $stats ]]; then echo "stats.json not found, is the decoder running?"; exit 1; fi - -oldstrong=$(cat $tmp/strong 2>/dev/null) -oldtotal=$(cat $tmp/total 2>/dev/null) -if [[ -z $oldstrong ]] || [[ -z $oldtotal ]]; then - oldstrong=0 - oldtotal=0 -fi - -if ! grep -qs total $stats | grep -qs -e strong_signals $stats; then - echo "the decoder doesn't seem to be using an rtl-sdr device, can't help with that." - exit 1 -fi - -# start=$(jq '.total.start' < $stats) -# end=$(jq '.total.end' < $stats) - -strong=$(jq '.total.local.strong_signals' < $stats | tee $tmp/strong) -total=$(jq '.total.local.accepted | add' < $stats | tee $tmp/total) - -if [[ -z $strong ]] || [[ -z $total ]]; then - echo "unrecognized format: $stats" - exit 1 -fi - -if ! awk "BEGIN{ exit ($total < 1000) }"; then - echo "The decoder hasn't been running long enough, wait a bit!" - exit 0 -fi - - -if (( oldtotal > total )) || (( oldstrong > strong )) || (( oldtotal == total )); then - oldstrong=0 - oldtotal=0 -fi - -strong=$((strong - oldstrong)) -total=$((total - oldtotal)) - -if [[ $total == 0 ]]; then - percent=0 -else - percent=$(awk "BEGIN {printf \"%.3f\", $strong * 100 / $total}") -fi - -strong=$percent - -if [[ $strong == "nan" ]]; then echo "Error, can't automatically adjust gain!"; exit 1; fi - - -# Get the gain -- updated for docker-tar1090 use by kx1t -if [[ ! -f /var/globe_history/autogain/gain ]]; then - oldgain="49.6" - echo "Initial run. Starting point for adjusting gain is $oldgain" -else - read -r oldgain < /var/globe_history/autogain/gain - oldgain="${oldgain:-49.6}" # needed for stupidity reasons -fi - -gain_index=28 -for i in "${!ga[@]}"; do - if ! awk "BEGIN{ exit (${oldgain} <= ${ga[$i]}) }"; then - gain_index="${i}" - break - fi -done - -if ! awk "BEGIN{ exit (${oldgain} > 49.6) }"; then - gain_index=28 -fi - -if [[ "$oldgain" == "-10" ]]; then - gain_index=28 -fi - - -if ! awk "BEGIN{ exit ($strong > $low) }" && ! awk "BEGIN{ exit ($strong < $high) }"; then - echo "No gain change needed, ${strong}% percentage of messages >-3dB is in nominal range. (${low}% < ${strong}% < ${high}%)" - exit 0 - -fi - -if ! awk "BEGIN{ exit ($strong < $low) }" && [[ $gain_index == 28 ]]; then - echo "Could have used some more gain, but gain is already at maximum! Strong (>-3dB) messages ${strong}% < ${low}%" - exit 0 -fi - -if ! awk "BEGIN{ exit ($strong < $low) }"; then - gain_index=$((gain_index+1)) - action=Increasing -fi - -if ! awk "BEGIN{ exit ($strong > $high) }" && [[ $gain_index == 0 ]]; then - echo "Could have used some lower gain, but gain already at minimum! Strong (>-3dB) messages ${strong}% > ${high}%" - exit 0 -fi - -if ! awk "BEGIN{ exit ($strong > $high) }"; then - gain_index=$((gain_index-1)) - action=Decreasing -fi - -gain="${ga[$gain_index]}" - -if [[ $gain == "" ]] || [[ $gain == "-10" ]]; then - echo "Could have used some more gain, but gain is already at maximum! Strong (>-3dB) messages ${strong}% < ${low}%" - exit 0 -fi - -# Set the gain -- updated for docker-tar1090 use by kx1t -echo "$gain" > /var/globe_history/autogain/gain -pkill readsb - -#reset numbers -echo 0 > $tmp/strong -echo 0 > $tmp/total - -if [[ "$action" == "Increasing" ]]; then - echo "Increasing gain to $gain (${strong}% messages >-3dB exceed lower boundary of ${low}%)" -elif [[ "$action" == "Decreasing" ]]; then - echo "Decreasing gain to $gain (${strong}% messages >-3dB exceed upper boundary of ${high}%)" -fi \ No newline at end of file