Augmenting CRSF telemetry parser for BATT frames with trailing sensor-id#7571
Augmenting CRSF telemetry parser for BATT frames with trailing sensor-id#7571wimalopaan wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughCrossfire telemetry processing now supports per-sensor identifiers. Battery frames conditionally extract ChangesCrossfire telemetry
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
radio/src/telemetry/crossfire.cpp (1)
366-381: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAlign length checks with sibling parsers and fix indentation.
While
rxBufferCount > 12correctly identifies the extended battery frame, other handlers in this file (such asBARO_ALT_ID) check the parsedcrsfPayloadLenvariable to determine the presence of optional trailing data. Additionally, the new logic uses deeper indentation (up to 10 spaces) instead of standard 2-space increments.Consider swapping to
crsfPayloadLen >= 11for consistency and adjusting the indentation to conform to the project's formatting style.♻️ Proposed refactor
case BATTERY_ID: { uint8_t sensorID = 0; - if (rxBufferCount > 12) { - if (getCrossfireTelemetryValue<1>(11, value, rxBuffer)) { - sensorID = value; - } - } - if (getCrossfireTelemetryValue<2>(3, value, rxBuffer)) - processCrossfireTelemetryValue(BATT_VOLTAGE_INDEX, value, sensorID); - if (getCrossfireTelemetryValue<2>(5, value, rxBuffer)) - processCrossfireTelemetryValue(BATT_CURRENT_INDEX, value, sensorID); - if (getCrossfireTelemetryValue<3>(7, value, rxBuffer)) - processCrossfireTelemetryValue(BATT_CAPACITY_INDEX, value, sensorID); - if (getCrossfireTelemetryValue<1>(10, value, rxBuffer)) - processCrossfireTelemetryValue(BATT_REMAINING_INDEX, value, sensorID); + if (crsfPayloadLen >= 11) { + if (getCrossfireTelemetryValue<1>(11, value, rxBuffer)) { + sensorID = value; + } + } + if (getCrossfireTelemetryValue<2>(3, value, rxBuffer)) + processCrossfireTelemetryValue(BATT_VOLTAGE_INDEX, value, sensorID); + if (getCrossfireTelemetryValue<2>(5, value, rxBuffer)) + processCrossfireTelemetryValue(BATT_CURRENT_INDEX, value, sensorID); + if (getCrossfireTelemetryValue<3>(7, value, rxBuffer)) + processCrossfireTelemetryValue(BATT_CAPACITY_INDEX, value, sensorID); + if (getCrossfireTelemetryValue<1>(10, value, rxBuffer)) + processCrossfireTelemetryValue(BATT_REMAINING_INDEX, value, sensorID); } break;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@radio/src/telemetry/crossfire.cpp` around lines 366 - 381, Update the extended battery parsing block to use crsfPayloadLen >= 11 instead of rxBufferCount > 12 when deciding whether to read sensorID, matching sibling parsers such as BARO_ALT_ID. Reformat the block with the project’s standard two-space indentation while preserving the existing telemetry extraction and processing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@radio/src/telemetry/crossfire.cpp`:
- Around line 366-381: Update the extended battery parsing block to use
crsfPayloadLen >= 11 instead of rxBufferCount > 12 when deciding whether to read
sensorID, matching sibling parsers such as BARO_ALT_ID. Reformat the block with
the project’s standard two-space indentation while preserving the existing
telemetry extraction and processing behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e394637c-577f-4361-a589-7c03f801e7bc
📒 Files selected for processing (1)
radio/src/telemetry/crossfire.cpp
The CRSF protocol definition allows to augment existing packet definitions in a backward compatible manner. It allows to extend the payload if the overall frame structure remains valid.
The problem:
The crsf BATT sensor type does not support multiple instances. This leads to problems, if e.g. multiple ESCs sends this kind of telemetry sensor frames.
Also, the BATT sensor is the only actually available type to measure current.
There is a proposal to the CRSF protocol definition to add also a multi-instance current sensor frame type like VOLTS, RPM or TEMP: tbs-fpv/tbs-crsf-spec#38
But this is not expected to be setup in the near future.
The solution:
The CRSF protocol definition allows to extend CRSF frames in a backward compatible manner by extending the payload with addition al fields.
This could be used by CRSF devices to add an instance id to the BATT payload (at the end).
This new frametype can be detected by the crsf parser easily and then handle the old type of BATT sensor frames as well as the new frames with instance id included.
This PR modifies the existing CRSF parser to handle old and new BATT sensor types correctly.
As an example, the follwing branch adds the new BATT frame structure to the well known ESCape32 ESC firmware: https://github.com/wimalopaan/ESCape32/tree/wm_crsf_batt_id
Summary by CodeRabbit