firmware: runtime preamble-detector length; generalized single-variable A/B harness

This commit is contained in:
Lars Nolden
2026-09-01 11:30:00 +02:00
parent 6bdcb2acad
commit 697e10e8cf
6 changed files with 160 additions and 2 deletions
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Controlled A/B of one runtime RF parameter, receiver-only (no SDR).
#
# Changes exactly one variable between two equal-length arms on the same
# meter population, with retransmission disabled so the receiver is measured
# in isolation. Meter traffic varies, so only large differences mean
# anything -- the report says so explicitly.
#
# Usage: param_ab.sh KEY VALUE_A VALUE_B [SECONDS_PER_ARM]
# e.g. param_ab.sh preamble_bits 8 16 900
# param_ab.sh fem_rx_csd 1 0 600
set -euo pipefail
cd "$(dirname "$0")/.."
KEY=$1; VA=$2; VB=$3; DUR=${4:-900}
PY=./result-py/bin/python3
eval "$(./tools/discover_devices.sh)"
OUT="captures/$(date +%Y-%m-%dT%H-%M-%S)-ab-$KEY"
mkdir -p "$OUT"
echo "DUT: $DUT_PORT"
echo "variable: $KEY arms: $VA vs $VB ${DUR}s each"
for V in "$VA" "$VB"; do
label="${KEY}_${V}"
echo "--- arm: $label"
$PY hil/dut_cmd.py "$DUT_PORT" --listen 4 \
"set repeat_enabled 0" "set $KEY $V" "clear_stats" \
> "$OUT/$label.setup.log" 2>&1
sleep 4
$PY hil/dut_cmd.py "$DUT_PORT" --listen "$DUR" status > "$OUT/$label.log" 2>&1
$PY hil/dut_cmd.py "$DUT_PORT" --listen 5 stats >> "$OUT/$label.log" 2>&1
done
# restore
$PY hil/dut_cmd.py "$DUT_PORT" --listen 4 \
"set $KEY $VA" "set repeat_enabled 1" > "$OUT/restore.log" 2>&1
$PY hil/param_ab_report.py "$OUT" "$KEY" "$VA" "$VB" | tee "$OUT/report.txt"
echo "artifacts: $OUT"
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
"""Summarise a single-variable receiver A/B experiment (hil/param_ab.sh)."""
import json
import sys
from collections import Counter
d, key, va, vb = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
print("=" * 60)
print(f"RECEIVER A/B: {key} ({va} vs {vb})")
print("=" * 60)
summary = {}
for v in (va, vb):
label = f"{key}_{v}"
rx, stats = [], None
try:
fh = open(f"{d}/{label}.log", errors="replace")
except OSError:
print(f"\n{key}={v}: no data")
continue
for line in fh:
line = line.strip()
if not line.startswith("{"):
continue
try:
ev = json.loads(line)
except json.JSONDecodeError:
continue
if ev.get("event") == "wmbus_rx":
rx.append(ev)
elif ev.get("event") == "stats":
stats = ev
ok = [r for r in rx if r.get("crc_ok")]
meters = Counter(r["raw"][8:16].lower() for r in ok
if len(r.get("raw", "")) >= 16)
rssi_ok = sorted(r["rssi_dbm"] for r in ok if "rssi_dbm" in r)
st = stats or {}
cand = st.get("rx_candidates")
notc1 = st.get("rx_not_c1")
summary[v] = {
"logged_frames": len(rx),
"crc_ok": len(ok),
"unique_meters": len(meters),
"median_rssi_crcok": rssi_ok[len(rssi_ok) // 2] if rssi_ok else None,
"weakest_crcok": rssi_ok[0] if rssi_ok else None,
"fw_candidates": cand,
"fw_valid": st.get("rx_valid"),
"fw_crc_fail": st.get("rx_crc_fail"),
"fw_not_c1": notc1,
"false_sync_pct": (round(100.0 * notc1 / cand, 1)
if cand and notc1 is not None else None),
}
s = summary[v]
print(f"""
{key} = {v}
CRC-valid frames: {s['crc_ok']}
unique meters: {s['unique_meters']}
median RSSI (CRC ok): {s['median_rssi_crcok']} dBm
weakest CRC-ok frame: {s['weakest_crcok']} dBm
firmware candidates: {s['fw_candidates']}
firmware valid: {s['fw_valid']}
firmware CRC failures: {s['fw_crc_fail']}
not C-mode (false sync + T1): {s['fw_not_c1']} ({s['false_sync_pct']} % of candidates)""")
a, b = summary.get(va), summary.get(vb)
if a and b:
print(f"\nCOMPARISON ({va} vs {vb})")
print(f" CRC-valid frames: {a['crc_ok']} vs {b['crc_ok']}")
print(f" unique meters: {a['unique_meters']} vs {b['unique_meters']}")
print(f" false-sync share: {a['false_sync_pct']} % vs {b['false_sync_pct']} %")
print(f" weakest CRC-ok: {a['weakest_crcok']} vs {b['weakest_crcok']} dBm")
# A useful change reduces false syncs without losing weak frames.
def verdict():
if a["crc_ok"] == 0 and b["crc_ok"] == 0:
return "no traffic in either arm - inconclusive"
big = max(3, min(a["crc_ok"], b["crc_ok"]) * 0.3)
if abs(a["crc_ok"] - b["crc_ok"]) < big:
fa, fb = a["false_sync_pct"], b["false_sync_pct"]
if fa is not None and fb is not None and abs(fa - fb) >= 10:
better = va if fa < fb else vb
return (f"comparable frame yield; {key}={better} has the lower "
f"false-sync share")
return "no clear difference at this sample size"
better = va if a["crc_ok"] > b["crc_ok"] else vb
return f"{key}={better} yielded clearly more CRC-valid frames"
print(f" verdict: {verdict()}")
print("\nCaveat: arms run sequentially, so meter traffic differs between")
print("them. Treat differences below ~30 % of frame count as noise.")
json.dump(summary, open(f"{d}/summary.json", "w"), indent=2, default=str)