prod2u_status.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. """Status decoding for the two Prod2U products matching the single frame protocol.
  2. GET_DATA:
  3. - 6400: 83 bytes (PTC0..23, Front0..3, Rear0..3, BMC0..23, CT0..26)
  4. - MRDIMM: 63 bytes (FAN0..3, PTC0..3, BMC0..23, CT0..26, lower_mask:u16le, upper_mask:u16le)
  5. """
  6. from __future__ import annotations
  7. from typing import Any
  8. TEMPERATURE_INVALID = 0xFF
  9. def decode_temperature(byte: int) -> int | None:
  10. value = int(byte) & 0xFF
  11. return None if value == TEMPERATURE_INVALID else value
  12. def state_6400(payload: bytes | bytearray, layout: dict[str, Any] | None = None) -> dict[str, Any]:
  13. p = bytes(payload)
  14. if len(p) != 83:
  15. raise ValueError(f"6400 GET_DATA payload length must be 83, got {len(p)}")
  16. ptc = list(p[0:24])
  17. front = list(p[24:28])
  18. rear = list(p[28:32])
  19. bmc_raw = list(p[32:56])
  20. bmc_temps = [decode_temperature(b) for b in bmc_raw]
  21. ct_raw = list(p[56:83])
  22. ct_temps = [decode_temperature(b) for b in ct_raw]
  23. return {
  24. "product": "6400-front-rear",
  25. "ptc_applied": ptc,
  26. "front_applied": front,
  27. "rear_applied": rear,
  28. "ptc": ptc,
  29. "front": front,
  30. "rear": rear,
  31. "bmc": {
  32. "raw": bmc_raw,
  33. "temperature_c": bmc_temps,
  34. "valid": [t is not None for t in bmc_temps],
  35. },
  36. "ct": {
  37. "raw": ct_raw,
  38. "temperature_c": ct_temps,
  39. "valid": [t is not None for t in ct_temps],
  40. },
  41. }
  42. def mrdimm_state(payload: bytes | bytearray, layout: dict[str, Any] | None = None) -> dict[str, Any]:
  43. p = bytes(payload)
  44. if len(p) != 63:
  45. raise ValueError(f"MRDIMM GET_DATA payload length must be 63, got {len(p)}")
  46. fan = list(p[0:4])
  47. ptc = list(p[4:8])
  48. bmc_raw = list(p[8:32])
  49. bmc_temps = [decode_temperature(b) for b in bmc_raw]
  50. ct_raw = list(p[32:59])
  51. ct_temps = [decode_temperature(b) for b in ct_raw]
  52. lower_mask = int.from_bytes(p[59:61], "little")
  53. upper_mask = int.from_bytes(p[61:63], "little")
  54. axes = {}
  55. for i in range(12):
  56. axes[f"axis{i}"] = {
  57. "index": i,
  58. "lower_limit": bool(lower_mask & (1 << i)),
  59. "upper_limit": bool(upper_mask & (1 << i)),
  60. }
  61. return {
  62. "product": "mrdimm-chamber",
  63. "fan_applied": fan,
  64. "ptc_applied": ptc,
  65. "fan": fan,
  66. "ptc": ptc,
  67. "lower_limit_mask": lower_mask,
  68. "upper_limit_mask": upper_mask,
  69. "axes": axes,
  70. "bmc": {
  71. "raw": bmc_raw,
  72. "temperature_c": bmc_temps,
  73. "valid": [t is not None for t in bmc_temps],
  74. },
  75. "ct": {
  76. "raw": ct_raw,
  77. "temperature_c": ct_temps,
  78. "valid": [t is not None for t in ct_temps],
  79. },
  80. }