Update HIL verification for hop-marked repeats
This commit is contained in:
+55
-13
@@ -10,8 +10,8 @@ Output: JSON report on stdout.
|
||||
Correlation model (developer repeat delay ~50 ms):
|
||||
SDR original <-> Heltec RX : same cooked bytes, |dt| < rx_window
|
||||
Heltec RX <-> Heltec TX : same hash (firmware log)
|
||||
Heltec TX <-> SDR repeat : same cooked bytes, dt in [min_delay, max_delay]
|
||||
after the SDR original
|
||||
SDR original <-> SDR repeat : only H changes 0 -> 1 on a supported header,
|
||||
dt in [min_delay, max_delay]
|
||||
|
||||
The Heltec logs raw over-the-air frames (with CRCs); rtl_wmbus prints
|
||||
"cooked" frames (CRCs stripped). cook() below mirrors rtl-wmbus.
|
||||
@@ -69,6 +69,42 @@ def cook_b(frame: bytes):
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def expected_repeat(cooked: bytes):
|
||||
"""Return the H-marked counterpart of a supported CRC-stripped original.
|
||||
|
||||
Both format A and rtl-wmbus-normalized format B use L = cooked length - 1.
|
||||
ELL hop control takes precedence over any encapsulated transport header.
|
||||
Unsupported layouts, H=1 and R=1 cannot originate a received repeat.
|
||||
"""
|
||||
if len(cooked) < 11 or cooked[0] != len(cooked) - 1:
|
||||
return None
|
||||
if cooked[1] not in (0x44, 0x46):
|
||||
return None
|
||||
ci = cooked[10]
|
||||
if ci in (0x8c, 0x8e):
|
||||
# CI + CC + ACC, optionally eight address bytes, then another CI.
|
||||
if len(cooked) < (14 if ci == 0x8c else 22):
|
||||
return None
|
||||
pos, h_mask = 11, 0x10
|
||||
else:
|
||||
if ci in (0x67, 0x6e, 0x74, 0x7a, 0x7d, 0x7f, 0x88, 0x8a,
|
||||
0x9e, 0xc1, 0xc4):
|
||||
pos = 13
|
||||
elif ci in (0x68, 0x6f, 0x72, 0x75, 0x7c, 0x7e, 0x87, 0x8b,
|
||||
0x9f, 0xc2, 0xc5):
|
||||
pos = 21
|
||||
else:
|
||||
return None
|
||||
if len(cooked) <= pos + 1 or cooked[pos + 1] & 0x1f not in (0, 5):
|
||||
return None
|
||||
h_mask = 0x01
|
||||
if cooked[pos] & (h_mask | 0x02):
|
||||
return None
|
||||
marked = bytearray(cooked)
|
||||
marked[pos] |= h_mask
|
||||
return bytes(marked)
|
||||
|
||||
|
||||
def parse_serial(path):
|
||||
"""Heltec JSON-lines -> (rx_events, tx_events, other)."""
|
||||
rx, tx, other = [], [], []
|
||||
@@ -133,31 +169,37 @@ def main():
|
||||
|
||||
heltec_rx, heltec_tx, other = parse_serial(args.serial)
|
||||
sdr = parse_sdr(args.sdr)
|
||||
sdr_c1 = [s for s in sdr if s["mode"] == "C1" and s["crc_ok"]]
|
||||
sdr_frames = [s for s in sdr if s["mode"] in ("C1", "T1") and s["crc_ok"]]
|
||||
|
||||
# rtl_wmbus runs two demodulator algorithms concurrently; a single burst
|
||||
# can be reported twice within ~1 ms. Collapse identical bytes < 5 ms apart.
|
||||
deduped = []
|
||||
for s in sorted(sdr_c1, key=lambda x: x["t"]):
|
||||
if deduped and deduped[-1]["cooked"] == s["cooked"] \
|
||||
for s in sorted(sdr_frames, key=lambda x: x["t"]):
|
||||
if deduped and deduped[-1]["mode"] == s["mode"] \
|
||||
and deduped[-1]["cooked"] == s["cooked"] \
|
||||
and s["t"] - deduped[-1]["t"] < 0.005:
|
||||
continue
|
||||
deduped.append(s)
|
||||
sdr_c1 = deduped
|
||||
sdr_frames = deduped
|
||||
expected = [expected_repeat(s["cooked"]) for s in sdr_frames]
|
||||
|
||||
# --- classify SDR frames into originals vs repeats ---------------------
|
||||
# A repeat is an SDR frame with identical cooked bytes to an earlier SDR
|
||||
# frame within [min_delay, max_delay]. Everything else is an original.
|
||||
# A repeat changes only H from 0 to 1 on a supported original header
|
||||
# within [min_delay, max_delay]. Same-H duplicates are not repeats.
|
||||
originals, repeats = [], []
|
||||
for i, s in enumerate(sdr_c1):
|
||||
used_originals = set()
|
||||
for i, s in enumerate(sdr_frames):
|
||||
matched = None
|
||||
for j in range(i - 1, -1, -1):
|
||||
prev = sdr_c1[j]
|
||||
prev = sdr_frames[j]
|
||||
dt = s["t"] - prev["t"]
|
||||
if dt > args.max_delay:
|
||||
break
|
||||
if prev["cooked"] == s["cooked"] and args.min_delay <= dt <= args.max_delay:
|
||||
if (j not in used_originals and prev["mode"] == s["mode"]
|
||||
and expected[j] == s["cooked"]
|
||||
and args.min_delay <= dt <= args.max_delay):
|
||||
matched = (j, dt)
|
||||
used_originals.add(j)
|
||||
break
|
||||
if matched is not None:
|
||||
repeats.append({"idx": i, "orig_idx": matched[0], "dt": matched[1], **s})
|
||||
@@ -197,7 +239,6 @@ def main():
|
||||
|
||||
verified_repeats = 0
|
||||
for rep in repeats:
|
||||
orig = sdr_c1[rep["orig_idx"]]
|
||||
o_entry = next((o for o in originals if o["idx"] == rep["orig_idx"]), None)
|
||||
hr = o_entry.get("heltec_rx") if o_entry else None
|
||||
if hr and hr.get("hash") in tx_by_hash:
|
||||
@@ -213,7 +254,8 @@ def main():
|
||||
|
||||
report = {
|
||||
"sdr_frames_total": len(sdr),
|
||||
"sdr_c1_crc_ok": len(sdr_c1),
|
||||
"sdr_c1_crc_ok": sum(s["mode"] == "C1" for s in sdr_frames),
|
||||
"sdr_t1_crc_ok": sum(s["mode"] == "T1" for s in sdr_frames),
|
||||
"sdr_originals": len(originals),
|
||||
"sdr_repeats": len(repeats),
|
||||
"heltec_rx": len(heltec_rx),
|
||||
|
||||
Reference in New Issue
Block a user