| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- """Status decoding for the two Prod2U products matching the single frame protocol.
- GET_DATA:
- - 6400: 83 bytes (PTC0..23, Front0..3, Rear0..3, BMC0..23, CT0..26)
- - MRDIMM: 63 bytes (FAN0..3, PTC0..3, BMC0..23, CT0..26, lower_mask:u16le, upper_mask:u16le)
- """
- from __future__ import annotations
- from typing import Any
- TEMPERATURE_INVALID = 0xFF
- def decode_temperature(byte: int) -> int | None:
- value = int(byte) & 0xFF
- return None if value == TEMPERATURE_INVALID else value
- def state_6400(payload: bytes | bytearray, layout: dict[str, Any] | None = None) -> dict[str, Any]:
- p = bytes(payload)
- if len(p) == 94:
- ptc = list(p[0:35])
- front = list(p[35:39])
- rear = list(p[39:43])
- bmc_raw = list(p[43:67])
- ct_raw = list(p[67:94])
- elif len(p) == 83:
- ptc = list(p[0:24])
- front = list(p[24:28])
- rear = list(p[28:32])
- bmc_raw = list(p[32:56])
- ct_raw = list(p[56:83])
- else:
- raise ValueError(f"6400 GET_DATA payload length must be 83 or 94, got {len(p)}")
- bmc_temps = [decode_temperature(b) for b in bmc_raw]
- ct_temps = [decode_temperature(b) for b in ct_raw]
- return {
- "product": "6400-front-rear",
- "ptc_applied": ptc,
- "front_applied": front,
- "rear_applied": rear,
- "ptc": ptc,
- "front": front,
- "rear": rear,
- "bmc": {
- "raw": bmc_raw,
- "temperature_c": bmc_temps,
- "valid": [t is not None for t in bmc_temps],
- },
- "ct": {
- "raw": ct_raw,
- "temperature_c": ct_temps,
- "valid": [t is not None for t in ct_temps],
- },
- }
- def mrdimm_state(payload: bytes | bytearray, layout: dict[str, Any] | None = None) -> dict[str, Any]:
- p = bytes(payload)
- if len(p) != 63:
- raise ValueError(f"MRDIMM GET_DATA payload length must be 63, got {len(p)}")
- fan = list(p[0:4])
- ptc = list(p[4:8])
- bmc_raw = list(p[8:32])
- bmc_temps = [decode_temperature(b) for b in bmc_raw]
- ct_raw = list(p[32:59])
- ct_temps = [decode_temperature(b) for b in ct_raw]
- lower_mask = int.from_bytes(p[59:61], "little")
- upper_mask = int.from_bytes(p[61:63], "little")
- axes = {}
- for i in range(12):
- axes[f"axis{i}"] = {
- "index": i,
- "lower_limit": bool(lower_mask & (1 << i)),
- "upper_limit": bool(upper_mask & (1 << i)),
- }
- return {
- "product": "mrdimm-chamber",
- "fan_applied": fan,
- "ptc_applied": ptc,
- "fan": fan,
- "ptc": ptc,
- "lower_limit_mask": lower_mask,
- "upper_limit_mask": upper_mask,
- "axes": axes,
- "bmc": {
- "raw": bmc_raw,
- "temperature_c": bmc_temps,
- "valid": [t is not None for t in bmc_temps],
- },
- "ct": {
- "raw": ct_raw,
- "temperature_c": ct_temps,
- "valid": [t is not None for t in ct_temps],
- },
- }
|