Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Dec 31, 2025

Summary

Fixes blackbox log corruption that occurs when BLACKBOX_FEATURE_MOTORS is enabled but no motors are defined in the mixer (e.g., after mmix reset or on fixed-wing with servos only).

Problem

When getMotorCount() == 0 but the MOTORS feature flag is enabled, the encoder writes a spurious null byte in I-frames, causing the decoder to fail catastrophically with most frames failing to decode.

Root Cause

Condition mismatch between field definitions and write functions:

  • Field definitions use AT_LEAST_MOTORS_1 (checks motorCount >= 1 AND flag)
  • I-frame write uses MOTORS (checks flag only)
  • Result: Header declares 0 motor fields, but I-frame unconditionally writes motor[0]

Changes

  • Line 1079: Change I-frame motor write condition from MOTORS to AT_LEAST_MOTORS_1
  • Line 1346: Change P-frame motor write condition from MOTORS to AT_LEAST_MOTORS_1 (consistency)

Testing

  • Platform: JHEMCUF435 (AT32F43x) with motorCount=0
  • Before fix: 207 decoder failures, 0.050s duration
  • After fix: 3 decoder failures (baseline), 12.067s duration
  • Binary size: unchanged

Problem:
- Field definitions use AT_LEAST_MOTORS_N (checks motorCount AND flag)
- I-frame write used MOTORS (checks flag only)
- When motorCount=0 and flag=true: header declares 0 fields, I-frame writes 1 byte
- motor[0] - getThrottleIdleValue() = 0 - 0 = 0 → encodes as 0x00
- Decoder expects frame marker, finds null byte → catastrophic failure

Fix:
- Change I-frame write from FLIGHT_LOG_FIELD_CONDITION_MOTORS
  to FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_1
- Change P-frame write for consistency
- Now matches field definition condition exactly

Testing:
- Board with motorCount=0, MOTORS flag enabled
- Before: 207 decoder failures (0.050s duration)
- After: 3 decoder failures (12s duration) - matches baseline

Files:
- src/main/blackbox/blackbox.c lines 1079, 1346

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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.

1 participant