9
9
#include " esp32-hal.h"
10
10
#include " esp_wifi.h"
11
11
12
- static void (*new_cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) = NULL ;
13
- static void *new_arg = NULL ; // * tx_arg = NULL , * rx_arg = NULL ,
12
+ static void (*new_cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) = nullptr ;
13
+ static void *new_arg = nullptr ; // * tx_arg = nullptr , * rx_arg = nullptr ,
14
14
static bool _esp_now_has_begun = false ;
15
15
static ESP_NOW_Peer *_esp_now_peers[ESP_NOW_MAX_TOTAL_PEER_NUM];
16
16
17
- static esp_err_t _esp_now_add_peer (const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, ESP_NOW_Peer *_peer = NULL ) {
17
+ static esp_err_t _esp_now_add_peer (const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, ESP_NOW_Peer *_peer = nullptr ) {
18
18
log_v (MACSTR, MAC2STR (mac_addr));
19
19
if (esp_now_is_peer_exist (mac_addr)) {
20
20
log_e (" Peer Already Exists" );
@@ -26,16 +26,16 @@ static esp_err_t _esp_now_add_peer(const uint8_t *mac_addr, uint8_t channel, wif
26
26
memcpy (peer.peer_addr , mac_addr, ESP_NOW_ETH_ALEN);
27
27
peer.channel = channel;
28
28
peer.ifidx = iface;
29
- peer.encrypt = lmk != NULL ;
29
+ peer.encrypt = lmk != nullptr ;
30
30
if (lmk) {
31
31
memcpy (peer.lmk , lmk, ESP_NOW_KEY_LEN);
32
32
}
33
33
34
34
esp_err_t result = esp_now_add_peer (&peer);
35
35
if (result == ESP_OK) {
36
- if (_peer != NULL ) {
36
+ if (_peer != nullptr ) {
37
37
for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
38
- if (_esp_now_peers[i] == NULL ) {
38
+ if (_esp_now_peers[i] == nullptr ) {
39
39
_esp_now_peers[i] = _peer;
40
40
return ESP_OK;
41
41
}
@@ -67,8 +67,8 @@ static esp_err_t _esp_now_del_peer(const uint8_t *mac_addr) {
67
67
}
68
68
69
69
for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
70
- if (_esp_now_peers[i] != NULL && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
71
- _esp_now_peers[i] = NULL ;
70
+ if (_esp_now_peers[i] != nullptr && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
71
+ _esp_now_peers[i] = nullptr ;
72
72
break ;
73
73
}
74
74
}
@@ -87,7 +87,7 @@ static esp_err_t _esp_now_modify_peer(const uint8_t *mac_addr, uint8_t channel,
87
87
memcpy (peer.peer_addr , mac_addr, ESP_NOW_ETH_ALEN);
88
88
peer.channel = channel;
89
89
peer.ifidx = iface;
90
- peer.encrypt = lmk != NULL ;
90
+ peer.encrypt = lmk != nullptr ;
91
91
if (lmk) {
92
92
memcpy (peer.lmk , lmk, ESP_NOW_KEY_LEN);
93
93
}
@@ -111,17 +111,17 @@ static void _esp_now_rx_cb(const esp_now_recv_info_t *info, const uint8_t *data,
111
111
bool broadcast = memcmp (info->des_addr , ESP_NOW.BROADCAST_ADDR , ESP_NOW_ETH_ALEN) == 0 ;
112
112
log_v (" %s from " MACSTR " , data length : %u" , broadcast ? " Broadcast" : " Unicast" , MAC2STR (info->src_addr ), len);
113
113
log_buf_v (data, len);
114
- if (!esp_now_is_peer_exist (info->src_addr ) && new_cb != NULL ) {
114
+ if (!esp_now_is_peer_exist (info->src_addr ) && new_cb != nullptr ) {
115
115
log_v (" Calling new_cb, peer not found." );
116
116
new_cb (info, data, len, new_arg);
117
117
return ;
118
118
}
119
119
// find the peer and call it's callback
120
120
for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
121
- if (_esp_now_peers[i] != NULL ) {
121
+ if (_esp_now_peers[i] != nullptr ) {
122
122
log_v (" Checking peer " MACSTR, MAC2STR (_esp_now_peers[i]->addr ()));
123
123
}
124
- if (_esp_now_peers[i] != NULL && memcmp (info->src_addr , _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
124
+ if (_esp_now_peers[i] != nullptr && memcmp (info->src_addr , _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
125
125
log_v (" Calling onReceive" );
126
126
_esp_now_peers[i]->onReceive (data, len, broadcast);
127
127
return ;
@@ -133,7 +133,7 @@ static void _esp_now_tx_cb(const uint8_t *mac_addr, esp_now_send_status_t status
133
133
log_v (MACSTR " : %s" , MAC2STR (mac_addr), (status == ESP_NOW_SEND_SUCCESS) ? " SUCCESS" : " FAILED" );
134
134
// find the peer and call it's callback
135
135
for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
136
- if (_esp_now_peers[i] != NULL && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
136
+ if (_esp_now_peers[i] != nullptr && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
137
137
_esp_now_peers[i]->onSent (status == ESP_NOW_SEND_SUCCESS);
138
138
return ;
139
139
}
@@ -197,7 +197,7 @@ bool ESP_NOW_Class::end() {
197
197
}
198
198
// remove all peers
199
199
for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
200
- if (_esp_now_peers[i] != NULL ) {
200
+ if (_esp_now_peers[i] != nullptr ) {
201
201
removePeer (*_esp_now_peers[i]);
202
202
}
203
203
}
@@ -249,7 +249,7 @@ size_t ESP_NOW_Class::write(const uint8_t *data, size_t len) {
249
249
if (len > ESP_NOW_MAX_DATA_LEN) {
250
250
len = ESP_NOW_MAX_DATA_LEN;
251
251
}
252
- esp_err_t result = esp_now_send (NULL , data, len);
252
+ esp_err_t result = esp_now_send (nullptr , data, len);
253
253
if (result == ESP_OK) {
254
254
return len;
255
255
} else if (result == ESP_ERR_ESPNOW_NOT_INIT) {
@@ -292,7 +292,7 @@ ESP_NOW_Peer::ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel, wifi_interf
292
292
}
293
293
chan = channel;
294
294
ifc = iface;
295
- encrypt = lmk != NULL ;
295
+ encrypt = lmk != nullptr ;
296
296
if (encrypt) {
297
297
memcpy (key, lmk, 16 );
298
298
}
@@ -305,7 +305,7 @@ bool ESP_NOW_Peer::add() {
305
305
if (added) {
306
306
return true ;
307
307
}
308
- if (_esp_now_add_peer (mac, chan, ifc, encrypt ? key : NULL , this ) != ESP_OK) {
308
+ if (_esp_now_add_peer (mac, chan, ifc, encrypt ? key : nullptr , this ) != ESP_OK) {
309
309
return false ;
310
310
}
311
311
log_v (" Peer added - " MACSTR, MAC2STR (mac));
@@ -350,7 +350,7 @@ bool ESP_NOW_Peer::setChannel(uint8_t channel) {
350
350
if (!_esp_now_has_begun || !added) {
351
351
return true ;
352
352
}
353
- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
353
+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
354
354
}
355
355
356
356
wifi_interface_t ESP_NOW_Peer::getInterface () const {
@@ -362,22 +362,22 @@ bool ESP_NOW_Peer::setInterface(wifi_interface_t iface) {
362
362
if (!_esp_now_has_begun || !added) {
363
363
return true ;
364
364
}
365
- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
365
+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
366
366
}
367
367
368
368
bool ESP_NOW_Peer::isEncrypted () const {
369
369
return encrypt;
370
370
}
371
371
372
372
bool ESP_NOW_Peer::setKey (const uint8_t *lmk) {
373
- encrypt = lmk != NULL ;
373
+ encrypt = lmk != nullptr ;
374
374
if (encrypt) {
375
375
memcpy (key, lmk, 16 );
376
376
}
377
377
if (!_esp_now_has_begun || !added) {
378
378
return true ;
379
379
}
380
- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
380
+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
381
381
}
382
382
383
383
size_t ESP_NOW_Peer::send (const uint8_t *data, int len) {
0 commit comments