Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for returning TX backpack version #75

Merged
merged 3 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/MSP/msp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 1 addition & 5 deletions lib/MSP/msp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

#include <Arduino.h>

// 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) {\
Expand Down
3 changes: 3 additions & 0 deletions lib/MSP/msptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/Tx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
pkendall64 marked this conversation as resolved.
Show resolved Hide resolved

connectionState_e connectionState = starting;
unsigned long rebootTime = 0;

Expand Down Expand Up @@ -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 ; i<sizeof(version) ; i++)
pkendall64 marked this conversation as resolved.
Show resolved Hide resolved
out.addByte(version[i]);
msp.sendPacket(&out, &Serial);
}

void ProcessMSPPacketFromTX(mspPacket_t *packet)
{
if (packet->function == MSP_ELRS_BIND)
Expand Down Expand Up @@ -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);
Expand Down