99#include " esp32-hal.h"
1010#include " esp_wifi.h"
1111
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 ,
1414static bool _esp_now_has_begun = false ;
1515static ESP_NOW_Peer *_esp_now_peers[ESP_NOW_MAX_TOTAL_PEER_NUM];
1616
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 ) {
1818 log_v (MACSTR, MAC2STR (mac_addr));
1919 if (esp_now_is_peer_exist (mac_addr)) {
2020 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
2626 memcpy (peer.peer_addr , mac_addr, ESP_NOW_ETH_ALEN);
2727 peer.channel = channel;
2828 peer.ifidx = iface;
29- peer.encrypt = lmk != NULL ;
29+ peer.encrypt = lmk != nullptr ;
3030 if (lmk) {
3131 memcpy (peer.lmk , lmk, ESP_NOW_KEY_LEN);
3232 }
3333
3434 esp_err_t result = esp_now_add_peer (&peer);
3535 if (result == ESP_OK) {
36- if (_peer != NULL ) {
36+ if (_peer != nullptr ) {
3737 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 ) {
3939 _esp_now_peers[i] = _peer;
4040 return ESP_OK;
4141 }
@@ -67,8 +67,8 @@ static esp_err_t _esp_now_del_peer(const uint8_t *mac_addr) {
6767 }
6868
6969 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 ;
7272 break ;
7373 }
7474 }
@@ -87,7 +87,7 @@ static esp_err_t _esp_now_modify_peer(const uint8_t *mac_addr, uint8_t channel,
8787 memcpy (peer.peer_addr , mac_addr, ESP_NOW_ETH_ALEN);
8888 peer.channel = channel;
8989 peer.ifidx = iface;
90- peer.encrypt = lmk != NULL ;
90+ peer.encrypt = lmk != nullptr ;
9191 if (lmk) {
9292 memcpy (peer.lmk , lmk, ESP_NOW_KEY_LEN);
9393 }
@@ -111,17 +111,17 @@ static void _esp_now_rx_cb(const esp_now_recv_info_t *info, const uint8_t *data,
111111 bool broadcast = memcmp (info->des_addr , ESP_NOW.BROADCAST_ADDR , ESP_NOW_ETH_ALEN) == 0 ;
112112 log_v (" %s from " MACSTR " , data length : %u" , broadcast ? " Broadcast" : " Unicast" , MAC2STR (info->src_addr ), len);
113113 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 ) {
115115 log_v (" Calling new_cb, peer not found." );
116116 new_cb (info, data, len, new_arg);
117117 return ;
118118 }
119119 // find the peer and call it's callback
120120 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 ) {
122122 log_v (" Checking peer " MACSTR, MAC2STR (_esp_now_peers[i]->addr ()));
123123 }
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 ) {
125125 log_v (" Calling onReceive" );
126126 _esp_now_peers[i]->onReceive (data, len, broadcast);
127127 return ;
@@ -138,7 +138,7 @@ static void _esp_now_tx_cb(const uint8_t *mac_addr, esp_now_send_status_t status
138138 log_v (MACSTR " : %s" , MAC2STR (mac_addr), (status == ESP_NOW_SEND_SUCCESS) ? " SUCCESS" : " FAILED" );
139139 // find the peer and call it's callback
140140 for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
141- if (_esp_now_peers[i] != NULL && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
141+ if (_esp_now_peers[i] != nullptr && memcmp (mac_addr, _esp_now_peers[i]->addr (), ESP_NOW_ETH_ALEN) == 0 ) {
142142 _esp_now_peers[i]->onSent (status == ESP_NOW_SEND_SUCCESS);
143143 return ;
144144 }
@@ -202,7 +202,7 @@ bool ESP_NOW_Class::end() {
202202 }
203203 // remove all peers
204204 for (uint8_t i = 0 ; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) {
205- if (_esp_now_peers[i] != NULL ) {
205+ if (_esp_now_peers[i] != nullptr ) {
206206 removePeer (*_esp_now_peers[i]);
207207 }
208208 }
@@ -254,7 +254,7 @@ size_t ESP_NOW_Class::write(const uint8_t *data, size_t len) {
254254 if (len > ESP_NOW_MAX_DATA_LEN) {
255255 len = ESP_NOW_MAX_DATA_LEN;
256256 }
257- esp_err_t result = esp_now_send (NULL , data, len);
257+ esp_err_t result = esp_now_send (nullptr , data, len);
258258 if (result == ESP_OK) {
259259 return len;
260260 } else if (result == ESP_ERR_ESPNOW_NOT_INIT) {
@@ -297,7 +297,7 @@ ESP_NOW_Peer::ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel, wifi_interf
297297 }
298298 chan = channel;
299299 ifc = iface;
300- encrypt = lmk != NULL ;
300+ encrypt = lmk != nullptr ;
301301 if (encrypt) {
302302 memcpy (key, lmk, 16 );
303303 }
@@ -310,7 +310,7 @@ bool ESP_NOW_Peer::add() {
310310 if (added) {
311311 return true ;
312312 }
313- if (_esp_now_add_peer (mac, chan, ifc, encrypt ? key : NULL , this ) != ESP_OK) {
313+ if (_esp_now_add_peer (mac, chan, ifc, encrypt ? key : nullptr , this ) != ESP_OK) {
314314 return false ;
315315 }
316316 log_v (" Peer added - " MACSTR, MAC2STR (mac));
@@ -355,7 +355,7 @@ bool ESP_NOW_Peer::setChannel(uint8_t channel) {
355355 if (!_esp_now_has_begun || !added) {
356356 return true ;
357357 }
358- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
358+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
359359}
360360
361361wifi_interface_t ESP_NOW_Peer::getInterface () const {
@@ -367,22 +367,22 @@ bool ESP_NOW_Peer::setInterface(wifi_interface_t iface) {
367367 if (!_esp_now_has_begun || !added) {
368368 return true ;
369369 }
370- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
370+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
371371}
372372
373373bool ESP_NOW_Peer::isEncrypted () const {
374374 return encrypt;
375375}
376376
377377bool ESP_NOW_Peer::setKey (const uint8_t *lmk) {
378- encrypt = lmk != NULL ;
378+ encrypt = lmk != nullptr ;
379379 if (encrypt) {
380380 memcpy (key, lmk, 16 );
381381 }
382382 if (!_esp_now_has_begun || !added) {
383383 return true ;
384384 }
385- return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : NULL ) == ESP_OK;
385+ return _esp_now_modify_peer (mac, chan, ifc, encrypt ? key : nullptr ) == ESP_OK;
386386}
387387
388388size_t ESP_NOW_Peer::send (const uint8_t *data, int len) {
0 commit comments