From b67b440ede37d48dffa0187b32ee1584bee7b986 Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Mon, 9 Jan 2023 15:28:50 +1300 Subject: [PATCH 1/2] Add support for returning TX backpack version --- lib/MSP/msp.cpp | 5 ++++- lib/MSP/msp.h | 6 +----- lib/MSP/msptypes.h | 3 +++ src/Tx_main.cpp | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/MSP/msp.cpp b/lib/MSP/msp.cpp index ff1ac10..04b2e8e 100644 --- a/lib/MSP/msp.cpp +++ b/lib/MSP/msp.cpp @@ -97,7 +97,10 @@ MSP::processReceivedByte(uint8_t c) m_packet.flags = header->flags; // reset the offset iterator for re-use in payload below m_offset = 0; - m_inputState = MSP_PAYLOAD_V2_NATIVE; + if (m_packet.payloadSize == 0) + m_inputState = MSP_CHECKSUM_V2_NATIVE; + else + m_inputState = MSP_PAYLOAD_V2_NATIVE; } break; diff --git a/lib/MSP/msp.h b/lib/MSP/msp.h index db51b06..7e99ee0 100644 --- a/lib/MSP/msp.h +++ b/lib/MSP/msp.h @@ -2,11 +2,7 @@ #include -// TODO: MSP_PORT_INBUF_SIZE should be changed to -// dynamically allocate array length based on the payload size -// Hardcoding payload size to 8 bytes for now, since MSP is -// limited to a 4 byte payload on the BF side -#define MSP_PORT_INBUF_SIZE 8 +#define MSP_PORT_INBUF_SIZE 32 #define CHECK_PACKET_PARSING() \ if (packet->readError) {\ diff --git a/lib/MSP/msptypes.h b/lib/MSP/msptypes.h index 5a59156..63768d1 100644 --- a/lib/MSP/msptypes.h +++ b/lib/MSP/msptypes.h @@ -16,6 +16,9 @@ #define MSP_ELRS_REQU_VTX_PKT 0x0B #define MSP_ELRS_SET_TX_BACKPACK_WIFI_MODE 0x0C #define MSP_ELRS_SET_VRX_BACKPACK_WIFI_MODE 0x0D +#define MSP_ELRS_SET_RX_WIFI_MODE 0x0E +#define MSP_ELRS_SET_RX_LOAN_MODE 0x0F +#define MSP_ELRS_GET_BACKPACK_VERSION 0x10 // CRSF encapsulated msp defines #define ENCAPSULATED_MSP_PAYLOAD_SIZE 4 diff --git a/src/Tx_main.cpp b/src/Tx_main.cpp index 9f69b0d..7cd64b8 100644 --- a/src/Tx_main.cpp +++ b/src/Tx_main.cpp @@ -23,6 +23,8 @@ uint8_t broadcastAddress[6] = {0, 0, 0, 0, 0, 0}; #endif uint8_t bindingAddress[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +const uint8_t version[] = {LATEST_VERSION}; + connectionState_e connectionState = starting; unsigned long rebootTime = 0; @@ -98,6 +100,17 @@ void OnDataRecv(uint8_t * mac_addr, uint8_t *data, uint8_t data_len) blinkLED(); } +void SendVersionResponse() +{ + mspPacket_t out; + out.reset(); + out.makeResponse(); + out.function = MSP_ELRS_GET_BACKPACK_VERSION; + for (size_t i=0 ; ifunction == MSP_ELRS_BIND) @@ -134,6 +147,10 @@ void ProcessMSPPacketFromTX(mspPacket_t *packet) DBGLN("Processing MSP_ELRS_SET_TX_BACKPACK_WIFI_MODE..."); RebootIntoWifi(); break; + case MSP_ELRS_GET_BACKPACK_VERSION: + DBGLN("Processing MSP_ELRS_GET_BACKPACK_VERSION..."); + SendVersionResponse(); + break; default: // transparently forward MSP packets via espnow to any subscribers sendMSPViaEspnow(packet); From 330c7e3ab83063f077454f955de3746a25a40ee1 Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Sun, 12 Feb 2023 20:47:07 +1300 Subject: [PATCH 2/2] cleanup after review --- src/Tx_main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Tx_main.cpp b/src/Tx_main.cpp index 7cd64b8..6354172 100644 --- a/src/Tx_main.cpp +++ b/src/Tx_main.cpp @@ -106,8 +106,10 @@ void SendVersionResponse() out.reset(); out.makeResponse(); out.function = MSP_ELRS_GET_BACKPACK_VERSION; - for (size_t i=0 ; i