hil: IQ repeat proof phase, 3-level SDR sensitivity, proof-gain option

This commit is contained in:
Lars Nolden
2026-09-01 09:03:19 +02:00
parent 78a8635ac8
commit 3fea191008
4 changed files with 239 additions and 14 deletions
+36 -1
View File
@@ -4,9 +4,11 @@
# discover devices -> verify SDR actually receives -> build+flash
# -> phase A: TX decodability proof (synthetic C1 bursts)
# -> phase B: real-meter RX/repeat correlation
# -> phase C: decode-independent IQ repeat proof
# -> report (text + JSON), nonzero exit on FAIL
#
# Usage: ./hil/run.sh [--duration N] [--no-flash] [--tx-power N] [--delay MS]
# [--iq-seconds N] [--proof-gain G]
# [--gain G] [--min-repeats N] [--no-proof]
set -euo pipefail
cd "$(dirname "$0")/.."
@@ -17,6 +19,8 @@ TXPOW=-9
DELAY=200
GAIN=42.1
MIN_REPEATS=1
IQ_SECONDS=120
PROOF_GAIN=""
PROOF=1
while [ $# -gt 0 ]; do
case "$1" in
@@ -27,6 +31,8 @@ while [ $# -gt 0 ]; do
--delay) DELAY=$2; shift 2 ;;
--gain) GAIN=$2; shift 2 ;;
--min-repeats) MIN_REPEATS=$2; shift 2 ;;
--iq-seconds) IQ_SECONDS=$2; shift 2 ;;
--proof-gain) PROOF_GAIN=$2; shift 2 ;;
*) echo "unknown arg: $1" >&2; exit 2 ;;
esac
done
@@ -80,7 +86,7 @@ $PY hil/dut_cmd.py "$DUT_PORT" --listen 3 \
# so it isolates "can the SDR decode our C1 TX" from bench dynamic range.
if [ "$PROOF" = 1 ]; then
echo "phase A: TX decodability proof"
./hil/capture_sdr.sh 70 "$RUN_DIR/proof_sdr.log" "$GAIN" &
./hil/capture_sdr.sh 70 "$RUN_DIR/proof_sdr.log" "${PROOF_GAIN:-$GAIN}" &
SDR_PID=$!
sleep 10
for L in 19 60 98; do
@@ -108,6 +114,32 @@ wait "$SERIAL_PID" || true
$PY hil/dut_cmd.py "$DUT_PORT" --listen 4 stats > "$RUN_DIR/final_stats.log" 2>&1 || true
cat "$RUN_DIR/final_stats.log" >> "$RUN_DIR/serial.log"
# --- phase C: RF-level repeat proof from raw IQ ---------------------------
# Decode-independent: measures whether a second transmission occurs at the
# configured delay with the expected airtime. Needed because our repeat
# arrives ~36 dB hotter than meter traffic and often clips the dongle.
if [ "$IQ_SECONDS" -gt 0 ]; then
echo "phase C: IQ repeat proof (${IQ_SECONDS}s)"
IQ="$RUN_DIR/iq.raw"
timeout $((IQ_SECONDS + 15)) rtl_sdr -f 868950000 -s 1600000 -g "$GAIN" \
-n $((IQ_SECONDS * 1600000)) "$IQ" 2> "$RUN_DIR/iq_capture.err" &
IQ_PID=$!
$PY hil/dut_cmd.py "$DUT_PORT" --listen "$IQ_SECONDS" status \
> "$RUN_DIR/iq_serial.log" 2>&1
wait "$IQ_PID" || true
if [ -s "$IQ" ]; then
$PY hil/verify_repeats_iq.py --iq "$IQ" --serial "$RUN_DIR/iq_serial.log" \
--delay-ms "$DELAY" > "$RUN_DIR/iq_proof.txt" 2>&1 || true
$PY hil/verify_repeats_iq.py --iq "$IQ" --serial "$RUN_DIR/iq_serial.log" \
--delay-ms "$DELAY" --json > "$RUN_DIR/iq_proof.json" 2>&1 || true
cat "$RUN_DIR/iq_proof.txt"
fi
# IQ is large; keep only if it produced no pairs (for later inspection)
if grep -q '"repeat_pairs_at_delay": [1-9]' "$RUN_DIR/iq_proof.json" 2>/dev/null; then
rm -f "$IQ"
fi
fi
# --- 13-14. correlate ------------------------------------------------------
$PY hil/correlate.py --serial "$RUN_DIR/serial.log" --sdr "$RUN_DIR/rtlwmbus.log" \
--min-delay 0.010 --max-delay 0.400 > "$RUN_DIR/report.json"
@@ -122,11 +154,14 @@ fi
# --- 16-18. report ---------------------------------------------------------
STREAMED=$(sed -n 's/^streamed_seconds=//p' "$RUN_DIR/rtlwmbus.stats" 2>/dev/null || echo "?")
SENS=$(sed -n 's/^SDR_SENSITIVITY=//p' "$RUN_DIR/sdr_health.txt" 2>/dev/null || echo unknown)
$PY hil/report.py "$RUN_DIR/report.json" \
--min-repeats "$MIN_REPEATS" --duration "$DURATION" \
--tx-power "$TXPOW" --repeat-delay "$DELAY" \
--sdr-streamed "$STREAMED" \
--sdr-sensitivity "${SENS:-unknown}" \
--tx-proof "$RUN_DIR/tx_proof.json" \
--iq-proof "$RUN_DIR/iq_proof.json" \
| tee "$RUN_DIR/report.txt"
RC=${PIPESTATUS[0]}
echo "artifacts: $RUN_DIR"