#!/usr/bin/env python3 """Fail-closed validation for the active 6400 lock.""" from __future__ import annotations import sys from pathlib import Path try: import yaml except Exception as exc: # pragma: no cover print(f"LOCK_FAIL yaml unavailable: {exc}", file=sys.stderr) raise SystemExit(2) ROOT = Path(__file__).resolve().parents[1] LOCK = ROOT / "ACTIVE_6400_MANUAL_I2C_LOCK.yaml" EXPECTED = { "product": "6400-front-rear", "board": "FCB V1.1", "device": "EF2L45BG256B", "clock_hz": 25_000_000, "pll": "forbidden", "firmware_count": 1, "gui_count": 1, } def main() -> int: if not LOCK.is_file(): print("LOCK_FAIL missing ACTIVE_6400_MANUAL_I2C_LOCK.yaml", file=sys.stderr) return 2 data = yaml.safe_load(LOCK.read_text(encoding="utf-8")) for key, value in EXPECTED.items(): if data.get(key) != value: print(f"LOCK_FAIL {key}: expected {value!r}, got {data.get(key)!r}", file=sys.stderr) return 2 outputs = data.get("outputs", {}) if outputs.get("ptc_count") != 24 or outputs.get("front_fan_count") != 4 or outputs.get("rear_fan_count") != 4: print("LOCK_FAIL actuator counts", file=sys.stderr) return 2 if outputs.get("ptc_pwm_hz") != 500 or outputs.get("fan_pwm_hz") != 500: print("LOCK_FAIL PWM frequency", file=sys.stderr) return 2 uart = data.get("uart", {}) if uart.get("baud") != 921600 or uart.get("format") != "8N1": print("LOCK_FAIL UART", file=sys.stderr) return 2 if data.get("host_i2c", {}).get("address_7bit") != 0x2A: print("LOCK_FAIL Host-I2C address", file=sys.stderr) return 2 if data.get("pid", {}).get("active_logic") != 0 or data.get("pid", {}).get("dsp_use") != 0: print("LOCK_FAIL PID is active", file=sys.stderr) return 2 print("LOCK_PASS") return 0 if __name__ == "__main__": raise SystemExit(main())