diff --git a/src/main/rx/crsf.c b/src/main/rx/crsf.c index f37cba0ae4..e06c6dc8d1 100644 --- a/src/main/rx/crsf.c +++ b/src/main/rx/crsf.c @@ -190,6 +190,7 @@ STATIC_UNIT_TESTED uint8_t crsfFrameStatus(void) // TODO: CRC CHECK scheduleDeviceInfoResponse(); return RX_FRAME_COMPLETE; +#if defined(USE_MSP_OVER_TELEMETRY) } else if (crsfFrame.frame.type == CRSF_FRAMETYPE_MSP_REQ || crsfFrame.frame.type == CRSF_FRAMETYPE_MSP_WRITE) { // TODO: CRC CHECK uint8_t *frameStart = (uint8_t *)&crsfFrame.frame.payload + 2; @@ -198,6 +199,7 @@ STATIC_UNIT_TESTED uint8_t crsfFrameStatus(void) scheduleMspResponse(); } return RX_FRAME_COMPLETE; +#endif } } } diff --git a/src/main/target/common_fc_post.h b/src/main/target/common_fc_post.h index 9fecb75121..19362d6766 100644 --- a/src/main/target/common_fc_post.h +++ b/src/main/target/common_fc_post.h @@ -50,3 +50,9 @@ #undef USE_BARO_MS5611 #endif #endif + +#if defined(USE_MSP_OVER_TELEMETRY) +#if !defined(TELEMETRY_SMARTPORT) && !defined(TELEMETRY_CRSF) +#undef USE_MSP_OVER_TELEMETRY +#endif +#endif diff --git a/src/main/target/common_fc_pre.h b/src/main/target/common_fc_pre.h index 4f0c4165d5..faf9f078d8 100644 --- a/src/main/target/common_fc_pre.h +++ b/src/main/target/common_fc_pre.h @@ -102,6 +102,7 @@ #define TELEMETRY_LTM #define TELEMETRY_SMARTPORT #define USE_RESOURCE_MGMT +#define USE_SERVOS #endif #if (FLASH_SIZE > 128) @@ -117,7 +118,6 @@ #define USE_RX_MSP #define USE_SERIALRX_JETIEXBUS #define USE_SENSOR_NAMES -#define USE_SERVOS #define USE_VIRTUAL_CURRENT_METER #define VTX_COMMON #define VTX_CONTROL @@ -126,6 +126,7 @@ #define USE_CAMERA_CONTROL #define USE_HUFFMAN #define USE_COPY_PROFILE_CMS_MENU +#define USE_MSP_OVER_TELEMETRY #ifdef USE_SERIALRX_SPEKTRUM #define USE_SPEKTRUM_BIND diff --git a/src/main/telemetry/crsf.c b/src/main/telemetry/crsf.c index c1deb636b3..2071ea404e 100644 --- a/src/main/telemetry/crsf.c +++ b/src/main/telemetry/crsf.c @@ -63,7 +63,9 @@ static bool crsfTelemetryEnabled; static bool deviceInfoReplyPending; +#if defined(USE_MSP_OVER_TELEMETRY) static bool mspReplyPending; +#endif static uint8_t crsfFrame[CRSF_FRAME_SIZE_MAX]; static void crsfInitializeFrame(sbuf_t *dst) @@ -280,6 +282,7 @@ typedef enum { static uint8_t crsfScheduleCount; static uint8_t crsfSchedule[CRSF_SCHEDULE_COUNT_MAX]; +#if defined(USE_MSP_OVER_TELEMETRY) void scheduleMspResponse() { if (!mspReplyPending) { mspReplyPending = true; @@ -298,7 +301,8 @@ void crsfSendMspResponse(uint8_t *payload) sbufWriteU8(dst, CRSF_ADDRESS_BETAFLIGHT); sbufWriteData(dst, payload, CRSF_FRAME_TX_MSP_PAYLOAD_SIZE); crsfFinalize(dst); - } +} +#endif static void processCrsf(void) { @@ -341,7 +345,9 @@ void initCrsfTelemetry(void) crsfTelemetryEnabled = crsfRxIsActive(); deviceInfoReplyPending = false; +#if defined(USE_MSP_OVER_TELEMETRY) mspReplyPending = false; +#endif int index = 0; crsfSchedule[index++] = BV(CRSF_FRAME_ATTITUDE_INDEX); @@ -384,8 +390,10 @@ void handleCrsfTelemetry(timeUs_t currentTimeUs) crsfFrameDeviceInfo(dst); crsfFinalize(dst); deviceInfoReplyPending = false; +#if defined(USE_MSP_OVER_TELEMETRY) } else if (mspReplyPending) { mspReplyPending = sendMspReply(CRSF_FRAME_TX_MSP_PAYLOAD_SIZE, &crsfSendMspResponse); +#endif } else { processCrsf(); } diff --git a/src/main/telemetry/msp_shared.c b/src/main/telemetry/msp_shared.c index 699571f3d7..29eb38b6d0 100644 --- a/src/main/telemetry/msp_shared.c +++ b/src/main/telemetry/msp_shared.c @@ -6,7 +6,7 @@ #include "platform.h" -#ifdef TELEMETRY +#if defined(USE_MSP_OVER_TELEMETRY) #include "build/build_config.h" diff --git a/src/main/telemetry/smartport.c b/src/main/telemetry/smartport.c index e29e45fe2a..888d4cc485 100644 --- a/src/main/telemetry/smartport.c +++ b/src/main/telemetry/smartport.c @@ -169,7 +169,9 @@ typedef struct smartPortFrame_s { static smartPortFrame_t smartPortRxBuffer; static uint8_t smartPortRxBytes = 0; static bool smartPortFrameReceived = false; +#if defined(USE_MSP_OVER_TELEMETRY) static bool smartPortMspReplyPending = false; +#endif static void smartPortDataReceive(uint16_t c) { @@ -327,9 +329,11 @@ void checkSmartPortTelemetryState(void) freeSmartPortTelemetryPort(); } +#if defined(USE_MSP_OVER_TELEMETRY) void smartPortSendMspResponse(uint8_t *payload) { smartPortSendPackageEx(FSSP_MSPS_FRAME, payload); } +#endif void handleSmartPortTelemetry(void) { @@ -352,6 +356,8 @@ void handleSmartPortTelemetry(void) smartPortFrameReceived = false; // do not check the physical ID here again // unless we start receiving other sensors' packets + +#if defined(USE_MSP_OVER_TELEMETRY) if (smartPortRxBuffer.frameId == FSSP_MSPC_FRAME) { // Pass only the payload: skip sensorId & frameId @@ -361,6 +367,7 @@ void handleSmartPortTelemetry(void) smartPortMspReplyPending = handleMspFrame(frameStart, frameEnd); } } +#endif } while (smartPortHasRequest) { @@ -370,11 +377,13 @@ void handleSmartPortTelemetry(void) return; } +#if defined(USE_MSP_OVER_TELEMETRY) if (smartPortMspReplyPending) { smartPortMspReplyPending = sendMspReply(SMARTPORT_PAYLOAD_SIZE, &smartPortSendMspResponse); smartPortHasRequest = 0; return; } +#endif // we can send back any data we want, our table keeps track of the order and frequency of each data type we send uint16_t id = frSkyDataIdTable[smartPortIdCnt]; diff --git a/src/main/telemetry/telemetry.c b/src/main/telemetry/telemetry.c index 9f9fe12663..369d8a38c4 100644 --- a/src/main/telemetry/telemetry.c +++ b/src/main/telemetry/telemetry.c @@ -101,7 +101,9 @@ void telemetryInit(void) #ifdef TELEMETRY_IBUS initIbusTelemetry(); #endif +#if defined(USE_MSP_OVER_TELEMETRY) initSharedMsp(); +#endif telemetryCheckState(); } diff --git a/src/test/Makefile b/src/test/Makefile index 7a18803e3c..96562f9eb7 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -214,6 +214,13 @@ telemetry_crsf_unittest_SRC := \ $(USER_DIR)/common/typeconversion.c \ $(USER_DIR)/fc/runtime_config.c +telemetry_crsf_unittest_DEFINES := \ + FLASH_SIZE=128 \ + STM32F10X_MD \ + __TARGET__="TEST" \ + __REVISION__="revision" + + telemetry_crsf_msp_unittest_SRC := \ $(USER_DIR)/rx/crsf.c \ $(USER_DIR)/common/crc.c \ @@ -227,12 +234,8 @@ telemetry_crsf_msp_unittest_SRC := \ $(USER_DIR)/telemetry/msp_shared.c \ $(USER_DIR)/fc/runtime_config.c - -telemetry_crsf_unittest_DEFINES := \ - FLASH_SIZE=128 \ - STM32F10X_MD \ - __TARGET__="TEST" \ - __REVISION__="revision" +telemetry_crsf_msp_unittest_DEFINES := \ + USE_MSP_OVER_TELEMETRY telemetry_hott_unittest_SRC := \