Skip to content

Conversation

@sensei-hacker
Copy link
Member

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

User description

Summary

Adds minPowerIndex (byte 12) to MSP_VTX_CONFIG response to indicate the minimum valid power index for VTX devices.

This complements the existing powerCount field and enables configurator to display all available power levels without hardcoding device-specific logic.

Related Configurator PR: iNavFlight/inav-configurator#2486

Changes

File: src/main/fc/fc_msp.c

Added single byte to MSP_VTX_CONFIG response after powerCount:

uint8_t minPowerIndex = 1;  // Default for most VTX devices
if (deviceType == VTXDEV_MSP) {
    minPowerIndex = 0;  // MSP supports power off
}
sbufWriteU8(dst, minPowerIndex);

Values:

  • MSP VTX: minPowerIndex = 0 (supports power off at index 0)
  • SmartAudio/Tramp: minPowerIndex = 1 (power off not supported)

Protocol Change

Before (11 bytes):

  1. device_type
  2. band
  3. channel
  4. power
  5. pitmode
  6. ready
  7. low_power_disarm
  8. vtxtable_available
  9. band_count
  10. channel_count
  11. power_count

After (12 bytes):

1-11. (same as above)
12. minPowerIndex (NEW)

Compatibility

✅ Backward Compatible

  • Old configurators (9.0) + New firmware (9.1): Works - old configurators ignore byte 12
  • New configurators (9.1) + Old firmware (9.0): Works - new configurators have fallback logic

MSP Power Level Examples

MSP VTX (minPowerIndex=0, powerCount=4):

  • Valid indices: 0, 1, 2, 3, 4
  • Index 0 = power off
  • Indices 1-4 = active power levels

SmartAudio (minPowerIndex=1, powerCount=8):

  • Valid indices: 1, 2, 3, 4, 5, 6, 7, 8
  • Power off not supported (pit mode instead)

Rationale

Current firmware sends powerCount (maximum valid index) but not the minimum. This works for most VTX devices which start at index 1, but MSP VTX devices support power off at index 0.

Without this change, configurators must hardcode device-type-specific logic:

// Hardcoded logic (bad)
var minPower = (device_type == DEV_MSP) ? 0 : 1;

With this change, configurator gets complete info from firmware:

// Dynamic from firmware (good)
var minPower = FC.VTX_CONFIG.power_min;

Testing

  • ✅ Code compiles cleanly
  • ✅ Backward compatibility verified (old configurators ignore extra byte)
  • ✅ Forward compatibility verified (new configurator has fallback)
  • 🔲 Hardware testing pending (MSP, SmartAudio, Tramp VTX devices)

Related

Description

  • Adds minPowerIndex field to MSP_VTX_CONFIG response

  • Enables configurators to display power levels dynamically

  • MSP VTX devices report minPowerIndex=0, others report 1

  • Maintains backward compatibility with older configurators


Diagram Walkthrough

flowchart LR
  A["MSP_VTX_CONFIG Request"] --> B["Check Device Type"]
  B --> C{"Is MSP VTX?"}
  C -->|Yes| D["minPowerIndex = 0"]
  C -->|No| E["minPowerIndex = 1"]
  D --> F["Send 12-byte Response"]
  E --> F
  F --> G["Configurator Receives Complete Power Range Info"]
Loading

File Walkthrough

Relevant files
Enhancement
fc_msp.c
Add minPowerIndex to VTX config response                                 

src/main/fc/fc_msp.c

  • Added minPowerIndex field (byte 12) to MSP_VTX_CONFIG response
  • Sets minPowerIndex to 0 for VTXDEV_MSP devices, 1 for others
  • Placed after powerCount field in response buffer
  • Enables dynamic power level configuration without hardcoding device
    logic
+6/-0     

Adds minPowerIndex (byte 12) to MSP_VTX_CONFIG response to indicate
the minimum valid power index for the VTX device.

- MSP VTX: minPowerIndex = 0 (supports power off at index 0)
- SmartAudio/Tramp: minPowerIndex = 1 (power off not supported)

This allows configurator to correctly display all available power
levels without hardcoding device-specific logic.

Backward compatible: old configurators will ignore the extra byte.

Related: iNavFlight/inav-configurator#2486

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Comment on lines 1528 to +1534
sbufWriteU8(dst, vtxDevice->capability.powerCount);

uint8_t minPowerIndex = 1;
if (deviceType == VTXDEV_MSP) {
minPowerIndex = 0;
}
sbufWriteU8(dst, minPowerIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Adding a new byte to the MSP reply increases the payload size; ensure the destination buffer has room (or update the reply-size calculation) before writing to avoid overruns. [Learned best practice, importance: 6]

Suggested change
sbufWriteU8(dst, vtxDevice->capability.powerCount);
uint8_t minPowerIndex = 1;
if (deviceType == VTXDEV_MSP) {
minPowerIndex = 0;
}
sbufWriteU8(dst, minPowerIndex);
sbufWriteU8(dst, vtxDevice->capability.powerCount);
const uint8_t minPowerIndex = (deviceType == VTXDEV_MSP) ? 0 : 1;
if (sbufBytesRemaining(dst) < 1) {
return false;
}
sbufWriteU8(dst, minPowerIndex);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant