Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kx1t authored Sep 23, 2024
2 parents a662470 + 3f0c39b commit e55bc57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
10 changes: 5 additions & 5 deletions rootfs/etc/s6-overlay/scripts/autogain
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function collect_gain_values() {
local rssi
local endtime
local cutoff="${2:--3.5}"
cutoff="$(bc -l <<< "scale=0; ${cutoff/#-} * 10 / 1")"
cutoff="$(bc -l <<< "scale=0; ${cutoff} * 10 / 1")"
unset GAIN_COLLECTION

if [[ -z "$1" ]]; then
Expand All @@ -57,15 +57,15 @@ function collect_gain_values() {
# create a FD with a data stream of rssi values
if chk_enabled "$READSB_AUTOGAIN_USE_RAW"; then
# parse all messages that have an ";rssi=-xx.xx" element, regardless of any error indicators
while ! exec 3< <(stdbuf -oL sed -n 's|^.*;rssi=-\([0-9]\+\)\.\([0-9]*\);.*$|\1\2|p' </dev/tcp/localhost/30978 2>/dev/null) 2>/dev/null; do
while ! exec 3< <(stdbuf -oL sed -n 's|^.*;rssi=\([0-9-]\+\)\.\([0-9]*\);.*$|\1\2|p' </dev/tcp/localhost/30978 2>/dev/null) 2>/dev/null; do
sleep 5
exec 3>&-
done
else
# ignore messages that have anything between the raw message string and ";rssi="
# These messages have an error code ";ts=x" between the raw msg and the rssi element
# In that case, we're only considering "accepted" messages
while ! exec 3< <(stdbuf -oL sed -n 's|^-[0-9a-f]*;rssi=-\([0-9]\+\)\.\([0-9]*\);.*$|\1\2|p' </dev/tcp/localhost/30978 2>/dev/null) 2>/dev/null; do
while ! exec 3< <(stdbuf -oL sed -n 's|^-[0-9a-f]*;rssi=\([0-9-]\+\)\.\([0-9]*\);.*$|\1\2|p' </dev/tcp/localhost/30978 2>/dev/null) 2>/dev/null; do
sleep 5
exec 3>&-
done
Expand All @@ -76,7 +76,7 @@ function collect_gain_values() {
starttime="$(date +%s)"
while IFS= read -r rssi <&3; do
(( total_msg++ )) || true
(( ${rssi##0} < cutoff )) && (( strong_msg++ )) || true
(( ${rssi##0} > cutoff )) && (( strong_msg++ )) || true
# read messages until we have least READSB_AUTOGAIN_MIN_SAMPLES, and the max time is exhausted
# in other words - even if the max time expires, continue collecting messages until at least the minimum has been reached
if (( total_msg >= READSB_AUTOGAIN_MIN_SAMPLES )) && (( $(date +%s) > starttime + $1 )); then
Expand All @@ -90,7 +90,7 @@ function collect_gain_values() {
exec 3>&-

GAIN_COLLECTION="$total_msg;$strong_msg;"
if (( strong_msg * total_msg > 0 )); then
if (( total_msg > 0 )); then
GAIN_COLLECTION="${GAIN_COLLECTION}$(bc -l <<< "scale=1; 100 * $strong_msg / $total_msg / 1")"
else
GAIN_COLLECTION="${GAIN_COLLECTION}na"
Expand Down
2 changes: 2 additions & 0 deletions rootfs/scripts/autogain.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/command/with-contenv bash
# shellcheck shell=bash

# !!! DEPRECATED !!!

# If troubleshooting:
if [[ -n "$DEBUG_LOGGING" ]]; then
set -x
Expand Down
9 changes: 6 additions & 3 deletions rootfs/usr/local/bin/autogain978
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

# This script is only for dump978 autogain

# called by /etc/s6-overlay/scripts/autogain
# or called manually by the user to reset autogain

source /scripts/common

READSB_AUTOGAIN_LOW_PCT="${DUMP978_AUTOGAIN_LOW_PCT:-${READSB_AUTOGAIN_LOW_PCT:-5.0}}"
Expand Down Expand Up @@ -43,8 +46,8 @@ if [[ -z $oldstrong ]] || [[ -z $oldtotal ]]; then
fi

# use the values that were passed in via the commandline. Format is "total;strong;strong_pct" but we only use total and strong here
total="$(awk -F';' '{print $1}' <<< "$1" | tee $autogain_dir/strong)"
strong="$(awk -F';' '{print $2}' <<< "$1"| tee $autogain_dir/total)"
total="$(awk -F';' '{print $1}' <<< "$1" | tee $autogain_dir/total)"
strong="$(awk -F';' '{print $2}' <<< "$1"| tee $autogain_dir/strong)"

if [[ -z "$strong" ]] || [[ -z "$total" ]]; then
echo "[INFO] Stats not yet ready. Skipping this $(basename "$0") run"
Expand Down Expand Up @@ -148,4 +151,4 @@ s6-svc -r /run/service/stats 2>/dev/null || true

#reset numbers
echo 0 > $autogain_dir/strong
echo 0 > $autogain_dir/total
echo 0 > $autogain_dir/total

0 comments on commit e55bc57

Please sign in to comment.