Commit e5bfe79
Fix CRSF telemetry corruption from PR iNavFlight#11025
This commit fixes the critical bugs that caused PR iNavFlight#11025 to be reverted
(PR iNavFlight#11139). The original implementation caused telemetry stream corruption
by emitting malformed frames when sensors were unavailable.
Root Cause:
The original PR scheduled telemetry frames unconditionally (if feature
compiled in) but frame functions only wrote data when sensors were available.
This resulted in frames containing only [SYNC][CRC] instead of the proper
[SYNC][LENGTH][TYPE][PAYLOAD][CRC] structure, corrupting the CRSF protocol
stream and breaking ALL telemetry (not just new frames).
Fixes Implemented:
1. RPM Frame (Bug #1 - CRITICAL):
- Added conditional scheduling: only schedule if ESC_SENSOR_ENABLED
and motorCount > 0
- Added protocol limit enforcement: max 19 RPM values per CRSF spec
- Location: src/main/telemetry/crsf.c:705-707, 337-343
2. Temperature Frame (Bug #2 - CRITICAL):
- Added conditional scheduling: only schedule if temperature sources
are actually available (ESC sensors OR temperature sensors)
- Added bounds checking: prevent buffer overflow beyond 20 temperatures
- Location: src/main/telemetry/crsf.c:709-732, 361-381
3. Buffer Overflow Protection (Bug #4):
- Added MAX_CRSF_TEMPS constant and bounds checks in loops
- Prevents array overflow if >20 temperature sources configured
- Location: src/main/telemetry/crsf.c:361, 368, 376
4. Protocol Limit Enforcement (Bug #5):
- Added MAX_CRSF_RPM_VALUES constant (19 per CRSF spec)
- Clamp motorCount to protocol limit before sending
- Location: src/main/telemetry/crsf.c:337, 342-344
Implementation Pattern:
Follows the GPS frame pattern:
✓ Conditional scheduling - only schedule if sensor available
✓ Unconditional writing - always write complete frame data when called
Testing:
- Code compiles successfully (verified with SITL build)
- No syntax errors or warnings
- All fixes follow existing code patterns in crsf.c
Related Issues:
- Original PR: iNavFlight#11025 (merged Nov 28, 2025, reverted same day)
- Revert PR: iNavFlight#11139
- Investigation: claude/developer/sent/pr11025-root-cause-analysis.md
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent f8dc0bc commit e5bfe79
1 file changed
Lines changed: 34 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| 337 | + | |
337 | 338 | | |
338 | 339 | | |
339 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
340 | 346 | | |
341 | 347 | | |
342 | 348 | | |
| |||
358 | 364 | | |
359 | 365 | | |
360 | 366 | | |
361 | | - | |
| 367 | + | |
362 | 368 | | |
363 | 369 | | |
364 | 370 | | |
365 | 371 | | |
366 | 372 | | |
367 | 373 | | |
368 | | - | |
| 374 | + | |
369 | 375 | | |
370 | 376 | | |
371 | 377 | | |
372 | 378 | | |
373 | 379 | | |
374 | 380 | | |
375 | 381 | | |
376 | | - | |
| 382 | + | |
377 | 383 | | |
378 | 384 | | |
379 | 385 | | |
| |||
702 | 708 | | |
703 | 709 | | |
704 | 710 | | |
705 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
706 | 714 | | |
707 | 715 | | |
708 | | - | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
709 | 738 | | |
710 | 739 | | |
711 | 740 | | |
| |||
0 commit comments