Lamp testbench in Rust around the HPCS 6500

lampbench station / export / label / tm30 / calibrate replace the Python
lamp_station.py, lamp_export.py, label_printer.py, tm30.py and
calibration.py that lived in HPCS6500-py. The driver is a submodule
(HPCS6500/, like mppt-testbench). Workspace crates: tm30 (TM-30-18 port of
colour-science 0.4.7), brother-ql (raster protocol, byte-identical to
brother_ql) and lamp-label (QR + ID labels for the QL-820NWB).

Bundles are byte-identical to lamp_export.py's (golden tests); the station
runs end to end in a test against the simulated instrument.
This commit is contained in:
grabowski committed 2026-10-22 17:26:14 +07:00
commit 2a3f28001c
241 files changed
+46390

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
"""Golden lamp bundles from the former lamp_export.write_bundle (Python).
Usage: python make_bundles.py <driver fixtures dir> <out dir>
Run it next to hpcs6500.py, lamp_export.py and tm30.py from HPCS6500-py tag
python-final (colour-science 0.4.7), e.g.
python tools/make_bundles.py HPCS6500/tests/fixtures tests/golden/bundles
Each case: readings parsed from the driver's fixture blocks, averaged, written
with a fixed measured_at. Writes <out>/<case>/{spd.csv,tm30.csv,metrics.json}
and <out>/cases.json describing the inputs.
"""
import datetime as _dt
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
import hpcs6500 as h # noqa: E402
import lamp_export as le # noqa: E402
FIX = Path(sys.argv[1])
OUT = Path(sys.argv[2])
OUT.mkdir(parents=True, exist_ok=True)
STAMP = "2026-07-09T16:22:57+07:00"
class FixedDatetime(_dt.datetime):
@classmethod
def now(cls, tz=None):
return _dt.datetime.fromisoformat(STAMP)
le.datetime = FixedDatetime
dev = h.HPCS6500.__new__(h.HPCS6500)
def reading(name):
meas = (FIX / f"{name}_meas.bin").read_bytes()
r = dev._parse_measurement(meas)
e = FIX / f"{name}_elec.bin"
if e.exists():
r.update(dev._parse_electrical(e.read_bytes()))
return r
supply = {"ac_voltage": 230.0, "ac_frequency": 50.0, "dc_voltage": 24.0, "dc_current": 5.0, "mode": "AC"}
cases = [
{"case": "export_avg5", "readings": ["r01", "r04", "r05", "r06", "r02"],
"meta": {"name": "philips-a60", "manufacturer": "Philips", "model": "A60 8W 927", "notes": ""}, "supply": None},
{"case": "station_full", "readings": ["r05", "r06", "r04"],
"meta": {"name": "L0042", "ean": "8718696844984", "type": "led", "dimmable": False, "variant": "cool white",
"manufacturer": "Philips", "model": "MyCare 9.5W Caf\u00e9 \u00fc \u0e44\u0e1f", "notes": "box says \"warm\"\tok",
"rated": {"Phi_lm": 1050, "Power_W": 9.5, "lifetime_h": 15000}},
"supply": supply},
{"case": "harmonics_single", "readings": ["r02"],
"meta": {"name": "L0007", "ean": "", "type": "halogen", "dimmable": True, "variant": "", "manufacturer": "",
"model": "", "notes": "", "rated": {}}, "supply": supply},
{"case": "external_power", "readings": ["r07"],
"meta": {"name": "dc-strip", "manufacturer": "", "model": "", "notes": "powered externally"}, "supply": None},
]
for c in cases:
rs = [reading(n) for n in c["readings"]]
avg = le.average_readings(rs)
tm = le.write_bundle(avg, OUT / c["case"], c["meta"], len(rs), c["supply"])
print(c["case"], round(tm["Rf"], 2), round(tm["Rg"], 2))
(OUT / "cases.json").write_text(json.dumps({"measured_at": STAMP, "cases": cases}, indent=1))