fix: standalone verifier counted noise flutter as repeats; require frame-like bursts and report graded verdict
This commit is contained in:
@@ -104,8 +104,19 @@ if len(idx):
|
||||
prev = i
|
||||
bursts.append((start, prev))
|
||||
|
||||
binfo = [{"t_ms": int(s), "dur_ms": int(e - s + 1),
|
||||
"peak_db": float(db[s:e + 1].max() - floor)} for s, e in bursts]
|
||||
binfo_all = [{"t_ms": int(s), "dur_ms": int(e - s + 1),
|
||||
"peak_db": float(db[s:e + 1].max() - floor)} for s, e in bursts]
|
||||
|
||||
# Only frame-like bursts may be considered transmissions. A C1 frame at
|
||||
# 100 kbps is >= ~5 ms even when short, and a real transmission stands well
|
||||
# clear of the floor. Without this filter, 1 ms noise-floor flutter at the
|
||||
# +6 dB detection threshold pairs with itself and manufactures hundreds of
|
||||
# bogus "repeats" -- an earlier revision of this script did exactly that and
|
||||
# reported a repeater ONLINE when the device was not transmitting at all.
|
||||
MIN_FRAME_MS = 5
|
||||
MIN_FRAME_DB = 10.0
|
||||
binfo = [b for b in binfo_all
|
||||
if b["dur_ms"] >= MIN_FRAME_MS and b["peak_db"] >= MIN_FRAME_DB]
|
||||
|
||||
# RF-level repeat: a burst followed by a comparable-or-stronger burst of
|
||||
# similar duration inside the delay window. Duration similarity matters --
|
||||
@@ -130,7 +141,8 @@ gaps = sorted(p["gap_ms"] for p in pairs)
|
||||
result = {
|
||||
"iq_seconds": round(len(db) / 1000.0, 1),
|
||||
"noise_floor_db": round(floor, 1),
|
||||
"bursts_total": len(binfo),
|
||||
"bursts_total": len(binfo_all),
|
||||
"frame_like_bursts": len(binfo),
|
||||
"c1_decodes": len(dedup),
|
||||
"unique_meters": len(meters),
|
||||
"decoded_repeats": decoded_repeats,
|
||||
@@ -138,7 +150,13 @@ result = {
|
||||
"gap_ms": {"min": gaps[0] if gaps else None,
|
||||
"median": gaps[len(gaps) // 2] if gaps else None,
|
||||
"max": gaps[-1] if gaps else None},
|
||||
"repeater_online": bool(decoded_repeats or pairs),
|
||||
# A decoded repeat is unambiguous. An RF pair alone is suggestive but
|
||||
# not proof: a strong isolated burst can equally be a nearby meter, and
|
||||
# our own repeat of a weak original appears as a strong singleton. Say
|
||||
# so instead of forcing a binary verdict.
|
||||
"verdict": ("confirmed" if decoded_repeats
|
||||
else "likely" if pairs
|
||||
else "not observed"),
|
||||
"pairs": pairs[:20],
|
||||
"top_meters": meters.most_common(10),
|
||||
}
|
||||
@@ -148,7 +166,8 @@ if args.json:
|
||||
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" RF bursts in window: {len(binfo)}")
|
||||
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}")
|
||||
print(f" RF-level repeat pairs: {len(pairs)}")
|
||||
if gaps:
|
||||
@@ -158,6 +177,16 @@ else:
|
||||
print(f" t={p['orig_t_ms']/1000:7.3f}s +{p['gap_ms']:3d} ms "
|
||||
f"{p['orig_dur_ms']}ms/{p['repeat_dur_ms']}ms "
|
||||
f"{p['orig_db']:+.1f}/{p['repeat_db']:+.1f} dB")
|
||||
print(f"\n REPEATER {'ONLINE' if result['repeater_online'] else 'NOT OBSERVED'}")
|
||||
v = result["verdict"]
|
||||
print(f"\n VERDICT: repeater activity {v.upper()}")
|
||||
if v == "likely":
|
||||
print(" (RF pairs only -- suggestive, not proof. A strong isolated")
|
||||
print(" burst may be a nearby meter, and a repeat of a weak original")
|
||||
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(" the device is not transmitting, or it transmitted nothing in")
|
||||
print(" this window. Firmware counters over USB are decisive.)")
|
||||
|
||||
sys.exit(0 if result["repeater_online"] else 1)
|
||||
sys.exit(0 if result["verdict"] == "confirmed" else 1)
|
||||
|
||||
Reference in New Issue
Block a user