Skip to content

Raise servo mixer rules from 36 to 42 - #12279

Open
GrumpyOldNerd wants to merge 1 commit into
iNavFlight:maintenance-11.xfrom
GrumpyOldNerd:feature/servo-rules-42
Open

GrumpyOldNerd wants to merge 1 commit into
iNavFlight:maintenance-11.xfrom
GrumpyOldNerd:feature/servo-rules-42

Conversation

@GrumpyOldNerd

@GrumpyOldNerd GrumpyOldNerd commented Dec 5, 2026 •

Copy link
Copy Markdown

Raises MAX_SERVO_RULES from 36 to 42 per mixer profile, for all targets. Gliders with several flap segments, camber and butterfly run out of rules at 36.

Why 42: MSP2_INAV_SERVO_MIXER sends both mixer profiles in one reply (6 bytes per rule). 2 × 42 × 6 = 504 bytes is the most that fits the 512-byte reply buffers (serial on targets without a flash blackbox, MSP over telemetry), so no MSP paging is needed. Static asserts guard both buffers.

Changes

  • MAX_SERVO_RULES 42 (was 2 * MAX_SUPPORTED_SERVOS)
  • PG_MIXER_PROFILE version bump: mixer profiles reset to defaults on upgrade, restore via diff. A diff with smix 36 to smix 41 gives parse errors on older firmware.
  • MSP2_INAV_MIXER appends maxServoRules (u8), MSP spec 2.2.0. Older Configurators ignore the byte but handle only 36 rules per profile; rules 37 to 42 need Mixer: take the servo rule count from the FC inav-configurator#2868.
  • Docs: Mixer.md, MSP spec

Cost (local build against maintenance-11.x): flash +8 to +68 bytes, RAM +160 to +248 bytes (MATEKF411, F722SE, F405, F765, H743).

This applies to all targets. F722 and F411 are included only for simplicity; if they cause any conflict, they drop out right away.

Tested in SITL: 42 rules accepted and the 43rd rejected; rule 42 drives its servo; MSP2_INAV_SERVO_MIXER 504 bytes with profile 2 at the right offset; MSP2_INAV_MIXER reports 42; rules survive save and reboot; upgrading an old EEPROM resets the mixer and keeps other settings. Unit tests 647/647, PG version check passes. Not tested on hardware yet.


🤖 Generated with Claude Code

@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Raise servo mixer rules from 36 to 42

✨ Enhancement 📝 Documentation ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Raises MAX_SERVO_RULES from 36 to 42 per mixer profile, for all targets.
• Adds a static assert that the two-profile servo mixer reply fits the MSP buffer.
• MSP2_INAV_MIXER appends maxServoRules; mixer profile PG version bumped, resetting profiles on
 upgrade.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: Mixer configuration and servo control.
  • The changed rule-array size and profile layout are consumed by the same mixer-profile loader and servo-output path; they determine the configured servo control behavior rather than an independent technical layer.
  • The capability is the bounded mixer-configuration integration exposed through MSP.
  • The advertised limit and serialized rule blocks are one client-facing operation, not separate storage or transport capabilities.
Sources

src/main/flight/servos.h[150-152]

// 42 is the most that fits MSP2_INAV_SERVO_MIXER (2 profiles x 6 bytes per rule) into the 512-byte MSP reply buffers
// (serial without flash blackbox, MSP over telemetry), see the static asserts in fc_msp.c
#define MAX_SERVO_RULES 42
Behavioral complexity 🟡 Medium 🧩 Compatibility cases, Coordinated invariants

  • Before, the previous PG version and smaller rule array allowed matching stored mixer profiles to load.
  • After, the profile version changes and the rule array grows to 42 entries.
  • New correctness conditions are: old and new profile layouts must select the intended reset or load behavior, all mixer consumers must agree on the new bound, and the expanded arrays must not alter rule ordering or runtime limits.
  • The changed profile version is a compatibility transition, not merely a constant increase.
Sources

src/main/flight/servos.h[150-152]

// 42 is the most that fits MSP2_INAV_SERVO_MIXER (2 profiles x 6 bytes per rule) into the 512-byte MSP reply buffers
// (serial without flash blackbox, MSP over telemetry), see the static asserts in fc_msp.c
#define MAX_SERVO_RULES 42
Potential damage 🟡 Medium 🩹 Incorrect results

  • On upgrade, the version mismatch causes the existing mixer profile to remain at reset defaults.
  • For aircraft relying on custom motor or servo mixer settings, outputs can therefore be absent or incorrect until configuration is restored.
  • Reverting before saving the new defaults can restore the old EEPROM record; after an upgrade save, manual reconfiguration or backup restoration is required.
  • Potentially recoverable by reverting before overwriting configuration, restoring a configuration backup, or manually re-entering mixer settings.
  • The source does not provide automatic migration of the old profile.
Assessed commit 8310b95
Diagram

graph TD
  servos["servos.h: MAX_SERVO_RULES=42"] --> mixer["mixer_profile.c: PG version bump"] --> msp["fc_msp.c: MSP serializers"] --> buf["MSP reply buffer 512B"]
  msp --> cfg["Configurator: reads maxServoRules"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Page MSP2_INAV_SERVO_MIXER per profile
  • ➕ Removes the reply-size ceiling, so the rule limit could grow further
  • ➕ Works on targets with small buffers without a static cap
  • ➖ Needs Configurator changes to request pages, so older Configurators break
  • ➖ More protocol state and more test surface
2. Derive the limit from the output buffer size per target
  • ➕ Gives larger limits on targets with bigger MSP buffers
  • ➕ No hand-picked constant
  • ➖ Rule count differs per target, which complicates Configurator behaviour and docs
  • ➖ The EEPROM layout then varies by target

Recommendation: Keeping a fixed constant of 42 with a static assert is the simplest option that avoids MSP paging. The PR's approach is reasonable for the current need. Paging would support larger limits but needs Configurator changes and more protocol state.

Files changed (6) +18 / -5

Enhancement (2) +7 / -1
fc_msp.cAdd static assert and append maxServoRules to MSP mixer reply +5/-0

Add static assert and append maxServoRules to MSP mixer reply

• Defines a static assert that MAX_SERVO_RULES * MAX_MIXER_PROFILE_COUNT * 6 fits in MSP_PORT_OUTBUF_SIZE. MSP2_INAV_MIXER now writes MAX_SERVO_RULES as a trailing byte.

src/main/fc/fc_msp.c

servos.hSet MAX_SERVO_RULES to 42 independent of servo count +2/-1

Set MAX_SERVO_RULES to 42 independent of servo count

• Replaces the 2 * MAX_SUPPORTED_SERVOS definition with a fixed value of 42. A comment explains that the value is the largest that fits the MSP reply buffer.

src/main/flight/servos.h

Documentation (3) +9 / -2
Mixer.mdDocument the 0 to 41 servo rule index range +1/-1

Document the 0 to 41 servo rule index range

• The smix command description now states the valid index range is 0 to 41 and that each mixer profile holds up to 42 rules.

docs/Mixer.md

README.mdDocument maxServoRules in MSP2_INAV_MIXER +1/-0

Document maxServoRules in MSP2_INAV_MIXER

• Adds a row for the new uint8_t maxServoRules field. It notes that older firmware omits the byte and has 2 * maxServos rules.

docs/development/msp/README.md

msp_messages.jsonAdd maxServoRules field and bump spec patch version +7/-1

Add maxServoRules field and bump spec patch version

• Adds a uint8_t maxServoRules entry to the MSP2_INAV_MIXER schema and bumps the spec patch version from 3 to 4.

docs/development/msp/msp_messages.json

Other (1) +2 / -2
mixer_profile.cBump mixer profile PG version to reset stored profiles +2/-2

Bump mixer profile PG version to reset stored profiles

• Increments the PG_MIXER_PROFILE version in both the USE_AUTO_TRANSITION and default branches. Stored mixer profiles reset to defaults because the array layout changed.

src/main/flight/mixer_profile.c

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Configurator hides six servo rules 🔗 Cross-repo conflict ≡ Correctness
Description
Raising MAX_SERVO_RULES to 42 and appending maxServoRules to MSP2_INAV_MIXER leaves
inav-configurator deriving its limit as twice the 18-servo count and splitting the combined profile
response after 36 rules. On this firmware, rules 36–41 are classified as inactive profile data, so
users cannot view or edit them in the mixer UI or send them through its save path.
Code

src/main/flight/servos.h[151]

+#define MAX_SERVO_RULES 42
Evidence
Firmware advertises 42 rules and serializes that many per profile, while the configurator ignores
the advertised count and places every rule after the first 36 outside the collection used for
display and saving.

inav -> inav-configurator
src/main/flight/servos.h[149-151]
src/main/fc/fc_msp.c[657-666]
src/main/fc/fc_msp.c[1775-1778]
External repo: iNavFlight/inav-configurator, js/msp/MSPHelper.js [1469-1480]
External repo: iNavFlight/inav-configurator, js/servoMixerRuleCollection.js [17-26]
External repo: iNavFlight/inav-configurator, tabs/mixer.js [334-341]
External repo: iNavFlight/inav-configurator, js/msp/MSPHelper.js [2433-2463]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The firmware now sends 42 servo rules per profile, but the pinned inav-configurator assumes two rules per servo (36) when splitting and editing the response.
## Fix Focus Areas
- src/main/flight/servos.h[150-151]
- src/main/fc/fc_msp.c[1776-1778]
- /cross_repos/inav-configurator/js/msp/MSPHelper.js[1469-1480]
- /cross_repos/inav-configurator/js/servoMixerRuleCollection.js[17-26]
- /cross_repos/inav-configurator/js/msp/MSPHelper.js[2433-2463]
## Recommended Fix
Update inav-configurator to read the optional `maxServoRules` byte, fall back to twice the servo count for older firmware, and use the resulting capacity to split profile responses, display rules, and write rule indexes. Coordinate availability of that configurator update with firmware release.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Schema version mislabels the new field ✓ Resolved Bug Maintainability

Resolving commit: 8310b95

Resolution reason
At PR head, the version block in docs/development/msp/msp_messages.json reads major 2, minor 2,
patch 0. The minor version was incremented and the patch reset to 0, which is the versioning rule
the finding asked for (a minor bump with patch reset for a backward-compatible extension). The exact
target 2.2.0 from the suggested fix is matched; the file's current version is 2.2.0.
Description
The JSON specification increments only version.patch even though it adds maxServoRules to the
MSP2_INAV_MIXER reply schema. Because the field is appended after the existing reply fields, this
is a backward-compatible schema extension for which the documented versioning rule requires a minor
increment and a patch reset.

Grey Divider

Tip of the day
💡 Did you know, you can open the rule or relationship behind a finding in one click

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

42 is the most that fits MSP2_INAV_SERVO_MIXER (two mixer profiles,
6 bytes per rule) into the 512-byte MSP reply buffers: serial on
targets without a flash blackbox and MSP over telemetry. sbuf writes
are not bounds-checked, so static asserts guard both.

MSP2_INAV_MIXER reports MAX_SERVO_RULES as a trailing byte, so the
Configurator no longer has to assume two rules per servo. MSP spec
version 2.2.0 for the appended field.

The mixer profile layout changes, so the PG version is bumped and the
mixer profiles reset to defaults on upgrade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GrumpyOldNerd
GrumpyOldNerd force-pushed the feature/servo-rules-42 branch from 3add75b to 8310b95 Compare December 5, 2026 11:38
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