Repository navigation
Conversation
The ESC already returns Smart Battery pages with its ordinary telemetry. Decode the cells and pack temperature, expose them through the CLI and send them over CRSF. Require battery metadata before publishing so the placeholders returned by Lite ESCs do not become cell readings. Use receiver ID 0x21 in place of 0x31 so the Avian's battery replies pass the normal address check. Control frames and telemetry scheduling stay as they were. Checked with a 6S Avian Smart 100A and a Smart 4000 mAh pack. Normal ESC telemetry and FC-only restart recovery also worked on the 100A and Lite 85A, with the Lite's battery placeholders suppressed.
PR Summary by QodoAdd Spektrum Smart Battery telemetry to SRXL2 ESC support
AI Description
Diagram
High-Level Assessment
Files changed (9)
|
Code Review by Qodo
1. Radios can show an incomplete cell pack
|
| const uint8_t count = battery.cellCount; | ||
| if (!count || count > CRSF_SMART_BATTERY_RADIO_MAX_CELLS | ||
| || battery.validCells != (1u << count) - 1) { | ||
| return false; |
There was a problem hiding this comment.
1. Radios can show an incomplete cell pack 🐞 Bug ≡ Correctness
crsfFrameSmartBattery accepts battery.cellCount even when it came from the highest observed cell rather than a fresh identification page. If the limits page and first cell page arrive before identification for a pack with more than six cells, the radio receives those six cells as a complete pack.
Agent Prompt
## Issue description
The CRSF completeness check can treat the highest observed cell number as the pack's total cell count and publish a partial pack.
## Fix Focus Areas
- src/main/telemetry/crsf.c[467-473]
- src/main/io/srxl2_smart_battery.c[108-116]
## Recommended Fix
Require `battery.cellCountValid` before emitting a Voltage Group frame. Keep the observed count available for CLI diagnostics, but do not use it to establish CRSF pack completeness.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| if (!source) { | ||
| for (unsigned i = 0; i < SRXL2_SMART_BATTERY_SLOTS; i++) { | ||
| if (!state->source[i].used) { | ||
| source = &state->source[i]; | ||
| source->used = true; |
There was a problem hiding this comment.
2. New battery sources stop appearing 🐞 Bug ☼ Reliability
srxl2SmartBatteryReceive permanently reserves both source slots once their identities have been seen, while invalidation clears only page validity. If a later battery source has a different secondary or battery ID after both slots have been used, its pages are dropped even after the earlier sources have gone stale or the link has restarted.
Agent Prompt
## Issue description
Two previously seen source identities occupy the only slots indefinitely, preventing telemetry from a later distinct source.
## Fix Focus Areas
- src/main/io/srxl2_smart_battery.c[45-67]
- src/main/io/srxl2_smart_battery.c[88-97]
## Recommended Fix
When a new identity arrives and both slots are occupied, reclaim a source only after all of its pages are stale or invalid. Clear its cached pages and observed count before assigning the new identity, while retaining stable slots for sources that are still active.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
|
@UltraFly I checked that this PR and #12085 work together, since #12085 answers the ESC during start-up with the board's device ID and this PR changes it to 0x21. They merge without conflicts (dcdc34e on top of 81bde78), and I tried the result on a TBS Lucid H7 Wing with an Avian 70A on UART8, both on one 6S battery:
I have no Smart Battery, so the battery pages are not covered. |
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #12077 251 targets built. Find your board's
|
Adds cell voltages and pack temperature from Smart Battery sensor
0x42to the existing Smart ESC driver, with CLI readout and native CRSF telemetry. The battery pages arrive through the existing ESC telemetry requests; no extra polling is needed.Use receiver address
0x21instead of0x31so the Avian's battery replies pass the normal destination check. Control frames and telemetry scheduling are unchanged. Avian Lite ESCs, including the 70A and 85A, lack the third battery-data wire. They still provide ESC telemetry, but their placeholder battery pages must not become cell readings.Tested with a 6S Avian Smart 100A and a Spektrum Smart 4000 mAh 6S Gen 1 pack: cell voltages and pack temperature matched the received data. Normal ESC telemetry and FC-only restart recovery also worked on the 100A and Lite 85A, with the Lite's battery placeholders correctly suppressed. These bench tests used existing local NEXUS support, outside this change. Host checks and MATEKF405SE/MATEKF722 builds pass.