92 lines
3.8 KiB
Bash
Executable File
92 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Overnight segmented RF soak for a STANDALONE repeater (no serial link).
|
|
# Per segment: bounded rtl_sdr capture -> offline rtl_wmbus decode ->
|
|
# hil/verify_standalone.py verdict appended to soak.jsonl.
|
|
#
|
|
# Designed around the known observer faults (docs/HARDWARE.md): bounded
|
|
# segments, usbreset recovery on short captures, and a deaf-observer
|
|
# heuristic -- the neighbouring meter rails the dongle at a steady rate,
|
|
# so consecutive near-empty segments mean a dead receiver, not a quiet
|
|
# night. Disk is bounded: confirmed segments drop their IQ; only the two
|
|
# newest unconfirmed segments keep raw IQ for offline audit.
|
|
#
|
|
# Run via the devshell so usbreset is on PATH:
|
|
# nix develop --command ./hil/standalone_soak.sh 0855 300
|
|
#
|
|
# Usage: standalone_soak.sh [END_HHMM] [SEG_SECONDS] [DELAY_MS]
|
|
# standalone_soak.sh 0855 300 500
|
|
set -u
|
|
cd "$(dirname "$0")/.."
|
|
END_HHMM=${1:-0855}
|
|
SEG=${2:-300}
|
|
DELAY_MS=${3:-500} # must match the DUT's persisted repeat_delay_ms
|
|
PY=./result-py/bin/python3
|
|
WMBUS=./result-rtl-wmbus/bin/rtl_wmbus
|
|
[ -x "$PY" ] || { echo "run 'nix build .#hil-python -o result-py' first" >&2; exit 2; }
|
|
[ -x "$WMBUS" ] || { echo "missing result-rtl-wmbus" >&2; exit 2; }
|
|
|
|
OUT="captures/$(date +%Y-%m-%dT%H-%M-%S)-standalone-soak"
|
|
mkdir -p "$OUT"
|
|
END_EPOCH=$(date -d "$END_HHMM" +%s 2>/dev/null) || { echo "bad end time: $END_HHMM" >&2; exit 2; }
|
|
if [ "$END_EPOCH" -le "$(date +%s)" ]; then
|
|
END_EPOCH=$(date -d "tomorrow $END_HHMM" +%s)
|
|
fi
|
|
echo "soak until $(date -d "@$END_EPOCH" '+%F %T'), segment ${SEG}s -> $OUT"
|
|
command -v usbreset >/dev/null || echo "WARNING: usbreset not on PATH; dongle recovery disabled" >&2
|
|
|
|
low_bursts=0
|
|
short_caps=0
|
|
i=0
|
|
while [ $(( $(date +%s) + SEG )) -le "$END_EPOCH" ]; do
|
|
i=$((i + 1))
|
|
D="$OUT/seg$i"
|
|
mkdir -p "$D"
|
|
timeout $((SEG + 60)) rtl_sdr -f 868950000 -s 1600000 -g 42.1 \
|
|
-n $((SEG * 1600000)) "$D/iq.raw" 2> "$D/rtl_sdr.err"
|
|
SZ=$(stat -c %s "$D/iq.raw" 2>/dev/null || echo 0)
|
|
T=$(date +%s)
|
|
if [ "$SZ" -lt $((SEG * 3200000 * 8 / 10)) ]; then
|
|
echo "{\"seg\":$i,\"error\":\"short_capture\",\"bytes\":$SZ,\"t\":$T}" >> "$OUT/soak.jsonl"
|
|
rm -f "$D/iq.raw"
|
|
usbreset 0bda:2838 >/dev/null 2>&1
|
|
short_caps=$((short_caps + 1))
|
|
# A de-enumerated dongle (needs physical replug) is unrecoverable
|
|
# from software: back off instead of hammering, keep probing in
|
|
# case it re-appears.
|
|
if [ "$short_caps" -ge 5 ]; then sleep 300; else sleep 20; fi
|
|
continue
|
|
fi
|
|
short_caps=0
|
|
V=$($PY hil/verify_standalone.py --iq "$D/iq.raw" --delay-ms "$DELAY_MS" \
|
|
--decodes "$D/decodes.log" --json 2> "$D/verdict.err")
|
|
RC=$?
|
|
if [ -n "$V" ]; then
|
|
printf '%s\n' "$V" | $PY -c \
|
|
"import json,sys; d=json.load(sys.stdin); d['seg']=$i; d['rc']=$RC; d['t']=$T; print(json.dumps(d))" \
|
|
>> "$OUT/soak.jsonl"
|
|
else
|
|
echo "{\"seg\":$i,\"rc\":$RC,\"error\":\"no_verdict\",\"t\":$T}" >> "$OUT/soak.jsonl"
|
|
fi
|
|
if grep -q "lost at least" "$D/rtl_sdr.err" 2>/dev/null; then
|
|
echo "{\"seg\":$i,\"note\":\"sample_drops\",\"t\":$T}" >> "$OUT/soak.jsonl"
|
|
fi
|
|
|
|
B=$(printf '%s\n' "$V" | $PY -c \
|
|
"import json,sys; print(json.load(sys.stdin).get('bursts_total',0))" \
|
|
2>/dev/null || echo 0)
|
|
if [ "${B:-0}" -lt 3 ]; then low_bursts=$((low_bursts + 1)); else low_bursts=0; fi
|
|
if [ "$low_bursts" -ge 2 ]; then
|
|
echo "{\"seg\":$i,\"note\":\"observer_suspect_reset\",\"t\":$(date +%s)}" >> "$OUT/soak.jsonl"
|
|
usbreset 0bda:2838 >/dev/null 2>&1
|
|
low_bursts=0
|
|
fi
|
|
|
|
if printf '%s' "$V" | grep -q '"verdict": "confirmed"'; then
|
|
rm -f "$D/iq.raw"
|
|
fi
|
|
ls -1t "$OUT"/seg*/iq.raw 2>/dev/null | tail -n +3 | xargs -r rm -f
|
|
|
|
sleep 15
|
|
done
|
|
echo "soak complete: $OUT/soak.jsonl"
|