Skip to content

Commit

Permalink
Merge branch 'main' into kx1t-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
kx1t authored May 1, 2024
2 parents 5ed1829 + 0738e20 commit 0393610
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 51 deletions.
2 changes: 1 addition & 1 deletion rootfs/etc/nginx.tar1090/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
user www-data;
worker_processes auto;
worker_processes 1;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
daemon off;
Expand Down
3 changes: 2 additions & 1 deletion rootfs/etc/s6-overlay/scripts/nginx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

source /scripts/common

if chk_enabled "${TAR1090_DISABLE}"; then
if [[ "$(find /etc/nginx/sites-enabled/ -type f | wc -l)" == "0" ]]; then
exec sleep infinity
fi


mkdir -p /var/log/nginx

exec s6wrap --quiet --prepend=nginx --timestamps --args /usr/sbin/nginx
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/startup.d/02-tar1090-update
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

source /scripts/common

if ! chk_enabled "${UPDATE_TAR1090}"; then
if ! chk_enabled "${UPDATE_TAR1090}" || chk_enabled "${TAR1090_DISABLE}"; then
exit 0
fi

Expand Down
7 changes: 7 additions & 0 deletions rootfs/etc/s6-overlay/startup.d/04-tar1090-configure
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

source /scripts/common


if chk_enabled "${TAR1090_DISABLE}"; then
rm -f /etc/nginx/sites-enabled/tar1090
exit 0
fi


# create symlink so /var/cache/fontconfig is in tmpfs
# as per Wiedehopf - https://discord.com/channels/734090820684349521/1102603003376177172/1203826726023729162
# shellcheck disable=SC2174
Expand Down
4 changes: 4 additions & 0 deletions rootfs/etc/s6-overlay/startup.d/06-range-outline
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

source /scripts/common

if chk_enabled "${TAR1090_DISABLE}"; then
exit 0
fi

# https://github.com/wiedehopf/tar1090#heywhatsthatcom-range-outline

if [ -n "${HEYWHATSTHAT_PANORAMA_ID}" ]; then
Expand Down
8 changes: 0 additions & 8 deletions rootfs/etc/s6-overlay/startup.d/08-graphs1090-down

This file was deleted.

85 changes: 45 additions & 40 deletions rootfs/usr/local/bin/autogain1090
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@ source /scripts/common

low="${READSB_AUTOGAIN_LOW_PCT:-2.5}"
high="${READSB_AUTOGAIN_HIGH_PCT:-6.0}"
gain_array=(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)

# this excludes 58 / tuner agc as the step is rather big resulting in oscillations and it's rarely a big improvement to use it
gain_array=(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)

autogain_dir="/var/globe_history/autogain"
mkdir -p $autogain_dir

if [[ -f "${autogain_dir}/suspend" ]]; then
# allow temporary suspending of autogain by touching this file
exit 0
fi

touch $autogain_dir/strong $autogain_dir/total


# if there are no messages received and noise is lower than this, increase gain
low_noise=-30
# if noise is higher than this, never increase gain
# if noise is higher than this, reduce gain
# this is valuable for cases of strong interference where we might not see any messages at all until the gain is lowered
high_noise=-15


# if noise is lower than this, increase gain
# this is valuable for cases of unamplified SDRs combined with bad antennas and a low initial gain setting
low_noise=-36


#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
stats=/run/readsb/stats.json

if [[ "$1" == "reset" ]]; then
echo "Reset AutoGain - restarting with initial values and initialization process"
Expand All @@ -46,42 +52,47 @@ if [[ -z $oldstrong ]] || [[ -z $oldtotal ]]; then
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 $autogain_dir/strong)
total=$(jq '.total.local.accepted | add' < $stats | tee $autogain_dir/total)
newstrong=$(jq '.total.local.strong_signals' < $stats)
newtotal=$(jq '.total.local.accepted | add' < $stats)

noise=$(jq '.last1min.local.noise'< $stats)

if [[ -z $strong ]] || [[ -z $total ]]; then
echo "unrecognized format: $stats"
if [[ -z $newstrong ]] || [[ -z $newtotal ]]; then
echo "unrecognized format or no rtl-sdr in use: $stats"
exit 1
fi

if (( oldtotal > total )) || (( oldstrong > strong )); then
if (( oldtotal > newtotal )) || (( oldstrong > newstrong )); then
oldstrong=0
oldtotal=0
fi

strong=$((strong - oldstrong))
total=$((total - oldtotal))
strong=$((newstrong - oldstrong))
total=$((newtotal - oldtotal))

#echo "strong: $strong total: $total noise: $noise"

if ! awk "BEGIN{ exit ($total < 100) }"; then
if ! awk "BEGIN{ exit ($noise < $low_noise) }"; then
reason="Very few messages seen and noise is $noise < $low_noise"
action=Increasing
else
if ! awk "BEGIN{ exit ($noise > $high_noise) }"; then
reason="Noise high: $noise dBFS > $high_noise dBFS"
action=Decreasing
fi

if ! awk "BEGIN{ exit ($noise < $low_noise) }"; then
reason="Noise low: $noise dBFS < $low_noise dBFS"
action=Increasing
else


if [[ -z "$action" ]] && ! awk "BEGIN{ exit ($total < 500) }"; then
echo "The decoder hasn't been running long enough, wait a bit!"
exit 0
fi
fi

echo "$newstrong" > $autogain_dir/strong
echo "$newtotal" > $autogain_dir/total

if [[ $total == 0 ]]; then
percent=0
else
Expand Down Expand Up @@ -131,17 +142,11 @@ if [[ -z "$action" ]] && ! awk "BEGIN{ exit ($strong < $low) }"; then
action=Increasing
fi

if ! awk "BEGIN{ exit ($strong > $high) }"; then
if [[ -z "$action" ]] && ! awk "BEGIN{ exit ($strong > $high) }"; then
reason="${strong}% messages >-3dB exceed upper boundary of ${high}%"
action=Decreasing
fi

if ! awk "BEGIN{ exit ($noise > $high_noise) }"; then
# if noise is higher than this, decrease gain
reason="Noise at ${noise} dBFS, decreasing gain!"
action=Decreasing
fi

if [[ "$action" == "Decreasing" ]]; then
gain_index=$((gain_index-1))
elif [[ "$action" == "Increasing" ]]; then
Expand All @@ -150,12 +155,12 @@ fi

gain="${gain_array[$gain_index]}"

if [[ "$action" == "Decreasing" ]] && [[ $gain_index == 0 ]]; then
if (( gain_index < 0 )); then
echo "Could have used some lower gain, but gain already at minimum! ($reason)"
exit 0
fi

if [[ $gain == "" ]] || [[ $gain == "-10" ]]; then
if [[ "$action" == "Increasing" ]] && [[ $gain == "" ]]; then
echo "Could have used some more gain, but gain is already at maximum! ($reason)"
exit 0
fi
Expand Down

0 comments on commit 0393610

Please sign in to comment.