hil: LNA A/B experiment scripts, refine health railed check

This commit is contained in:
Lars Nolden
2026-09-01 08:35:08 +02:00
parent a422305059
commit 78a8635ac8
5 changed files with 267 additions and 11 deletions
Executable
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# KCT8103L LNA (CSD) A/B experiment - Heltec only, no SDR required.
#
# Runs two equal-length RX-only windows on the same meter population, one
# with the FEM enabled in RX (CSD high, LNA path) and one with it disabled
# (CSD low), then reports frame counts, CRC success and RSSI distribution.
#
# Usage: lna_ab.sh [SECONDS_PER_ARM]
set -euo pipefail
cd "$(dirname "$0")/.."
DUR=${1:-600}
PY=./result-py/bin/python3
eval "$(./tools/discover_devices.sh)"
OUT="captures/$(date +%Y-%m-%dT%H-%M-%S)-lna-ab"
mkdir -p "$OUT"
echo "DUT: $DUT_PORT"
echo "arm duration: ${DUR}s each"
# Retransmission off: this measures the receiver only, and avoids radiating
# during a sensitivity comparison.
for arm in 1 0; do
label=$([ "$arm" = 1 ] && echo "csd_high_lna" || echo "csd_low_bypass")
echo "--- arm: $label"
$PY hil/dut_cmd.py "$DUT_PORT" --listen 3 \
"set repeat_enabled 0" "set fem_rx_csd $arm" "clear_stats" radio_reset \
> "$OUT/$label.setup.log" 2>&1
sleep 3
$PY hil/dut_cmd.py "$DUT_PORT" --listen "$DUR" status \
> "$OUT/$label.log" 2>&1
$PY hil/dut_cmd.py "$DUT_PORT" --listen 4 stats >> "$OUT/$label.log" 2>&1
done
# restore normal operation
$PY hil/dut_cmd.py "$DUT_PORT" --listen 3 \
"set fem_rx_csd 1" "set repeat_enabled 1" radio_reset \
> "$OUT/restore.log" 2>&1
$PY hil/lna_report.py "$OUT" | tee "$OUT/report.txt"
echo "artifacts: $OUT"
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env python3
"""Summarise a KCT8103L CSD (LNA) A/B experiment directory."""
import json
import sys
from collections import Counter
d = sys.argv[1]
arms = [("csd_high_lna", "FEM enabled in RX (CSD high)"),
("csd_low_bypass", "FEM disabled in RX (CSD low)")]
print("=" * 56)
print("KCT8103L RX FRONT-END A/B (Heltec only, no SDR)")
print("=" * 56)
summary = {}
for arm, desc in arms:
rx, stats = [], None
try:
fh = open(f"{d}/{arm}.log", errors="replace")
except OSError:
print(f"\n{desc}: 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()
for r in ok:
raw = r.get("raw", "")
if len(raw) >= 16:
meters[raw[8:16].lower()] += 1
rssi = sorted(r["rssi_dbm"] for r in rx if "rssi_dbm" in r)
rssi_ok = sorted(r["rssi_dbm"] for r in ok if "rssi_dbm" in r)
summary[arm] = {
"candidates": len(rx),
"crc_ok": len(ok),
"unique_meters": len(meters),
"median_rssi": rssi[len(rssi) // 2] if rssi else None,
"best_rssi": rssi[-1] if rssi else None,
"median_rssi_crcok": rssi_ok[len(rssi_ok) // 2] if rssi_ok else None,
"stats": stats,
}
print(f"\n{desc}")
print(f" candidate frames: {len(rx)}"
+ (f" ({100*len(ok)/len(rx):.0f} % CRC ok)" if rx else ""))
print(f" CRC-valid frames: {len(ok)}")
print(f" unique meters: {len(meters)}")
print(f" median RSSI (all): {summary[arm]['median_rssi']} dBm")
print(f" median RSSI (CRC ok): {summary[arm]['median_rssi_crcok']} dBm")
print(f" strongest RSSI: {summary[arm]['best_rssi']} dBm")
if stats:
print(f" firmware counters: rx_candidates={stats.get('rx_candidates')} "
f"rx_valid={stats.get('rx_valid')} "
f"rx_crc_fail={stats.get('rx_crc_fail')} "
f"not_c1={stats.get('rx_not_c1')}")
a, b = summary.get("csd_high_lna"), summary.get("csd_low_bypass")
if a and b:
print("\nCOMPARISON (CSD high vs CSD low)")
print(f" CRC-valid frames: {a['crc_ok']} vs {b['crc_ok']}")
print(f" unique meters: {a['unique_meters']} vs {b['unique_meters']}")
if a["median_rssi"] is not None and b["median_rssi"] is not None:
print(f" median RSSI delta: {a['median_rssi'] - b['median_rssi']} dB "
f"(positive = CSD high stronger)")
if a["crc_ok"] > max(3, b["crc_ok"] * 1.3):
verdict = "FEM enabled in RX is clearly better"
elif b["crc_ok"] > max(3, a["crc_ok"] * 1.3):
verdict = "FEM disabled in RX is clearly better"
else:
verdict = "no clear difference at this sample size"
print(f" verdict: {verdict}")
print("\nNote: meter traffic varies between arms; treat small differences")
print("as inconclusive unless both arms saw a comparable meter population.")
json.dump(summary, open(f"{d}/summary.json", "w"), indent=2, default=str)
+5 -2
View File
@@ -76,8 +76,11 @@ if lo is None or hi is None:
delta = hi["mean_power_db"] - lo["mean_power_db"]
reasons = []
if hi["mean_power_db"] > RAILED_DB:
reasons.append(f"railed: mean power {hi['mean_power_db']:.1f} dB > {RAILED_DB}")
# Railed only counts as a fault together with a flat spectrum: a healthy
# receiver with a strong nearby signal can legitimately show high mean power.
if hi["mean_power_db"] > RAILED_DB and hi["spectrum_span_db"] < 15.0:
reasons.append(f"railed: mean power {hi['mean_power_db']:.1f} dB > {RAILED_DB} "
f"with flat spectrum")
if hi["spectrum_span_db"] < MIN_SPAN_DB:
reasons.append(f"flat spectrum: span {hi['spectrum_span_db']:.1f} dB < {MIN_SPAN_DB}")
if delta < MIN_GAIN_DELTA_DB: