Update HIL verification for hop-marked repeats

This commit is contained in:
Lars Nolden
2026-09-21 12:31:19 +02:00
parent a11a4b3b89
commit 8c44c54131
13 changed files with 525 additions and 309 deletions
+33 -20
View File
@@ -8,18 +8,18 @@ SDR observes. This is also the honest test of "power it up and leave it be".
Two independent lines of evidence, both derived from ONE recorded IQ file so
they cannot disagree about gain or time:
1. Decoded repeats - rtl_wmbus run over the recording; a repeat is the
same cooked payload decoded twice within the delay window.
1. Decoded repeats - a supported H=0 original followed by an H=1 frame
with every other cooked byte unchanged.
2. RF-level repeats - burst-envelope pairs separated by the delay window
where the second burst is at least as strong as the first. This catches
repeats that fail CRC because our transmission overloads the dongle
(docs/RF_FRONTEND_TESTS.md), which is the common case on this bench.
Usage:
verify_standalone.py --iq iq.raw --decodes decodes.log
[--min-ms 20] [--max-ms 400] [--rate 1600000] [--json]
verify_standalone.py --iq iq.raw --decodes decodes.log [--delay-ms 500]
[--delay-tol-ms 25] [--rate 1600000] [--json]
Exit 0 if at least one repeat was observed by either method.
Exit 0 only if a decoded hop transition confirms repeater activity.
"""
import argparse
import json
@@ -30,7 +30,7 @@ from datetime import datetime
import numpy as np
sys.path.insert(0, __file__.rsplit("/", 1)[0])
from correlate import SDR_RE # noqa: E402
from correlate import SDR_RE, expected_repeat # noqa: E402
ap = argparse.ArgumentParser()
ap.add_argument("--iq", required=True)
@@ -57,23 +57,35 @@ for line in open(args.decodes, errors="replace"):
"crc_ok": m["crc"] == "1",
"t": datetime.strptime(m["ts"].strip(), "%Y-%m-%d %H:%M:%S.%f").timestamp(),
"serial": m["serial"].lower(),
"hex": m["hex"].lower(),
"cooked": bytes.fromhex(m["hex"]),
})
rows.sort(key=lambda r: r["t"])
c1 = [r for r in rows if r["mode"] == "C1" and r["crc_ok"]]
decoded = [r for r in rows if r["mode"] in ("C1", "T1") and r["crc_ok"]]
# rtl_wmbus runs two demodulators; collapse identical bytes <5 ms apart
dedup = []
for r in c1:
if dedup and dedup[-1]["hex"] == r["hex"] and r["t"] - dedup[-1]["t"] < 0.005:
for r in decoded:
if (dedup and dedup[-1]["mode"] == r["mode"]
and dedup[-1]["cooked"] == r["cooked"]
and r["t"] - dedup[-1]["t"] < 0.005):
continue
dedup.append(r)
# A decoded repeat: identical payload seen twice. rtl_sdr delivers ~82 ms
# buffers so decode timestamps are quantised; count occurrences rather than
# trusting sub-100 ms timing (docs/FINDINGS.md).
occ = Counter(r["hex"] for r in dedup)
decoded_repeats = sum(v - 1 for v in occ.values() if v > 1)
# rtl_sdr delivers ~82 ms buffers, so decode timestamps are quantised.
# Preserve order rather than trusting sub-100 ms timing (docs/FINDINGS.md).
# Each supported H=0 original permits one later H=1 counterpart; never
# normalize H on both sides or count identical originals as repeats.
pending = Counter()
decoded_repeats = 0
for r in dedup:
key = (r["mode"], r["cooked"])
if pending[key]:
pending[key] -= 1
decoded_repeats += 1
else:
marked = expected_repeat(r["cooked"])
if marked is not None:
pending[(r["mode"], marked)] += 1
meters = Counter(r["serial"] for r in dedup)
# ---------------------------------------------------------------- IQ bursts
@@ -123,7 +135,7 @@ binfo = [b for b in binfo_all
# RF-level repeat: a burst followed by a comparable-or-stronger burst of
# similar duration inside the delay window. Duration similarity matters --
# a repeat carries the same frame, so its airtime should match.
# setting H leaves the frame length unchanged, so its airtime should match.
pairs = []
for i, a in enumerate(binfo):
a_end = a["t_ms"] + a["dur_ms"]
@@ -131,7 +143,7 @@ for i, a in enumerate(binfo):
gap = b["t_ms"] - a_end
if gap > args.delay_ms + args.delay_tol_ms:
break
# A repeat re-sends the SAME frame, so it must (a) sit at the
# A hop-marked repeat retains the frame length, so it must (a) sit at the
# configured delay, (b) have an airtime consistent with a C1 frame,
# and (c) match the original's duration closely. Pairs that merely
# fall in a wide window are usually unrelated 868 MHz traffic --
@@ -153,7 +165,8 @@ result = {
"noise_floor_db": round(floor, 1),
"bursts_total": len(binfo_all),
"frame_like_bursts": len(binfo),
"c1_decodes": len(dedup),
"c1_decodes": sum(r["mode"] == "C1" for r in dedup),
"t1_decodes": sum(r["mode"] == "T1" for r in dedup),
"unique_meters": len(meters),
"decoded_repeats": decoded_repeats,
"rf_repeat_pairs": len(pairs),
@@ -176,7 +189,7 @@ if args.json:
print(json.dumps(result, indent=2))
else:
print(f"STANDALONE CHECK iq={result['iq_seconds']}s floor={floor:.1f}dB")
print(f" C1 telegrams decoded: {len(dedup)} from {len(meters)} meters")
print(f" C1/T1 telegrams decoded: {len(dedup)} from {len(meters)} meters")
print(f" RF bursts (all): {len(binfo_all)}")
print(f" frame-like bursts: {len(binfo)} (>= {MIN_FRAME_MS} ms, >= +{MIN_FRAME_DB:.0f} dB)")
print(f" decoded repeats: {decoded_repeats}")
@@ -196,7 +209,7 @@ else:
print(" looks like a singleton. Read the firmware counters over USB")
print(" for an unambiguous answer.)")
elif v == "not observed":
print(" (No frame-like burst pairs and no decoded duplicates. Either")
print(" (No frame-like burst pairs and no decoded hop transitions. Either")
print(" the device is not transmitting, or it transmitted nothing in")
print(" this window. Firmware counters over USB are decisive.)")