From e4627d030d894234debd667cfc91c5879ad3b5e3 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sat, 2 Nov 2024 22:11:19 +0000 Subject: [PATCH 01/23] 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 02/23] 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 03/23] 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 04/23] 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 05/23] 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 06/23] 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 07/23] 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 99b1a1513424b4582d1880c47463d44f438d2442 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sun, 3 Nov 2024 15:45:59 +0000 Subject: [PATCH 08/23] 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 09/23] 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 10/23] 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 11/23] 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 12/23] 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 13/23] 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 14/23] 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 15/23] 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 16/23] 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 17/23] 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 18/23] 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 19/23] 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 ec014c51f5240bcb5dce4399aa7c644db7419e78 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Tue, 5 Nov 2024 20:47:17 +0000 Subject: [PATCH 20/23] 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 363bf09be0b4a9fe600ba287ba4594c41c905de4 Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Sat, 9 Nov 2024 08:36:01 +0000 Subject: [PATCH 21/23] 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 22/23] 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 23/23] 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