Draft
Conversation
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)
Replace the local BMS_CELL_TEMP_DISCONNECTED_C sentinel with the canonical TEMP_PROBE_DISCONNECTED constant from BMS_CAN. Update sanitizeBmsCellTempC and sanitizeCellProbeTemps to reference BMS_CAN::TEMP_PROBE_DISCONNECTED, and remove the duplicate local constant. Add a native test stub for BMS_CAN exposing the constexpr TEMP_PROBE_DISCONNECTED so tests compile. Also bump the ANT-BMS-CAN dependency reference in platformio.ini to the commit that contains this change. This centralizes the probe-disconnected sentinel in the BMS_CAN library while keeping application-level policy (max ignored disconnected probes) in the app.
Sanitize BMS cell probe handling to accept NaN from the BMS library and apply an app-level tolerance: allow up to BMS_MAX_IGNORED_DISCONNECTED_PROBES NaNs to pass through, but replace any additional NaNs with the TEMP_PROBE_DISCONNECTED sentinel so monitors alert. Removed the old single-value sanitizer, made sanitizeCellProbeTemps a two-pass routine that counts NaNs and writes either NaN, the original temp, or the sentinel. Updated bms.cpp to consume the new API (pass-through NaNs from library, call sanitizeCellProbeTemps, and use library-provided highest/lowest temps), removed recomputeBmsTemperatureExtrema, and adjusted connection-logging comments. Tests were updated to feed NaN for disconnected probes and to reflect the new alerting/tolerance behavior. Also updated the ANT-BMS-CAN dependency reference in platformio.ini.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
sanitizeBmsCellTempC()and theBMS_CELL_TEMP_DISCONNECTED_Cconstant to reliably detect and sanitize disconnected cell probes (which report exactly -40°C), converting them toNaNfor downstream logic.t1_temperature–t4_temperature) are now stored asNaNif disconnected, and this is reflected in the telemetry struct documentation.Telemetry and BLE Data Improvements:
User Interface (LVGL) Updates:
Testing Enhancements:
Test Infrastructure:
BMS_CANandSPIClassto 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.