22
22
#include < esp_err.h>
23
23
#include " BLEUtils.h"
24
24
#include " GeneralUtils.h"
25
-
26
- #if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
27
25
#include " esp32-hal-log.h"
28
- #define LOG_TAG " "
29
- #else
30
- #include " esp_log.h"
31
- static const char * LOG_TAG = " BLEAdvertising" ;
32
- #endif
33
-
34
-
35
26
36
27
/* *
37
28
* @brief Construct a default advertising object.
@@ -120,25 +111,25 @@ void BLEAdvertising::setScanResponse(bool set) {
120
111
* @param [in] connectWhitelistOnly If true, only allow connections from those on the white list.
121
112
*/
122
113
void BLEAdvertising::setScanFilter (bool scanRequestWhitelistOnly, bool connectWhitelistOnly) {
123
- ESP_LOGD (LOG_TAG, " >> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d" , scanRequestWhitelistOnly, connectWhitelistOnly);
114
+ log_v ( " >> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d" , scanRequestWhitelistOnly, connectWhitelistOnly);
124
115
if (!scanRequestWhitelistOnly && !connectWhitelistOnly) {
125
116
m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY;
126
- ESP_LOGD (LOG_TAG, " << setScanFilter" );
117
+ log_v ( " << setScanFilter" );
127
118
return ;
128
119
}
129
120
if (scanRequestWhitelistOnly && !connectWhitelistOnly) {
130
121
m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY;
131
- ESP_LOGD (LOG_TAG, " << setScanFilter" );
122
+ log_v ( " << setScanFilter" );
132
123
return ;
133
124
}
134
125
if (!scanRequestWhitelistOnly && connectWhitelistOnly) {
135
126
m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST;
136
- ESP_LOGD (LOG_TAG, " << setScanFilter" );
127
+ log_v ( " << setScanFilter" );
137
128
return ;
138
129
}
139
130
if (scanRequestWhitelistOnly && connectWhitelistOnly) {
140
131
m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST;
141
- ESP_LOGD (LOG_TAG, " << setScanFilter" );
132
+ log_v ( " << setScanFilter" );
142
133
return ;
143
134
}
144
135
} // setScanFilter
@@ -149,15 +140,15 @@ void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWh
149
140
* @param [in] advertisementData The data to be advertised.
150
141
*/
151
142
void BLEAdvertising::setAdvertisementData (BLEAdvertisementData& advertisementData) {
152
- ESP_LOGD (LOG_TAG, " >> setAdvertisementData" );
143
+ log_v ( " >> setAdvertisementData" );
153
144
esp_err_t errRc = ::esp_ble_gap_config_adv_data_raw (
154
145
(uint8_t *)advertisementData.getPayload ().data (),
155
146
advertisementData.getPayload ().length ());
156
147
if (errRc != ESP_OK) {
157
- ESP_LOGE (LOG_TAG, " esp_ble_gap_config_adv_data_raw: %d %s" , errRc, GeneralUtils::errorToString (errRc));
148
+ log_e ( " esp_ble_gap_config_adv_data_raw: %d %s" , errRc, GeneralUtils::errorToString (errRc));
158
149
}
159
150
m_customAdvData = true ; // Set the flag that indicates we are using custom advertising data.
160
- ESP_LOGD (LOG_TAG, " << setAdvertisementData" );
151
+ log_v ( " << setAdvertisementData" );
161
152
} // setAdvertisementData
162
153
163
154
@@ -166,15 +157,15 @@ void BLEAdvertising::setAdvertisementData(BLEAdvertisementData& advertisementDat
166
157
* @param [in] advertisementData The data to be advertised.
167
158
*/
168
159
void BLEAdvertising::setScanResponseData (BLEAdvertisementData& advertisementData) {
169
- ESP_LOGD (LOG_TAG, " >> setScanResponseData" );
160
+ log_v ( " >> setScanResponseData" );
170
161
esp_err_t errRc = ::esp_ble_gap_config_scan_rsp_data_raw (
171
162
(uint8_t *)advertisementData.getPayload ().data (),
172
163
advertisementData.getPayload ().length ());
173
164
if (errRc != ESP_OK) {
174
- ESP_LOGE (LOG_TAG, " esp_ble_gap_config_scan_rsp_data_raw: %d %s" , errRc, GeneralUtils::errorToString (errRc));
165
+ log_e ( " esp_ble_gap_config_scan_rsp_data_raw: %d %s" , errRc, GeneralUtils::errorToString (errRc));
175
166
}
176
167
m_customScanResponseData = true ; // Set the flag that indicates we are using custom scan response data.
177
- ESP_LOGD (LOG_TAG, " << setScanResponseData" );
168
+ log_v ( " << setScanResponseData" );
178
169
} // setScanResponseData
179
170
180
171
/* *
@@ -183,7 +174,7 @@ void BLEAdvertising::setScanResponseData(BLEAdvertisementData& advertisementData
183
174
* @return N/A.
184
175
*/
185
176
void BLEAdvertising::start () {
186
- ESP_LOGD (LOG_TAG, " >> start: customAdvData: %d, customScanResponseData: %d" , m_customAdvData, m_customScanResponseData);
177
+ log_v ( " >> start: customAdvData: %d, customScanResponseData: %d" , m_customAdvData, m_customScanResponseData);
187
178
188
179
// We have a vector of service UUIDs that we wish to advertise. In order to use the
189
180
// ESP-IDF framework, these must be supplied in a contiguous array of their 128bit (16 byte)
@@ -195,14 +186,14 @@ void BLEAdvertising::start() {
195
186
m_advData.p_service_uuid = new uint8_t [m_advData.service_uuid_len ];
196
187
uint8_t * p = m_advData.p_service_uuid ;
197
188
for (int i = 0 ; i < numServices; i++) {
198
- ESP_LOGD (LOG_TAG, " - advertising service: %s" , m_serviceUUIDs[i].toString ().c_str ());
189
+ log_d ( " - advertising service: %s" , m_serviceUUIDs[i].toString ().c_str ());
199
190
BLEUUID serviceUUID128 = m_serviceUUIDs[i].to128 ();
200
191
memcpy (p, serviceUUID128.getNative ()->uuid .uuid128 , 16 );
201
192
p += 16 ;
202
193
}
203
194
} else {
204
195
m_advData.service_uuid_len = 0 ;
205
- ESP_LOGD (LOG_TAG, " - no services advertised" );
196
+ log_d ( " - no services advertised" );
206
197
}
207
198
208
199
esp_err_t errRc;
@@ -214,7 +205,7 @@ void BLEAdvertising::start() {
214
205
m_advData.include_txpower = !m_scanResp;
215
206
errRc = ::esp_ble_gap_config_adv_data (&m_advData);
216
207
if (errRc != ESP_OK) {
217
- ESP_LOGE (LOG_TAG, " << esp_ble_gap_config_adv_data: rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
208
+ log_e ( " << esp_ble_gap_config_adv_data: rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
218
209
return ;
219
210
}
220
211
}
@@ -225,7 +216,7 @@ void BLEAdvertising::start() {
225
216
m_advData.include_txpower = m_scanResp;
226
217
errRc = ::esp_ble_gap_config_adv_data (&m_advData);
227
218
if (errRc != ESP_OK) {
228
- ESP_LOGE (LOG_TAG, " << esp_ble_gap_config_adv_data (Scan response): rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
219
+ log_e ( " << esp_ble_gap_config_adv_data (Scan response): rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
229
220
return ;
230
221
}
231
222
}
@@ -240,10 +231,10 @@ void BLEAdvertising::start() {
240
231
// Start advertising.
241
232
errRc = ::esp_ble_gap_start_advertising (&m_advParams);
242
233
if (errRc != ESP_OK) {
243
- ESP_LOGE (LOG_TAG, " << esp_ble_gap_start_advertising: rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
234
+ log_e ( " << esp_ble_gap_start_advertising: rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
244
235
return ;
245
236
}
246
- ESP_LOGD (LOG_TAG, " << start" );
237
+ log_v ( " << start" );
247
238
} // start
248
239
249
240
@@ -253,13 +244,13 @@ void BLEAdvertising::start() {
253
244
* @return N/A.
254
245
*/
255
246
void BLEAdvertising::stop () {
256
- ESP_LOGD (LOG_TAG, " >> stop" );
247
+ log_v ( " >> stop" );
257
248
esp_err_t errRc = ::esp_ble_gap_stop_advertising ();
258
249
if (errRc != ESP_OK) {
259
- ESP_LOGE (LOG_TAG, " esp_ble_gap_stop_advertising: rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
250
+ log_e ( " esp_ble_gap_stop_advertising: rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
260
251
return ;
261
252
}
262
- ESP_LOGD (LOG_TAG, " << stop" );
253
+ log_v ( " << stop" );
263
254
} // stop
264
255
265
256
/* *
@@ -352,12 +343,12 @@ void BLEAdvertisementData::setFlags(uint8_t flag) {
352
343
* @param [in] data Manufacturer data.
353
344
*/
354
345
void BLEAdvertisementData::setManufacturerData (std::string data) {
355
- ESP_LOGD (" BLEAdvertisementData" , " >> setManufacturerData" );
346
+ log_d (" BLEAdvertisementData" , " >> setManufacturerData" );
356
347
char cdata[2 ];
357
348
cdata[0 ] = data.length () + 1 ;
358
349
cdata[1 ] = ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE; // 0xff
359
350
addData (std::string (cdata, 2 ) + data);
360
- ESP_LOGD (" BLEAdvertisementData" , " << setManufacturerData" );
351
+ log_d (" BLEAdvertisementData" , " << setManufacturerData" );
361
352
} // setManufacturerData
362
353
363
354
@@ -366,12 +357,12 @@ void BLEAdvertisementData::setManufacturerData(std::string data) {
366
357
* @param [in] The complete name of the device.
367
358
*/
368
359
void BLEAdvertisementData::setName (std::string name) {
369
- ESP_LOGD (" BLEAdvertisementData" , " >> setName: %s" , name.c_str ());
360
+ log_d (" BLEAdvertisementData" , " >> setName: %s" , name.c_str ());
370
361
char cdata[2 ];
371
362
cdata[0 ] = name.length () + 1 ;
372
363
cdata[1 ] = ESP_BLE_AD_TYPE_NAME_CMPL; // 0x09
373
364
addData (std::string (cdata, 2 ) + name);
374
- ESP_LOGD (" BLEAdvertisementData" , " << setName" );
365
+ log_d (" BLEAdvertisementData" , " << setName" );
375
366
} // setName
376
367
377
368
@@ -455,12 +446,12 @@ void BLEAdvertisementData::setServiceData(BLEUUID uuid, std::string data) {
455
446
* @param [in] The short name of the device.
456
447
*/
457
448
void BLEAdvertisementData::setShortName (std::string name) {
458
- ESP_LOGD (" BLEAdvertisementData" , " >> setShortName: %s" , name.c_str ());
449
+ log_d (" BLEAdvertisementData" , " >> setShortName: %s" , name.c_str ());
459
450
char cdata[2 ];
460
451
cdata[0 ] = name.length () + 1 ;
461
452
cdata[1 ] = ESP_BLE_AD_TYPE_NAME_SHORT; // 0x08
462
453
addData (std::string (cdata, 2 ) + name);
463
- ESP_LOGD (" BLEAdvertisementData" , " << setShortName" );
454
+ log_d (" BLEAdvertisementData" , " << setShortName" );
464
455
} // setShortName
465
456
466
457
@@ -476,7 +467,7 @@ void BLEAdvertising::handleGAPEvent(
476
467
esp_gap_ble_cb_event_t event,
477
468
esp_ble_gap_cb_param_t * param) {
478
469
479
- ESP_LOGD (LOG_TAG, " handleGAPEvent [event no: %d]" , (int )event);
470
+ log_d ( " handleGAPEvent [event no: %d]" , (int )event);
480
471
481
472
switch (event) {
482
473
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: {
@@ -492,7 +483,7 @@ void BLEAdvertising::handleGAPEvent(
492
483
break ;
493
484
}
494
485
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: {
495
- ESP_LOGI (LOG_TAG, " STOP advertising" );
486
+ log_i ( " STOP advertising" );
496
487
start ();
497
488
break ;
498
489
}
0 commit comments