Skip to content

Commit

Permalink
msp: expose number of vtx power levels, bands and channels
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Dec 10, 2024
1 parent 2a6ceeb commit 2dad829
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,11 +1488,18 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
sbufWriteU8(dst, vtxSettingsConfig()->channel);
sbufWriteU8(dst, vtxSettingsConfig()->power);
sbufWriteU8(dst, pitmode);
// technically there is bug here, we are missing the 16bit
// freqency bf is transmitting
// sbufWriteU16(dst, vtxSettingsConfig()->freq);

// Betaflight < 4 doesn't send these fields
sbufWriteU8(dst, vtxCommonDeviceIsReady(vtxDevice) ? 1 : 0);
sbufWriteU8(dst, vtxSettingsConfig()->lowPowerDisarm);
// future extensions here...

sbufWriteU8(dst, 1); // vtxtable is available
sbufWriteU8(dst, vtxDevice->capability.bandCount);
sbufWriteU8(dst, vtxDevice->capability.channelCount);
sbufWriteU8(dst, vtxDevice->capability.powerCount);
}
else {
sbufWriteU8(dst, VTXDEV_UNKNOWN); // no VTX configured
Expand Down Expand Up @@ -4261,6 +4268,28 @@ bool mspFCProcessInOutCommand(uint16_t cmdMSP, sbuf_t *dst, sbuf_t *src, mspResu
break;
#endif

case MSP_VTXTABLE_POWERLEVEL: {
vtxDevice_t *vtxDevice = vtxCommonDevice();
if (!vtxDevice) {
return MSP_RESULT_ERROR;
}

const uint8_t powerLevel = sbufBytesRemaining(src) ? sbufReadU8(src) : 0;
if (powerLevel == 0 || powerLevel > vtxDevice->capability.powerCount) {
return MSP_RESULT_ERROR;
}

sbufWriteU8(dst, powerLevel);
sbufWriteU16(dst, 0);

const char *str = vtxDevice->capability.powerNames[powerLevel - 1];
const uint32_t str_len = strnlen(str, 5); // these _should_ all be null-terminated
sbufWriteU8(dst, str_len);
for (uint32_t i = 0; i < str_len; i++)
sbufWriteU8(dst, str[i]);

} break;

default:
// Not handled
return false;
Expand Down

0 comments on commit 2dad829

Please sign in to comment.