1111
1212#include " msp.h"
1313#include " msptypes.h"
14+ #include " ESPNOW_Helpers.h"
1415#include " logging.h"
1516#include " config.h"
1617#include " common.h"
2829
2930// ///////// GLOBALS ///////////
3031
31- uint8_t bindingAddress[6 ] = {0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
32-
3332const uint8_t version[] = {LATEST_VERSION};
3433
3534connectionState_e connectionState = starting;
@@ -61,11 +60,6 @@ mspPacket_t cachedHTPacket;
6160MAVLink mavlink;
6261#endif
6362
64- // ///////// FUNCTION DEFS ///////////
65-
66- void sendMSPViaEspnow (mspPacket_t *packet);
67-
68- // ///////////////////////////////////
6963
7064#if defined(PLATFORM_ESP32)
7165// This seems to need to be global, as per this page,
@@ -200,7 +194,7 @@ void ProcessMSPPacketFromTX(mspPacket_t *packet)
200194 DBG (" " ); // Extra line for serial output readability
201195 config.Commit ();
202196 // delay(500); // delay may not be required
203- sendMSPViaEspnow (packet);
197+ ESPNOW:: sendMSPViaEspnow (packet);
204198 // delay(500); // delay may not be required
205199 rebootTime = millis (); // restart to set SetSoftMACAddress
206200 }
@@ -212,11 +206,11 @@ void ProcessMSPPacketFromTX(mspPacket_t *packet)
212206 cachedVTXPacket = *packet;
213207 cacheFull = true ;
214208 // transparently forward MSP packets via espnow to any subscribers
215- sendMSPViaEspnow (packet);
209+ ESPNOW:: sendMSPViaEspnow (packet);
216210 break ;
217211 case MSP_ELRS_SET_VRX_BACKPACK_WIFI_MODE:
218212 DBGLN (" Processing MSP_ELRS_SET_VRX_BACKPACK_WIFI_MODE..." );
219- sendMSPViaEspnow (packet);
213+ ESPNOW:: sendMSPViaEspnow (packet);
220214 break ;
221215 case MSP_ELRS_SET_TX_BACKPACK_WIFI_MODE:
222216 DBGLN (" Processing MSP_ELRS_SET_TX_BACKPACK_WIFI_MODE..." );
@@ -230,13 +224,13 @@ void ProcessMSPPacketFromTX(mspPacket_t *packet)
230224 DBGLN (" Processing MSP_ELRS_BACKPACK_SET_HEAD_TRACKING..." );
231225 cachedHTPacket = *packet;
232226 cacheFull = true ;
233- sendMSPViaEspnow (packet);
227+ ESPNOW:: sendMSPViaEspnow (packet);
234228 break ;
235229 case MSP_ELRS_BACKPACK_CRSF_TLM:
236230 DBGLN (" Processing MSP_ELRS_BACKPACK_CRSF_TLM..." );
237231 if (config.GetTelemMode () != BACKPACK_TELEM_MODE_OFF)
238232 {
239- sendMSPViaEspnow (packet);
233+ ESPNOW:: sendMSPViaEspnow (packet);
240234 }
241235 break ;
242236 case MSP_ELRS_BACKPACK_CONFIG:
@@ -245,36 +239,11 @@ void ProcessMSPPacketFromTX(mspPacket_t *packet)
245239 break ;
246240 default :
247241 // transparently forward MSP packets via espnow to any subscribers
248- sendMSPViaEspnow (packet);
242+ ESPNOW:: sendMSPViaEspnow (packet);
249243 break ;
250244 }
251245}
252246
253- void sendMSPViaEspnow (mspPacket_t *packet)
254- {
255- uint8_t packetSize = msp.getTotalPacketSize (packet);
256- uint8_t nowDataOutput[packetSize];
257-
258- uint8_t result = msp.convertToByteArray (packet, nowDataOutput);
259-
260- if (!result)
261- {
262- // packet could not be converted to array, bail out
263- return ;
264- }
265-
266- if (packet->function == MSP_ELRS_BIND)
267- {
268- esp_now_send (bindingAddress, (uint8_t *) &nowDataOutput, packetSize); // Send Bind packet with the broadcast address
269- }
270- else
271- {
272- esp_now_send (firmwareOptions.uid , (uint8_t *) &nowDataOutput, packetSize);
273- }
274-
275- blinkLED ();
276- }
277-
278247void SendCachedMSP ()
279248{
280249 if (!cacheFull)
@@ -285,11 +254,11 @@ void SendCachedMSP()
285254
286255 if (cachedVTXPacket.type != MSP_PACKET_UNKNOWN)
287256 {
288- sendMSPViaEspnow (&cachedVTXPacket);
257+ ESPNOW:: sendMSPViaEspnow (&cachedVTXPacket);
289258 }
290259 if (cachedHTPacket.type != MSP_PACKET_UNKNOWN)
291260 {
292- sendMSPViaEspnow (&cachedHTPacket);
261+ ESPNOW:: sendMSPViaEspnow (&cachedHTPacket);
293262 }
294263}
295264
0 commit comments