Skip to content

Bms extended telemetry#94

Draft
zjwhitehead wants to merge 4 commits intomasterfrom
bms-extended-telemetry
Draft

Bms extended telemetry#94
zjwhitehead wants to merge 4 commits intomasterfrom
bms-extended-telemetry

Conversation

@zjwhitehead
Copy link
Member

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

  • Added new BLE_BMS_Extended_Telemetry_V1 struct 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]
  • Defined BMS_TEMPERATURE_SENSORS_NUM macro for temperature sensor array sizing and ordering. (inc/sp140/structs.h, inc/sp140/structs.hR70)

Packet Creation Refactoring

  • Moved packed and extended telemetry packet construction into dedicated functions: buildBMSPackedTelemetryV1 and buildBMSExtendedTelemetryV1, encapsulated in new bms_packet_codec module. (inc/sp140/ble/bms_packet_codec.h, src/sp140/ble/bms_packet_codec.cpp, [1] [2]
  • Updated BLE service logic to use these builder functions for packet creation, improving maintainability and consistency. (src/sp140/ble/bms_service.cpp, src/sp140/ble/bms_service.cppL46-R59)

BLE Service Enhancements

  • Added new BLE characteristic for extended telemetry (pBMSExtendedTelemetry), initialized and updated alongside packed telemetry. (src/sp140/ble/bms_service.cpp, [1] [2]
  • Added updateBMSExtendedTelemetry function 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

  • Scheduled extended telemetry updates at a lower rate (2Hz) than packed telemetry (10Hz) to optimize BLE bandwidth. (src/sp140/sp140.ino, [1] [2]
  • Fixed telemetry queue logic in bmsTask to ensure latest data is always available for BLE transmission. (src/sp140/sp140.ino, src/sp140/sp140.inoR545-L544)

Unit Testing

  • Added unit tests to verify correct mapping from internal telemetry to packed and extended BLE packets, and to check struct sizes against expectations.

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.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_V1 struct with per-cell voltages and temperature arrays, validated to fit within BLE MTU limits
  • Refactored packet construction into buildBMSPackedTelemetryV1 and buildBMSExtendedTelemetryV1 functions in new bms_packet_codec module
  • Added new BLE characteristic for extended telemetry with 2Hz update rate (vs 10Hz for packed telemetry)
  • Fixed queue logic bug by moving xQueueOverwrite call outside connection state check in bmsTask
  • 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.

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