"""Golden fixtures for the Rust hpcs6500 driver, produced by the legacy Python driver. Run it next to hpcs6500.py from tag python-final, with the USB captures in C:\dev\HPCS\captures (not in git): git show python-final:hpcs6500.py > /tmp/py/hpcs6500.py; cp tools/make_fixtures.py /tmp/py/ python /tmp/py/make_fixtures.py # then copy /fixtures and /golden to tests/ pyfmt.json was trimmed to ~2000 cases afterwards. Writes into /: fixtures/rNN_meas.bin, rNN_elec.bin raw blocks from real USB captures golden/readings.json Python dict per fixture reading (floats as repr strings) golden/format_*.txt format_reading / format_quick output golden/csv_row.txt CSV row (without timestamp) as DictWriter writes it golden/pyfmt.json repr / .6g / .2f / .0f / .1f of many floats golden/parse_.txt `hpcs6500.py --parse` output, full and --quick --spectrum """ import contextlib import csv import io import json import math import random import struct import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) import hpcs6500 as h # noqa: E402 out = Path(sys.argv[1]) captures = Path(r"C:\dev\HPCS\captures") (out / "fixtures").mkdir(parents=True, exist_ok=True) (out / "golden").mkdir(parents=True, exist_ok=True) pairs = [] # (name, meas, elec) for f in sorted(captures.glob("*.pcap")): if f.stat().st_size < 100: continue m = h.parse_pcap_messages(str(f)) b = [x for x in m if x["dir"] == "RX" and len(x["data"]) == 3904 and x["data"][:8] == b"HPCS6500"] e = [x for x in m if x["dir"] == "RX" and len(x["data"]) == 1584] for i, blk in enumerate(b): el = e[i]["data"] if i < len(e) else None harm = el is not None and abs(struct.unpack_from("