From a04491f0e23ae565d4608d272359fd2bdec59811 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Tue, 10 Sep 2024 18:01:12 +0100 Subject: [PATCH 01/48] Rewrite MSP VTX support for proper integration. --- src/main/fc/fc_msp.c | 16 +- src/main/fc/fc_tasks.c | 3 - src/main/io/vtx_msp.c | 722 +++++++------------------ src/main/io/vtx_msp.h | 36 +- src/main/programming/logic_condition.c | 15 +- 5 files changed, 220 insertions(+), 572 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index e7a7a4aa3a6..7993dae6eef 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2686,10 +2686,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) if (sbufBytesRemaining(src) > 1) { uint8_t newPower = sbufReadU8(src); - uint8_t currentPower = 0; - vtxCommonGetPowerIndex(vtxDevice, ¤tPower); - if (newPower != currentPower) { - vtxCommonSetPowerByIndex(vtxDevice, newPower); + if (vtxSettingsConfig()->power != newPower) { vtxSettingsConfigMutable()->power = newPower; } @@ -2715,9 +2712,14 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) // API version 1.42 - extensions for non-encoded versions of the band, channel or frequency if (sbufBytesRemaining(src) >= 4) { uint8_t newBand = sbufReadU8(src); + if (vtxSettingsConfig()->band != newBand) { + vtxSettingsConfigMutable()->band = newBand; + } + const uint8_t newChannel = sbufReadU8(src); - vtxSettingsConfigMutable()->band = newBand; - vtxSettingsConfigMutable()->channel = newChannel; + if (vtxSettingsConfig()->channel != newChannel) { + vtxSettingsConfigMutable()->channel = newChannel; + } } /* if (sbufBytesRemaining(src) >= 4) { @@ -3684,7 +3686,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst) while (bytesCount < 80) //whole response should be less 155 bytes at worst. { bool blink1; - uint16_t lastChar; + uint16_t lastChar = 0; count = 0; while ( true ) diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index afb880db526..fbe119c272b 100755 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -120,9 +120,6 @@ void taskHandleSerial(timeUs_t currentTimeUs) #ifdef USE_MSP_OSD // Capture MSP Displayport messages to determine if VTX is connected mspOsdSerialProcess(mspFcProcessCommand); -#ifdef USE_VTX_MSP - mspVtxSerialProcess(mspFcProcessCommand); -#endif #endif } diff --git a/src/main/io/vtx_msp.c b/src/main/io/vtx_msp.c index 696918e5705..13a3247eb14 100644 --- a/src/main/io/vtx_msp.c +++ b/src/main/io/vtx_msp.c @@ -17,157 +17,115 @@ * * If not, see . */ +/* Created by geoffsim */ -/* Created by phobos- */ - -#include #include -#include -#include -#include #include +#include #include "platform.h" #if defined(USE_VTX_MSP) && defined(USE_VTX_CONTROL) && defined(USE_VTX_COMMON) -#include "build/debug.h" - -//#include "cms/cms_menu_vtx_msp.h" -#include "common/crc.h" #include "common/log.h" -#include "config/feature.h" - +#include "common/crc.h" #include "drivers/vtx_common.h" -//#include "drivers/vtx_table.h" - -#include "fc/runtime_config.h" -#include "flight/failsafe.h" - -#include "io/serial.h" -#include "io/vtx_msp.h" -#include "io/vtx_control.h" -#include "io/vtx_string.h" -#include "io/vtx_smartaudio.h" -#include "io/vtx.h" -#include "io/displayport_msp_osd.h" - #include "msp/msp_protocol.h" -#include "msp/msp_serial.h" -#include "msp/msp.h" - -//#include "pg/vtx_table.h" -#include "fc/settings.h" - -#include "rx/crsf.h" -//#include "rx/crsf_protocol.h" #include "rx/rx.h" - -#include "telemetry/msp_shared.h" - -//static uint16_t mspConfFreq = 0; -static uint8_t mspConfBand = SETTING_VTX_BAND_DEFAULT; -static uint8_t mspConfChannel = SETTING_VTX_CHANNEL_DEFAULT; -//static uint16_t mspConfPower = 0; -static uint16_t mspConfPowerIndex = SETTING_VTX_POWER_DEFAULT; -static uint8_t mspConfPitMode = 0; -static bool mspVtxConfigChanged = false; -static timeUs_t mspVtxLastTimeUs = 0; -static bool prevLowPowerDisarmedState = false; - -static const vtxVTable_t mspVTable; // forward -static vtxDevice_t vtxMsp = { - .vTable = &mspVTable, - .capability.bandCount = VTX_MSP_TABLE_MAX_BANDS, - .capability.channelCount = VTX_MSP_TABLE_MAX_CHANNELS, - .capability.powerCount = VTX_MSP_TABLE_MAX_POWER_LEVELS, - .capability.bandNames = (char **)vtx58BandNames, - .capability.channelNames = (char **)vtx58ChannelNames, - .capability.powerNames = (char**)saPowerNames - +#include "rx/crsf.h" +#include "telemetry/crsf.h" +#include "vtx.h" +#include "displayport_msp_osd.h" +#include "vtx_string.h" +#include "vtx_msp.h" + +#define VTX_MSP_MIN_BAND (1) +#define VTX_MSP_MAX_BAND (VTX_MSP_MIN_BAND + VTX_MSP_BAND_COUNT - 1) +#define VTX_MSP_MIN_CHANNEL (1) +#define VTX_MSP_MAX_CHANNEL (VTX_MSP_MIN_CHANNEL + VTX_MSP_CHANNEL_COUNT -1) + +#define VTX_UPDATE_REQ_NONE 0x00 +#define VTX_UPDATE_REQ_FREQUENCY 0x01 +#define VTX_UPDATE_REQ_POWER 0x02 +#define VTX_UPDATE_REQ_PIT_MODE 0x04 + +typedef struct { + bool ready; + uint8_t timeouts; + uint8_t updateReqMask; + bool crsfTelemetryEnabled; + + struct { + uint8_t band; + uint8_t channel; + uint16_t freq; + uint8_t power; + uint8_t powerIndex; + uint8_t pitMode; + } request; +; +} vtxProtoState_t; + +const char * const vtxMspBandNames[VTX_MSP_BAND_COUNT + 1] = { + "-----", "A 2.4", "B 2.4", "E 2.4", "F 2.4", "R 2.4" }; -STATIC_UNIT_TESTED mspVtxStatus_e mspVtxStatus = MSP_VTX_STATUS_OFFLINE; -static uint8_t mspVtxPortIdentifier = 255; +const char * vtxMspBandLetters = "-ABEFR"; -#define MSP_VTX_REQUEST_PERIOD_US (200 * 1000) // 200ms - -static bool isCrsfPortConfig(const serialPortConfig_t *portConfig) -{ - return portConfig->functionMask & FUNCTION_RX_SERIAL && portConfig->functionMask & FUNCTION_VTX_MSP && rxConfig()->serialrx_provider == SERIALRX_CRSF; -} - -static bool isLowPowerDisarmed(void) -{ - return (!ARMING_FLAG(ARMED) && !failsafeIsActive() && - (vtxSettingsConfig()->lowPowerDisarm == VTX_LOW_POWER_DISARM_ALWAYS || - (vtxSettingsConfig()->lowPowerDisarm == VTX_LOW_POWER_DISARM_UNTIL_FIRST_ARM && !ARMING_FLAG(WAS_EVER_ARMED)))); -} - -bool isVtxConfigValid(const vtxConfig_t *cfg) -{ - LOG_DEBUG(VTX, "msp isVtxConfigValid\r\n"); - for (int i = 0; i < MAX_CHANNEL_ACTIVATION_CONDITION_COUNT; ++i) { - - if (cfg->vtxChannelActivationConditions[i].band || - (cfg->vtxChannelActivationConditions[i].range.startStep && cfg->vtxChannelActivationConditions[i].range.endStep) || - cfg->vtxChannelActivationConditions[i].auxChannelIndex || - cfg->vtxChannelActivationConditions[i].channel) { - return true; - } - } - - LOG_DEBUG(VTX, "msp Invalid Config!\r\n"); - return false; -} +const char * const vtxMspChannelNames[VTX_MSP_CHANNEL_COUNT + 1] = { + "-", "1", "2", "3", "4", "5", "6", "7", "8" +}; +const char * const vtxMspPowerNames[VTX_MSP_POWER_COUNT + 1] = { + "---", "25", "200", "500", "MAX" +}; -void setMspVtxDeviceStatusReady(const int descriptor) -{ - LOG_DEBUG(VTX, "msp setMspVtxDeviceStatusReady\r\n"); - UNUSED(descriptor); +const unsigned vtxMspPowerTable[VTX_MSP_POWER_COUNT] = { + 25, 200, 500, 1000 +}; - mspVtxStatus = MSP_VTX_STATUS_READY; - mspVtxConfigChanged = true; -} +static serialPortIdentifier_e mspVtxPortIdentifier; +static vtxProtoState_t vtxState; +static vtxDevType_e vtxMspGetDeviceType(const vtxDevice_t *); +static bool vtxMspIsReady(const vtxDevice_t *); -void prepareMspFrame(uint8_t *mspFrame) +static void prepareMspFrame(vtxDevice_t *vtxDevice, uint8_t *mspFrame) { - LOG_DEBUG(VTX, "msp PrepareMspFrame\r\n"); -/* -HDZERO parsing - fc_band_rx = msp_rx_buf[1]; - fc_channel_rx = msp_rx_buf[2]; - fc_pwr_rx = msp_rx_buf[3]; - fc_pit_rx = msp_rx_buf[4]; - fc_lp_rx = msp_rx_buf[8]; -*/ - - uint8_t pitmode = 0; - vtxCommonGetPitMode(&vtxMsp, &pitmode); - - mspFrame[0] = VTXDEV_MSP, - mspFrame[1] = vtxSettingsConfig()->band; - mspFrame[2] = vtxSettingsConfig()->channel; - mspFrame[3] = isLowPowerDisarmed() ? 1 : vtxSettingsConfig()->power; // index based - mspFrame[4] = pitmode; - mspFrame[5] = 0; // Freq_L - mspFrame[6] = 0; // Freq_H - mspFrame[7] = (mspVtxStatus == MSP_VTX_STATUS_READY) ? 1 : 0; - mspFrame[8] = isLowPowerDisarmed(); - mspFrame[9] = 0; // Pitmode freq Low - mspFrame[10] = 0; // pitmod freq High + LOG_DEBUG(VTX, "msp prepareMspFrame\r\n"); + //UNUSED(vtxDevice); + + // Send an MSP_VTX_V2 frame to the VTX + + mspFrame[0] = vtxMspGetDeviceType(vtxDevice); + mspFrame[1] = vtxState.request.band; + mspFrame[2] = vtxState.request.channel; + mspFrame[3] = vtxState.request.powerIndex; + mspFrame[4] = vtxState.request.pitMode; + mspFrame[5] = 0; // Freq_L + mspFrame[6] = 0; // Freq_H + mspFrame[7] = vtxMspIsReady(vtxDevice); + mspFrame[8] = vtxSettingsConfig()->lowPowerDisarm; + mspFrame[9] = 0; // pitmode freq Low + mspFrame[10] = 0; // pitmode freq High mspFrame[11] = 0; // 1 if using vtx table - mspFrame[12] = 0; // vtx table bands or 0 - mspFrame[13] = 0; // vtx table channels or 0 - mspFrame[14] = 0; // vtx table power levels or 0 -} + mspFrame[12] = 6; // bands or 0 + mspFrame[13] = 8; // channels or 0 + mspFrame[14] = 5; // power levels or 0 + + LOG_DEBUG(VTX, "msp device [%d]\r\n", mspFrame[0]); + LOG_DEBUG(VTX, "msp band [%d]\r\n", mspFrame[1]); + LOG_DEBUG(VTX, "msp channel [%d]\r\n", mspFrame[2]); + LOG_DEBUG(VTX, "msp power [%d]\r\n", mspFrame[3]); + LOG_DEBUG(VTX, "msp freq [%d]\r\n", ((uint16_t)mspFrame[6] << 8) + mspFrame[5]); + LOG_DEBUG(VTX, "msp pitmode [%d]\r\n", mspFrame[4]); + LOG_DEBUG(VTX, "msp isready [%d]\r\n", mspFrame[7]); + LOG_DEBUG(VTX, "msp lowPower [%d]\r\n", mspFrame[8]); +} static void mspCrsfPush(const uint8_t mspCommand, const uint8_t *mspFrame, const uint8_t mspFrameSize) { - - LOG_DEBUG(VTX, "msp CrsfPush\r\n"); + LOG_DEBUG(VTX, "msp mspCrsfPush\r\n"); #ifndef USE_TELEMETRY_CRSF UNUSED(mspCommand); UNUSED(mspFrame); @@ -201,285 +159,157 @@ static void mspCrsfPush(const uint8_t mspCommand, const uint8_t *mspFrame, const crc8_dvb_s2_sbuf_append(dst, &crsfFrame[2]); // start at byte 2, since CRC does not include device address and frame length sbufSwitchToReader(dst, crsfFrame); - crsfRxSendTelemetryData(); //give the FC a chance to send outstanding telemetry + crsfRxSendTelemetryData(); // give the FC a chance to send outstanding telemetry crsfRxWriteTelemetryData(sbufPtr(dst), sbufBytesRemaining(dst)); crsfRxSendTelemetryData(); #endif } -static uint16_t packetCounter = 0; - -static bool isVtxConfigChanged(void) -{ - if(mspVtxStatus == MSP_VTX_STATUS_READY) { - if (mspVtxConfigChanged == true) - return true; - - if (isLowPowerDisarmed() != prevLowPowerDisarmedState) { - LOG_DEBUG(VTX, "msp vtx config changed (lower power disarm 2)\r\n"); - mspVtxConfigChanged = true; - prevLowPowerDisarmedState = isLowPowerDisarmed(); - } - - if (mspConfPowerIndex != vtxSettingsConfig()->power) { - LOG_DEBUG(VTX, "msp vtx config changed (power 2)\r\n"); - mspVtxConfigChanged = true; - } - - if (mspConfBand != vtxSettingsConfig()->band || mspConfChannel != vtxSettingsConfig()->channel) { - LOG_DEBUG(VTX, "msp vtx config changed (band and channel 2)\r\n"); - mspVtxConfigChanged = true; - } - - return mspVtxConfigChanged; - } - - return false; -} - static void vtxMspProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs) { + LOG_DEBUG(VTX, "msp vtxMspProcess\r\n"); UNUSED(vtxDevice); - const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_MSP_OSD); - uint8_t frame[15]; + uint8_t mspFrame[15]; - switch (mspVtxStatus) { - case MSP_VTX_STATUS_OFFLINE: - LOG_DEBUG(VTX, "msp MspProcess: OFFLINE\r\n"); - // wait for MSP communication from the VTX -#ifdef USE_CMS - //mspCmsUpdateStatusString(); -#endif - break; - case MSP_VTX_STATUS_READY: - LOG_DEBUG(VTX, "msp MspProcess: READY\r\n"); - // send an update if stuff has changed with 200ms period - if ((isVtxConfigChanged()) && cmp32(currentTimeUs, mspVtxLastTimeUs) >= MSP_VTX_REQUEST_PERIOD_US) { - - LOG_DEBUG(VTX, "msp-vtx: vtxInfo Changed\r\n"); - prepareMspFrame(frame); - - if (isCrsfPortConfig(portConfig)) { - mspCrsfPush(MSP_VTX_CONFIG, frame, sizeof(frame)); - } else { - mspPort_t *port = getMspOsdPort(); - if(port != NULL && port->port) { - LOG_DEBUG(VTX, "msp-vtx: mspSerialPushPort\r\n"); - int sent = mspSerialPushPort(MSP_VTX_CONFIG, frame, sizeof(frame), port, MSP_V2_NATIVE); - if (sent <= 0) { - break; - } - } + mspPort_t *mspPort = getMspOsdPort(); + unsigned lastActivity = (currentTimeUs/1000) - mspPort->lastActivityMs; + if (lastActivity > VTX_MSP_TIMEOUT) { + if (vtxState.timeouts++ > 3) { + if (vtxState.ready) { + vtxState.ready = false; } - packetCounter++; - mspVtxLastTimeUs = currentTimeUs; - mspVtxConfigChanged = false; - -#ifdef USE_CMS - //mspCmsUpdateStatusString(); -#endif } - break; - default: - mspVtxStatus = MSP_VTX_STATUS_OFFLINE; - break; + } else { // active + if (!vtxState.ready) { + vtxState.ready = true; + } } -#if 0 - DEBUG_SET(DEBUG_VTX_MSP, 0, packetCounter); - DEBUG_SET(DEBUG_VTX_MSP, 1, isCrsfPortConfig(portConfig)); - DEBUG_SET(DEBUG_VTX_MSP, 2, isLowPowerDisarmed()); -#if defined(USE_MSP_OVER_TELEMETRY) - DEBUG_SET(DEBUG_VTX_MSP, 3, isCrsfPortConfig(portConfig) ? getMspTelemetryDescriptor() : getMspSerialPortDescriptor(mspVtxPortIdentifier)); -#else - DEBUG_SET(DEBUG_VTX_MSP, 3, getMspSerialPortDescriptor(mspVtxPortIdentifier)); -#endif -#endif + if (vtxState.ready) { + if (vtxState.updateReqMask != VTX_UPDATE_REQ_NONE) { + prepareMspFrame(vtxDevice, mspFrame); + if (vtxState.crsfTelemetryEnabled) { // keep ELRS LUA up to date ? + mspCrsfPush(MSP_VTX_CONFIG, mspFrame, sizeof(mspFrame)); + } + + int sent = mspSerialPushPort(MSP_VTX_CONFIG, mspFrame, sizeof(mspFrame), mspPort, MSP_V2_NATIVE); + if (sent > 0) { + vtxState.updateReqMask = VTX_UPDATE_REQ_NONE; + } + } + } } static vtxDevType_e vtxMspGetDeviceType(const vtxDevice_t *vtxDevice) { - //LOG_DEBUG(VTX, "msp GetDeviceType\r\n"); + LOG_DEBUG(VTX, "msp vtxMspGetDeviceType\r\n"); UNUSED(vtxDevice); + return VTXDEV_MSP; } static bool vtxMspIsReady(const vtxDevice_t *vtxDevice) { - //LOG_DEBUG(VTX, "msp vtxIsReady: %s\r\n", (vtxDevice != NULL && mspVtxStatus == MSP_VTX_STATUS_READY) ? "Y": "N"); - return vtxDevice != NULL && mspVtxStatus == MSP_VTX_STATUS_READY; + LOG_DEBUG(VTX, "msp vtxMspIsReady\r\n"); + return vtxDevice != NULL && mspVtxPortIdentifier >=0 && vtxState.ready; } static void vtxMspSetBandAndChannel(vtxDevice_t *vtxDevice, uint8_t band, uint8_t channel) { - LOG_DEBUG(VTX, "msp SetBandAndChannel\r\n"); + LOG_DEBUG(VTX, "msp vtxMspSetBandAndChannel\r\n"); UNUSED(vtxDevice); - if (band != mspConfBand || channel != mspConfChannel) { - LOG_DEBUG(VTX, "msp vtx config changed (band and channel)\r\n"); - mspVtxConfigChanged = true; + + if (band < VTX_MSP_MIN_BAND || band > VTX_MSP_MAX_BAND || channel < VTX_MSP_MIN_CHANNEL || channel > VTX_MSP_MAX_CHANNEL) { + return; } - mspConfBand = band; - mspConfChannel = channel; + + vtxState.request.band = band; + vtxState.request.channel = channel; + vtxState.request.freq = vtx58_Bandchan2Freq(band, channel); + vtxState.updateReqMask |= VTX_UPDATE_REQ_FREQUENCY; } static void vtxMspSetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t index) { - LOG_DEBUG(VTX, "msp SetPowerByIndex\r\n"); + LOG_DEBUG(VTX, "msp vtxMspSetPowerByIndex\r\n"); UNUSED(vtxDevice); - if (index > 0 && (index < VTX_MSP_TABLE_MAX_POWER_LEVELS)) - { - if (index != mspConfPowerIndex) - { - LOG_DEBUG(VTX, "msp vtx config changed (power by index)\r\n"); - mspVtxConfigChanged = true; - } - mspConfPowerIndex = index; - } + vtxState.request.power = vtxMspPowerTable[index - 1]; + vtxState.request.powerIndex = index; + vtxState.updateReqMask |= VTX_UPDATE_REQ_POWER; } -static void vtxMspSetPitMode(vtxDevice_t *vtxDevice, uint8_t onoff) +static void vtxMspSetPitMode(vtxDevice_t *vtxDevice, uint8_t onOff) { - LOG_DEBUG(VTX, "msp SetPitMode\r\n"); + LOG_DEBUG(VTX, "msp vtxMspSetPitMode\r\n"); UNUSED(vtxDevice); - if (onoff != mspConfPitMode) { - LOG_DEBUG(VTX, "msp vtx config changed (pitmode)\r\n"); - mspVtxConfigChanged = true; - } - mspConfPitMode = onoff; -} -#if 0 -static void vtxMspSetFreq(vtxDevice_t *vtxDevice, uint16_t freq) -{ - UNUSED(vtxDevice); - if (freq != mspConfFreq) { - mspVtxConfigChanged = true; - } - mspConfFreq = freq; + vtxState.request.pitMode = onOff; + vtxState.updateReqMask |= VTX_UPDATE_REQ_PIT_MODE; } -#endif - - - static bool vtxMspGetBandAndChannel(const vtxDevice_t *vtxDevice, uint8_t *pBand, uint8_t *pChannel) { - if (!vtxMspIsReady(vtxDevice)) { - return false; - } - - *pBand = vtxSettingsConfig()->band; - *pChannel = vtxSettingsConfig()->channel; - - //LOG_DEBUG(VTX, "msp GetBandAndChannel: %02x:%02x\r\n", vtxSettingsConfig()->band, vtxSettingsConfig()->channel); + LOG_DEBUG(VTX, "msp vtxMspGetBandAndChannel\r\n"); + UNUSED(vtxDevice); + *pBand = vtxState.request.band; + *pChannel = vtxState.request.channel; return true; } static bool vtxMspGetPowerIndex(const vtxDevice_t *vtxDevice, uint8_t *pIndex) { - if (!vtxMspIsReady(vtxDevice)) { - return false; - } - - uint8_t power = isLowPowerDisarmed() ? 1 : vtxSettingsConfig()->power; - // Special case, power not set - if (power > VTX_MSP_TABLE_MAX_POWER_LEVELS) { - *pIndex = 0; - //LOG_DEBUG(VTX, "msp GetPowerIndex: %u\r\n", *pIndex); - return true; - } - - *pIndex = power; + LOG_DEBUG(VTX, "msp vtxMspGetPowerIndex\r\n"); + UNUSED(vtxDevice); - //LOG_DEBUG(VTX, "msp GetPowerIndex: %u\r\n", *pIndex); + *pIndex = vtxState.request.powerIndex; return true; } -static bool vtxMspGetFreq(const vtxDevice_t *vtxDevice, uint16_t *pFreq) +static bool vtxMspGetPitMode(const vtxDevice_t *vtxDevice, uint8_t *pOnOff) { - LOG_DEBUG(VTX, "msp GetFreq\r\n"); - if (!vtxMspIsReady(vtxDevice)) { - return false; - } + LOG_DEBUG(VTX, "msp vtxMspGetPitMode\r\n"); + UNUSED(vtxDevice); - *pFreq = 5800; + *pOnOff = vtxState.request.pitMode; return true; } -static bool vtxMspGetPower(const vtxDevice_t *vtxDevice, uint8_t *pIndex, uint16_t *pPowerMw) +static bool vtxMspGetFreq(const vtxDevice_t *vtxDevice, uint16_t *pFreq) { - LOG_DEBUG(VTX, "msp GetPower\r\n"); - uint8_t powerIndex; - - if (!vtxMspGetPowerIndex(vtxDevice, &powerIndex)) { - return false; - } - + LOG_DEBUG(VTX, "msp vtxMspGetFreq\r\n"); + UNUSED(vtxDevice); - *pIndex = powerIndex; - *pPowerMw = *pIndex; + *pFreq = vtxState.request.freq; return true; } -static bool vtxMspGetOsdInfo(const vtxDevice_t *vtxDevice, vtxDeviceOsdInfo_t * pOsdInfo) +static bool vtxMspGetPower(const vtxDevice_t *vtxDevice, uint8_t *pIndex, uint16_t *pPowerMw) { - LOG_DEBUG(VTX, "msp GetOsdInfo\r\n"); - uint8_t powerIndex; - uint16_t powerMw; - uint16_t freq; - uint8_t band, channel; - - if (!vtxMspGetBandAndChannel(vtxDevice, &band, &channel)) { - return false; - } - - if (!vtxMspGetFreq(vtxDevice, &freq)) { - return false; - } - - if (!vtxMspGetPower(vtxDevice, &powerIndex, &powerMw)) { - return false; - } + LOG_DEBUG(VTX, "msp vtxMspGetPower\r\n"); + UNUSED(vtxDevice); - pOsdInfo->band = band; - pOsdInfo->channel = channel; - pOsdInfo->frequency = freq; - pOsdInfo->powerIndex = powerIndex; - pOsdInfo->powerMilliwatt = powerMw; - pOsdInfo->bandLetter = vtx58BandNames[band][0]; - pOsdInfo->bandName = vtx58BandNames[band]; - pOsdInfo->channelName = vtx58ChannelNames[channel]; - pOsdInfo->powerIndexLetter = '0' + powerIndex; + *pIndex = vtxState.request.powerIndex; + *pPowerMw = vtxState.request.power; return true; } - -bool vtxMspInit(void) +static bool vtxMspGetOsdInfo(const vtxDevice_t *vtxDevice, vtxDeviceOsdInfo_t *pOsdInfo) { - LOG_DEBUG(VTX, "msp %s\r\n", __FUNCTION__); - // don't bother setting up this device if we don't have MSP vtx enabled - // Port is shared with MSP_OSD - const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_MSP_OSD); - if (!portConfig) { - return false; - } - - mspVtxPortIdentifier = portConfig->identifier; - - // XXX Effect of USE_VTX_COMMON should be reviewed, as following call to vtxInit will do nothing if vtxCommonSetDevice is not called. -#if defined(USE_VTX_COMMON) - vtxCommonSetDevice(&vtxMsp); -#endif - - mspConfBand = vtxSettingsConfig()->band; - mspConfChannel = vtxSettingsConfig()->channel; - mspConfPowerIndex = isLowPowerDisarmed() ? 1 : vtxSettingsConfig()->power; // index based - vtxCommonGetPitMode(&vtxMsp, &mspConfPitMode); + LOG_DEBUG(VTX, "msp vtxMspGetOsdInfo\r\n"); + UNUSED(vtxDevice); - vtxInit(); + pOsdInfo->band = vtxState.request.band; + pOsdInfo->channel = vtxState.request.channel; + pOsdInfo->frequency = vtxState.request.freq; + pOsdInfo->powerIndex = vtxState.request.powerIndex; + pOsdInfo->powerMilliwatt = vtxState.request.power; + pOsdInfo->bandName = vtxMspBandNames[vtxState.request.band]; + pOsdInfo->bandLetter = vtxMspBandLetters[vtxState.request.band]; + pOsdInfo->channelName = vtxMspChannelNames[vtxState.request.channel]; + pOsdInfo->powerIndexLetter = '0' + vtxState.request.powerIndex; return true; } @@ -491,211 +321,51 @@ static const vtxVTable_t mspVTable = { .setBandAndChannel = vtxMspSetBandAndChannel, .setPowerByIndex = vtxMspSetPowerByIndex, .setPitMode = vtxMspSetPitMode, - //.setFrequency = vtxMspSetFreq, .getBandAndChannel = vtxMspGetBandAndChannel, .getPowerIndex = vtxMspGetPowerIndex, + .getPitMode = vtxMspGetPitMode, .getFrequency = vtxMspGetFreq, - //.getStatus = vtxMspGetStatus, .getPower = vtxMspGetPower, - //.serializeCustomDeviceStatus = NULL, - .getOsdInfo = vtxMspGetOsdInfo, + .getOsdInfo = vtxMspGetOsdInfo }; -static mspResult_e mspVtxProcessMspCommand(mspPacket_t *cmd, mspPacket_t *reply, mspPostProcessFnPtr *mspPostProcessFn) -{ - //LOG_DEBUG(VTX, "msp VTX_MSP_PROCESS\r\n"); - UNUSED(mspPostProcessFn); - - sbuf_t *dst = &reply->buf; - sbuf_t *src = &cmd->buf; - - const unsigned int dataSize = sbufBytesRemaining(src); - UNUSED(dst); - UNUSED(src); - - // Start initializing the reply message - reply->cmd = cmd->cmd; - reply->result = MSP_RESULT_ACK; - - vtxDevice_t *vtxDevice = vtxCommonDevice(); - if (!vtxDevice || vtxCommonGetDeviceType(vtxDevice) != VTXDEV_MSP) { - LOG_DEBUG(VTX, "msp wrong vtx\r\n"); - return MSP_RESULT_ERROR; - } - - switch (cmd->cmd) - { - case MSP_VTXTABLE_BAND: - { - LOG_DEBUG(VTX, "msp MSP_VTXTABLE_BAND\r\n"); - uint8_t deviceType = vtxCommonGetDeviceType(vtxDevice); - if (deviceType == VTXDEV_MSP) - { - /* - char bandName[MSP_VTX_TABLE_BAND_NAME_LENGTH + 1]; - memset(bandName, 0, MSP_VTX_TABLE_BAND_NAME_LENGTH + 1); - uint16_t frequencies[MSP_VTX_TABLE_MAX_CHANNELS]; - const uint8_t band = sbufReadU8(src); - const uint8_t bandNameLength = sbufReadU8(src); - for (int i = 0; i < bandNameLength; i++) { - const char nameChar = sbufReadU8(src); - if (i < MSP_VTX_TABLE_BAND_NAME_LENGTH) { - bandName[i] = toupper(nameChar); - } - } - const char bandLetter = toupper(sbufReadU8(src)); - const bool isFactoryBand = (bool)sbufReadU8(src); - const uint8_t channelCount = sbufReadU8(src); - for (int i = 0; i < channelCount; i++) - { - const uint16_t frequency = sbufReadU16(src); - if (i < vtxTableConfig()->channels) - { - frequencies[i] = frequency; - } - } - */ - - setMspVtxDeviceStatusReady(1); - } - break; - } - case MSP_VTXTABLE_POWERLEVEL: - { - LOG_DEBUG(VTX, "msp MSP_VTXTABLE_POWERLEVEL\r\n"); - - /* - char powerLevelLabel[VTX_TABLE_POWER_LABEL_LENGTH + 1]; - memset(powerLevelLabel, 0, VTX_TABLE_POWER_LABEL_LENGTH + 1); - const uint8_t powerLevel = sbufReadU8(src); - const uint16_t powerValue = sbufReadU16(src); - const uint8_t powerLevelLabelLength = sbufReadU8(src); - for (int i = 0; i < powerLevelLabelLength; i++) - { - const char labelChar = sbufReadU8(src); - if (i < VTX_TABLE_POWER_LABEL_LENGTH) - { - powerLevelLabel[i] = toupper(labelChar); - } - } - */ - setMspVtxDeviceStatusReady(1); - } - break; - case MSP_VTX_CONFIG: - { - LOG_DEBUG(VTX, "msp MSP_VTX_CONFIG received\r\n"); - LOG_DEBUG(VTX, "msp MSP_VTX_CONFIG VTXDEV_MSP\r\n"); - uint8_t pitmode = 0; - vtxCommonGetPitMode(vtxDevice, &pitmode); - - // VTXDEV_MSP, - sbufWriteU8(dst, VTXDEV_MSP); - // band; - sbufWriteU8(dst, vtxSettingsConfig()->band); - // channel; - sbufWriteU8(dst, vtxSettingsConfig()->channel); - // power; // index based - sbufWriteU8(dst, vtxSettingsConfig()->power); - // pit mode; - // Freq_L - sbufWriteU8(dst, 0); - // Freq_H - sbufWriteU8(dst, 0); - // vtx status - sbufWriteU8(dst, 1); - // lowPowerDisarm - - sbufWriteU8(dst, vtxSettingsConfig()->lowPowerDisarm); - // Pitmode freq Low - sbufWriteU8(dst, 0); - // pitmod freq High - sbufWriteU8(dst, 0); - // 1 if using vtx table - sbufWriteU8(dst, 0); - // vtx table bands or 0 - sbufWriteU8(dst, 0); - // vtx table channels or 0 - sbufWriteU8(dst, 0); - - setMspVtxDeviceStatusReady(1); - break; - } - case MSP_SET_VTX_CONFIG: - LOG_DEBUG(VTX, "msp MSP_SET_VTX_CONFIG\r\n"); - if (dataSize == 15) - { - if (vtxCommonGetDeviceType(vtxDevice) != VTXDEV_UNKNOWN) - { - for (int i = 0; i < 15; ++i) - { - uint8_t data = sbufReadU8(src); - switch (i) - { - case 1: - vtxSettingsConfigMutable()->band = data; - break; - case 2: - vtxSettingsConfigMutable()->channel = data; - break; - case 3: - vtxSettingsConfigMutable()->power = data; - break; - case 4: - vtxCommonSetPitMode(vtxDevice, data); - break; - case 7: - // vtx ready - break; - case 8: - vtxSettingsConfigMutable()->lowPowerDisarm = data; - break; - } - } - } - - setMspVtxDeviceStatusReady(1); - break; - } - LOG_DEBUG(VTX, "msp MSP_RESULT_ERROR\r\n"); - return MSP_RESULT_ERROR; - default: - // debug[1]++; - // debug[2] = cmd->cmd; - if(cmd->cmd != MSP_STATUS && cmd->cmd != MSP_STATUS_EX && cmd->cmd != MSP_RC) { - LOG_DEBUG(VTX, "msp default: %02x\r\n", cmd->cmd); - } - reply->result = MSP_RESULT_ERROR; - break; - } - - // Process DONT_REPLY flag - if (cmd->flags & MSP_FLAG_DONT_REPLY) - { - reply->result = MSP_RESULT_NO_REPLY; - } - - return reply->result; -} +static vtxDevice_t vtxMsp = { + .vTable = &mspVTable, + .capability.bandCount = VTX_MSP_MAX_BAND, + .capability.channelCount = VTX_MSP_MAX_CHANNEL, + .capability.powerCount = VTX_MSP_POWER_COUNT, + .capability.bandNames = (char **)vtxMspBandNames, + .capability.channelNames = (char **)vtxMspChannelNames, + .capability.powerNames = (char **)vtxMspPowerNames +}; -void mspVtxSerialProcess(mspProcessCommandFnPtr mspProcessCommandFn) +bool vtxMspInit(void) { - UNUSED(mspProcessCommandFn); - // Check if VTX is ready - /* - if (mspVtxStatus != MSP_VTX_STATUS_READY) { - LOG_DEBUG(VTX, "msp VTX NOT READY, skipping\r\n"); - return; + LOG_DEBUG(VTX, "msp %s\r\n", __FUNCTION__); + const serialPortConfig_t *portConfig; + + // Shares MSP_OSD port + portConfig = findSerialPortConfig(FUNCTION_VTX_MSP); + if (!portConfig) { + return false; } - */ - mspPort_t *port = getMspOsdPort(); + portConfig = findSerialPortConfig(FUNCTION_RX_SERIAL); - if(port) { - mspSerialProcessOnePort(port, MSP_SKIP_NON_MSP_DATA, mspVtxProcessMspCommand); - } + vtxState.ready = false; + vtxState.timeouts = 0; + vtxState.updateReqMask = VTX_UPDATE_REQ_NONE; + vtxState.crsfTelemetryEnabled = crsfRxIsActive() && checkCrsfTelemetryState(); + vtxState.request.band = vtxSettingsConfig()->band; + vtxState.request.channel = vtxSettingsConfig()->channel; + vtxState.request.freq = vtx58_Bandchan2Freq(vtxState.request.band, vtxState.request.channel); + vtxState.request.power = vtxSettingsConfig()->power; + uint8_t pitmode = 0; + vtxCommonGetPitMode(&vtxMsp, &pitmode); + vtxState.request.pitMode = pitmode; + vtxCommonSetDevice(&vtxMsp); + return true; } - #endif \ No newline at end of file diff --git a/src/main/io/vtx_msp.h b/src/main/io/vtx_msp.h index 30ca245fed3..ceb2d5bea17 100644 --- a/src/main/io/vtx_msp.h +++ b/src/main/io/vtx_msp.h @@ -17,37 +17,17 @@ * * If not, see . */ +/* Created by geoffsim */ -#pragma once +#ifndef _VTX_MSP_H +#define _VTX_MSP_H -#include - -#include "build/build_config.h" - -#include "msp/msp_protocol.h" -#include "msp/msp_serial.h" - -typedef enum { - // Offline - device hasn't responded yet - MSP_VTX_STATUS_OFFLINE = 0, - MSP_VTX_STATUS_READY, -} mspVtxStatus_e; - -typedef struct mspPowerTable_s { - int mW; // rfpower - int16_t dbi; // valueV1 -} mspPowerTable_t; - -#define VTX_MSP_TABLE_MAX_BANDS 5 // default freq table has 5 bands -#define VTX_MSP_TABLE_MAX_CHANNELS 8 // and eight channels -#define VTX_MSP_TABLE_MAX_POWER_LEVELS 5 //max of VTX_TRAMP_POWER_COUNT, VTX_SMARTAUDIO_POWER_COUNT and VTX_RTC6705_POWER_COUNT -#define VTX_MSP_TABLE_CHANNEL_NAME_LENGTH 1 -#define VTX_MSP_TABLE_BAND_NAME_LENGTH 8 -#define VTX_MSP_TABLE_POWER_LABEL_LENGTH 3 +#define VTX_MSP_TIMEOUT 250 // ms +#define VTX_MSP_BAND_COUNT 5 +#define VTX_MSP_CHANNEL_COUNT 8 +#define VTX_MSP_POWER_COUNT 4 bool vtxMspInit(void); -void setMspVtxDeviceStatusReady(const int descriptor); -void prepareMspFrame(uint8_t *mspFrame); -void mspVtxSerialProcess(mspProcessCommandFnPtr mspProcessCommandFn); +#endif // _VTX_MSP_H diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index 594db21417c..b078e25f751 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -296,14 +296,13 @@ static int logicConditionCompute( #endif case LOGIC_CONDITION_SET_VTX_POWER_LEVEL: #if defined(USE_VTX_CONTROL) -#if(defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP)) - if ( - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] != operandA && - vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability) - ) { - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = constrain(operandA, VTX_SETTINGS_MIN_POWER, vtxDeviceCapability.powerCount); - vtxSettingsConfigMutable()->power = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; - return logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; +#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) || defined(USE_VTX_MSP) + uint8_t newpower = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; + if ( newpower != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + newpower = constrain(operandA, VTX_SETTINGS_MIN_POWER, VTX_SETTINGS_MAX_POWER); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = newpower; + vtxSettingsConfigMutable()->power = newpower; + return newpower; } else { return false; } From fd71bed9a2dbc2b38a4f1bfa066a2d0f57c1b4a2 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Thu, 12 Sep 2024 16:52:37 +0100 Subject: [PATCH 02/48] Restrict band/channel/power in logic conditions to the specific device capabilities. Add one to the power to allow HDZERO 0mW option. --- src/main/programming/logic_condition.c | 38 ++++++++++++-------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index b078e25f751..f02cdc1fa76 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -294,12 +294,13 @@ static int logicConditionCompute( return true; break; #endif - case LOGIC_CONDITION_SET_VTX_POWER_LEVEL: + #if defined(USE_VTX_CONTROL) -#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) || defined(USE_VTX_MSP) + case LOGIC_CONDITION_SET_VTX_POWER_LEVEL: uint8_t newpower = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; - if ( newpower != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { - newpower = constrain(operandA, VTX_SETTINGS_MIN_POWER, VTX_SETTINGS_MAX_POWER); + if (newpower != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + // HDZERO VTX max power+1 is 0mW. + newpower = constrain(operandA, VTX_SETTINGS_MIN_POWER, vtxDeviceCapability.powerCount+1); logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = newpower; vtxSettingsConfigMutable()->power = newpower; return newpower; @@ -307,30 +308,25 @@ static int logicConditionCompute( return false; } break; -#else - return false; -#endif case LOGIC_CONDITION_SET_VTX_BAND: - if ( - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] != operandA && - vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability) - ) { - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] = constrain(operandA, VTX_SETTINGS_MIN_BAND, VTX_SETTINGS_MAX_BAND); - vtxSettingsConfigMutable()->band = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND]; - return logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND]; + uint8_t newband = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND]; + if (newband != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + newband = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.bandCount); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] = newband; + vtxSettingsConfigMutable()->band = newband; + return newband; } else { return false; } break; case LOGIC_CONDITION_SET_VTX_CHANNEL: - if ( - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] != operandA && - vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability) - ) { - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = constrain(operandA, VTX_SETTINGS_MIN_CHANNEL, VTX_SETTINGS_MAX_CHANNEL); - vtxSettingsConfigMutable()->channel = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL]; - return logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL]; + uint8_t newchannel = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL]; + if (newchannel != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + newchannel = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.channelCount); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = newchannel; + vtxSettingsConfigMutable()->band = newchannel; + return newchannel; } else { return false; } From 77a0f20970c67d502c4f265b139e9190b0ea4079 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Thu, 12 Sep 2024 18:27:31 +0100 Subject: [PATCH 03/48] Move crsf include to the correct header. Include uint definitions. --- src/main/programming/logic_condition.c | 1 + src/main/rx/crsf.h | 1 + src/main/telemetry/crsf.h | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) mode change 100755 => 100644 src/main/telemetry/crsf.h diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index f02cdc1fa76..bdc008af8a8 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -22,6 +22,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ +#include #include #include "config/config_reset.h" diff --git a/src/main/rx/crsf.h b/src/main/rx/crsf.h index 69777a0390c..da7aa9024e2 100755 --- a/src/main/rx/crsf.h +++ b/src/main/rx/crsf.h @@ -133,5 +133,6 @@ struct rxConfig_s; struct rxRuntimeConfig_s; bool crsfRxInit(const struct rxConfig_s *initialRxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig); bool crsfRxIsActive(void); +bool checkCrsfTelemetryState(void); void crsfBind(void); diff --git a/src/main/telemetry/crsf.h b/src/main/telemetry/crsf.h old mode 100755 new mode 100644 index 6ffa4df3588..f738c71bf28 --- a/src/main/telemetry/crsf.h +++ b/src/main/telemetry/crsf.h @@ -24,7 +24,6 @@ #define CRSF_MSP_TX_BUF_SIZE 128 void initCrsfTelemetry(void); -bool checkCrsfTelemetryState(void); void handleCrsfTelemetry(timeUs_t currentTimeUs); void crsfScheduleDeviceInfoResponse(void); void crsfScheduleMspResponse(void); From 05fa7e6dee895dbcf8194f58a9514e58327289ec Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Fri, 13 Sep 2024 13:06:38 +0100 Subject: [PATCH 04/48] Fix SITL compile issues. Move telemetry function definition back to correct place. --- src/main/io/vtx_msp.c | 2 +- src/main/programming/logic_condition.c | 12 ++++++++---- src/main/rx/crsf.h | 1 - src/main/telemetry/crsf.h | 1 + 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/io/vtx_msp.c b/src/main/io/vtx_msp.c index 13a3247eb14..7868fed6717 100644 --- a/src/main/io/vtx_msp.c +++ b/src/main/io/vtx_msp.c @@ -355,7 +355,7 @@ bool vtxMspInit(void) vtxState.ready = false; vtxState.timeouts = 0; vtxState.updateReqMask = VTX_UPDATE_REQ_NONE; - vtxState.crsfTelemetryEnabled = crsfRxIsActive() && checkCrsfTelemetryState(); + vtxState.crsfTelemetryEnabled = crsfRxIsActive(); vtxState.request.band = vtxSettingsConfig()->band; vtxState.request.channel = vtxSettingsConfig()->channel; vtxState.request.freq = vtx58_Bandchan2Freq(vtxState.request.band, vtxState.request.channel); diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index bdc008af8a8..98ae76f8710 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -22,7 +22,6 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -#include #include #include "config/config_reset.h" @@ -298,6 +297,7 @@ static int logicConditionCompute( #if defined(USE_VTX_CONTROL) case LOGIC_CONDITION_SET_VTX_POWER_LEVEL: + { uint8_t newpower = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; if (newpower != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { // HDZERO VTX max power+1 is 0mW. @@ -309,8 +309,9 @@ static int logicConditionCompute( return false; } break; - + } case LOGIC_CONDITION_SET_VTX_BAND: + { uint8_t newband = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND]; if (newband != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { newband = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.bandCount); @@ -321,17 +322,20 @@ static int logicConditionCompute( return false; } break; + } case LOGIC_CONDITION_SET_VTX_CHANNEL: + { uint8_t newchannel = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL]; if (newchannel != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { - newchannel = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.channelCount); + newchannel = constrain(operandA, VTX_SETTINGS_MIN_CHANNEL, vtxDeviceCapability.channelCount); logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = newchannel; - vtxSettingsConfigMutable()->band = newchannel; + vtxSettingsConfigMutable()->channel = newchannel; return newchannel; } else { return false; } break; + } #endif case LOGIC_CONDITION_INVERT_ROLL: LOGIC_CONDITION_GLOBAL_FLAG_ENABLE(LOGIC_CONDITION_GLOBAL_FLAG_OVERRIDE_INVERT_ROLL); diff --git a/src/main/rx/crsf.h b/src/main/rx/crsf.h index da7aa9024e2..69777a0390c 100755 --- a/src/main/rx/crsf.h +++ b/src/main/rx/crsf.h @@ -133,6 +133,5 @@ struct rxConfig_s; struct rxRuntimeConfig_s; bool crsfRxInit(const struct rxConfig_s *initialRxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig); bool crsfRxIsActive(void); -bool checkCrsfTelemetryState(void); void crsfBind(void); diff --git a/src/main/telemetry/crsf.h b/src/main/telemetry/crsf.h index f738c71bf28..6ffa4df3588 100644 --- a/src/main/telemetry/crsf.h +++ b/src/main/telemetry/crsf.h @@ -24,6 +24,7 @@ #define CRSF_MSP_TX_BUF_SIZE 128 void initCrsfTelemetry(void); +bool checkCrsfTelemetryState(void); void handleCrsfTelemetry(timeUs_t currentTimeUs); void crsfScheduleDeviceInfoResponse(void); void crsfScheduleMspResponse(void); From 73857e22b8793aa5405cc4d5480b99800aa81de4 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Sat, 14 Sep 2024 18:56:04 +0100 Subject: [PATCH 05/48] Remove debug code. Simplify initialisation. --- src/main/io/vtx_msp.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/main/io/vtx_msp.c b/src/main/io/vtx_msp.c index 7868fed6717..9271f2e5eca 100644 --- a/src/main/io/vtx_msp.c +++ b/src/main/io/vtx_msp.c @@ -92,9 +92,6 @@ static bool vtxMspIsReady(const vtxDevice_t *); static void prepareMspFrame(vtxDevice_t *vtxDevice, uint8_t *mspFrame) { - LOG_DEBUG(VTX, "msp prepareMspFrame\r\n"); - //UNUSED(vtxDevice); - // Send an MSP_VTX_V2 frame to the VTX mspFrame[0] = vtxMspGetDeviceType(vtxDevice); @@ -125,7 +122,6 @@ static void prepareMspFrame(vtxDevice_t *vtxDevice, uint8_t *mspFrame) static void mspCrsfPush(const uint8_t mspCommand, const uint8_t *mspFrame, const uint8_t mspFrameSize) { - LOG_DEBUG(VTX, "msp mspCrsfPush\r\n"); #ifndef USE_TELEMETRY_CRSF UNUSED(mspCommand); UNUSED(mspFrame); @@ -167,7 +163,6 @@ static void mspCrsfPush(const uint8_t mspCommand, const uint8_t *mspFrame, const static void vtxMspProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs) { - LOG_DEBUG(VTX, "msp vtxMspProcess\r\n"); UNUSED(vtxDevice); uint8_t mspFrame[15]; @@ -203,21 +198,17 @@ static void vtxMspProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs) static vtxDevType_e vtxMspGetDeviceType(const vtxDevice_t *vtxDevice) { - LOG_DEBUG(VTX, "msp vtxMspGetDeviceType\r\n"); UNUSED(vtxDevice); - return VTXDEV_MSP; } static bool vtxMspIsReady(const vtxDevice_t *vtxDevice) { - LOG_DEBUG(VTX, "msp vtxMspIsReady\r\n"); return vtxDevice != NULL && mspVtxPortIdentifier >=0 && vtxState.ready; } static void vtxMspSetBandAndChannel(vtxDevice_t *vtxDevice, uint8_t band, uint8_t channel) { - LOG_DEBUG(VTX, "msp vtxMspSetBandAndChannel\r\n"); UNUSED(vtxDevice); if (band < VTX_MSP_MIN_BAND || band > VTX_MSP_MAX_BAND || channel < VTX_MSP_MIN_CHANNEL || channel > VTX_MSP_MAX_CHANNEL) { @@ -232,7 +223,6 @@ static void vtxMspSetBandAndChannel(vtxDevice_t *vtxDevice, uint8_t band, uint8_ static void vtxMspSetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t index) { - LOG_DEBUG(VTX, "msp vtxMspSetPowerByIndex\r\n"); UNUSED(vtxDevice); vtxState.request.power = vtxMspPowerTable[index - 1]; @@ -242,7 +232,6 @@ static void vtxMspSetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t index) static void vtxMspSetPitMode(vtxDevice_t *vtxDevice, uint8_t onOff) { - LOG_DEBUG(VTX, "msp vtxMspSetPitMode\r\n"); UNUSED(vtxDevice); vtxState.request.pitMode = onOff; @@ -251,7 +240,6 @@ static void vtxMspSetPitMode(vtxDevice_t *vtxDevice, uint8_t onOff) static bool vtxMspGetBandAndChannel(const vtxDevice_t *vtxDevice, uint8_t *pBand, uint8_t *pChannel) { - LOG_DEBUG(VTX, "msp vtxMspGetBandAndChannel\r\n"); UNUSED(vtxDevice); *pBand = vtxState.request.band; @@ -261,7 +249,6 @@ static bool vtxMspGetBandAndChannel(const vtxDevice_t *vtxDevice, uint8_t *pBand static bool vtxMspGetPowerIndex(const vtxDevice_t *vtxDevice, uint8_t *pIndex) { - LOG_DEBUG(VTX, "msp vtxMspGetPowerIndex\r\n"); UNUSED(vtxDevice); *pIndex = vtxState.request.powerIndex; @@ -270,7 +257,6 @@ static bool vtxMspGetPowerIndex(const vtxDevice_t *vtxDevice, uint8_t *pIndex) static bool vtxMspGetPitMode(const vtxDevice_t *vtxDevice, uint8_t *pOnOff) { - LOG_DEBUG(VTX, "msp vtxMspGetPitMode\r\n"); UNUSED(vtxDevice); *pOnOff = vtxState.request.pitMode; @@ -279,7 +265,6 @@ static bool vtxMspGetPitMode(const vtxDevice_t *vtxDevice, uint8_t *pOnOff) static bool vtxMspGetFreq(const vtxDevice_t *vtxDevice, uint16_t *pFreq) { - LOG_DEBUG(VTX, "msp vtxMspGetFreq\r\n"); UNUSED(vtxDevice); *pFreq = vtxState.request.freq; @@ -288,7 +273,6 @@ static bool vtxMspGetFreq(const vtxDevice_t *vtxDevice, uint16_t *pFreq) static bool vtxMspGetPower(const vtxDevice_t *vtxDevice, uint8_t *pIndex, uint16_t *pPowerMw) { - LOG_DEBUG(VTX, "msp vtxMspGetPower\r\n"); UNUSED(vtxDevice); *pIndex = vtxState.request.powerIndex; @@ -298,7 +282,6 @@ static bool vtxMspGetPower(const vtxDevice_t *vtxDevice, uint8_t *pIndex, uint16 static bool vtxMspGetOsdInfo(const vtxDevice_t *vtxDevice, vtxDeviceOsdInfo_t *pOsdInfo) { - LOG_DEBUG(VTX, "msp vtxMspGetOsdInfo\r\n"); UNUSED(vtxDevice); pOsdInfo->band = vtxState.request.band; @@ -341,7 +324,6 @@ static vtxDevice_t vtxMsp = { bool vtxMspInit(void) { - LOG_DEBUG(VTX, "msp %s\r\n", __FUNCTION__); const serialPortConfig_t *portConfig; // Shares MSP_OSD port @@ -360,9 +342,7 @@ bool vtxMspInit(void) vtxState.request.channel = vtxSettingsConfig()->channel; vtxState.request.freq = vtx58_Bandchan2Freq(vtxState.request.band, vtxState.request.channel); vtxState.request.power = vtxSettingsConfig()->power; - uint8_t pitmode = 0; - vtxCommonGetPitMode(&vtxMsp, &pitmode); - vtxState.request.pitMode = pitmode; + vtxState.request.pitMode = 0; vtxCommonSetDevice(&vtxMsp); return true; From 2f0d50362d84c3ce37f0b09068e3abe1e5b16bff Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Tue, 17 Sep 2024 13:29:11 +0100 Subject: [PATCH 06/48] Remove direct call to band and channel setting. --- src/main/fc/fc_msp.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 7993dae6eef..08b7b336ae7 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2675,13 +2675,10 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) if (newFrequency <= VTXCOMMON_MSP_BANDCHAN_CHKVAL) { //value is band and channel const uint8_t newBand = (newFrequency / 8) + 1; const uint8_t newChannel = (newFrequency % 8) + 1; - - if(vtxSettingsConfig()->band != newBand || vtxSettingsConfig()->channel != newChannel) { - vtxCommonSetBandAndChannel(vtxDevice, newBand, newChannel); + if (vtxSettingsConfig()->band != newBand || vtxSettingsConfig()->channel != newChannel) { + vtxSettingsConfigMutable()->band = newBand; + vtxSettingsConfigMutable()->channel = newChannel; } - - vtxSettingsConfigMutable()->band = newBand; - vtxSettingsConfigMutable()->channel = newChannel; } if (sbufBytesRemaining(src) > 1) { From 3009d7d86c3469f8a8fc9f18c4df069ff588bf1a Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Tue, 17 Sep 2024 13:30:28 +0100 Subject: [PATCH 07/48] Ensure VTX logic switches take priority over FC/VTX menu settings. --- src/main/programming/logic_condition.c | 53 ++++++++++++++------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index 98ae76f8710..9ca587ad9c8 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -298,42 +298,45 @@ static int logicConditionCompute( #if defined(USE_VTX_CONTROL) case LOGIC_CONDITION_SET_VTX_POWER_LEVEL: { - uint8_t newpower = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; - if (newpower != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { - // HDZERO VTX max power+1 is 0mW. - newpower = constrain(operandA, VTX_SETTINGS_MIN_POWER, vtxDeviceCapability.powerCount+1); - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = newpower; - vtxSettingsConfigMutable()->power = newpower; - return newpower; - } else { - return false; + if (vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + uint8_t power = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; + if (power != operandA || power != vtxSettingsConfig()->power) { + // HDZERO VTX max power+1 is 0mW. + power = constrain(operandA, VTX_SETTINGS_MIN_POWER, vtxDeviceCapability.powerCount+1); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = power; + vtxSettingsConfigMutable()->power = power; + return power; + } } + return false; break; } case LOGIC_CONDITION_SET_VTX_BAND: { - uint8_t newband = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND]; - if (newband != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { - newband = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.bandCount); - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] = newband; - vtxSettingsConfigMutable()->band = newband; - return newband; - } else { - return false; + if (vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + uint8_t band = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND]; + if (band != operandA || band != vtxSettingsConfig()->band) { + band = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.bandCount); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] = band; + vtxSettingsConfigMutable()->band = band; + return band; + } } + return false; break; } case LOGIC_CONDITION_SET_VTX_CHANNEL: { - uint8_t newchannel = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL]; - if (newchannel != operandA && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { - newchannel = constrain(operandA, VTX_SETTINGS_MIN_CHANNEL, vtxDeviceCapability.channelCount); - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = newchannel; - vtxSettingsConfigMutable()->channel = newchannel; - return newchannel; - } else { - return false; + if (vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + uint8_t channel = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL]; + if (channel != operandA || channel != vtxSettingsConfig()->channel) { + channel = constrain(operandA, VTX_SETTINGS_MIN_CHANNEL, vtxDeviceCapability.channelCount); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = channel; + vtxSettingsConfigMutable()->channel = channel; + return channel; + } } + return false; break; } #endif From 79026ed027bb75a105ca28fb8b37f4db806fabf4 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Fri, 20 Sep 2024 15:31:30 +0100 Subject: [PATCH 08/48] Include MSP VTX with Smart Audio and Tramp defines. --- src/main/fc/fc_tasks.c | 2 +- src/main/fc/rc_adjustments.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index fbe119c272b..97cf005a5b6 100755 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -406,7 +406,7 @@ void fcTasksInit(void) setTaskEnabled(TASK_OPFLOW, sensors(SENSOR_OPFLOW)); #endif #ifdef USE_VTX_CONTROL -#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) +#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) || defined(USE_VTX_MSP) setTaskEnabled(TASK_VTXCTRL, true); #endif #endif diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index 37c338fedd8..27b88800841 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -576,7 +576,7 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t case ADJUSTMENT_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE: applyAdjustmentU16(ADJUSTMENT_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE, &navConfigMutable()->fw.minThrottleDownPitchAngle, delta, SETTING_FW_MIN_THROTTLE_DOWN_PITCH_MIN, SETTING_FW_MIN_THROTTLE_DOWN_PITCH_MAX); break; -#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) +#if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) || defined(USE_VTX_MSP) case ADJUSTMENT_VTX_POWER_LEVEL: { vtxDeviceCapability_t vtxDeviceCapability; From defd28358411c3a58183c5a52a8b8aef72992f9f Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Fri, 20 Sep 2024 15:34:07 +0100 Subject: [PATCH 09/48] Allow VTX to specify number of power levels available. --- src/main/fc/fc_msp.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 08b7b336ae7..0601cd89a78 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2699,9 +2699,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) vtxSettingsConfigMutable()->lowPowerDisarm = sbufReadU8(src); } - // ////////////////////////////////////////////////////////// - // this code is taken from BF, it's hack for HDZERO VTX MSP frame - // API version 1.42 - this parameter kept separate since clients may already be supplying + // API version 1.42 - extension for pitmode frequency if (sbufBytesRemaining(src) >= 2) { sbufReadU16(src); //skip pitModeFreq } @@ -2719,13 +2717,16 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) } } - /* if (sbufBytesRemaining(src) >= 4) { - sbufRead8(src); // freq_l - sbufRead8(src); // freq_h - sbufRead8(src); // band count - sbufRead8(src); // channel count - }*/ - // ////////////////////////////////////////////////////////// + if (sbufBytesRemaining(src) >= 5) { + sbufReadU16(src); // freq + sbufReadU8(src); // band count + sbufReadU8(src); // channel count + + uint8_t newPowerCount = sbufReadU8(src); + if (newPowerCount > 0 && newPowerCount < (vtxDevice->capability.powerCount)) { + vtxDevice->capability.powerCount = newPowerCount; + } + } } } } From f4abd1c3b7e7ad72259e6c753f34bda1024ddf76 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Fri, 20 Sep 2024 15:36:58 +0100 Subject: [PATCH 10/48] Allow FC Logic to specifiy a VTX power level of 0. --- src/main/programming/logic_condition.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index 9ca587ad9c8..6501ab527c5 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -301,8 +301,7 @@ static int logicConditionCompute( if (vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { uint8_t power = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; if (power != operandA || power != vtxSettingsConfig()->power) { - // HDZERO VTX max power+1 is 0mW. - power = constrain(operandA, VTX_SETTINGS_MIN_POWER, vtxDeviceCapability.powerCount+1); + power = constrain(operandA, 0, vtxDeviceCapability.powerCount); // Allow a power level of 0 logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = power; vtxSettingsConfigMutable()->power = power; return power; From c7d55874b88047eade4430929fad1cf5cc0bc278 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Thu, 26 Sep 2024 13:46:03 +0100 Subject: [PATCH 11/48] Allow min power of 0 (will need configurator change at some point). Set band/channel/power max values sent from VTX. Optimise VTX logic condition code. --- src/main/drivers/vtx_common.h | 4 +-- src/main/fc/fc_msp.c | 5 ++- src/main/io/vtx_msp.c | 25 +++++---------- src/main/programming/logic_condition.c | 42 +++++++++++--------------- 4 files changed, 32 insertions(+), 44 deletions(-) diff --git a/src/main/drivers/vtx_common.h b/src/main/drivers/vtx_common.h index 80b957c5d13..83e608dc49b 100644 --- a/src/main/drivers/vtx_common.h +++ b/src/main/drivers/vtx_common.h @@ -36,11 +36,11 @@ #define VTX_SETTINGS_POWER_COUNT 8 #define VTX_SETTINGS_DEFAULT_POWER 1 -#define VTX_SETTINGS_MIN_POWER 1 +#define VTX_SETTINGS_MIN_POWER 0 #define VTX_SETTINGS_MIN_USER_FREQ 5000 #define VTX_SETTINGS_MAX_USER_FREQ 5999 #define VTX_SETTINGS_FREQCMD -#define VTX_SETTINGS_MAX_POWER (VTX_SETTINGS_POWER_COUNT - VTX_SETTINGS_MIN_POWER + 1) +#define VTX_SETTINGS_MAX_POWER (VTX_SETTINGS_POWER_COUNT - VTX_SETTINGS_MIN_POWER) #else diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 69552d03173..bfa57bee833 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2708,8 +2708,11 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) } } - if (sbufBytesRemaining(src) >= 5) { + if (sbufBytesRemaining(src) >= 2) { sbufReadU16(src); // freq + } + + if (sbufBytesRemaining(src) >= 3) { sbufReadU8(src); // band count sbufReadU8(src); // channel count diff --git a/src/main/io/vtx_msp.c b/src/main/io/vtx_msp.c index 9271f2e5eca..84746e0c9f3 100644 --- a/src/main/io/vtx_msp.c +++ b/src/main/io/vtx_msp.c @@ -77,11 +77,11 @@ const char * const vtxMspChannelNames[VTX_MSP_CHANNEL_COUNT + 1] = { }; const char * const vtxMspPowerNames[VTX_MSP_POWER_COUNT + 1] = { - "---", "25", "200", "500", "MAX" + "0", "25", "200", "500", "MAX" }; -const unsigned vtxMspPowerTable[VTX_MSP_POWER_COUNT] = { - 25, 200, 500, 1000 +const unsigned vtxMspPowerTable[VTX_MSP_POWER_COUNT + 1] = { + 0, 25, 200, 500, 1000 }; static serialPortIdentifier_e mspVtxPortIdentifier; @@ -89,11 +89,11 @@ static vtxProtoState_t vtxState; static vtxDevType_e vtxMspGetDeviceType(const vtxDevice_t *); static bool vtxMspIsReady(const vtxDevice_t *); +static vtxDevice_t vtxMsp; static void prepareMspFrame(vtxDevice_t *vtxDevice, uint8_t *mspFrame) { // Send an MSP_VTX_V2 frame to the VTX - mspFrame[0] = vtxMspGetDeviceType(vtxDevice); mspFrame[1] = vtxState.request.band; mspFrame[2] = vtxState.request.channel; @@ -106,18 +106,9 @@ static void prepareMspFrame(vtxDevice_t *vtxDevice, uint8_t *mspFrame) mspFrame[9] = 0; // pitmode freq Low mspFrame[10] = 0; // pitmode freq High mspFrame[11] = 0; // 1 if using vtx table - mspFrame[12] = 6; // bands or 0 - mspFrame[13] = 8; // channels or 0 - mspFrame[14] = 5; // power levels or 0 - - LOG_DEBUG(VTX, "msp device [%d]\r\n", mspFrame[0]); - LOG_DEBUG(VTX, "msp band [%d]\r\n", mspFrame[1]); - LOG_DEBUG(VTX, "msp channel [%d]\r\n", mspFrame[2]); - LOG_DEBUG(VTX, "msp power [%d]\r\n", mspFrame[3]); - LOG_DEBUG(VTX, "msp freq [%d]\r\n", ((uint16_t)mspFrame[6] << 8) + mspFrame[5]); - LOG_DEBUG(VTX, "msp pitmode [%d]\r\n", mspFrame[4]); - LOG_DEBUG(VTX, "msp isready [%d]\r\n", mspFrame[7]); - LOG_DEBUG(VTX, "msp lowPower [%d]\r\n", mspFrame[8]); + mspFrame[12] = vtxMsp.capability.bandCount; // bands or 0 + mspFrame[13] = vtxMsp.capability.channelCount; // channels or 0 + mspFrame[14] = vtxMsp.capability.powerCount; // power levels or 0 } static void mspCrsfPush(const uint8_t mspCommand, const uint8_t *mspFrame, const uint8_t mspFrameSize) @@ -225,7 +216,7 @@ static void vtxMspSetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t index) { UNUSED(vtxDevice); - vtxState.request.power = vtxMspPowerTable[index - 1]; + vtxState.request.power = vtxMspPowerTable[index]; vtxState.request.powerIndex = index; vtxState.updateReqMask |= VTX_UPDATE_REQ_POWER; } diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index 6501ab527c5..e99ab92cfe9 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -298,42 +298,36 @@ static int logicConditionCompute( #if defined(USE_VTX_CONTROL) case LOGIC_CONDITION_SET_VTX_POWER_LEVEL: { - if (vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { - uint8_t power = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; - if (power != operandA || power != vtxSettingsConfig()->power) { - power = constrain(operandA, 0, vtxDeviceCapability.powerCount); // Allow a power level of 0 - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = power; - vtxSettingsConfigMutable()->power = power; - return power; - } + uint8_t newPower = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL]; + if ((newPower != operandA || newPower != vtxSettingsConfig()->power) && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + newPower = constrain(operandA, VTX_SETTINGS_MIN_POWER, vtxDeviceCapability.powerCount); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = newPower; + vtxSettingsConfigMutable()->power = newPower; + return newPower; } return false; break; } case LOGIC_CONDITION_SET_VTX_BAND: { - if (vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { - uint8_t band = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND]; - if (band != operandA || band != vtxSettingsConfig()->band) { - band = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.bandCount); - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] = band; - vtxSettingsConfigMutable()->band = band; - return band; - } + uint8_t newBand = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND]; + if ((newBand != operandA || newBand != vtxSettingsConfig()->band) && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + newBand = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.bandCount); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] = newBand; + vtxSettingsConfigMutable()->band = newBand; + return newBand; } return false; break; } case LOGIC_CONDITION_SET_VTX_CHANNEL: { - if (vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { - uint8_t channel = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL]; - if (channel != operandA || channel != vtxSettingsConfig()->channel) { - channel = constrain(operandA, VTX_SETTINGS_MIN_CHANNEL, vtxDeviceCapability.channelCount); - logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = channel; - vtxSettingsConfigMutable()->channel = channel; - return channel; - } + uint8_t newChannel = logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL]; + if ((newChannel != operandA || newChannel != vtxSettingsConfig()->channel) && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { + newChannel = constrain(operandA, VTX_SETTINGS_MIN_CHANNEL, vtxDeviceCapability.channelCount); + logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = newChannel; + vtxSettingsConfigMutable()->channel = newChannel; + return newChannel; } return false; break; From b41bcdc1b02ea870b6a0380acb1d9f4e70389b38 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Fri, 27 Sep 2024 14:15:37 +0100 Subject: [PATCH 12/48] Ensure VTX logic settings override any external changes. --- src/main/programming/logic_condition.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index e99ab92cfe9..697091ff7a0 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -302,6 +302,9 @@ static int logicConditionCompute( if ((newPower != operandA || newPower != vtxSettingsConfig()->power) && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { newPower = constrain(operandA, VTX_SETTINGS_MIN_POWER, vtxDeviceCapability.powerCount); logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_POWER_LEVEL] = newPower; + if (newPower != vtxSettingsConfig()->power) { + vtxCommonSetPowerByIndex(vtxCommonDevice(), newPower); // Force setting if modified elsewhere + } vtxSettingsConfigMutable()->power = newPower; return newPower; } @@ -314,6 +317,9 @@ static int logicConditionCompute( if ((newBand != operandA || newBand != vtxSettingsConfig()->band) && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { newBand = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.bandCount); logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] = newBand; + if (newBand != vtxSettingsConfig()->band) { + vtxCommonSetPowerByIndex(vtxCommonDevice(), newBand); + } vtxSettingsConfigMutable()->band = newBand; return newBand; } @@ -326,6 +332,9 @@ static int logicConditionCompute( if ((newChannel != operandA || newChannel != vtxSettingsConfig()->channel) && vtxCommonGetDeviceCapability(vtxCommonDevice(), &vtxDeviceCapability)) { newChannel = constrain(operandA, VTX_SETTINGS_MIN_CHANNEL, vtxDeviceCapability.channelCount); logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = newChannel; + if (newChannel != vtxSettingsConfig()->channel) { + vtxCommonSetPowerByIndex(vtxCommonDevice(), newChannel); + } vtxSettingsConfigMutable()->channel = newChannel; return newChannel; } From ac6a1de0885412c3c119e8fc92edeafc132b55f4 Mon Sep 17 00:00:00 2001 From: Geoff Sim Date: Mon, 7 Oct 2024 16:56:18 +0100 Subject: [PATCH 13/48] Fix cut/paste error in band and channel logic override. --- src/main/programming/logic_condition.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index 697091ff7a0..1c19889fe47 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -318,7 +318,7 @@ static int logicConditionCompute( newBand = constrain(operandA, VTX_SETTINGS_MIN_BAND, vtxDeviceCapability.bandCount); logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_BAND] = newBand; if (newBand != vtxSettingsConfig()->band) { - vtxCommonSetPowerByIndex(vtxCommonDevice(), newBand); + vtxCommonSetBandAndChannel(vtxCommonDevice(), newBand, vtxSettingsConfig()->channel); } vtxSettingsConfigMutable()->band = newBand; return newBand; @@ -333,7 +333,7 @@ static int logicConditionCompute( newChannel = constrain(operandA, VTX_SETTINGS_MIN_CHANNEL, vtxDeviceCapability.channelCount); logicConditionValuesByType[LOGIC_CONDITION_SET_VTX_CHANNEL] = newChannel; if (newChannel != vtxSettingsConfig()->channel) { - vtxCommonSetPowerByIndex(vtxCommonDevice(), newChannel); + vtxCommonSetBandAndChannel(vtxCommonDevice(), vtxSettingsConfig()->band, newChannel); } vtxSettingsConfigMutable()->channel = newChannel; return newChannel; From a3afa3fe7bd2fa2ea6d386d7ddd96db7ccc9467a Mon Sep 17 00:00:00 2001 From: megazar <48863881+ultrazar@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:50:00 +0200 Subject: [PATCH 14/48] Added IMUTemperature read function for ICM42605 --- src/main/drivers/accgyro/accgyro_icm42605.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/accgyro/accgyro_icm42605.c b/src/main/drivers/accgyro/accgyro_icm42605.c index 13bc22fcee7..d0c4e3490aa 100644 --- a/src/main/drivers/accgyro/accgyro_icm42605.c +++ b/src/main/drivers/accgyro/accgyro_icm42605.c @@ -62,6 +62,7 @@ #define ICM42605_RA_GYRO_DATA_X1 0x25 #define ICM42605_RA_ACCEL_DATA_X1 0x1F +#define ICM42605_RA_TEMP_DATA1 0x1D #define ICM42605_RA_INT_CONFIG 0x14 #define ICM42605_INT1_MODE_PULSED (0 << 2) @@ -321,6 +322,20 @@ static bool icm42605GyroRead(gyroDev_t *gyro) return true; } +static bool icm42605ReadTemperature(gyroDev_t *gyro, int16_t * temp) +{ + uint8_t data[2]; + + const bool ack = busReadBuf(gyro->busDev, ICM42605_RA_TEMP_DATA1, data, 2); + if (!ack) { + return false; + } + // From datasheet: Temperature in Degrees Centigrade = (TEMP_DATA / 132.48) + 25 + *temp = ( int16_val_big_endian(data, 0) / 13.248 ) + 250; // Temperature stored as degC*10 + + return true; +} + bool icm42605GyroDetect(gyroDev_t *gyro) { gyro->busDev = busDeviceInit(BUSTYPE_ANY, DEVHW_ICM42605, gyro->imuSensorToUse, OWNER_MPU); @@ -340,7 +355,7 @@ bool icm42605GyroDetect(gyroDev_t *gyro) gyro->initFn = icm42605AccAndGyroInit; gyro->readFn = icm42605GyroRead; gyro->intStatusFn = gyroCheckDataReady; - gyro->temperatureFn = NULL; + gyro->temperatureFn = icm42605ReadTemperature; gyro->scale = 1.0f / 16.4f; // 16.4 dps/lsb scalefactor gyro->gyroAlign = gyro->busDev->param; From 81e79b731a64fa771659d5dc67996dc4ef9c0af0 Mon Sep 17 00:00:00 2001 From: TUNERC-Aria <71423100+TUNERC-Aria@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:19:54 +0800 Subject: [PATCH 15/48] Update target.h Add the inverter's control pin for target TUNERCF405 --- src/main/target/TUNERCF405/target.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/target/TUNERCF405/target.h b/src/main/target/TUNERCF405/target.h index f193377c6ea..093da2fadf6 100644 --- a/src/main/target/TUNERCF405/target.h +++ b/src/main/target/TUNERCF405/target.h @@ -103,6 +103,9 @@ #define USE_UART4 #define UART4_RX_PIN PA1 #define UART4_TX_PIN PA0 +#define USE_UART_INVERTER +#define INVERTER_PIN_UART4_RX PC14 +#define INVERTER_PIN_USART4_RX PC14 #define USE_UART5 #define UART5_RX_PIN PD2 From a20064e45df235f7de1e27fca4be2e2255890302 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Wed, 30 Oct 2024 16:26:06 +0100 Subject: [PATCH 16/48] Update DPS310 driver to support SPL07-003 --- src/main/drivers/barometer/barometer_dps310.c | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/main/drivers/barometer/barometer_dps310.c b/src/main/drivers/barometer/barometer_dps310.c index 51e18eb12b0..663dcb27117 100644 --- a/src/main/drivers/barometer/barometer_dps310.c +++ b/src/main/drivers/barometer/barometer_dps310.c @@ -61,6 +61,7 @@ #define DPS310_ID_REV_AND_PROD_ID (0x10) +#define SPL07_003_CHIP_ID (0x11) #define DPS310_RESET_BIT_SOFT_RST (0x09) // 0b1001 @@ -96,6 +97,8 @@ typedef struct { int16_t c20; // 16bit int16_t c21; // 16bit int16_t c30; // 16bit + int16_t c31; // 12bit + int16_t c40; // 12bit } calibrationCoefficients_t; typedef struct { @@ -105,6 +108,7 @@ typedef struct { } baroState_t; static baroState_t baroState; +static uint8_t chipId[1]; // Helper functions @@ -167,7 +171,10 @@ static bool deviceConfigure(busDevice_t * busDev) // 1. Read the pressure calibration coefficients (c00, c10, c20, c30, c01, c11, and c21) from the Calibration Coefficient register. // Note: The coefficients read from the coefficient register are 2's complement numbers. - uint8_t coef[18]; + + unsigned coefficientLength = chipId[0] == SPL07_003_CHIP_ID ? 21 : 18; + uint8_t coef[coefficientLength]; + if (!busReadBuf(busDev, DPS310_REG_COEF, coef, sizeof(coef))) { return false; } @@ -199,6 +206,17 @@ static bool deviceConfigure(busDevice_t * busDev) // 0x20 c30 [15:8] + 0x21 c30 [7:0] baroState.calib.c30 = getTwosComplement(((uint32_t)coef[16] << 8) | (uint32_t)coef[17], 16); + if (chipId[0] == SPL07_003_CHIP_ID) { + // 0x23 c31 [3:0] + 0x22 c31 [11:4] + baroState.calib.c31 = getTwosComplement(((uint32_t)coef[18] << 4) | (((uint32_t)coef[19] >> 4) & 0x0F), 12); + + // 0x23 c40 [11:8] + 0x24 c40 [7:0] + baroState.calib.c40 = getTwosComplement((((uint32_t)coef[19] & 0x0F) << 8) | (uint32_t)coef[20], 12); + } else { + baroState.calib.c31 = 0; + baroState.calib.c40 = 0; + } + // MEAS_CFG: Make sure the device is in IDLE mode registerWriteBits(busDev, DPS310_REG_MEAS_CFG, DPS310_MEAS_CFG_MEAS_CTRL_MASK, DPS310_MEAS_CFG_MEAS_IDLE); @@ -218,8 +236,12 @@ static bool deviceConfigure(busDevice_t * busDev) registerSetBits(busDev, DPS310_REG_PRS_CFG, DPS310_PRS_CFG_BIT_PM_RATE_32HZ | DPS310_PRS_CFG_BIT_PM_PRC_16); // TMP_CFG: temperature measurement rate (32 Hz) and oversampling (16 times) - const uint8_t TMP_COEF_SRCE = registerRead(busDev, DPS310_REG_COEF_SRCE) & DPS310_COEF_SRCE_BIT_TMP_COEF_SRCE; - registerSetBits(busDev, DPS310_REG_TMP_CFG, DPS310_TMP_CFG_BIT_TMP_RATE_32HZ | DPS310_TMP_CFG_BIT_TMP_PRC_16 | TMP_COEF_SRCE); + if (chipId[0] == SPL07_003_CHIP_ID) { + registerSetBits(busDev, DPS310_REG_TMP_CFG, DPS310_TMP_CFG_BIT_TMP_RATE_32HZ | DPS310_TMP_CFG_BIT_TMP_PRC_16); + } else { + const uint8_t TMP_COEF_SRCE = registerRead(busDev, DPS310_REG_COEF_SRCE) & DPS310_COEF_SRCE_BIT_TMP_COEF_SRCE; + registerSetBits(busDev, DPS310_REG_TMP_CFG, DPS310_TMP_CFG_BIT_TMP_RATE_32HZ | DPS310_TMP_CFG_BIT_TMP_PRC_16 | TMP_COEF_SRCE); + } // CFG_REG: set pressure and temperature result bit-shift (required when the oversampling rate is >8 times) registerSetBits(busDev, DPS310_REG_CFG_REG, DPS310_CFG_REG_BIT_T_SHIFT | DPS310_CFG_REG_BIT_P_SHIFT); @@ -265,9 +287,17 @@ static bool deviceReadMeasurement(baroDev_t *baro) const float c20 = baroState.calib.c20; const float c21 = baroState.calib.c21; const float c30 = baroState.calib.c30; + const float c31 = baroState.calib.c31; + const float c40 = baroState.calib.c40; // See section 4.9.1, How to Calculate Compensated Pressure Values, of datasheet - baroState.pressure = c00 + Praw_sc * (c10 + Praw_sc * (c20 + Praw_sc * c30)) + Traw_sc * c01 + Traw_sc * Praw_sc * (c11 + Praw_sc * c21); + // baroState.pressure = c00 + Praw_sc * (c10 + Praw_sc * (c20 + Praw_sc * c30)) + Traw_sc * c01 + Traw_sc * Praw_sc * (c11 + Praw_sc * c21); + if (chipId[0] == SPL07_003_CHIP_ID) { + baroState.pressure = c00 + Praw_sc * (c10 + Praw_sc * (c20 + Praw_sc * (c30 + Praw_sc * c40))) + Traw_sc * c01 + Traw_sc * Praw_sc * (c11 + Praw_sc * (c21 + Praw_sc * c31)); + } else { + baroState.pressure = c00 + Praw_sc * (c10 + Praw_sc * (c20 + Praw_sc * c30)) + Traw_sc * c01 + Traw_sc * Praw_sc * (c11 + Praw_sc * c21); + } + const float c0 = baroState.calib.c0; const float c1 = baroState.calib.c1; @@ -299,13 +329,11 @@ static bool deviceCalculate(baroDev_t *baro, int32_t *pressure, int32_t *tempera static bool deviceDetect(busDevice_t * busDev) { for (int retry = 0; retry < DETECTION_MAX_RETRY_COUNT; retry++) { - uint8_t chipId[1]; - delay(100); bool ack = busReadBuf(busDev, DPS310_REG_ID, chipId, 1); - if (ack && chipId[0] == DPS310_ID_REV_AND_PROD_ID) { + if (ack && (chipId[0] == DPS310_ID_REV_AND_PROD_ID || chipId[0] == SPL07_003_CHIP_ID)) { return true; } }; From e4627d030d894234debd667cfc91c5879ad3b5e3 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sat, 2 Nov 2024 22:11:19 +0000 Subject: [PATCH 17/48] Add stats and info MSP commands for MSP RC This is an initial, basic implementation. This can be expanded in the future to deal with multiple sublinks etc. --- src/main/fc/fc_msp.c | 36 ++++++++++++++++++++++++++ src/main/msp/msp_protocol_v2_common.h | 37 +++++++++++++++------------ src/main/rx/rx.h | 16 +++++++----- 3 files changed, 66 insertions(+), 23 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index f87b7f079c7..afa5df2741d 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2914,6 +2914,42 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) return MSP_RESULT_ERROR; break; +#ifdef USE_RX_MSP + case MSP2_COMMON_SET_MSP_RC_LINK_STATS: + if (dataSize == 48) { + uint8_t sublinkID = sbufReadU8(src); // Sublink ID + sbufReadU8(src); // Valid link (Failsafe backup) + if (sublinkID == 1) { + rxLinkStatistics.uplinkRSSI = -sbufReadU8(src); + rxLinkStatistics.downlinkLQ = sbufReadU8(src); + rxLinkStatistics.uplinkLQ = sbufReadU8(src); + rxLinkStatistics.uplinkSNR = sbufReadU8(src); + } + } else + return MSP_RESULT_ERROR; + break; + + case MSP2_COMMON_SET_MSP_RC_INFO: + if (dataSize == 104) { + uint8_t sublinkID = sbufReadU8(src); + + if (sublinkID == 1) { + rxLinkStatistics.uplinkTXPower = sbufReadU8(src); + rxLinkStatistics.downlinkTXPower = sbufReadU8(src); + + for (int i = 0; i < 4 - 1; i++) { + rxLinkStatistics.band[i] = sbufReadU8(src); + } + + for (int i = 0; i < 6 - 1; i++) { + rxLinkStatistics.mode[i] = sbufReadU8(src); + } + } + } else + return MSP_RESULT_ERROR; + break; +#endif + case MSP_SET_FAILSAFE_CONFIG: if (dataSize == 20) { failsafeConfigMutable()->failsafe_delay = sbufReadU8(src); diff --git a/src/main/msp/msp_protocol_v2_common.h b/src/main/msp/msp_protocol_v2_common.h index e778a1808c9..8784b253114 100644 --- a/src/main/msp/msp_protocol_v2_common.h +++ b/src/main/msp/msp_protocol_v2_common.h @@ -15,22 +15,25 @@ * along with INAV. If not, see . */ -#define MSP2_COMMON_TZ 0x1001 //out message Gets the TZ offset for the local time (returns: minutes(i16)) -#define MSP2_COMMON_SET_TZ 0x1002 //in message Sets the TZ offset for the local time (args: minutes(i16)) -#define MSP2_COMMON_SETTING 0x1003 //in/out message Returns the value for a setting -#define MSP2_COMMON_SET_SETTING 0x1004 //in message Sets the value for a setting +#define MSP2_COMMON_TZ 0x1001 //out message Gets the TZ offset for the local time (returns: minutes(i16)) +#define MSP2_COMMON_SET_TZ 0x1002 //in message Sets the TZ offset for the local time (args: minutes(i16)) +#define MSP2_COMMON_SETTING 0x1003 //in/out message Returns the value for a setting +#define MSP2_COMMON_SET_SETTING 0x1004 //in message Sets the value for a setting + +#define MSP2_COMMON_MOTOR_MIXER 0x1005 +#define MSP2_COMMON_SET_MOTOR_MIXER 0x1006 + +#define MSP2_COMMON_SETTING_INFO 0x1007 //in/out message Returns info about a setting (PG, type, flags, min/max, etc..). +#define MSP2_COMMON_PG_LIST 0x1008 //in/out message Returns a list of the PG ids used by the settings + +#define MSP2_COMMON_SERIAL_CONFIG 0x1009 +#define MSP2_COMMON_SET_SERIAL_CONFIG 0x100A + +// radar commands +#define MSP2_COMMON_SET_RADAR_POS 0x100B //SET radar position information +#define MSP2_COMMON_SET_RADAR_ITD 0x100C //SET radar information to display -#define MSP2_COMMON_MOTOR_MIXER 0x1005 -#define MSP2_COMMON_SET_MOTOR_MIXER 0x1006 +#define MSP2_COMMON_SET_MSP_RC_LINK_STATS 0x100D //in message Sets the MSP RC stats +#define MSP2_COMMON_SET_MSP_RC_INFO 0x100E //in message Sets the MSP RC info -#define MSP2_COMMON_SETTING_INFO 0x1007 //in/out message Returns info about a setting (PG, type, flags, min/max, etc..). -#define MSP2_COMMON_PG_LIST 0x1008 //in/out message Returns a list of the PG ids used by the settings - -#define MSP2_COMMON_SERIAL_CONFIG 0x1009 -#define MSP2_COMMON_SET_SERIAL_CONFIG 0x100A - -// radar commands -#define MSP2_COMMON_SET_RADAR_POS 0x100B //SET radar position information -#define MSP2_COMMON_SET_RADAR_ITD 0x100C //SET radar information to display - -#define MSP2_BETAFLIGHT_BIND 0x3000 +#define MSP2_BETAFLIGHT_BIND 0x3000 diff --git a/src/main/rx/rx.h b/src/main/rx/rx.h index c841838a5ea..4d8a76fecf5 100644 --- a/src/main/rx/rx.h +++ b/src/main/rx/rx.h @@ -181,12 +181,16 @@ typedef enum { } rssiSource_e; typedef struct rxLinkStatistics_s { - int16_t uplinkRSSI; // RSSI value in dBm - uint8_t uplinkLQ; // A protocol specific measure of the link quality in [0..100] - int8_t uplinkSNR; // The SNR of the uplink in dB - uint8_t rfMode; // A protocol specific measure of the transmission bandwidth [2 = 150Hz, 1 = 50Hz, 0 = 4Hz] - uint16_t uplinkTXPower; // power in mW - uint8_t activeAntenna; + int16_t uplinkRSSI; // RSSI value in dBm + uint8_t uplinkLQ; // A protocol specific measure of the link quality in [0..100] + uint8_t downlinkLQ; // A protocol specific measure of the link quality in [0..100] + int8_t uplinkSNR; // The SNR of the uplink in dB + uint8_t rfMode; // A protocol specific measure of the transmission bandwidth [2 = 150Hz, 1 = 50Hz, 0 = 4Hz] + uint16_t uplinkTXPower; // power in mW + uint16_t downlinkTXPower; // power in mW + uint8_t activeAntenna; + char band[4]; + char mode[6]; } rxLinkStatistics_t; typedef uint16_t (*rcReadRawDataFnPtr)(const rxRuntimeConfig_t *rxRuntimeConfig, uint8_t chan); // used by receiver driver to return channel data From 66e9be42c3176fd27efffaceedb828a9b5b2592f Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sat, 2 Nov 2024 22:15:26 +0000 Subject: [PATCH 18/48] Update fc_msp.c --- src/main/fc/fc_msp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index afa5df2741d..62e09cf1ace 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2920,6 +2920,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) uint8_t sublinkID = sbufReadU8(src); // Sublink ID sbufReadU8(src); // Valid link (Failsafe backup) if (sublinkID == 1) { + // RSSI % rxLinkStatistics.uplinkRSSI = -sbufReadU8(src); rxLinkStatistics.downlinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkLQ = sbufReadU8(src); From a807056a560de2df0225548b5ffeeb6c96cce3c4 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 08:47:34 +0000 Subject: [PATCH 19/48] Corrected int types --- src/main/fc/fc_msp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 62e09cf1ace..f4f144e8bd7 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2916,12 +2916,12 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) #ifdef USE_RX_MSP case MSP2_COMMON_SET_MSP_RC_LINK_STATS: - if (dataSize == 48) { + if (dataSize == 56) { uint8_t sublinkID = sbufReadU8(src); // Sublink ID sbufReadU8(src); // Valid link (Failsafe backup) if (sublinkID == 1) { - // RSSI % - rxLinkStatistics.uplinkRSSI = -sbufReadU8(src); + sbufReadU8(src); // RSSI % + rxLinkStatistics.uplinkRSSI = -sbufReadU16(src); rxLinkStatistics.downlinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkSNR = sbufReadU8(src); @@ -2931,12 +2931,12 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) break; case MSP2_COMMON_SET_MSP_RC_INFO: - if (dataSize == 104) { + if (dataSize == 120) { uint8_t sublinkID = sbufReadU8(src); if (sublinkID == 1) { - rxLinkStatistics.uplinkTXPower = sbufReadU8(src); - rxLinkStatistics.downlinkTXPower = sbufReadU8(src); + rxLinkStatistics.uplinkTXPower = sbufReadU16(src); + rxLinkStatistics.downlinkTXPower = sbufReadU16(src); for (int i = 0; i < 4 - 1; i++) { rxLinkStatistics.band[i] = sbufReadU8(src); From 8a729cda495ac8e99c83319d0c458efdda89948a Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 11:34:24 +0000 Subject: [PATCH 20/48] corrected dataSize check to bytes --- src/main/fc/fc_msp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index f4f144e8bd7..f5cc24e7a11 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2916,7 +2916,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) #ifdef USE_RX_MSP case MSP2_COMMON_SET_MSP_RC_LINK_STATS: - if (dataSize == 56) { + if (dataSize == 7) { uint8_t sublinkID = sbufReadU8(src); // Sublink ID sbufReadU8(src); // Valid link (Failsafe backup) if (sublinkID == 1) { @@ -2931,7 +2931,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) break; case MSP2_COMMON_SET_MSP_RC_INFO: - if (dataSize == 120) { + if (dataSize == 15) { uint8_t sublinkID = sbufReadU8(src); if (sublinkID == 1) { From 2f51a7a7cd5629f79c87fd1710fa3acc16941050 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 11:39:02 +0000 Subject: [PATCH 21/48] Added comment to assist on hover check of variable --- src/main/fc/fc_msp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index f5cc24e7a11..0bba60c1825 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -1807,7 +1807,7 @@ static void mspFcWaypointOutCommand(sbuf_t *dst, sbuf_t *src) #ifdef USE_FLASHFS static void mspFcDataFlashReadCommand(sbuf_t *dst, sbuf_t *src) { - const unsigned int dataSize = sbufBytesRemaining(src); + const unsigned int dataSize = sbufBytesRemaining(src); /* Payload size in Bytes */ uint16_t readLength; const uint32_t readAddress = sbufReadU32(src); From 80c47fad20838938754ff0a2e12c136fd9c24e71 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 11:42:47 +0000 Subject: [PATCH 22/48] Ditto --- src/main/fc/fc_msp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 0bba60c1825..8bbf880b790 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -215,7 +215,7 @@ static void mspSerialPassthroughFn(serialPort_t *serialPort) static void mspFcSetPassthroughCommand(sbuf_t *dst, sbuf_t *src, mspPostProcessFnPtr *mspPostProcessFn) { - const unsigned int dataSize = sbufBytesRemaining(src); + const unsigned int dataSize = sbufBytesRemaining(src); /* Payload size in Bytes */ if (dataSize == 0) { // Legacy format @@ -1831,7 +1831,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) uint8_t tmp_u8; uint16_t tmp_u16; - const unsigned int dataSize = sbufBytesRemaining(src); + const unsigned int dataSize = sbufBytesRemaining(src); /* Payload size in Bytes */ switch (cmdMSP) { case MSP_SELECT_SETTING: From a9f327fae094b18ffb30d77a8a7eb721cb524258 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 12:21:41 +0000 Subject: [PATCH 23/48] Update fc_msp.c - Add RSSI - Allow extended versions of future MSP2_COMMON_SET_MSP_RC_LINK_STATS and MSP2_COMMON_SET_MSP_RC_INFO still work with older (from now) INAV versions. Except for the new data. --- src/main/fc/fc_msp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 8bbf880b790..ab8a3b2061c 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2916,11 +2916,11 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) #ifdef USE_RX_MSP case MSP2_COMMON_SET_MSP_RC_LINK_STATS: - if (dataSize == 7) { + if (dataSize >= 7) { uint8_t sublinkID = sbufReadU8(src); // Sublink ID sbufReadU8(src); // Valid link (Failsafe backup) if (sublinkID == 1) { - sbufReadU8(src); // RSSI % + setRSSIFromMSP(sbufReadU8(src)); // RSSI % rxLinkStatistics.uplinkRSSI = -sbufReadU16(src); rxLinkStatistics.downlinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkLQ = sbufReadU8(src); @@ -2931,7 +2931,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) break; case MSP2_COMMON_SET_MSP_RC_INFO: - if (dataSize == 15) { + if (dataSize >= 15) { uint8_t sublinkID = sbufReadU8(src); if (sublinkID == 1) { From 4aaa12f379e18a44e038f2e2a7c0a2c14c3e415d Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 14:24:45 +0000 Subject: [PATCH 24/48] Have RSSI go from 0-100%, rather than 0-99% --- src/main/io/osd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 41c20dda928..b6abbc30f49 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -616,11 +616,11 @@ char *osdFormatTrimWhiteSpace(char *buff) /** * Converts RSSI into a % value used by the OSD. + * Range is [0, 100] */ -static uint16_t osdConvertRSSI(void) +static uint8_t osdConvertRSSI(void) { - // change range to [0, 99] - return constrain(getRSSI() * 100 / RSSI_MAX_VALUE, 0, 99); + return constrain(getRSSI() * 100 / RSSI_MAX_VALUE, 0, 100); } static uint16_t osdGetCrsfLQ(void) @@ -1712,9 +1712,13 @@ static bool osdDrawSingleElement(uint8_t item) } case OSD_RSSI_VALUE: { - uint16_t osdRssi = osdConvertRSSI(); + uint8_t osdRssi = osdConvertRSSI(); buff[0] = SYM_RSSI; - tfp_sprintf(buff + 1, "%2d", osdRssi); + if (osdRssi < 100) + tfp_sprintf(buff + 1, "%2d", osdRssi); + else + tfp_sprintf(buff + 1, " %c", SYM_MAX); + if (osdRssi < osdConfig()->rssi_alarm) { TEXT_ATTRIBUTES_ADD_BLINK(elemAttr); } From 1a2659c153cdfbf1bceb1c42ebb9da6d1324bbff Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 14:30:08 +0000 Subject: [PATCH 25/48] Update osd.c --- src/main/io/osd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index b6abbc30f49..39f05390352 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -181,7 +181,7 @@ typedef struct statistic_s { uint16_t min_voltage; // /100 int16_t max_current; int32_t max_power; - int16_t min_rssi; + int8_t min_rssi; int16_t min_lq; // for CRSF int16_t min_rssi_dbm; // for CRSF int32_t max_altitude; @@ -4586,7 +4586,7 @@ static void osdResetStats(void) stats.max_3D_speed = 0; stats.max_air_speed = 0; stats.min_voltage = 12000; - stats.min_rssi = 99; + stats.min_rssi = 100; stats.min_lq = 300; stats.min_rssi_dbm = 0; stats.max_altitude = 0; From 823aa828912f81da916b55129d7912854308b5a9 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 14:33:13 +0000 Subject: [PATCH 26/48] Update osd.c --- src/main/io/osd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 39f05390352..73ea8200330 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -181,7 +181,7 @@ typedef struct statistic_s { uint16_t min_voltage; // /100 int16_t max_current; int32_t max_power; - int8_t min_rssi; + uint8_t min_rssi; int16_t min_lq; // for CRSF int16_t min_rssi_dbm; // for CRSF int32_t max_altitude; From 6a77be500cfe655a8275c8ad922b27852975e9b7 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 15:26:22 +0000 Subject: [PATCH 27/48] Update osd.c --- src/main/io/osd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 73ea8200330..d3419a65288 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -1717,7 +1717,7 @@ static bool osdDrawSingleElement(uint8_t item) if (osdRssi < 100) tfp_sprintf(buff + 1, "%2d", osdRssi); else - tfp_sprintf(buff + 1, " %c", SYM_MAX); + tfp_sprintf(buff + 1, "%c ", SYM_MAX); if (osdRssi < osdConfig()->rssi_alarm) { TEXT_ATTRIBUTES_ADD_BLINK(elemAttr); From 99b1a1513424b4582d1880c47463d44f438d2442 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 15:45:59 +0000 Subject: [PATCH 28/48] Fixed datasize --- src/main/fc/fc_msp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index ab8a3b2061c..c8eb95dd890 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2916,7 +2916,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) #ifdef USE_RX_MSP case MSP2_COMMON_SET_MSP_RC_LINK_STATS: - if (dataSize >= 7) { + if (dataSize >= 8) { uint8_t sublinkID = sbufReadU8(src); // Sublink ID sbufReadU8(src); // Valid link (Failsafe backup) if (sublinkID == 1) { From f16f63548208e49c90d5dd562228f4e068877b9f Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 15:50:15 +0000 Subject: [PATCH 29/48] Fix for crap added by GitHub Copilot --- src/main/fc/fc_msp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index c8eb95dd890..168d0817126 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2938,11 +2938,11 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) rxLinkStatistics.uplinkTXPower = sbufReadU16(src); rxLinkStatistics.downlinkTXPower = sbufReadU16(src); - for (int i = 0; i < 4 - 1; i++) { + for (int i = 0; i < 4; i++) { rxLinkStatistics.band[i] = sbufReadU8(src); } - for (int i = 0; i < 6 - 1; i++) { + for (int i = 0; i < 6; i++) { rxLinkStatistics.mode[i] = sbufReadU8(src); } } From b5b9e586a859b2f68253533125728ba2eb4995b8 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 16:22:28 +0000 Subject: [PATCH 30/48] Allow signed for SNR --- src/main/common/streambuf.c | 5 +++++ src/main/common/streambuf.h | 1 + src/main/fc/fc_msp.c | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/common/streambuf.c b/src/main/common/streambuf.c index 7a4e8c8cc99..5a766423421 100644 --- a/src/main/common/streambuf.c +++ b/src/main/common/streambuf.c @@ -98,6 +98,11 @@ uint8_t sbufReadU8(sbuf_t *src) return *src->ptr++; } +int8_t sbufReadI8(sbuf_t *src) +{ + return *src->ptr++; +} + uint16_t sbufReadU16(sbuf_t *src) { uint16_t ret; diff --git a/src/main/common/streambuf.h b/src/main/common/streambuf.h index 74331147da8..a2ac1f681a6 100644 --- a/src/main/common/streambuf.h +++ b/src/main/common/streambuf.h @@ -42,6 +42,7 @@ void sbufWriteU16BigEndian(sbuf_t *dst, uint16_t val); void sbufWriteU32BigEndian(sbuf_t *dst, uint32_t val); uint8_t sbufReadU8(sbuf_t *src); +int8_t sbufReadI8(sbuf_t *src); uint16_t sbufReadU16(sbuf_t *src); uint32_t sbufReadU32(sbuf_t *src); void sbufReadData(const sbuf_t *dst, void *data, int len); diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 168d0817126..50146de8aac 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2924,7 +2924,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) rxLinkStatistics.uplinkRSSI = -sbufReadU16(src); rxLinkStatistics.downlinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkLQ = sbufReadU8(src); - rxLinkStatistics.uplinkSNR = sbufReadU8(src); + rxLinkStatistics.uplinkSNR = sbufReadI8(src); } } else return MSP_RESULT_ERROR; From 1311e2be797f284dbe7e16d5152baeb38d2132b7 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 16:37:52 +0000 Subject: [PATCH 31/48] Allow snr_alarm to be set up to 99dB --- docs/Settings.md | 2 +- src/main/fc/settings.yaml | 2 +- src/main/io/osd.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Settings.md b/docs/Settings.md index ce4ff9c1ce4..f52da9c2c4b 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -5178,7 +5178,7 @@ Value below which Crossfire SNR Alarm pops-up. (dB) | Default | Min | Max | | --- | --- | --- | -| 4 | -20 | 10 | +| 4 | -20 | 99 | --- diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index fd6073fa4bd..f7ba8eb7bbd 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -3376,7 +3376,7 @@ groups: default_value: 4 field: snr_alarm min: -20 - max: 10 + max: 99 - name: osd_link_quality_alarm condition: USE_SERIALRX_CRSF description: "LQ % indicator blinks below this value. For Crossfire use 70%, for Tracer use 50%" diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 41c20dda928..67e401f6abc 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -2535,7 +2535,7 @@ static bool osdDrawSingleElement(uint8_t item) } } else if (snrFiltered <= osdConfig()->snr_alarm) { buff[0] = SYM_SNR; - if (snrFiltered <= -10) { + if (snrFiltered <= -10 || >= 10) { tfp_sprintf(buff + 1, "%3d%c", snrFiltered, SYM_DB); } else { tfp_sprintf(buff + 1, "%2d%c%c", snrFiltered, SYM_DB, ' '); From 7f2136c413ff144a7c398356a802a6cfb8a8d754 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 16:39:53 +0000 Subject: [PATCH 32/48] PG Bump --- src/main/io/osd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 67e401f6abc..2fdf8276814 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -224,7 +224,7 @@ static bool osdDisplayHasCanvas; #define AH_MAX_PITCH_DEFAULT 20 // Specify default maximum AHI pitch value displayed (degrees) -PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t, osdConfig, PG_OSD_CONFIG, 13); +PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t, osdConfig, PG_OSD_CONFIG, 14); PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 2); void osdStartedSaveProcess(void) { From 2c1afa1d5b010d74bdf5dbc843c01c24ce398245 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 16:41:10 +0000 Subject: [PATCH 33/48] Bug fix on OSD output of SNR --- src/main/io/osd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 2fdf8276814..2b8b634f001 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -2535,7 +2535,7 @@ static bool osdDrawSingleElement(uint8_t item) } } else if (snrFiltered <= osdConfig()->snr_alarm) { buff[0] = SYM_SNR; - if (snrFiltered <= -10 || >= 10) { + if (snrFiltered <= -10 || snrFiltered >= 10) { tfp_sprintf(buff + 1, "%3d%c", snrFiltered, SYM_DB); } else { tfp_sprintf(buff + 1, "%2d%c%c", snrFiltered, SYM_DB, ' '); From b48d7c8ad4e674ca412f248b1265b72b0d01a933 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 17:11:31 +0000 Subject: [PATCH 34/48] Add function to set the RSSI from MSP_RC --- src/main/fc/fc_msp.c | 2 +- src/main/rx/rx.c | 12 ++++++++++++ src/main/rx/rx.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 50146de8aac..20b30a71f1f 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2920,7 +2920,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) uint8_t sublinkID = sbufReadU8(src); // Sublink ID sbufReadU8(src); // Valid link (Failsafe backup) if (sublinkID == 1) { - setRSSIFromMSP(sbufReadU8(src)); // RSSI % + setRSSIFromMSP_RC(sbufReadU8(src)); // RSSI % rxLinkStatistics.uplinkRSSI = -sbufReadU16(src); rxLinkStatistics.downlinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkLQ = sbufReadU8(src); diff --git a/src/main/rx/rx.c b/src/main/rx/rx.c index f941eaebe20..5743f514959 100755 --- a/src/main/rx/rx.c +++ b/src/main/rx/rx.c @@ -572,6 +572,18 @@ static void setRSSIValue(uint16_t rssiValue, rssiSource_e source, bool filtered) rssi = constrain(scaleRange(rssi, rssiMin, rssiMax, 0, RSSI_MAX_VALUE), 0, RSSI_MAX_VALUE); } +void setRSSIFromMSP_RC(uint8_t newMspRssi) +{ + if (activeRssiSource == RSSI_SOURCE_NONE && (rxConfig()->rssi_source == RSSI_SOURCE_MSP || rxConfig()->rssi_source == RSSI_SOURCE_AUTO)) { + activeRssiSource = RSSI_SOURCE_MSP; + } + + if (activeRssiSource == RSSI_SOURCE_MSP) { + rssi = constrain(scaleRange(newMspRssi, 0, 100, 0, RSSI_MAX_VALUE), 0, RSSI_MAX_VALUE); + lastMspRssiUpdateUs = micros(); + } +} + void setRSSIFromMSP(uint8_t newMspRssi) { if (activeRssiSource == RSSI_SOURCE_NONE && (rxConfig()->rssi_source == RSSI_SOURCE_MSP || rxConfig()->rssi_source == RSSI_SOURCE_AUTO)) { diff --git a/src/main/rx/rx.h b/src/main/rx/rx.h index 4d8a76fecf5..64b97b172e2 100644 --- a/src/main/rx/rx.h +++ b/src/main/rx/rx.h @@ -216,6 +216,7 @@ bool isRxPulseValid(uint16_t pulseDuration); uint8_t calculateChannelRemapping(const uint8_t *channelMap, uint8_t channelMapEntryCount, uint8_t channelToRemap); void parseRcChannels(const char *input); +void setRSSIFromMSP_RC(uint8_t newMspRssi); void setRSSIFromMSP(uint8_t newMspRssi); void updateRSSI(timeUs_t currentTimeUs); // Returns RSSI in [0, RSSI_MAX_VALUE] range. From 102875384fe6b70049294db089d7ba894296500d Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 19:24:15 +0000 Subject: [PATCH 35/48] Update - Set base sublink ID to 0 - changed RSSI dB to uint8 as 16 is not needed - Added constraint to ensure that RSSI % is between 0 and 100 --- src/main/fc/fc_msp.c | 8 ++++---- src/main/rx/rx.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 20b30a71f1f..1ba0d3780f4 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2916,12 +2916,12 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) #ifdef USE_RX_MSP case MSP2_COMMON_SET_MSP_RC_LINK_STATS: - if (dataSize >= 8) { + if (dataSize >= 7) { uint8_t sublinkID = sbufReadU8(src); // Sublink ID sbufReadU8(src); // Valid link (Failsafe backup) - if (sublinkID == 1) { + if (sublinkID == 0) { setRSSIFromMSP_RC(sbufReadU8(src)); // RSSI % - rxLinkStatistics.uplinkRSSI = -sbufReadU16(src); + rxLinkStatistics.uplinkRSSI = -sbufReadU8(src); rxLinkStatistics.downlinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkSNR = sbufReadI8(src); @@ -2934,7 +2934,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) if (dataSize >= 15) { uint8_t sublinkID = sbufReadU8(src); - if (sublinkID == 1) { + if (sublinkID == 0) { rxLinkStatistics.uplinkTXPower = sbufReadU16(src); rxLinkStatistics.downlinkTXPower = sbufReadU16(src); diff --git a/src/main/rx/rx.c b/src/main/rx/rx.c index 5743f514959..00ed23ab25c 100755 --- a/src/main/rx/rx.c +++ b/src/main/rx/rx.c @@ -579,7 +579,7 @@ void setRSSIFromMSP_RC(uint8_t newMspRssi) } if (activeRssiSource == RSSI_SOURCE_MSP) { - rssi = constrain(scaleRange(newMspRssi, 0, 100, 0, RSSI_MAX_VALUE), 0, RSSI_MAX_VALUE); + rssi = constrain(scaleRange(constrain(newMspRssi, 0, 100), 0, 100, 0, RSSI_MAX_VALUE), 0, RSSI_MAX_VALUE); lastMspRssiUpdateUs = micros(); } } From 313459e19c6fce4dfe71868503ff835be9a8a2aa Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 19:41:53 +0000 Subject: [PATCH 36/48] Return `MSP_RESULT_NO_REPLY` flag --- src/main/fc/fc_msp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 1ba0d3780f4..0ef822231fe 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -1861,6 +1861,8 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) } rxMspFrameReceive(frame, channelCount); } + + return MSP_RESULT_NO_REPLY; } break; #endif @@ -2926,6 +2928,8 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) rxLinkStatistics.uplinkLQ = sbufReadU8(src); rxLinkStatistics.uplinkSNR = sbufReadI8(src); } + + return MSP_RESULT_NO_REPLY; } else return MSP_RESULT_ERROR; break; @@ -2946,6 +2950,8 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) rxLinkStatistics.mode[i] = sbufReadU8(src); } } + + return MSP_RESULT_NO_REPLY; } else return MSP_RESULT_ERROR; break; From 0655460ebef06c2c4485865af5006c322df8b9ee Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 20:13:51 +0000 Subject: [PATCH 37/48] Update fc_msp.c --- src/main/fc/fc_msp.c | 62 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 0ef822231fe..3182ede9700 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2917,43 +2917,45 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) break; #ifdef USE_RX_MSP - case MSP2_COMMON_SET_MSP_RC_LINK_STATS: - if (dataSize >= 7) { - uint8_t sublinkID = sbufReadU8(src); // Sublink ID - sbufReadU8(src); // Valid link (Failsafe backup) - if (sublinkID == 0) { - setRSSIFromMSP_RC(sbufReadU8(src)); // RSSI % - rxLinkStatistics.uplinkRSSI = -sbufReadU8(src); - rxLinkStatistics.downlinkLQ = sbufReadU8(src); - rxLinkStatistics.uplinkLQ = sbufReadU8(src); - rxLinkStatistics.uplinkSNR = sbufReadI8(src); - } + case MSP2_COMMON_SET_MSP_RC_LINK_STATS: { + if (dataSize >= 7) { + uint8_t sublinkID = sbufReadU8(src); // Sublink ID + sbufReadU8(src); // Valid link (Failsafe backup) + if (sublinkID == 0) { + setRSSIFromMSP_RC(sbufReadU8(src)); // RSSI % + rxLinkStatistics.uplinkRSSI = -sbufReadU8(src); + rxLinkStatistics.downlinkLQ = sbufReadU8(src); + rxLinkStatistics.uplinkLQ = sbufReadU8(src); + rxLinkStatistics.uplinkSNR = sbufReadI8(src); + } - return MSP_RESULT_NO_REPLY; - } else - return MSP_RESULT_ERROR; + return MSP_RESULT_NO_REPLY; + } else + return MSP_RESULT_ERROR; + } break; - case MSP2_COMMON_SET_MSP_RC_INFO: - if (dataSize >= 15) { - uint8_t sublinkID = sbufReadU8(src); + case MSP2_COMMON_SET_MSP_RC_INFO: { + if (dataSize >= 15) { + uint8_t sublinkID = sbufReadU8(src); - if (sublinkID == 0) { - rxLinkStatistics.uplinkTXPower = sbufReadU16(src); - rxLinkStatistics.downlinkTXPower = sbufReadU16(src); - - for (int i = 0; i < 4; i++) { - rxLinkStatistics.band[i] = sbufReadU8(src); - } + if (sublinkID == 0) { + rxLinkStatistics.uplinkTXPower = sbufReadU16(src); + rxLinkStatistics.downlinkTXPower = sbufReadU16(src); + + for (int i = 0; i < 4; i++) { + rxLinkStatistics.band[i] = sbufReadU8(src); + } - for (int i = 0; i < 6; i++) { - rxLinkStatistics.mode[i] = sbufReadU8(src); + for (int i = 0; i < 6; i++) { + rxLinkStatistics.mode[i] = sbufReadU8(src); + } } - } - return MSP_RESULT_NO_REPLY; - } else - return MSP_RESULT_ERROR; + return MSP_RESULT_NO_REPLY; + } else + return MSP_RESULT_ERROR; + } break; #endif From 5b6f691a6cf86d0f75b357be305ebd9d5ad98044 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Mon, 4 Nov 2024 20:11:12 +0000 Subject: [PATCH 38/48] Add PF and OSD code - Added new RX operands to programming framework - Added new OSD elements - Updated CRSF elements that are no longer exclusive to CRSF --- src/main/cms/cms_menu_osd.c | 8 +-- src/main/fc/settings.yaml | 10 ++-- src/main/io/osd.c | 77 ++++++++++++++++++-------- src/main/io/osd.h | 14 +++-- src/main/programming/logic_condition.c | 24 +++++--- src/main/programming/logic_condition.h | 5 +- 6 files changed, 91 insertions(+), 47 deletions(-) diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index e99e0cc52f2..0e85d0e656d 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -147,10 +147,10 @@ static const OSD_Entry menuCrsfRxEntries[]= OSD_SETTING_ENTRY("LQ ALARM LEVEL", SETTING_OSD_LINK_QUALITY_ALARM), OSD_SETTING_ENTRY("SNR ALARM LEVEL", SETTING_OSD_SNR_ALARM), OSD_SETTING_ENTRY("RX SENSITIVITY", SETTING_OSD_RSSI_DBM_MIN), - OSD_ELEMENT_ENTRY("RX RSSI DBM", OSD_CRSF_RSSI_DBM), - OSD_ELEMENT_ENTRY("RX LQ", OSD_CRSF_LQ), - OSD_ELEMENT_ENTRY("RX SNR ALARM", OSD_CRSF_SNR_DB), - OSD_ELEMENT_ENTRY("TX POWER", OSD_CRSF_TX_POWER), + OSD_ELEMENT_ENTRY("RX RSSI DBM", OSD_RSSI_DBM), + OSD_ELEMENT_ENTRY("RX LQ", OSD_LQ_UPLINK), + OSD_ELEMENT_ENTRY("RX SNR ALARM", OSD_SNR_DB), + OSD_ELEMENT_ENTRY("TX POWER", OSD_TX_POWER_UPLINK), OSD_BACK_AND_END_ENTRY, }; diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index f7ba8eb7bbd..1960e5dac67 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -3371,35 +3371,35 @@ groups: min: -550 max: 1250 - name: osd_snr_alarm - condition: USE_SERIALRX_CRSF + condition: USE_SERIALRX_CRSF || USE_RX_MSP description: "Value below which Crossfire SNR Alarm pops-up. (dB)" default_value: 4 field: snr_alarm min: -20 max: 99 - name: osd_link_quality_alarm - condition: USE_SERIALRX_CRSF + condition: USE_SERIALRX_CRSF || USE_RX_MSP description: "LQ % indicator blinks below this value. For Crossfire use 70%, for Tracer use 50%" default_value: 70 field: link_quality_alarm min: 0 max: 100 - name: osd_rssi_dbm_alarm - condition: USE_SERIALRX_CRSF + condition: USE_SERIALRX_CRSF || USE_RX_MSP description: "RSSI dBm indicator blinks below this value [dBm]. 0 disables this alarm" default_value: 0 field: rssi_dbm_alarm min: -130 max: 0 - name: osd_rssi_dbm_max - condition: USE_SERIALRX_CRSF + condition: USE_SERIALRX_CRSF || USE_RX_MSP description: "RSSI dBm upper end of curve. Perfect rssi (max) = 100%" default_value: -30 field: rssi_dbm_max min: -50 max: 0 - name: osd_rssi_dbm_min - condition: USE_SERIALRX_CRSF + condition: USE_SERIALRX_CRSF || USE_RX_MSP description: "RSSI dBm lower end of curve or RX sensitivity level. Worst rssi (min) = 0%" default_value: -120 field: rssi_dbm_min diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 2b8b634f001..71081843c78 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -225,7 +225,7 @@ static bool osdDisplayHasCanvas; #define AH_MAX_PITCH_DEFAULT 20 // Specify default maximum AHI pitch value displayed (degrees) PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t, osdConfig, PG_OSD_CONFIG, 14); -PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 2); +PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 3); void osdStartedSaveProcess(void) { savingSettings = true; @@ -2463,8 +2463,8 @@ static bool osdDrawSingleElement(uint8_t item) return true; } -#if defined(USE_SERIALRX_CRSF) - case OSD_CRSF_RSSI_DBM: +#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) + case OSD_RSSI_DBM: { int16_t rssi = rxLinkStatistics.uplinkRSSI; buff[0] = (rxLinkStatistics.activeAntenna == 0) ? SYM_RSSI : SYM_2RSS; // Separate symbols for each antenna @@ -2480,19 +2480,15 @@ static bool osdDrawSingleElement(uint8_t item) } break; } - case OSD_CRSF_LQ: + case OSD_LQ_UPLINK: { buff[0] = SYM_LQ; - int16_t statsLQ = rxLinkStatistics.uplinkLQ; - int16_t scaledLQ = scaleRange(constrain(statsLQ, 0, 100), 0, 100, 170, 300); - switch (osdConfig()->crsf_lq_format) { - case OSD_CRSF_LQ_TYPE1: - if (!failsafeIsReceivingRxData()) { - tfp_sprintf(buff+1, "%3d", 0); - } else { - tfp_sprintf(buff+1, "%3d", rxLinkStatistics.uplinkLQ); - } - break; + uint8_t lqFormat = osdConfig()->crsf_lq_format; + + if (rxConfig()->receiverType == RX_TYPE_MSP) + lqFormat = OSD_CRSF_LQ_TYPE1; + + switch (lqFormat) { case OSD_CRSF_LQ_TYPE2: if (!failsafeIsReceivingRxData()) { tfp_sprintf(buff+1, "%s:%3d", " ", 0); @@ -2504,9 +2500,18 @@ static bool osdDrawSingleElement(uint8_t item) if (!failsafeIsReceivingRxData()) { tfp_sprintf(buff+1, "%3d", 0); } else { + int16_t scaledLQ = scaleRange(constrain(rxLinkStatistics.uplinkLQ, 0, 100), 0, 100, 170, 300); tfp_sprintf(buff+1, "%3d", rxLinkStatistics.rfMode >= 2 ? scaledLQ : rxLinkStatistics.uplinkLQ); } break; + case OSD_CRSF_LQ_TYPE1: + default: + if (!failsafeIsReceivingRxData()) { + tfp_sprintf(buff+1, "%3d", 0); + } else { + tfp_sprintf(buff+1, "%3d", rxLinkStatistics.uplinkLQ); + } + break; } if (!failsafeIsReceivingRxData()) { TEXT_ATTRIBUTES_ADD_BLINK(elemAttr); @@ -2516,7 +2521,24 @@ static bool osdDrawSingleElement(uint8_t item) break; } - case OSD_CRSF_SNR_DB: + case OSD_LQ_DOWNLINK: + { + buff[0] = SYM_LQ; + if (!failsafeIsReceivingRxData()) { + tfp_sprintf(buff+1, "%3d%c", 0, SYM_AH_DECORATION_DOWN); + } else { + tfp_sprintf(buff+1, "%3d%c", rxLinkStatistics.downlinkLQ, SYM_AH_DECORATION_DOWN); + } + + if (!failsafeIsReceivingRxData()) { + TEXT_ATTRIBUTES_ADD_BLINK(elemAttr); + } else if (rxLinkStatistics.downlinkLQ < osdConfig()->link_quality_alarm) { + TEXT_ATTRIBUTES_ADD_BLINK(elemAttr); + } + break; + } + + case OSD_SNR_DB: { static pt1Filter_t snrFilterState; static timeMs_t snrUpdated = 0; @@ -2544,7 +2566,7 @@ static bool osdDrawSingleElement(uint8_t item) break; } - case OSD_CRSF_TX_POWER: + case OSD_TX_POWER_UPLINK: { if (!failsafeIsReceivingRxData()) tfp_sprintf(buff, "%s%c", " ", SYM_BLANK); @@ -2552,6 +2574,15 @@ static bool osdDrawSingleElement(uint8_t item) tfp_sprintf(buff, "%4d%c", rxLinkStatistics.uplinkTXPower, SYM_MW); break; } + + case OSD_RX_POWER_DOWNLINK: + { + if (!failsafeIsReceivingRxData()) + tfp_sprintf(buff, "%s%c%c", " ", SYM_BLANK, SYM_BLANK); + else + tfp_sprintf(buff, "%4d%c%c", rxLinkStatistics.downlinkTXPower, SYM_MW, SYM_AH_DECORATION_DOWN); + break; + } #endif case OSD_FORMATION_FLIGHT: @@ -3992,7 +4023,7 @@ PG_RESET_TEMPLATE(osdConfig_t, osdConfig, .adsb_distance_alert = SETTING_OSD_ADSB_DISTANCE_ALERT_DEFAULT, .adsb_ignore_plane_above_me_limit = SETTING_OSD_ADSB_IGNORE_PLANE_ABOVE_ME_LIMIT_DEFAULT, #endif -#ifdef USE_SERIALRX_CRSF +#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) .snr_alarm = SETTING_OSD_SNR_ALARM_DEFAULT, .crsf_lq_format = SETTING_OSD_CRSF_LQ_FORMAT_DEFAULT, .link_quality_alarm = SETTING_OSD_LINK_QUALITY_ALARM_DEFAULT, @@ -4143,11 +4174,13 @@ void pgResetFn_osdLayoutsConfig(osdLayoutsConfig_t *osdLayoutsConfig) osdLayoutsConfig->item_pos[0][OSD_PILOT_LOGO] = OSD_POS(20, 3); osdLayoutsConfig->item_pos[0][OSD_VTX_CHANNEL] = OSD_POS(8, 6); -#ifdef USE_SERIALRX_CRSF - osdLayoutsConfig->item_pos[0][OSD_CRSF_RSSI_DBM] = OSD_POS(23, 12); - osdLayoutsConfig->item_pos[0][OSD_CRSF_LQ] = OSD_POS(23, 11); - osdLayoutsConfig->item_pos[0][OSD_CRSF_SNR_DB] = OSD_POS(24, 9); - osdLayoutsConfig->item_pos[0][OSD_CRSF_TX_POWER] = OSD_POS(24, 10); +#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) + osdLayoutsConfig->item_pos[0][OSD_RSSI_DBM] = OSD_POS(23, 12); + osdLayoutsConfig->item_pos[0][OSD_LQ_UPLINK] = OSD_POS(23, 10); + osdLayoutsConfig->item_pos[0][OSD_LQ_DOWNLINK] = OSD_POS(23, 11); + osdLayoutsConfig->item_pos[0][OSD_SNR_DB] = OSD_POS(24, 9); + osdLayoutsConfig->item_pos[0][OSD_TX_POWER_UPLINK] = OSD_POS(24, 10); + osdLayoutsConfig->item_pos[0][OSD_RX_POWER_DOWNLINK] = OSD_POS(24, 11); #endif osdLayoutsConfig->item_pos[0][OSD_ONTIME] = OSD_POS(23, 8); diff --git a/src/main/io/osd.h b/src/main/io/osd.h index b0423d40eff..da2c9bb015c 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -242,10 +242,10 @@ typedef enum { OSD_ESC_RPM, OSD_ESC_TEMPERATURE, OSD_AZIMUTH, - OSD_CRSF_RSSI_DBM, - OSD_CRSF_LQ, - OSD_CRSF_SNR_DB, - OSD_CRSF_TX_POWER, + OSD_RSSI_DBM, + OSD_LQ_UPLINK, + OSD_SNR_DB, + OSD_TX_POWER_UPLINK, OSD_GVAR_0, OSD_GVAR_1, OSD_GVAR_2, @@ -291,7 +291,9 @@ typedef enum { OSD_CUSTOM_ELEMENT_5, OSD_CUSTOM_ELEMENT_6, OSD_CUSTOM_ELEMENT_7, - OSD_CUSTOM_ELEMENT_8, // 158 + OSD_CUSTOM_ELEMENT_8, + OSD_LQ_DOWNLINK, + OSD_RX_POWER_DOWNLINK, // 160 OSD_ITEM_COUNT // MUST BE LAST } osd_items_e; @@ -369,7 +371,7 @@ typedef struct osdConfig_s { float gforce_alarm; float gforce_axis_alarm_min; float gforce_axis_alarm_max; -#ifdef USE_SERIALRX_CRSF +#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) int8_t snr_alarm; //CRSF SNR alarm in dB int8_t link_quality_alarm; int16_t rssi_dbm_alarm; // in dBm diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index 594db21417c..facc595c3f4 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -796,20 +796,28 @@ static int logicConditionGetFlightOperandValue(int operand) { return constrain(calc_length_pythagorean_2D(GPS_distanceToHome, getEstimatedActualPosition(Z) / 100.0f), 0, INT32_MAX); break; - case LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_LQ: - #ifdef USE_SERIALRX_CRSF + case LOGIC_CONDITION_OPERAND_FLIGHT_LQ_UPLINK: +#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) return rxLinkStatistics.uplinkLQ; - #else +#else return 0; - #endif +#endif break; - case LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_SNR: - #ifdef USE_SERIALRX_CRSF +case LOGIC_CONDITION_OPERAND_FLIGHT_LQ_DOWNLINK: +#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) + return rxLinkStatistics.downlinkLQ; +#else + return 0; +#endif + break; + + case LOGIC_CONDITION_OPERAND_FLIGHT_SNR: +#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) return rxLinkStatistics.uplinkSNR; - #else +#else return 0; - #endif +#endif break; case LOGIC_CONDITION_OPERAND_FLIGHT_ACTIVE_PROFILE: // int diff --git a/src/main/programming/logic_condition.h b/src/main/programming/logic_condition.h index 74a7765be40..aaa80d51d53 100644 --- a/src/main/programming/logic_condition.h +++ b/src/main/programming/logic_condition.h @@ -129,8 +129,8 @@ typedef enum { LOGIC_CONDITION_OPERAND_FLIGHT_STABILIZED_PITCH, // 26 LOGIC_CONDITION_OPERAND_FLIGHT_STABILIZED_YAW, // 27 LOGIC_CONDITION_OPERAND_FLIGHT_3D_HOME_DISTANCE, // 28 - LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_LQ, // 29 - LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_SNR, // 39 + LOGIC_CONDITION_OPERAND_FLIGHT_LQ_UPLINK, // 29 + LOGIC_CONDITION_OPERAND_FLIGHT_SNR, // 39 LOGIC_CONDITION_OPERAND_FLIGHT_GPS_VALID, // 0/1 // 31 LOGIC_CONDITION_OPERAND_FLIGHT_LOITER_RADIUS, // 32 LOGIC_CONDITION_OPERAND_FLIGHT_ACTIVE_PROFILE, //int // 33 @@ -144,6 +144,7 @@ typedef enum { LOGIC_CONDITION_OPERAND_FLIGHT_FW_LAND_STATE, // 41 LOGIC_CONDITION_OPERAND_FLIGHT_BATT_PROFILE, // int // 42 LOGIC_CONDITION_OPERAND_FLIGHT_FLOWN_LOITER_RADIUS, // 43 + LOGIC_CONDITION_OPERAND_FLIGHT_LQ_DOWNLINK, // 44 } logicFlightOperands_e; typedef enum { From 4fa7acd25e055856b4bbdb1e780fa9b84a64aed9 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Mon, 4 Nov 2024 22:30:46 +0000 Subject: [PATCH 39/48] Added RX band and mode elements --- src/main/drivers/osd_symbols.h | 2 ++ src/main/io/osd.c | 11 +++++++++++ src/main/io/osd.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/main/drivers/osd_symbols.h b/src/main/drivers/osd_symbols.h index 90c0bc97131..fe673c93a57 100644 --- a/src/main/drivers/osd_symbols.h +++ b/src/main/drivers/osd_symbols.h @@ -234,6 +234,8 @@ #define SYM_AH_CH_CENTER 0x166 // 358 Crossair center #define SYM_FLIGHT_DIST_REMAINING 0x167 // 359 Flight distance reminaing #define SYM_ODOMETER 0x168 // 360 Odometer +#define SYM_RX_BAND 0x169 // 361 RX Band +#define SYM_RX_MODE 0x16A // 362 RX Mode #define SYM_AH_CH_TYPE3 0x190 // 400 to 402, crosshair 3 #define SYM_AH_CH_TYPE4 0x193 // 403 to 405, crosshair 4 diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 71081843c78..a7f9f024868 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -2583,6 +2583,15 @@ static bool osdDrawSingleElement(uint8_t item) tfp_sprintf(buff, "%4d%c%c", rxLinkStatistics.downlinkTXPower, SYM_MW, SYM_AH_DECORATION_DOWN); break; } + case OSD_RX_BAND: + displayWriteChar(osdDisplayPort, elemPosX++, elemPosY, SYM_RX_BAND); + strcat(buff, rxLinkStatistics.band); + break; + + case OSD_RX_MODE: + displayWriteChar(osdDisplayPort, elemPosX++, elemPosY, SYM_RX_MODE); + strcat(buff, rxLinkStatistics.mode); + break; #endif case OSD_FORMATION_FLIGHT: @@ -4181,6 +4190,8 @@ void pgResetFn_osdLayoutsConfig(osdLayoutsConfig_t *osdLayoutsConfig) osdLayoutsConfig->item_pos[0][OSD_SNR_DB] = OSD_POS(24, 9); osdLayoutsConfig->item_pos[0][OSD_TX_POWER_UPLINK] = OSD_POS(24, 10); osdLayoutsConfig->item_pos[0][OSD_RX_POWER_DOWNLINK] = OSD_POS(24, 11); + osdLayoutsConfig->item_pos[0][OSD_RX_BAND] = OSD_POS(24, 12); + osdLayoutsConfig->item_pos[0][OSD_RX_MODE] = OSD_POS(24, 13); #endif osdLayoutsConfig->item_pos[0][OSD_ONTIME] = OSD_POS(23, 8); diff --git a/src/main/io/osd.h b/src/main/io/osd.h index da2c9bb015c..c57bd62f640 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -294,6 +294,8 @@ typedef enum { OSD_CUSTOM_ELEMENT_8, OSD_LQ_DOWNLINK, OSD_RX_POWER_DOWNLINK, // 160 + OSD_RX_BAND, + OSD_RX_MODE, OSD_ITEM_COUNT // MUST BE LAST } osd_items_e; From 44aca2a86bee25732ae686442736927e602a2aae Mon Sep 17 00:00:00 2001 From: TUNERC-Aria <71423100+TUNERC-Aria@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:42:56 +0800 Subject: [PATCH 40/48] Update target.h Removed the wrong USART4 --- src/main/target/TUNERCF405/target.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/target/TUNERCF405/target.h b/src/main/target/TUNERCF405/target.h index 093da2fadf6..b359545e697 100644 --- a/src/main/target/TUNERCF405/target.h +++ b/src/main/target/TUNERCF405/target.h @@ -105,7 +105,6 @@ #define UART4_TX_PIN PA0 #define USE_UART_INVERTER #define INVERTER_PIN_UART4_RX PC14 -#define INVERTER_PIN_USART4_RX PC14 #define USE_UART5 #define UART5_RX_PIN PD2 From 95f0f47bdffa4a53f1bbf0aff9aeff4dd127d9bf Mon Sep 17 00:00:00 2001 From: TUNERC-Aria <71423100+TUNERC-Aria@users.noreply.github.com> Date: Tue, 5 Nov 2024 23:59:17 +0800 Subject: [PATCH 41/48] Update uart_inverter.c f405 does not have USART4. --- src/main/drivers/uart_inverter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/uart_inverter.c b/src/main/drivers/uart_inverter.c index b815883df79..5168831b471 100644 --- a/src/main/drivers/uart_inverter.c +++ b/src/main/drivers/uart_inverter.c @@ -145,7 +145,12 @@ void uartInverterSet(USART_TypeDef *USARTx, uartInverterLine_e line, bool enable // UART4 #if defined(INVERTER_PIN_UART4_RX) || defined(INVERTER_PIN_UART4_TX) - if (USARTx == USART4) { +#if defined(STM32F4) + if (USARTx == UART4) +#else + if (USARTx == USART4) +#endif + { #if defined(INVERTER_PIN_UART4_RX) rx_pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART4_RX)); #endif From ec014c51f5240bcb5dce4399aa7c644db7419e78 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Tue, 5 Nov 2024 20:47:17 +0000 Subject: [PATCH 42/48] Added uplink RSSI dBm to programming framework --- src/main/programming/logic_condition.c | 8 ++++++++ src/main/programming/logic_condition.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index facc595c3f4..5b7310b4b1f 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -804,6 +804,14 @@ static int logicConditionGetFlightOperandValue(int operand) { #endif break; + case LOGIC_CONDITION_OPERAND_FLIGHT_UPLINK_RSSI_DBM: +#if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) + return rxLinkStatistics.uplinkRSSI; +#else + return 0; +#endif + break; + case LOGIC_CONDITION_OPERAND_FLIGHT_LQ_DOWNLINK: #if defined(USE_SERIALRX_CRSF) || defined(USE_RX_MSP) return rxLinkStatistics.downlinkLQ; diff --git a/src/main/programming/logic_condition.h b/src/main/programming/logic_condition.h index aaa80d51d53..f5653bb68cc 100644 --- a/src/main/programming/logic_condition.h +++ b/src/main/programming/logic_condition.h @@ -145,6 +145,7 @@ typedef enum { LOGIC_CONDITION_OPERAND_FLIGHT_BATT_PROFILE, // int // 42 LOGIC_CONDITION_OPERAND_FLIGHT_FLOWN_LOITER_RADIUS, // 43 LOGIC_CONDITION_OPERAND_FLIGHT_LQ_DOWNLINK, // 44 + LOGIC_CONDITION_OPERAND_FLIGHT_UPLINK_RSSI_DBM, // 45 } logicFlightOperands_e; typedef enum { From 24c1ed91f9cfe2e926bed9431d5b77857f56c9cd Mon Sep 17 00:00:00 2001 From: jamming Date: Thu, 7 Nov 2024 15:21:50 +0800 Subject: [PATCH 43/48] Add spa06 and spl07 baro for Kakutef4/f7 FC --- src/main/target/KAKUTEF4/target.h | 2 ++ src/main/target/KAKUTEF7/target.h | 2 ++ src/main/target/KAKUTEF7MINIV3/target.h | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/main/target/KAKUTEF4/target.h b/src/main/target/KAKUTEF4/target.h index c1ce47b9e80..92cbcf13414 100644 --- a/src/main/target/KAKUTEF4/target.h +++ b/src/main/target/KAKUTEF4/target.h @@ -78,6 +78,8 @@ # define BARO_I2C_BUS BUS_I2C1 # define USE_BARO_MS5611 # define USE_BARO_BMP280 +# define USE_BARO_DPS310 +# define USE_BARO_SPL06 #else // V1 does not have I2C exposed, common_post.h will pull in USE_*_MSP # define USE_BARO # define USE_MAG diff --git a/src/main/target/KAKUTEF7/target.h b/src/main/target/KAKUTEF7/target.h index f3f4edfed40..79f9d079353 100644 --- a/src/main/target/KAKUTEF7/target.h +++ b/src/main/target/KAKUTEF7/target.h @@ -131,6 +131,8 @@ #define USE_BARO #define USE_BARO_BMP280 #define USE_BARO_MS5611 +#define USE_BARO_DPS310 +#define USE_BARO_SPL06 #define BARO_I2C_BUS BUS_I2C1 #define USE_MAG diff --git a/src/main/target/KAKUTEF7MINIV3/target.h b/src/main/target/KAKUTEF7MINIV3/target.h index bf485ebc82b..89ba7c632b5 100644 --- a/src/main/target/KAKUTEF7MINIV3/target.h +++ b/src/main/target/KAKUTEF7MINIV3/target.h @@ -117,6 +117,8 @@ #define BARO_I2C_BUS BUS_I2C1 #define USE_BARO_BMP280 #define USE_BARO_MS5611 +#define USE_BARO_DPS310 +#define USE_BARO_SPL06 /* * Mag From 363bf09be0b4a9fe600ba287ba4594c41c905de4 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sat, 9 Nov 2024 08:36:01 +0000 Subject: [PATCH 44/48] Updates - Force band and mode to uppercase - Fix bug with band and mode not finalising the string output to the OSD - Changed RSSI dBm and SNR display outputs slightly. So that the OSD is more consistent - Show mW symbol for power elements when no data is present. Again, more consistency and doesn't make people wonder why the elements are not showing up. --- src/main/fc/fc_msp.c | 5 +++++ src/main/io/osd.c | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 3182ede9700..989fdee5521 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -34,6 +34,7 @@ #include "common/color.h" #include "common/maths.h" #include "common/streambuf.h" +#include "common/string_light.h" #include "common/bitarray.h" #include "common/time.h" #include "common/utils.h" @@ -2947,9 +2948,13 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) rxLinkStatistics.band[i] = sbufReadU8(src); } + sl_toupperptr(rxLinkStatistics.band); + for (int i = 0; i < 6; i++) { rxLinkStatistics.mode[i] = sbufReadU8(src); } + + sl_toupperptr(rxLinkStatistics.mode); } return MSP_RESULT_NO_REPLY; diff --git a/src/main/io/osd.c b/src/main/io/osd.c index a7f9f024868..3370ced1075 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -2471,7 +2471,7 @@ static bool osdDrawSingleElement(uint8_t item) if (rssi <= -100) { tfp_sprintf(buff + 1, "%4d%c", rssi, SYM_DBM); } else { - tfp_sprintf(buff + 1, "%3d%c%c", rssi, SYM_DBM, ' '); + tfp_sprintf(buff + 1, " %3d%c", rssi, SYM_DBM); } if (!failsafeIsReceivingRxData()){ TEXT_ATTRIBUTES_ADD_BLINK(elemAttr); @@ -2560,7 +2560,7 @@ static bool osdDrawSingleElement(uint8_t item) if (snrFiltered <= -10 || snrFiltered >= 10) { tfp_sprintf(buff + 1, "%3d%c", snrFiltered, SYM_DB); } else { - tfp_sprintf(buff + 1, "%2d%c%c", snrFiltered, SYM_DB, ' '); + tfp_sprintf(buff + 1, " %2d%c", snrFiltered, SYM_DB); } } break; @@ -2569,7 +2569,7 @@ static bool osdDrawSingleElement(uint8_t item) case OSD_TX_POWER_UPLINK: { if (!failsafeIsReceivingRxData()) - tfp_sprintf(buff, "%s%c", " ", SYM_BLANK); + tfp_sprintf(buff, "%s%c", " ", SYM_MW); else tfp_sprintf(buff, "%4d%c", rxLinkStatistics.uplinkTXPower, SYM_MW); break; @@ -2578,7 +2578,7 @@ static bool osdDrawSingleElement(uint8_t item) case OSD_RX_POWER_DOWNLINK: { if (!failsafeIsReceivingRxData()) - tfp_sprintf(buff, "%s%c%c", " ", SYM_BLANK, SYM_BLANK); + tfp_sprintf(buff, "%s%c%c", " ", SYM_MW, SYM_AH_DECORATION_DOWN); else tfp_sprintf(buff, "%4d%c%c", rxLinkStatistics.downlinkTXPower, SYM_MW, SYM_AH_DECORATION_DOWN); break; @@ -2586,11 +2586,13 @@ static bool osdDrawSingleElement(uint8_t item) case OSD_RX_BAND: displayWriteChar(osdDisplayPort, elemPosX++, elemPosY, SYM_RX_BAND); strcat(buff, rxLinkStatistics.band); + buff[4] = '\0'; break; case OSD_RX_MODE: displayWriteChar(osdDisplayPort, elemPosX++, elemPosY, SYM_RX_MODE); strcat(buff, rxLinkStatistics.mode); + buff[6] = '\0'; break; #endif From 026ca5897636675af34ff821ddbbd56f2dd7f263 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sat, 9 Nov 2024 10:06:18 +0000 Subject: [PATCH 45/48] Set lengths for strings in band and mode --- src/main/io/osd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 3370ced1075..729c98474bd 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -2585,13 +2585,13 @@ static bool osdDrawSingleElement(uint8_t item) } case OSD_RX_BAND: displayWriteChar(osdDisplayPort, elemPosX++, elemPosY, SYM_RX_BAND); - strcat(buff, rxLinkStatistics.band); + tfp_sprintf(buff, "%4s", rxLinkStatistics.band); buff[4] = '\0'; break; case OSD_RX_MODE: displayWriteChar(osdDisplayPort, elemPosX++, elemPosY, SYM_RX_MODE); - strcat(buff, rxLinkStatistics.mode); + tfp_sprintf(buff, "%6s", rxLinkStatistics.mode); buff[6] = '\0'; break; #endif From 619948e7b69b65f094593098dff881879b6a8e77 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sat, 9 Nov 2024 11:17:52 +0000 Subject: [PATCH 46/48] Make band and mode left aligned --- src/main/io/osd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 729c98474bd..ac88e83c476 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -2585,13 +2585,19 @@ static bool osdDrawSingleElement(uint8_t item) } case OSD_RX_BAND: displayWriteChar(osdDisplayPort, elemPosX++, elemPosY, SYM_RX_BAND); - tfp_sprintf(buff, "%4s", rxLinkStatistics.band); + strcat(buff, rxLinkStatistics.band); + if (strlen(rxLinkStatistics.band) < 4) + for (uint8_t i = strlen(rxLinkStatistics.band); i < 4; i++) + buff[i] = ' '; buff[4] = '\0'; break; case OSD_RX_MODE: displayWriteChar(osdDisplayPort, elemPosX++, elemPosY, SYM_RX_MODE); - tfp_sprintf(buff, "%6s", rxLinkStatistics.mode); + strcat(buff, rxLinkStatistics.mode); + if (strlen(rxLinkStatistics.mode) < 6) + for (uint8_t i = strlen(rxLinkStatistics.mode); i < 6; i++) + buff[i] = ' '; buff[6] = '\0'; break; #endif From dc3477fa46a536ffa2b1c591e90be774c00591e8 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Mon, 11 Nov 2024 16:59:25 +0000 Subject: [PATCH 47/48] Update fc_msp.c --- src/main/fc/fc_msp.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 7a0ed98bdf9..57b68f02402 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -1862,8 +1862,6 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) } rxMspFrameReceive(frame, channelCount); } - - return MSP_RESULT_NO_REPLY; } break; #endif From 9fb51e0655b067aa9ca4e7bcbb1bcfda304fbadc Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Wed, 13 Nov 2024 18:22:57 +0000 Subject: [PATCH 48/48] [mspv2] pass "flags" field back to sender, define ILMI flag (#10464) --- src/main/fc/fc_msp.c | 12 ++++++------ src/main/msp/msp.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 57b68f02402..f490d28128a 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2717,7 +2717,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) vtxSettingsConfigMutable()->lowPowerDisarm = sbufReadU8(src); } - // API version 1.42 - extension for pitmode frequency + // API version 1.42 - extension for pitmode frequency if (sbufBytesRemaining(src) >= 2) { sbufReadU16(src); //skip pitModeFreq } @@ -2738,15 +2738,15 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) if (sbufBytesRemaining(src) >= 2) { sbufReadU16(src); // freq } - + if (sbufBytesRemaining(src) >= 3) { sbufReadU8(src); // band count sbufReadU8(src); // channel count - + uint8_t newPowerCount = sbufReadU8(src); if (newPowerCount > 0 && newPowerCount < (vtxDevice->capability.powerCount)) { vtxDevice->capability.powerCount = newPowerCount; - } + } } } } @@ -2944,7 +2944,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) if (sublinkID == 0) { rxLinkStatistics.uplinkTXPower = sbufReadU16(src); rxLinkStatistics.downlinkTXPower = sbufReadU16(src); - + for (int i = 0; i < 4; i++) { rxLinkStatistics.band[i] = sbufReadU8(src); } @@ -4249,7 +4249,7 @@ mspResult_e mspFcProcessCommand(mspPacket_t *cmd, mspPacket_t *reply, mspPostPro if (cmd->flags & MSP_FLAG_DONT_REPLY) { ret = MSP_RESULT_NO_REPLY; } - + reply->flags = cmd->flags; reply->result = ret; return ret; } diff --git a/src/main/msp/msp.h b/src/main/msp/msp.h index 0c00b81ece7..e988ea2eddf 100644 --- a/src/main/msp/msp.h +++ b/src/main/msp/msp.h @@ -46,6 +46,7 @@ typedef struct mspPacket_s { typedef enum { MSP_FLAG_DONT_REPLY = (1 << 0), + MSP_FLAG_ILMI = (1 << 1), // "In-Line Message identifier" } mspFlags_e; struct serialPort_s;