hil: single-stream decode+IQ capture, clock-aligned RF TX proof

This commit is contained in:
Lars Nolden
2026-09-01 09:22:20 +02:00
parent 3fea191008
commit 74cb28daf7
4 changed files with 221 additions and 114 deletions
+22 -25
View File
@@ -101,12 +101,21 @@ if [ "$PROOF" = 1 ]; then
cat "$RUN_DIR/tx_proof.txt"
fi
# --- phase B: real meter traffic ------------------------------------------
echo "phase B: real-meter capture (${DURATION}s)"
# --- phase B: real meter traffic, decodes + IQ from ONE stream -------------
# One rtl_sdr stream feeds both rtl_wmbus (meter originals) and a raw IQ
# file (our transmissions, measured decode-independently). Separate
# captures are not comparable: this dongle's sensitivity drifts ~17 dB
# over minutes (docs/FINDINGS.md).
echo "phase B: real-meter capture (${DURATION}s, decodes + IQ)"
IQ="$RUN_DIR/iq.raw"
$PY hil/dut_cmd.py "$DUT_PORT" --listen "$DURATION" status \
> "$RUN_DIR/serial.log" 2>&1 &
SERIAL_PID=$!
./hil/capture_sdr.sh "$DURATION" "$RUN_DIR/rtlwmbus.log" "$GAIN" &
if [ "$IQ_SECONDS" -gt 0 ]; then
./hil/capture_both.sh "$DURATION" "$RUN_DIR/rtlwmbus.log" "$IQ" "$GAIN" &
else
./hil/capture_sdr.sh "$DURATION" "$RUN_DIR/rtlwmbus.log" "$GAIN" &
fi
SDR_PID=$!
wait "$SDR_PID" || true
wait "$SERIAL_PID" || true
@@ -114,28 +123,16 @@ 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
# --- RF-level repeat proof from the same stream's IQ ----------------------
if [ -s "$IQ" ]; then
echo "RF-level repeat proof from captured IQ"
$PY hil/verify_repeats_iq.py --iq "$IQ" --serial "$RUN_DIR/serial.log" \
--delay-ms "$DELAY" > "$RUN_DIR/iq_proof.txt" 2>&1 || true
$PY hil/verify_repeats_iq.py --iq "$IQ" --serial "$RUN_DIR/serial.log" \
--delay-ms "$DELAY" --json > "$RUN_DIR/iq_proof.json" 2>&1 || true
cat "$RUN_DIR/iq_proof.txt"
# IQ is large: keep it only when the proof failed, for offline inspection
if grep -q '"tx_events_with_rf": [1-9]' "$RUN_DIR/iq_proof.json" 2>/dev/null; then
rm -f "$IQ"
fi
fi