prod2u_status.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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) == 94:
  15. ptc = list(p[0:35])
  16. front = list(p[35:39])
  17. rear = list(p[39:43])
  18. bmc_raw = list(p[43:67])
  19. ct_raw = list(p[67:94])
  20. elif len(p) == 83:
  21. ptc = list(p[0:24])
  22. front = list(p[24:28])
  23. rear = list(p[28:32])
  24. bmc_raw = list(p[32:56])
  25. ct_raw = list(p[56:83])
  26. else:
  27. raise ValueError(f"6400 GET_DATA payload length must be 83 or 94, got {len(p)}")
  28. bmc_temps = [decode_temperature(b) for b in bmc_raw]
  29. ct_temps = [decode_temperature(b) for b in ct_raw]
  30. return {
  31. "product": "6400-front-rear",
  32. "ptc_applied": ptc,
  33. "front_applied": front,
  34. "rear_applied": rear,
  35. "ptc": ptc,
  36. "front": front,
  37. "rear": rear,
  38. "bmc": {
  39. "raw": bmc_raw,
  40. "temperature_c": bmc_temps,
  41. "valid": [t is not None for t in bmc_temps],
  42. },
  43. "ct": {
  44. "raw": ct_raw,
  45. "temperature_c": ct_temps,
  46. "valid": [t is not None for t in ct_temps],
  47. },
  48. }
  49. def mrdimm_state(payload: bytes | bytearray, layout: dict[str, Any] | None = None) -> dict[str, Any]:
  50. p = bytes(payload)
  51. if len(p) != 63:
  52. raise ValueError(f"MRDIMM GET_DATA payload length must be 63, got {len(p)}")
  53. fan = list(p[0:4])
  54. ptc = list(p[4:8])
  55. bmc_raw = list(p[8:32])
  56. bmc_temps = [decode_temperature(b) for b in bmc_raw]
  57. ct_raw = list(p[32:59])
  58. ct_temps = [decode_temperature(b) for b in ct_raw]
  59. lower_mask = int.from_bytes(p[59:61], "little")
  60. upper_mask = int.from_bytes(p[61:63], "little")
  61. axes = {}
  62. for i in range(12):
  63. axes[f"axis{i}"] = {
  64. "index": i,
  65. "lower_limit": bool(lower_mask & (1 << i)),
  66. "upper_limit": bool(upper_mask & (1 << i)),
  67. }
  68. return {
  69. "product": "mrdimm-chamber",
  70. "fan_applied": fan,
  71. "ptc_applied": ptc,
  72. "fan": fan,
  73. "ptc": ptc,
  74. "lower_limit_mask": lower_mask,
  75. "upper_limit_mask": upper_mask,
  76. "axes": axes,
  77. "bmc": {
  78. "raw": bmc_raw,
  79. "temperature_c": bmc_temps,
  80. "valid": [t is not None for t in bmc_temps],
  81. },
  82. "ct": {
  83. "raw": ct_raw,
  84. "temperature_c": ct_temps,
  85. "valid": [t is not None for t in ct_temps],
  86. },
  87. }