feat(bms): add read-only diagnostics and guarded operating switch commands

This commit is contained in:
DCCONSTRUCTIONS
2026-11-04 17:14:54 +03:00
parent ab8e977f11
commit 42213001ba
19 changed files with 919 additions and 40 deletions
+15 -3
View File
@@ -1,6 +1,7 @@
"""JK02_32S profile qualified against BD6A17S6P / 11.47.
Only 0x97 (identity) and 0x96 (telemetry subscription) can be constructed.
Only read requests are constructed here. Operating switches have a separate
strict encoder in settings.py; protection/calibration writes are absent.
Never expose the raw identity frame: it contains unrelated credential fields.
"""
@@ -63,7 +64,7 @@ class Frames:
if len(self.buffer) < 300:
break
frame = bytes(self.buffer[:300])
if sum(frame[:-1]) & 255 != frame[-1]:
if frame[4] not in (1, 2, 3) or sum(frame[:-1]) & 255 != frame[-1]:
del self.buffer[0]
self.rejected += 1
continue
@@ -85,6 +86,7 @@ def identity(frame):
"firmware": field(30, 38),
"name": field(46, 62),
"manufactured_raw": field(78, 84),
"serial_number": field(86, 97),
}
@@ -121,12 +123,22 @@ def telemetry(frame):
"power_w": round(voltage * current, 3),
"power_source": "voltage_times_current",
"remaining_ah": u(174) / 1000,
"configured_capacity_ah": u(178) / 1000,
"configured_capacity_ah": None,
"effective_capacity_ah": u(178) / 1000,
"reported_health_percent": u(190, 1) if u(190, 1) <= 100 else None,
"cycle_count": u(182),
"cycle_capacity_ah": u(186) / 1000,
"cell_count": count,
"cell_voltages_v": cells,
"cell_delta_v": u(76, 2) / 1000,
"cell_min_v": min(cells),
"cell_max_v": max(cells),
"cell_average_v": round(sum(cells) / count, 4),
"cell_min_index": cells.index(min(cells)) + 1,
"cell_max_index": cells.index(max(cells)) + 1,
"wire_resistances_ohm": [u(80 + i * 2, 2) / 1000 for i in range(count)],
"wire_warning_cells": [i + 1 for i in range(count) if u(146) & (1 << i)],
"protection_mask": u(166),
"charge_mos_on": bool(u(198, 1)),
"discharge_mos_on": bool(u(199, 1)),
"runtime_s": u(194),