Conversation
Introduce an extended binary BLE telemetry packet and codec for BMS data. Add BLE_BMS_Extended_Telemetry_V1 and BMS_TEMPERATURE_SENSORS_NUM to structs, plus a static_assert ensuring the packet fits BLE MTU. Implement buildBMSPackedTelemetryV1 and buildBMSExtendedTelemetryV1 (header + cpp) and a helper to pack temperature probes. Update BLE service to expose a new extended telemetry characteristic, initialize both characteristics, and add updateBMSExtendedTelemetry which is sent from updateBLETask at 2 Hz. Minor task/queue ordering tweak in bmsTask. Add unit tests validating mapping between STR_BMS_TELEMETRY_140 and both packed/extended packets and enforcing expected struct sizes.
Drop highest/lowest cell voltage, highest/lowest temperature and voltage differential from the BLE extended telemetry struct and payload mapping so clients compute these values from per-cell/-probe arrays. Update struct comment to reflect the change. Remove assignments in the codec that populated the removed fields. Adjust unit tests to expect the new fields (soc, battery voltage/current/power) and update the expected packed struct size (now 155 bytes, still <= 182). Files changed: inc/sp140/structs.h, src/sp140/ble/bms_packet_codec.cpp, test/test_ble_bms_packets/test_ble_bms_packets.cpp.
There was a problem hiding this comment.
Pull request overview
This pull request adds support for extended BMS telemetry over BLE, enabling transmission of detailed per-cell voltages and probe temperatures. The changes refactor telemetry packet creation into dedicated builder functions for improved maintainability, add a new BLE characteristic for extended telemetry with optimized 2Hz update rate, and include comprehensive unit tests to validate packet mapping and struct sizes. A bug fix ensures the BMS telemetry queue always receives the latest data regardless of connection state.
Changes:
- Added
BLE_BMS_Extended_Telemetry_V1struct with per-cell voltages and temperature arrays, validated to fit within BLE MTU limits - Refactored packet construction into
buildBMSPackedTelemetryV1andbuildBMSExtendedTelemetryV1functions in newbms_packet_codecmodule - Added new BLE characteristic for extended telemetry with 2Hz update rate (vs 10Hz for packed telemetry)
- Fixed queue logic bug by moving
xQueueOverwritecall outside connection state check inbmsTask - Added comprehensive unit tests for packet mapping, struct sizes, and connection state handling
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| inc/sp140/structs.h | Added BLE_BMS_Extended_Telemetry_V1 struct, BMS_TEMPERATURE_SENSORS_NUM macro, and MTU size assertion; changed word to uint16_t for portability |
| inc/sp140/ble/bms_packet_codec.h | Added header for new packet builder functions |
| src/sp140/ble/bms_packet_codec.cpp | Implemented packet builder functions with temperature array ordering and field mapping |
| inc/sp140/ble/bms_service.h | Added updateBMSExtendedTelemetry function declaration |
| src/sp140/ble/bms_service.cpp | Integrated packet builders, added extended telemetry characteristic with proper initialization |
| src/sp140/sp140.ino | Added 2Hz throttled extended telemetry updates; fixed queue bug by ensuring all telemetry data is queued regardless of connection state |
| test/test_ble_bms_packets/test_ble_bms_packets.cpp | Added unit tests for packet mapping, disconnected state handling, and struct size validation |
| .claude/settings.local.json | Added permission for pio test command |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request introduces support for a new extended BMS telemetry protocol over BLE, allowing transmission of detailed battery data including per-cell voltages and probe temperatures. It refactors the telemetry packet creation logic for maintainability, updates the BLE service to handle both packed and extended telemetry, and adds comprehensive unit tests to verify correct packet mapping and struct sizes.
Extended BMS Telemetry Protocol Support
BLE_BMS_Extended_Telemetry_V1struct to carry per-cell voltages and probe temperatures, with static assertions to ensure packet size fits BLE MTU limits. (inc/sp140/structs.h, [1] [2]BMS_TEMPERATURE_SENSORS_NUMmacro for temperature sensor array sizing and ordering. (inc/sp140/structs.h, inc/sp140/structs.hR70)Packet Creation Refactoring
buildBMSPackedTelemetryV1andbuildBMSExtendedTelemetryV1, encapsulated in newbms_packet_codecmodule. (inc/sp140/ble/bms_packet_codec.h,src/sp140/ble/bms_packet_codec.cpp, [1] [2]src/sp140/ble/bms_service.cpp, src/sp140/ble/bms_service.cppL46-R59)BLE Service Enhancements
pBMSExtendedTelemetry), initialized and updated alongside packed telemetry. (src/sp140/ble/bms_service.cpp, [1] [2]updateBMSExtendedTelemetryfunction and exposed it in the header. (src/sp140/ble/bms_service.cpp,inc/sp140/ble/bms_service.h, [1] [2]Task Scheduling and Queue Improvements
src/sp140/sp140.ino, [1] [2]bmsTaskto ensure latest data is always available for BLE transmission. (src/sp140/sp140.ino, src/sp140/sp140.inoR545-L544)Unit Testing