Skip to content

Handle bad BMS cell temperature probes#91

Draft
zjwhitehead wants to merge 8 commits intomasterfrom
bms-cell-low-temps
Draft

Handle bad BMS cell temperature probes#91
zjwhitehead wants to merge 8 commits intomasterfrom
bms-cell-low-temps

Conversation

@zjwhitehead
Copy link
Member

This pull request improves the robustness and accuracy of BMS (Battery Management System) cell temperature handling, especially in cases where cell temperature probes are disconnected. It introduces a clear mechanism for identifying disconnected probes, ensures that disconnected readings are excluded from calculations and user interfaces, and adds comprehensive tests for these behaviors.

BMS Cell Probe Disconnect Handling and Data Sanitization:

  • Introduced sanitizeBmsCellTempC() and the BMS_CELL_TEMP_DISCONNECTED_C constant to reliably detect and sanitize disconnected cell probes (which report exactly -40°C), converting them to NaN for downstream logic.
  • All BMS cell temperature readings (t1_temperaturet4_temperature) are now stored as NaN if disconnected, and this is reflected in the telemetry struct documentation.
  • Added logic to log connection/disconnection transitions for cell probes, aiding in field debugging. [1] [2]

Telemetry and BLE Data Improvements:

  • High/low temperature extrema are now recalculated to exclude disconnected (NaN) probes, ensuring only valid sensor readings are considered.
  • BLE temperature data now includes a bitmap indicating which sensors are connected, and only valid (non-NaN) readings are transmitted; disconnected sensors send zero.

User Interface (LVGL) Updates:

  • The main screen now calculates battery temperature using only connected cell probes, and displays "-" if no valid probe is connected, instead of showing a potentially misleading low value.

Testing Enhancements:

  • Added comprehensive unit tests to verify that disconnected probes are ignored, alerts are cleared when probes disconnect, and the sanitizer logic works as intended.

Test Infrastructure:

  • Added minimal stub implementations for BMS_CAN and SPIClass to support testing.

These changes make the system more robust against intermittent or faulty cell probe connections, improve user feedback, and ensure that temperature-related warnings and UI elements behave correctly in all cases.

zjwhitehead and others added 8 commits February 21, 2026 15:34
Detect and handle disconnected BMS cell temperature probes by treating known disconnected sentinel values as NaN. Add helpers (isBmsCellTempValidC, sanitizeBmsCellTempC) and constants to inc/sp140/bms.h, update telemetry struct comments to indicate NaN semantics, and sanitize raw cell temps in updateBMSData. Recompute highest/lowest temperature extrema from valid readings and log probe connection/disconnection transitions. Update BLE temperature characteristic to include a valid-sensor bitmap and send 0 for invalid sensors. Update LVGL main screen to compute battery temperature using only valid cell probes and only display it when a valid reading exists.
Inline BMS cell temperature validity into sanitizeBmsCellTempC and update call sites to use the sanitizer (and isnan checks) to treat disconnected probes as NaN. Update lvgl and bms logic to rely on sanitized values. Add unit tests covering sanitizer behavior and monitor handling of disconnected BMS probes, and include native test stubs for BMS_CAN and SPI. This centralizes validity logic and ensures disconnected readings are ignored consistently.
Unify handling of BMS cell probes by treating a raw -40.0°C as a disconnected probe and converting such readings to NaN.

Changes:
- inc/sp140/bms.h: add BMS_CELL_TEMP_DISCONNECTED_C constant and update sanitizeBmsCellTempC to return NaN for disconnected/invalid readings (use strict > to exclude -40.0).
- src/sp140/bms.cpp: reuse sanitizer for connection detection and logging, exclude NaN values from extrema computation, and recompute extrema after sanitization so published high/low temps match stored values.
- src/sp140/lvgl/lvgl_updates.cpp: sanitize cell temps before UI logic and show "-" when no valid battery temperature is available.

Reason: ensures consistent telemetry, logging and UI behavior for disconnected probes and helps field-debug intermittent wiring issues.
CI fix
Co-authored-by: zjwhitehead <4623792+zjwhitehead@users.noreply.github.com>
Introduce BMS_CELL_PROBE_COUNT and BMS_MAX_IGNORED_DISCONNECTED_PROBES and replace the single-value sanitizer with sanitizeCellProbeTemps(), which converts disconnected sentinel (-40°C) probes to NaN while ignoring up to two such sentinels before treating further -40°C readings as real temperatures. Update bms.cpp to produce and log using sanitized probe arrays and adjust LVGL code to assume probe values are pre-sanitized. Remove the old sanitizeBmsCellTempC overload that accepted a keep-disconnected flag and expand tests to cover the new multi-probe sanitization and alert transition behavior.
…gnore-logic

Normalize BMS -40C cell probe handling (ignore any 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants