13
13
few seconds so a single dropped frame is not critical.
14
14
*/
15
15
16
+ #ifdef COMPILE_ESPNOW
17
+
16
18
// Called from main loop
17
19
// Control incoming/outgoing RTCM data from internal ESP NOW radio
18
20
// Use the ESP32 to directly transmit/receive RTCM over 2.4GHz (no WiFi needed)
19
21
void updateEspnow ()
20
22
{
21
- #ifdef COMPILE_ESPNOW
22
23
if (settings.enableEspNow == true )
23
24
{
24
25
if (espnowState == ESPNOW_PAIRED || espnowState == ESPNOW_BROADCASTING)
@@ -51,7 +52,6 @@ void updateEspnow()
51
52
espnowRSSI = -255 ;
52
53
}
53
54
}
54
- #endif // COMPILE_ESPNOW
55
55
}
56
56
57
57
// Create a struct for ESP NOW pairing
@@ -64,7 +64,6 @@ typedef struct PairMessage
64
64
} PairMessage;
65
65
66
66
// Callback when data is sent
67
- #ifdef COMPILE_ESPNOW
68
67
void espnowOnDataSent (const uint8_t *mac_addr, esp_now_send_status_t status)
69
68
{
70
69
// systemPrint("Last Packet Send Status: ");
@@ -73,16 +72,10 @@ void espnowOnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
73
72
// else
74
73
// systemPrintln("Delivery Fail");
75
74
}
76
- #endif // COMPILE_ESPNOW
77
-
78
- #ifndef COMPILE_ESPNOW
79
- #define esp_now_recv_info uint8_t
80
- #endif
81
75
82
76
// Callback when data is received
83
77
void espnowOnDataReceived (const esp_now_recv_info *mac, const uint8_t *incomingData, int len)
84
78
{
85
- #ifdef COMPILE_ESPNOW
86
79
if (espnowState == ESPNOW_PAIRING)
87
80
{
88
81
if (len == sizeof (PairMessage)) // First error check
@@ -127,7 +120,6 @@ void espnowOnDataReceived(const esp_now_recv_info *mac, const uint8_t *incomingD
127
120
espnowIncomingRTCM = true ; // Display a download icon
128
121
lastEspnowRssiUpdate = millis ();
129
122
}
130
- #endif // COMPILE_ESPNOW
131
123
}
132
124
133
125
// Callback for all RX Packets
@@ -154,8 +146,6 @@ void espnowStart()
154
146
return ;
155
147
}
156
148
157
- #ifdef COMPILE_ESPNOW
158
-
159
149
// Before we can issue esp_wifi_() commands WiFi must be started
160
150
if (WiFi.getMode () != WIFI_STA)
161
151
WiFi.mode (WIFI_STA);
@@ -298,14 +288,12 @@ void espnowStart()
298
288
}
299
289
300
290
systemPrintln (" ESP-Now Started" );
301
- #endif // COMPILE_ESPNOW
302
291
}
303
292
304
293
// If WiFi is already enabled, simply remove the LR protocol
305
294
// If WiFi is off, stop the radio entirely
306
295
void espnowStop ()
307
296
{
308
- #ifdef COMPILE_ESPNOW
309
297
if (espnowState == ESPNOW_OFF)
310
298
return ;
311
299
@@ -377,8 +365,6 @@ void espnowStop()
377
365
systemPrintln (" ESP-Now starting WiFi" );
378
366
wifiStart (); // Force WiFi to restart
379
367
}
380
-
381
- #endif // COMPILE_ESPNOW
382
368
}
383
369
384
370
// Start ESP-Now if needed, put ESP-Now into broadcast state
@@ -396,7 +382,6 @@ void espnowBeginPairing()
396
382
// Regularly call during pairing to see if we've received a Pairing message
397
383
bool espnowIsPaired ()
398
384
{
399
- #ifdef COMPILE_ESPNOW
400
385
if (espnowState == ESPNOW_MAC_RECEIVED)
401
386
{
402
387
// Remove broadcast peer
@@ -430,14 +415,12 @@ bool espnowIsPaired()
430
415
espnowSetState (ESPNOW_PAIRED);
431
416
return (true );
432
417
}
433
- #endif // COMPILE_ESPNOW
434
418
return (false );
435
419
}
436
420
437
421
// Create special pair packet to a given MAC
438
422
esp_err_t espnowSendPairMessage (uint8_t *sendToMac)
439
423
{
440
- #ifdef COMPILE_ESPNOW
441
424
// Assemble message to send
442
425
PairMessage pairMessage;
443
426
@@ -451,9 +434,6 @@ esp_err_t espnowSendPairMessage(uint8_t *sendToMac)
451
434
pairMessage.crc += wifiMACAddress[x];
452
435
453
436
return (esp_now_send (sendToMac, (uint8_t *)&pairMessage, sizeof (pairMessage))); // Send packet to given MAC
454
- #else // COMPILE_ESPNOW
455
- return (ESP_OK);
456
- #endif // COMPILE_ESPNOW
457
437
}
458
438
459
439
// Add a given MAC address to the peer list
@@ -464,7 +444,6 @@ esp_err_t espnowAddPeer(uint8_t *peerMac)
464
444
465
445
esp_err_t espnowAddPeer (uint8_t *peerMac, bool encrypt)
466
446
{
467
- #ifdef COMPILE_ESPNOW
468
447
esp_now_peer_info_t peerInfo;
469
448
470
449
memcpy (peerInfo.peer_addr , peerMac, 6 );
@@ -482,15 +461,11 @@ esp_err_t espnowAddPeer(uint8_t *peerMac, bool encrypt)
482
461
peerMac[3 ], peerMac[4 ], peerMac[5 ]);
483
462
}
484
463
return (result);
485
- #else // COMPILE_ESPNOW
486
- return (ESP_OK);
487
- #endif // COMPILE_ESPNOW
488
464
}
489
465
490
466
// Remove a given MAC address from the peer list
491
467
esp_err_t espnowRemovePeer (uint8_t *peerMac)
492
468
{
493
- #ifdef COMPILE_ESPNOW
494
469
esp_err_t response = esp_now_del_peer (peerMac);
495
470
if (response != ESP_OK)
496
471
{
@@ -499,9 +474,6 @@ esp_err_t espnowRemovePeer(uint8_t *peerMac)
499
474
}
500
475
501
476
return (response);
502
- #else // COMPILE_ESPNOW
503
- return (ESP_OK);
504
- #endif // COMPILE_ESPNOW
505
477
}
506
478
507
479
// Update the state of the ESP Now state machine
@@ -540,7 +512,6 @@ void espnowSetState(ESPNOWState newState)
540
512
541
513
void espnowProcessRTCM (byte incoming)
542
514
{
543
- #ifdef COMPILE_ESPNOW
544
515
// If we are paired,
545
516
// Or if the radio is broadcasting
546
517
// Then add bytes to the outgoing buffer
@@ -571,7 +542,6 @@ void espnowProcessRTCM(byte incoming)
571
542
572
543
espnowOutgoingRTCM = true ;
573
544
}
574
- #endif // COMPILE_ESPNOW
575
545
}
576
546
577
547
// A blocking function that is used to pair two devices
@@ -622,7 +592,6 @@ void espnowStaticPairing()
622
592
// Returns the current channel being used by WiFi
623
593
uint8_t espnowGetChannel ()
624
594
{
625
- #ifdef COMPILE_ESPNOW
626
595
if (espnowState == ESPNOW_OFF)
627
596
return 0 ;
628
597
@@ -647,15 +616,11 @@ uint8_t espnowGetChannel()
647
616
esp_wifi_set_promiscuous (false );
648
617
649
618
return (primaryChannelNumber);
650
- #else
651
- return (0 );
652
- #endif
653
619
}
654
620
655
621
// Returns the current channel being used by WiFi
656
622
bool espnowSetChannel (uint8_t channelNumber)
657
623
{
658
- #ifdef COMPILE_ESPNOW
659
624
if (wifiIsConnected () == true )
660
625
{
661
626
systemPrintln (" ESP-NOW channel can't be modified while WiFi is connected." );
@@ -683,7 +648,6 @@ bool espnowSetChannel(uint8_t channelNumber)
683
648
esp_wifi_set_promiscuous (false );
684
649
685
650
return (setSuccess);
686
- #else
687
- return (false );
688
- #endif
689
651
}
652
+
653
+ #endif // COMPILE_ESPNOW
0 commit comments