validate_active_6400_lock.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. """Fail-closed validation for the active 6400 lock."""
  3. from __future__ import annotations
  4. import sys
  5. from pathlib import Path
  6. try:
  7. import yaml
  8. except Exception as exc: # pragma: no cover
  9. print(f"LOCK_FAIL yaml unavailable: {exc}", file=sys.stderr)
  10. raise SystemExit(2)
  11. ROOT = Path(__file__).resolve().parents[1]
  12. LOCK = ROOT / "ACTIVE_6400_MANUAL_I2C_LOCK.yaml"
  13. EXPECTED = {
  14. "product": "6400-front-rear",
  15. "board": "FCB V1.1",
  16. "device": "EF2L45BG256B",
  17. "clock_hz": 25_000_000,
  18. "pll": "forbidden",
  19. "firmware_count": 1,
  20. "gui_count": 1,
  21. }
  22. def main() -> int:
  23. if not LOCK.is_file():
  24. print("LOCK_FAIL missing ACTIVE_6400_MANUAL_I2C_LOCK.yaml", file=sys.stderr)
  25. return 2
  26. data = yaml.safe_load(LOCK.read_text(encoding="utf-8"))
  27. for key, value in EXPECTED.items():
  28. if data.get(key) != value:
  29. print(f"LOCK_FAIL {key}: expected {value!r}, got {data.get(key)!r}", file=sys.stderr)
  30. return 2
  31. outputs = data.get("outputs", {})
  32. if outputs.get("ptc_count") != 24 or outputs.get("front_fan_count") != 4 or outputs.get("rear_fan_count") != 4:
  33. print("LOCK_FAIL actuator counts", file=sys.stderr)
  34. return 2
  35. if outputs.get("ptc_pwm_hz") != 500 or outputs.get("fan_pwm_hz") != 500:
  36. print("LOCK_FAIL PWM frequency", file=sys.stderr)
  37. return 2
  38. uart = data.get("uart", {})
  39. if uart.get("baud") != 921600 or uart.get("format") != "8N1":
  40. print("LOCK_FAIL UART", file=sys.stderr)
  41. return 2
  42. if data.get("host_i2c", {}).get("address_7bit") != 0x2A:
  43. print("LOCK_FAIL Host-I2C address", file=sys.stderr)
  44. return 2
  45. if "pid" in data:
  46. print("LOCK_FAIL legacy PID field is present", file=sys.stderr)
  47. return 2
  48. print("LOCK_PASS")
  49. return 0
  50. if __name__ == "__main__":
  51. raise SystemExit(main())