Skip to content

Commit

Permalink
Merge pull request #75 from pkendall64/backpack-version
Browse files Browse the repository at this point in the history
Add support for returning TX backpack version
  • Loading branch information
pkendall64 committed Feb 12, 2023
2 parents 0021275 + 09d2dad commit 8b3b0f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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
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
#define MSP_ELRS_SET_OSD 0x00B6

// CRSF encapsulated msp defines
Expand Down
19 changes: 19 additions & 0 deletions src/Tx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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;

Expand Down Expand Up @@ -116,6 +118,19 @@ void OnDataRecv(const uint8_t * mac_addr, const uint8_t *data, int 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++)
{
out.addByte(version[i]);
}
msp.sendPacket(&out, &Serial);
}

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

0 comments on commit 8b3b0f2

Please sign in to comment.