2222#include  < esp_err.h> 
2323#include  " BLEUtils.h" 
2424#include  " GeneralUtils.h" 
25- 
26- #if  defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
2725#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- 
3526
3627/* *
3728 * @brief Construct a default advertising object. 
@@ -120,25 +111,25 @@ void BLEAdvertising::setScanResponse(bool set) {
120111 * @param [in] connectWhitelistOnly If true, only allow connections from those on the white list. 
121112 */  
122113void  BLEAdvertising::setScanFilter (bool  scanRequestWhitelistOnly, bool  connectWhitelistOnly) {
123- 	ESP_LOGD (LOG_TAG,  " >> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d" 
114+ 	log_v ( " >> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d" 
124115	if  (!scanRequestWhitelistOnly && !connectWhitelistOnly) {
125116		m_advParams.adv_filter_policy  = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY;
126- 		ESP_LOGD (LOG_TAG,  " << setScanFilter" 
117+ 		log_v ( " << setScanFilter" 
127118		return ;
128119	}
129120	if  (scanRequestWhitelistOnly && !connectWhitelistOnly) {
130121		m_advParams.adv_filter_policy  = ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY;
131- 		ESP_LOGD (LOG_TAG,  " << setScanFilter" 
122+ 		log_v ( " << setScanFilter" 
132123		return ;
133124	}
134125	if  (!scanRequestWhitelistOnly && connectWhitelistOnly) {
135126		m_advParams.adv_filter_policy  = ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST;
136- 		ESP_LOGD (LOG_TAG,  " << setScanFilter" 
127+ 		log_v ( " << setScanFilter" 
137128		return ;
138129	}
139130	if  (scanRequestWhitelistOnly && connectWhitelistOnly) {
140131		m_advParams.adv_filter_policy  = ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST;
141- 		ESP_LOGD (LOG_TAG,  " << setScanFilter" 
132+ 		log_v ( " << setScanFilter" 
142133		return ;
143134	}
144135} //  setScanFilter
@@ -149,15 +140,15 @@ void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWh
149140 * @param [in] advertisementData The data to be advertised. 
150141 */  
151142void  BLEAdvertising::setAdvertisementData (BLEAdvertisementData& advertisementData) {
152- 	ESP_LOGD (LOG_TAG,  " >> setAdvertisementData" 
143+ 	log_v ( " >> setAdvertisementData" 
153144	esp_err_t  errRc = ::esp_ble_gap_config_adv_data_raw (
154145		(uint8_t *)advertisementData.getPayload ().data (),
155146		advertisementData.getPayload ().length ());
156147	if  (errRc != ESP_OK) {
157- 		ESP_LOGE (LOG_TAG,  " esp_ble_gap_config_adv_data_raw: %d %s" GeneralUtils::errorToString (errRc));
148+ 		log_e ( " esp_ble_gap_config_adv_data_raw: %d %s" GeneralUtils::errorToString (errRc));
158149	}
159150	m_customAdvData = true ;   //  Set the flag that indicates we are using custom advertising data.
160- 	ESP_LOGD (LOG_TAG,  " << setAdvertisementData" 
151+ 	log_v ( " << setAdvertisementData" 
161152} //  setAdvertisementData
162153
163154
@@ -166,15 +157,15 @@ void BLEAdvertising::setAdvertisementData(BLEAdvertisementData& advertisementDat
166157 * @param [in] advertisementData The data to be advertised. 
167158 */  
168159void  BLEAdvertising::setScanResponseData (BLEAdvertisementData& advertisementData) {
169- 	ESP_LOGD (LOG_TAG,  " >> setScanResponseData" 
160+ 	log_v ( " >> setScanResponseData" 
170161	esp_err_t  errRc = ::esp_ble_gap_config_scan_rsp_data_raw (
171162		(uint8_t *)advertisementData.getPayload ().data (),
172163		advertisementData.getPayload ().length ());
173164	if  (errRc != ESP_OK) {
174- 		ESP_LOGE (LOG_TAG,  " esp_ble_gap_config_scan_rsp_data_raw: %d %s" GeneralUtils::errorToString (errRc));
165+ 		log_e ( " esp_ble_gap_config_scan_rsp_data_raw: %d %s" GeneralUtils::errorToString (errRc));
175166	}
176167	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" 
178169} //  setScanResponseData
179170
180171/* *
@@ -183,7 +174,7 @@ void BLEAdvertising::setScanResponseData(BLEAdvertisementData& advertisementData
183174 * @return N/A. 
184175 */  
185176void  BLEAdvertising::start () {
186- 	ESP_LOGD (LOG_TAG,  " >> start: customAdvData: %d, customScanResponseData: %d" 
177+ 	log_v ( " >> start: customAdvData: %d, customScanResponseData: %d" 
187178
188179	//  We have a vector of service UUIDs that we wish to advertise.  In order to use the
189180	//  ESP-IDF framework, these must be supplied in a contiguous array of their 128bit (16 byte)
@@ -195,14 +186,14 @@ void BLEAdvertising::start() {
195186		m_advData.p_service_uuid  = new  uint8_t [m_advData.service_uuid_len ];
196187		uint8_t * p = m_advData.p_service_uuid ;
197188		for  (int  i = 0 ; i < numServices; i++) {
198- 			ESP_LOGD (LOG_TAG,  " - advertising service: %s" toString ().c_str ());
189+ 			log_d ( " - advertising service: %s" toString ().c_str ());
199190			BLEUUID serviceUUID128 = m_serviceUUIDs[i].to128 ();
200191			memcpy (p, serviceUUID128.getNative ()->uuid .uuid128 , 16 );
201192			p += 16 ;
202193		}
203194	} else  {
204195		m_advData.service_uuid_len  = 0 ;
205- 		ESP_LOGD (LOG_TAG,  " - no services advertised" 
196+ 		log_d ( " - no services advertised" 
206197	}
207198
208199	esp_err_t  errRc;
@@ -214,7 +205,7 @@ void BLEAdvertising::start() {
214205		m_advData.include_txpower  = !m_scanResp;
215206		errRc = ::esp_ble_gap_config_adv_data (&m_advData);
216207		if  (errRc != ESP_OK) {
217- 			ESP_LOGE (LOG_TAG,  " << esp_ble_gap_config_adv_data: rc=%d %s" GeneralUtils::errorToString (errRc));
208+ 			log_e ( " << esp_ble_gap_config_adv_data: rc=%d %s" GeneralUtils::errorToString (errRc));
218209			return ;
219210		}
220211	}
@@ -225,7 +216,7 @@ void BLEAdvertising::start() {
225216		m_advData.include_txpower  = m_scanResp;
226217		errRc = ::esp_ble_gap_config_adv_data (&m_advData);
227218		if  (errRc != ESP_OK) {
228- 			ESP_LOGE (LOG_TAG,  " << esp_ble_gap_config_adv_data (Scan response): rc=%d %s" GeneralUtils::errorToString (errRc));
219+ 			log_e ( " << esp_ble_gap_config_adv_data (Scan response): rc=%d %s" GeneralUtils::errorToString (errRc));
229220			return ;
230221		}
231222	}
@@ -240,10 +231,10 @@ void BLEAdvertising::start() {
240231	//  Start advertising.
241232	errRc = ::esp_ble_gap_start_advertising (&m_advParams);
242233	if  (errRc != ESP_OK) {
243- 		ESP_LOGE (LOG_TAG,  " << esp_ble_gap_start_advertising: rc=%d %s" GeneralUtils::errorToString (errRc));
234+ 		log_e ( " << esp_ble_gap_start_advertising: rc=%d %s" GeneralUtils::errorToString (errRc));
244235		return ;
245236	}
246- 	ESP_LOGD (LOG_TAG,  " << start" 
237+ 	log_v ( " << start" 
247238} //  start
248239
249240
@@ -253,13 +244,13 @@ void BLEAdvertising::start() {
253244 * @return N/A. 
254245 */  
255246void  BLEAdvertising::stop () {
256- 	ESP_LOGD (LOG_TAG,  " >> stop" 
247+ 	log_v ( " >> stop" 
257248	esp_err_t  errRc = ::esp_ble_gap_stop_advertising ();
258249	if  (errRc != ESP_OK) {
259- 		ESP_LOGE (LOG_TAG,  " esp_ble_gap_stop_advertising: rc=%d %s" GeneralUtils::errorToString (errRc));
250+ 		log_e ( " esp_ble_gap_stop_advertising: rc=%d %s" GeneralUtils::errorToString (errRc));
260251		return ;
261252	}
262- 	ESP_LOGD (LOG_TAG,  " << stop" 
253+ 	log_v ( " << stop" 
263254} //  stop
264255
265256/* *
@@ -352,12 +343,12 @@ void BLEAdvertisementData::setFlags(uint8_t flag) {
352343 * @param [in] data Manufacturer data. 
353344 */  
354345void  BLEAdvertisementData::setManufacturerData (std::string data) {
355- 	ESP_LOGD (" BLEAdvertisementData" " >> setManufacturerData" 
346+ 	log_d (" BLEAdvertisementData" " >> setManufacturerData" 
356347	char  cdata[2 ];
357348	cdata[0 ] = data.length () + 1 ;
358349	cdata[1 ] = ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE;  //  0xff
359350	addData (std::string (cdata, 2 ) + data);
360- 	ESP_LOGD (" BLEAdvertisementData" " << setManufacturerData" 
351+ 	log_d (" BLEAdvertisementData" " << setManufacturerData" 
361352} //  setManufacturerData
362353
363354
@@ -366,12 +357,12 @@ void BLEAdvertisementData::setManufacturerData(std::string data) {
366357 * @param [in] The complete name of the device. 
367358 */  
368359void  BLEAdvertisementData::setName (std::string name) {
369- 	ESP_LOGD (" BLEAdvertisementData" " >> setName: %s" c_str ());
360+ 	log_d (" BLEAdvertisementData" " >> setName: %s" c_str ());
370361	char  cdata[2 ];
371362	cdata[0 ] = name.length () + 1 ;
372363	cdata[1 ] = ESP_BLE_AD_TYPE_NAME_CMPL;  //  0x09
373364	addData (std::string (cdata, 2 ) + name);
374- 	ESP_LOGD (" BLEAdvertisementData" " << setName" 
365+ 	log_d (" BLEAdvertisementData" " << setName" 
375366} //  setName
376367
377368
@@ -455,12 +446,12 @@ void BLEAdvertisementData::setServiceData(BLEUUID uuid, std::string data) {
455446 * @param [in] The short name of the device. 
456447 */  
457448void  BLEAdvertisementData::setShortName (std::string name) {
458- 	ESP_LOGD (" BLEAdvertisementData" " >> setShortName: %s" c_str ());
449+ 	log_d (" BLEAdvertisementData" " >> setShortName: %s" c_str ());
459450	char  cdata[2 ];
460451	cdata[0 ] = name.length () + 1 ;
461452	cdata[1 ] = ESP_BLE_AD_TYPE_NAME_SHORT;  //  0x08
462453	addData (std::string (cdata, 2 ) + name);
463- 	ESP_LOGD (" BLEAdvertisementData" " << setShortName" 
454+ 	log_d (" BLEAdvertisementData" " << setShortName" 
464455} //  setShortName
465456
466457
@@ -476,7 +467,7 @@ void BLEAdvertising::handleGAPEvent(
476467		esp_gap_ble_cb_event_t   event,
477468		esp_ble_gap_cb_param_t * param)  {
478469
479- 	ESP_LOGD (LOG_TAG,  " handleGAPEvent [event no: %d]" int )event);
470+ 	log_d ( " handleGAPEvent [event no: %d]" int )event);
480471
481472	switch (event) {
482473		case  ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: {
@@ -492,7 +483,7 @@ void BLEAdvertising::handleGAPEvent(
492483			break ;
493484		}
494485		case  ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: {
495- 			ESP_LOGI (LOG_TAG,  " STOP advertising" 
486+ 			log_i ( " STOP advertising" 
496487			start ();
497488			break ;
498489		}
0 commit comments