diff --git a/libraries/BLE/src/BLEAdvertisedDevice.cpp b/libraries/BLE/src/BLEAdvertisedDevice.cpp index 3f55e8c8..2cc2115c 100644 --- a/libraries/BLE/src/BLEAdvertisedDevice.cpp +++ b/libraries/BLE/src/BLEAdvertisedDevice.cpp @@ -16,13 +16,7 @@ #include #include "BLEAdvertisedDevice.h" #include "BLEUtils.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG="BLEAdvertisedDevice"; -#endif BLEAdvertisedDevice::BLEAdvertisedDevice() { m_adFlag = 0; @@ -249,7 +243,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len) length--; char* pHex = BLEUtils::buildHexData(nullptr, payload, length); - ESP_LOGD(LOG_TAG, "Type: 0x%.2x (%s), length: %d, data: %s", + log_d("Type: 0x%.2x (%s), length: %d, data: %s", ad_type, BLEUtils::advTypeToString(ad_type), length, pHex); free(pHex); @@ -308,7 +302,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len) case ESP_BLE_AD_TYPE_SERVICE_DATA: { // Adv Data Type: 0x16 (Service Data) - 2 byte UUID if (length < 2) { - ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA"); + log_e("Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA"); break; } uint16_t uuid = *(uint16_t*)payload; @@ -321,7 +315,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len) case ESP_BLE_AD_TYPE_32SERVICE_DATA: { // Adv Data Type: 0x20 (Service Data) - 4 byte UUID if (length < 4) { - ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA"); + log_e("Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA"); break; } uint32_t uuid = *(uint32_t*) payload; @@ -334,7 +328,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len) case ESP_BLE_AD_TYPE_128SERVICE_DATA: { // Adv Data Type: 0x21 (Service Data) - 16 byte UUID if (length < 16) { - ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA"); + log_e("Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA"); break; } @@ -346,7 +340,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len) } //ESP_BLE_AD_TYPE_32SERVICE_DATA default: { - ESP_LOGD(LOG_TAG, "Unhandled type: adType: %d - 0x%.2x", ad_type, ad_type); + log_d("Unhandled type: adType: %d - 0x%.2x", ad_type, ad_type); break; } } // switch @@ -386,7 +380,7 @@ void BLEAdvertisedDevice::setAdFlag(uint8_t adFlag) { void BLEAdvertisedDevice::setAppearance(uint16_t appearance) { m_appearance = appearance; m_haveAppearance = true; - ESP_LOGD(LOG_TAG, "- appearance: %d", m_appearance); + log_d("- appearance: %d", m_appearance); } // setAppearance @@ -398,7 +392,7 @@ void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) { m_manufacturerData = manufacturerData; m_haveManufacturerData = true; char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*) m_manufacturerData.data(), (uint8_t) m_manufacturerData.length()); - ESP_LOGD(LOG_TAG, "- manufacturer data: %s", pHex); + log_d("- manufacturer data: %s", pHex); free(pHex); } // setManufacturerData @@ -410,7 +404,7 @@ void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) { void BLEAdvertisedDevice::setName(std::string name) { m_name = name; m_haveName = true; - ESP_LOGD(LOG_TAG, "- setName(): name: %s", m_name.c_str()); + log_d("- setName(): name: %s", m_name.c_str()); } // setName @@ -421,7 +415,7 @@ void BLEAdvertisedDevice::setName(std::string name) { void BLEAdvertisedDevice::setRSSI(int rssi) { m_rssi = rssi; m_haveRSSI = true; - ESP_LOGD(LOG_TAG, "- setRSSI(): rssi: %d", m_rssi); + log_d("- setRSSI(): rssi: %d", m_rssi); } // setRSSI @@ -450,7 +444,7 @@ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) { void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) { m_serviceUUIDs.push_back(serviceUUID); m_haveServiceUUID = true; - ESP_LOGD(LOG_TAG, "- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str()); + log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str()); } // setServiceUUID @@ -481,7 +475,7 @@ void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) { void BLEAdvertisedDevice::setTXPower(int8_t txPower) { m_txPower = txPower; m_haveTXPower = true; - ESP_LOGD(LOG_TAG, "- txPower: %d", m_txPower); + log_d("- txPower: %d", m_txPower); } // setTXPower diff --git a/libraries/BLE/src/BLEAdvertising.cpp b/libraries/BLE/src/BLEAdvertising.cpp index 230d77cb..aa96baa4 100644 --- a/libraries/BLE/src/BLEAdvertising.cpp +++ b/libraries/BLE/src/BLEAdvertising.cpp @@ -22,16 +22,7 @@ #include #include "BLEUtils.h" #include "GeneralUtils.h" - -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEAdvertising"; -#endif - - /** * @brief Construct a default advertising object. @@ -120,25 +111,25 @@ void BLEAdvertising::setScanResponse(bool set) { * @param [in] connectWhitelistOnly If true, only allow connections from those on the white list. */ void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWhitelistOnly) { - ESP_LOGD(LOG_TAG, ">> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d", scanRequestWhitelistOnly, connectWhitelistOnly); + log_v(">> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d", scanRequestWhitelistOnly, connectWhitelistOnly); if (!scanRequestWhitelistOnly && !connectWhitelistOnly) { m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY; - ESP_LOGD(LOG_TAG, "<< setScanFilter"); + log_v("<< setScanFilter"); return; } if (scanRequestWhitelistOnly && !connectWhitelistOnly) { m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY; - ESP_LOGD(LOG_TAG, "<< setScanFilter"); + log_v("<< setScanFilter"); return; } if (!scanRequestWhitelistOnly && connectWhitelistOnly) { m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST; - ESP_LOGD(LOG_TAG, "<< setScanFilter"); + log_v("<< setScanFilter"); return; } if (scanRequestWhitelistOnly && connectWhitelistOnly) { m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST; - ESP_LOGD(LOG_TAG, "<< setScanFilter"); + log_v("<< setScanFilter"); return; } } // setScanFilter @@ -149,15 +140,15 @@ void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWh * @param [in] advertisementData The data to be advertised. */ void BLEAdvertising::setAdvertisementData(BLEAdvertisementData& advertisementData) { - ESP_LOGD(LOG_TAG, ">> setAdvertisementData"); + log_v(">> setAdvertisementData"); esp_err_t errRc = ::esp_ble_gap_config_adv_data_raw( (uint8_t*)advertisementData.getPayload().data(), advertisementData.getPayload().length()); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_config_adv_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_config_adv_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc)); } m_customAdvData = true; // Set the flag that indicates we are using custom advertising data. - ESP_LOGD(LOG_TAG, "<< setAdvertisementData"); + log_v("<< setAdvertisementData"); } // setAdvertisementData @@ -166,15 +157,15 @@ void BLEAdvertising::setAdvertisementData(BLEAdvertisementData& advertisementDat * @param [in] advertisementData The data to be advertised. */ void BLEAdvertising::setScanResponseData(BLEAdvertisementData& advertisementData) { - ESP_LOGD(LOG_TAG, ">> setScanResponseData"); + log_v(">> setScanResponseData"); esp_err_t errRc = ::esp_ble_gap_config_scan_rsp_data_raw( (uint8_t*)advertisementData.getPayload().data(), advertisementData.getPayload().length()); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_config_scan_rsp_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_config_scan_rsp_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc)); } m_customScanResponseData = true; // Set the flag that indicates we are using custom scan response data. - ESP_LOGD(LOG_TAG, "<< setScanResponseData"); + log_v("<< setScanResponseData"); } // setScanResponseData /** @@ -183,7 +174,7 @@ void BLEAdvertising::setScanResponseData(BLEAdvertisementData& advertisementData * @return N/A. */ void BLEAdvertising::start() { - ESP_LOGD(LOG_TAG, ">> start: customAdvData: %d, customScanResponseData: %d", m_customAdvData, m_customScanResponseData); + log_v(">> start: customAdvData: %d, customScanResponseData: %d", m_customAdvData, m_customScanResponseData); // We have a vector of service UUIDs that we wish to advertise. In order to use the // ESP-IDF framework, these must be supplied in a contiguous array of their 128bit (16 byte) @@ -195,14 +186,14 @@ void BLEAdvertising::start() { m_advData.p_service_uuid = new uint8_t[m_advData.service_uuid_len]; uint8_t* p = m_advData.p_service_uuid; for (int i = 0; i < numServices; i++) { - ESP_LOGD(LOG_TAG, "- advertising service: %s", m_serviceUUIDs[i].toString().c_str()); + log_d("- advertising service: %s", m_serviceUUIDs[i].toString().c_str()); BLEUUID serviceUUID128 = m_serviceUUIDs[i].to128(); memcpy(p, serviceUUID128.getNative()->uuid.uuid128, 16); p += 16; } } else { m_advData.service_uuid_len = 0; - ESP_LOGD(LOG_TAG, "- no services advertised"); + log_d("- no services advertised"); } esp_err_t errRc; @@ -214,7 +205,7 @@ void BLEAdvertising::start() { m_advData.include_txpower = !m_scanResp; errRc = ::esp_ble_gap_config_adv_data(&m_advData); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< esp_ble_gap_config_adv_data: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("<< esp_ble_gap_config_adv_data: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } } @@ -225,7 +216,7 @@ void BLEAdvertising::start() { m_advData.include_txpower = m_scanResp; errRc = ::esp_ble_gap_config_adv_data(&m_advData); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } } @@ -240,10 +231,10 @@ void BLEAdvertising::start() { // Start advertising. errRc = ::esp_ble_gap_start_advertising(&m_advParams); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< esp_ble_gap_start_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("<< esp_ble_gap_start_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } - ESP_LOGD(LOG_TAG, "<< start"); + log_v("<< start"); } // start @@ -253,13 +244,13 @@ void BLEAdvertising::start() { * @return N/A. */ void BLEAdvertising::stop() { - ESP_LOGD(LOG_TAG, ">> stop"); + log_v(">> stop"); esp_err_t errRc = ::esp_ble_gap_stop_advertising(); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_stop_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_stop_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } - ESP_LOGD(LOG_TAG, "<< stop"); + log_v("<< stop"); } // stop /** @@ -352,12 +343,12 @@ void BLEAdvertisementData::setFlags(uint8_t flag) { * @param [in] data Manufacturer data. */ void BLEAdvertisementData::setManufacturerData(std::string data) { - ESP_LOGD("BLEAdvertisementData", ">> setManufacturerData"); + log_d("BLEAdvertisementData", ">> setManufacturerData"); char cdata[2]; cdata[0] = data.length() + 1; cdata[1] = ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE; // 0xff addData(std::string(cdata, 2) + data); - ESP_LOGD("BLEAdvertisementData", "<< setManufacturerData"); + log_d("BLEAdvertisementData", "<< setManufacturerData"); } // setManufacturerData @@ -366,12 +357,12 @@ void BLEAdvertisementData::setManufacturerData(std::string data) { * @param [in] The complete name of the device. */ void BLEAdvertisementData::setName(std::string name) { - ESP_LOGD("BLEAdvertisementData", ">> setName: %s", name.c_str()); + log_d("BLEAdvertisementData", ">> setName: %s", name.c_str()); char cdata[2]; cdata[0] = name.length() + 1; cdata[1] = ESP_BLE_AD_TYPE_NAME_CMPL; // 0x09 addData(std::string(cdata, 2) + name); - ESP_LOGD("BLEAdvertisementData", "<< setName"); + log_d("BLEAdvertisementData", "<< setName"); } // setName @@ -455,12 +446,12 @@ void BLEAdvertisementData::setServiceData(BLEUUID uuid, std::string data) { * @param [in] The short name of the device. */ void BLEAdvertisementData::setShortName(std::string name) { - ESP_LOGD("BLEAdvertisementData", ">> setShortName: %s", name.c_str()); + log_d("BLEAdvertisementData", ">> setShortName: %s", name.c_str()); char cdata[2]; cdata[0] = name.length() + 1; cdata[1] = ESP_BLE_AD_TYPE_NAME_SHORT; // 0x08 addData(std::string(cdata, 2) + name); - ESP_LOGD("BLEAdvertisementData", "<< setShortName"); + log_d("BLEAdvertisementData", "<< setShortName"); } // setShortName @@ -476,7 +467,7 @@ void BLEAdvertising::handleGAPEvent( esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param) { - ESP_LOGD(LOG_TAG, "handleGAPEvent [event no: %d]", (int)event); + log_d("handleGAPEvent [event no: %d]", (int)event); switch(event) { case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: { @@ -492,7 +483,7 @@ void BLEAdvertising::handleGAPEvent( break; } case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: { - ESP_LOGI(LOG_TAG, "STOP advertising"); + log_i("STOP advertising"); start(); break; } diff --git a/libraries/BLE/src/BLEBeacon.cpp b/libraries/BLE/src/BLEBeacon.cpp index 68f8d8ed..1056cd54 100644 --- a/libraries/BLE/src/BLEBeacon.cpp +++ b/libraries/BLE/src/BLEBeacon.cpp @@ -8,13 +8,7 @@ #if defined(CONFIG_BT_ENABLED) #include #include "BLEBeacon.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEBeacon"; -#endif #define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8)) @@ -58,7 +52,7 @@ int8_t BLEBeacon::getSignalPower() { */ void BLEBeacon::setData(std::string data) { if (data.length() != sizeof(m_beaconData)) { - ESP_LOGE(LOG_TAG, "Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData)); + log_e("Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData)); return; } memcpy(&m_beaconData, data.data(), sizeof(m_beaconData)); diff --git a/libraries/BLE/src/BLECharacteristic.cpp b/libraries/BLE/src/BLECharacteristic.cpp index e3402874..95966cc7 100644 --- a/libraries/BLE/src/BLECharacteristic.cpp +++ b/libraries/BLE/src/BLECharacteristic.cpp @@ -18,13 +18,7 @@ #include "BLEUtils.h" #include "BLE2902.h" #include "GeneralUtils.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLECharacteristic"; -#endif #define NULL_HANDLE (0xffff) @@ -70,9 +64,9 @@ BLECharacteristic::~BLECharacteristic() { * @return N/A. */ void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) { - ESP_LOGD(LOG_TAG, ">> addDescriptor(): Adding %s to %s", pDescriptor->toString().c_str(), toString().c_str()); + log_v(">> addDescriptor(): Adding %s to %s", pDescriptor->toString().c_str(), toString().c_str()); m_descriptorMap.setByUUID(pDescriptor->getUUID(), pDescriptor); - ESP_LOGD(LOG_TAG, "<< addDescriptor()"); + log_v("<< addDescriptor()"); } // addDescriptor @@ -81,16 +75,16 @@ void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) { * @param [in] pService The service with which to associate this characteristic. */ void BLECharacteristic::executeCreate(BLEService* pService) { - ESP_LOGD(LOG_TAG, ">> executeCreate()"); + log_v(">> executeCreate()"); if (m_handle != NULL_HANDLE) { - ESP_LOGE(LOG_TAG, "Characteristic already has a handle."); + log_e("Characteristic already has a handle."); return; } m_pService = pService; // Save the service to which this characteristic belongs. - ESP_LOGD(LOG_TAG, "Registering characteristic (esp_ble_gatts_add_char): uuid: %s, service: %s", + log_d("Registering characteristic (esp_ble_gatts_add_char): uuid: %s, service: %s", getUUID().toString().c_str(), m_pService->toString().c_str()); @@ -107,7 +101,7 @@ void BLECharacteristic::executeCreate(BLEService* pService) { &control); // Whether to auto respond or not. if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_add_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("<< esp_ble_gatts_add_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } m_semaphoreCreateEvt.wait("executeCreate"); @@ -118,7 +112,7 @@ void BLECharacteristic::executeCreate(BLEService* pService) { pDescriptor = m_descriptorMap.getNext(); } // End while - ESP_LOGD(LOG_TAG, "<< executeCreate"); + log_v("<< executeCreate"); } // executeCreate @@ -200,7 +194,7 @@ void BLECharacteristic::handleGATTServerEvent( esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param) { - ESP_LOGD(LOG_TAG, ">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); + log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); switch(event) { // Events handled: @@ -238,7 +232,7 @@ void BLECharacteristic::handleGATTServerEvent( param->write.conn_id, param->write.trans_id, ESP_GATT_OK, nullptr); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } break; } // ESP_GATTS_EXEC_WRITE_EVT @@ -288,11 +282,11 @@ void BLECharacteristic::handleGATTServerEvent( setValue(param->write.value, param->write.len); } - ESP_LOGD(LOG_TAG, " - Response to write event: New value: handle: %.2x, uuid: %s", + log_d(" - Response to write event: New value: handle: %.2x, uuid: %s", getHandle(), getUUID().toString().c_str()); char* pHexData = BLEUtils::buildHexData(nullptr, param->write.value, param->write.len); - ESP_LOGD(LOG_TAG, " - Data: length: %d, data: %s", param->write.len, pHexData); + log_d(" - Data: length: %d, data: %s", param->write.len, pHexData); free(pHexData); if (param->write.need_rsp) { @@ -309,7 +303,7 @@ void BLECharacteristic::handleGATTServerEvent( param->write.conn_id, param->write.trans_id, ESP_GATT_OK, &rsp); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } } // Response needed @@ -361,9 +355,9 @@ void BLECharacteristic::handleGATTServerEvent( // get mtu for peer device that we are sending read request to uint16_t maxOffset = getService()->getServer()->getPeerMTU(param->read.conn_id) - 1; - ESP_LOGD(LOG_TAG, "mtu value: %d", maxOffset); + log_d("mtu value: %d", maxOffset); if (param->read.need_rsp) { - ESP_LOGD(LOG_TAG, "Sending a response (esp_ble_gatts_send_response)"); + log_d("Sending a response (esp_ble_gatts_send_response)"); esp_gatt_rsp_t rsp; if (param->read.is_long) { @@ -407,7 +401,7 @@ void BLECharacteristic::handleGATTServerEvent( rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; char *pHexData = BLEUtils::buildHexData(nullptr, rsp.attr_value.value, rsp.attr_value.len); - ESP_LOGD(LOG_TAG, " - Data: length=%d, data=%s, offset=%d", rsp.attr_value.len, pHexData, rsp.attr_value.offset); + log_d(" - Data: length=%d, data=%s, offset=%d", rsp.attr_value.len, pHexData, rsp.attr_value.offset); free(pHexData); esp_err_t errRc = ::esp_ble_gatts_send_response( @@ -416,7 +410,7 @@ void BLECharacteristic::handleGATTServerEvent( ESP_GATT_OK, &rsp); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } } // Response needed } // Handle matches this characteristic. @@ -431,7 +425,7 @@ void BLECharacteristic::handleGATTServerEvent( // - uint16_t conn_id – The connection used. // case ESP_GATTS_CONF_EVT: { - // ESP_LOGD(LOG_TAG, "m_handle = %d, conf->handle = %d", m_handle, param->conf.handle); + // log_d("m_handle = %d, conf->handle = %d", m_handle, param->conf.handle); if(param->conf.conn_id == getService()->getServer()->getConnId()) // && param->conf.handle == m_handle) // bug in esp-idf and not implemented in arduino yet m_semaphoreConfEvt.give(param->conf.status); break; @@ -456,7 +450,7 @@ void BLECharacteristic::handleGATTServerEvent( // event. m_descriptorMap.handleGATTServerEvent(event, gatts_if, param); - ESP_LOGD(LOG_TAG, "<< handleGATTServerEvent"); + log_v("<< handleGATTServerEvent"); } // handleGATTServerEvent @@ -468,9 +462,9 @@ void BLECharacteristic::handleGATTServerEvent( */ void BLECharacteristic::indicate() { - ESP_LOGD(LOG_TAG, ">> indicate: length: %d", m_value.getValue().length()); + log_v(">> indicate: length: %d", m_value.getValue().length()); notify(false); - ESP_LOGD(LOG_TAG, "<< indicate"); + log_v("<< indicate"); } // indicate @@ -481,7 +475,7 @@ void BLECharacteristic::indicate() { * @return N/A. */ void BLECharacteristic::notify(bool is_notification) { - ESP_LOGD(LOG_TAG, ">> notify: length: %d", m_value.getValue().length()); + log_v(">> notify: length: %d", m_value.getValue().length()); assert(getService() != nullptr); assert(getService()->getServer() != nullptr); @@ -489,7 +483,7 @@ void BLECharacteristic::notify(bool is_notification) { GeneralUtils::hexDump((uint8_t*)m_value.getValue().data(), m_value.getValue().length()); if (getService()->getServer()->getConnectedCount() == 0) { - ESP_LOGD(LOG_TAG, "<< notify: No connected clients."); + log_v("<< notify: No connected clients."); return; } @@ -499,20 +493,20 @@ void BLECharacteristic::notify(bool is_notification) { BLE2902 *p2902 = (BLE2902*)getDescriptorByUUID((uint16_t)0x2902); if(is_notification) { if (p2902 != nullptr && !p2902->getNotifications()) { - ESP_LOGD(LOG_TAG, "<< notifications disabled; ignoring"); + log_v("<< notifications disabled; ignoring"); return; } } else{ if (p2902 != nullptr && !p2902->getIndications()) { - ESP_LOGD(LOG_TAG, "<< indications disabled; ignoring"); + log_v("<< indications disabled; ignoring"); return; } } for (auto &myPair : getService()->getServer()->getPeerDevices(false)) { uint16_t _mtu = (myPair.second.mtu); if (m_value.getValue().length() > _mtu - 3) { - ESP_LOGW(LOG_TAG, "- Truncating to %d bytes (maximum notify size)", _mtu - 3); + log_w("- Truncating to %d bytes (maximum notify size)", _mtu - 3); } size_t length = m_value.getValue().length(); @@ -523,14 +517,14 @@ void BLECharacteristic::notify(bool is_notification) { myPair.first, getHandle(), length, (uint8_t*)m_value.getValue().data(), !is_notification); // The need_confirm = false makes this a notify. if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_send_ %s: rc=%d %s",is_notification?"notify":"indicate", errRc, GeneralUtils::errorToString(errRc)); + log_e("<< esp_ble_gatts_send_ %s: rc=%d %s",is_notification?"notify":"indicate", errRc, GeneralUtils::errorToString(errRc)); m_semaphoreConfEvt.give(); return; } if(!is_notification) m_semaphoreConfEvt.wait("indicate"); } - ESP_LOGD(LOG_TAG, "<< notify"); + log_v("<< notify"); } // Notify @@ -542,7 +536,7 @@ void BLECharacteristic::notify(bool is_notification) { * @return N/A */ void BLECharacteristic::setBroadcastProperty(bool value) { - //ESP_LOGD(LOG_TAG, "setBroadcastProperty(%d)", value); + //log_d("setBroadcastProperty(%d)", value); if (value) { m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_BROADCAST); } else { @@ -556,9 +550,9 @@ void BLECharacteristic::setBroadcastProperty(bool value) { * @param [in] pCallbacks An instance of a callbacks structure used to define any callbacks for the characteristic. */ void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) { - ESP_LOGD(LOG_TAG, ">> setCallbacks: 0x%x", (uint32_t)pCallbacks); + log_v(">> setCallbacks: 0x%x", (uint32_t)pCallbacks); m_pCallbacks = pCallbacks; - ESP_LOGD(LOG_TAG, "<< setCallbacks"); + log_v("<< setCallbacks"); } // setCallbacks @@ -573,9 +567,9 @@ void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) { * @param [in] handle The handle associated with this characteristic. */ void BLECharacteristic::setHandle(uint16_t handle) { - ESP_LOGD(LOG_TAG, ">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString().c_str()); + log_v(">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString().c_str()); m_handle = handle; - ESP_LOGD(LOG_TAG, "<< setHandle"); + log_v("<< setHandle"); } // setHandle @@ -584,7 +578,7 @@ void BLECharacteristic::setHandle(uint16_t handle) { * @param [in] value Set to true if we are to allow indicate messages. */ void BLECharacteristic::setIndicateProperty(bool value) { - //ESP_LOGD(LOG_TAG, "setIndicateProperty(%d)", value); + //log_d("setIndicateProperty(%d)", value); if (value) { m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_INDICATE); } else { @@ -598,7 +592,7 @@ void BLECharacteristic::setIndicateProperty(bool value) { * @param [in] value Set to true if we are to allow notification messages. */ void BLECharacteristic::setNotifyProperty(bool value) { - //ESP_LOGD(LOG_TAG, "setNotifyProperty(%d)", value); + //log_d("setNotifyProperty(%d)", value); if (value) { m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_NOTIFY); } else { @@ -612,7 +606,7 @@ void BLECharacteristic::setNotifyProperty(bool value) { * @param [in] value Set to true if we are to allow reads. */ void BLECharacteristic::setReadProperty(bool value) { - //ESP_LOGD(LOG_TAG, "setReadProperty(%d)", value); + //log_d("setReadProperty(%d)", value); if (value) { m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_READ); } else { @@ -628,14 +622,14 @@ void BLECharacteristic::setReadProperty(bool value) { */ void BLECharacteristic::setValue(uint8_t* data, size_t length) { char* pHex = BLEUtils::buildHexData(nullptr, data, length); - ESP_LOGD(LOG_TAG, ">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str()); + log_v(">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str()); free(pHex); if (length > ESP_GATT_MAX_ATTR_LEN) { - ESP_LOGE(LOG_TAG, "Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN); + log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN); return; } m_value.setValue(data, length); - ESP_LOGD(LOG_TAG, "<< setValue"); + log_v("<< setValue"); } // setValue @@ -693,7 +687,7 @@ void BLECharacteristic::setValue(double& data64) { * @param [in] value Set to true if we are to allow writes with no response. */ void BLECharacteristic::setWriteNoResponseProperty(bool value) { - //ESP_LOGD(LOG_TAG, "setWriteNoResponseProperty(%d)", value); + //log_d("setWriteNoResponseProperty(%d)", value); if (value) { m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_WRITE_NR); } else { @@ -707,7 +701,7 @@ void BLECharacteristic::setWriteNoResponseProperty(bool value) { * @param [in] value Set to true if we are to allow writes. */ void BLECharacteristic::setWriteProperty(bool value) { - //ESP_LOGD(LOG_TAG, "setWriteProperty(%d)", value); + //log_d("setWriteProperty(%d)", value); if (value) { m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_WRITE); } else { @@ -743,8 +737,8 @@ BLECharacteristicCallbacks::~BLECharacteristicCallbacks() {} * @param [in] pCharacteristic The characteristic that is the source of the event. */ void BLECharacteristicCallbacks::onRead(BLECharacteristic* pCharacteristic) { - ESP_LOGD("BLECharacteristicCallbacks", ">> onRead: default"); - ESP_LOGD("BLECharacteristicCallbacks", "<< onRead"); + log_d("BLECharacteristicCallbacks", ">> onRead: default"); + log_d("BLECharacteristicCallbacks", "<< onRead"); } // onRead @@ -753,8 +747,8 @@ void BLECharacteristicCallbacks::onRead(BLECharacteristic* pCharacteristic) { * @param [in] pCharacteristic The characteristic that is the source of the event. */ void BLECharacteristicCallbacks::onWrite(BLECharacteristic* pCharacteristic) { - ESP_LOGD("BLECharacteristicCallbacks", ">> onWrite: default"); - ESP_LOGD("BLECharacteristicCallbacks", "<< onWrite"); + log_d("BLECharacteristicCallbacks", ">> onWrite: default"); + log_d("BLECharacteristicCallbacks", "<< onWrite"); } // onWrite #endif /* CONFIG_BT_ENABLED */ diff --git a/libraries/BLE/src/BLEClient.cpp b/libraries/BLE/src/BLEClient.cpp index 0e552ece..f5f82bcd 100644 --- a/libraries/BLE/src/BLEClient.cpp +++ b/libraries/BLE/src/BLEClient.cpp @@ -18,14 +18,7 @@ #include #include #include "BLEDevice.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEClient"; -#endif - /* * Design @@ -75,14 +68,14 @@ BLEClient::~BLEClient() { * */ void BLEClient::clearServices() { - ESP_LOGD(LOG_TAG, ">> clearServices"); + log_v(">> clearServices"); // Delete all the services. for (auto &myPair : m_servicesMap) { delete myPair.second; } m_servicesMap.clear(); m_haveServices = false; - ESP_LOGD(LOG_TAG, "<< clearServices"); + log_v("<< clearServices"); } // clearServices /** @@ -100,7 +93,7 @@ bool BLEClient::connect(BLEAdvertisedDevice* device) { * @return True on success. */ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) { - ESP_LOGD(LOG_TAG, ">> connect(%s)", address.toString().c_str()); + log_v(">> connect(%s)", address.toString().c_str()); // We need the connection handle that we get from registering the application. We register the app // and then block on its completion. When the event has arrived, we will have the handle. @@ -111,7 +104,7 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) { // clearServices(); // we dont need to delete services since every client is unique? esp_err_t errRc = ::esp_ble_gattc_app_register(m_appId); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_app_register: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_app_register: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return false; } @@ -128,12 +121,12 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) { 1 // direct connection <-- maybe needs to be changed in case of direct indirect connection??? ); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return false; } uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete. - ESP_LOGD(LOG_TAG, "<< connect(), rc=%d", rc==ESP_GATT_OK); + log_v("<< connect(), rc=%d", rc==ESP_GATT_OK); return rc == ESP_GATT_OK; } // connect @@ -143,13 +136,13 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) { * @return N/A. */ void BLEClient::disconnect() { - ESP_LOGD(LOG_TAG, ">> disconnect()"); + log_v(">> disconnect()"); esp_err_t errRc = ::esp_ble_gattc_close(getGattcIf(), getConnId()); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_close: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_close: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } - ESP_LOGD(LOG_TAG, "<< disconnect()"); + log_v("<< disconnect()"); } // disconnect @@ -161,14 +154,14 @@ void BLEClient::gattClientEventHandler( esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam) { - ESP_LOGD(LOG_TAG, "gattClientEventHandler [esp_gatt_if: %d] ... %s", + log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s", gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str()); // Execute handler code based on the type of event received. switch(event) { case ESP_GATTC_SRVC_CHG_EVT: - ESP_LOGI(LOG_TAG, "SERVICE CHANGED"); + log_i("SERVICE CHANGED"); break; case ESP_GATTC_CLOSE_EVT: { @@ -234,7 +227,7 @@ void BLEClient::gattClientEventHandler( case ESP_GATTC_CFG_MTU_EVT: if(evtParam->cfg_mtu.status != ESP_GATT_OK) { - ESP_LOGE(LOG_TAG,"Config mtu failed"); + log_e("Config mtu failed"); } m_mtu = evtParam->cfg_mtu.mtu; break; @@ -243,7 +236,7 @@ void BLEClient::gattClientEventHandler( BLEDevice::updatePeerDevice(this, true, m_gattc_if); esp_err_t errRc = esp_ble_gattc_send_mtu_req(gattc_if, evtParam->connect.conn_id); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } #ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig if(BLEDevice::m_securityLevel){ @@ -263,17 +256,17 @@ void BLEClient::gattClientEventHandler( case ESP_GATTC_SEARCH_CMPL_EVT: { esp_ble_gattc_cb_param_t* p_data = (esp_ble_gattc_cb_param_t*)evtParam; if (p_data->search_cmpl.status != ESP_GATT_OK){ - ESP_LOGE(LOG_TAG, "search service failed, error status = %x", p_data->search_cmpl.status); + log_e("search service failed, error status = %x", p_data->search_cmpl.status); break; } #ifndef ARDUINO_ARCH_ESP32 // commented out just for now to keep backward compatibility // if(p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_REMOTE_DEVICE) { - // ESP_LOGI(LOG_TAG, "Get service information from remote device"); + // log_i("Get service information from remote device"); // } else if (p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_NVS_FLASH) { - // ESP_LOGI(LOG_TAG, "Get service information from flash"); + // log_i("Get service information from flash"); // } else { - // ESP_LOGI(LOG_TAG, "unknown service source"); + // log_i("unknown service source"); // } #endif m_semaphoreSearchCmplEvt.give(0); @@ -343,9 +336,9 @@ BLEAddress BLEClient::getPeerAddress() { * @return The RSSI value. */ int BLEClient::getRssi() { - ESP_LOGD(LOG_TAG, ">> getRssi()"); + log_v(">> getRssi()"); if (!isConnected()) { - ESP_LOGD(LOG_TAG, "<< getRssi(): Not connected"); + log_v("<< getRssi(): Not connected"); return 0; } // We make the API call to read the RSSI value which is an asynchronous operation. We expect to receive @@ -354,11 +347,11 @@ int BLEClient::getRssi() { m_semaphoreRssiCmplEvt.take("getRssi"); esp_err_t rc = ::esp_ble_gap_read_rssi(*getPeerAddress().getNative()); if (rc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< getRssi: esp_ble_gap_read_rssi: rc=%d %s", rc, GeneralUtils::errorToString(rc)); + log_e("<< getRssi: esp_ble_gap_read_rssi: rc=%d %s", rc, GeneralUtils::errorToString(rc)); return 0; } int rssiValue = m_semaphoreRssiCmplEvt.wait("getRssi"); - ESP_LOGD(LOG_TAG, "<< getRssi(): %d", rssiValue); + log_v("<< getRssi(): %d", rssiValue); return rssiValue; } // getRssi @@ -380,7 +373,7 @@ BLERemoteService* BLEClient::getService(const char* uuid) { * @throws BLEUuidNotFound */ BLERemoteService* BLEClient::getService(BLEUUID uuid) { - ESP_LOGD(LOG_TAG, ">> getService: uuid: %s", uuid.toString().c_str()); + log_v(">> getService: uuid: %s", uuid.toString().c_str()); // Design // ------ // We wish to retrieve the service given its UUID. It is possible that we have not yet asked the @@ -393,11 +386,11 @@ BLERemoteService* BLEClient::getService(BLEUUID uuid) { std::string uuidStr = uuid.toString(); for (auto &myPair : m_servicesMap) { if (myPair.first == uuidStr) { - ESP_LOGD(LOG_TAG, "<< getService: found the service with uuid: %s", uuid.toString().c_str()); + log_v("<< getService: found the service with uuid: %s", uuid.toString().c_str()); return myPair.second; } } // End of each of the services. - ESP_LOGD(LOG_TAG, "<< getService: not found"); + log_v("<< getService: not found"); return nullptr; } // getService @@ -416,7 +409,7 @@ std::map* BLEClient::getServices() { * peer BLE partner to be returned as events. Each event will be an an instance of ESP_GATTC_SEARCH_RES_EVT * and will culminate with an ESP_GATTC_SEARCH_CMPL_EVT when all have been received. */ - ESP_LOGD(LOG_TAG, ">> getServices"); + log_v(">> getServices"); // TODO implement retrieving services from cache clearServices(); // Clear any services that may exist. @@ -428,12 +421,12 @@ std::map* BLEClient::getServices() { m_semaphoreSearchCmplEvt.take("getServices"); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_search_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_search_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return &m_servicesMap; } // If sucessfull, remember that we now have services. m_haveServices = (m_semaphoreSearchCmplEvt.wait("getServices") == 0); - ESP_LOGD(LOG_TAG, "<< getServices"); + log_v("<< getServices"); return &m_servicesMap; } // getServices @@ -445,9 +438,9 @@ std::map* BLEClient::getServices() { * @throws BLEUuidNotFound */ std::string BLEClient::getValue(BLEUUID serviceUUID, BLEUUID characteristicUUID) { - ESP_LOGD(LOG_TAG, ">> getValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); + log_v(">> getValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); std::string ret = getService(serviceUUID)->getCharacteristic(characteristicUUID)->readValue(); - ESP_LOGD(LOG_TAG, "<> setValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); + log_v(">> setValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); getService(serviceUUID)->getCharacteristic(characteristicUUID)->writeValue(value); - ESP_LOGD(LOG_TAG, "<< setValue"); + log_v("<< setValue"); } // setValue uint16_t BLEClient::getMTU() { diff --git a/libraries/BLE/src/BLEDescriptor.cpp b/libraries/BLE/src/BLEDescriptor.cpp index ba5753de..22df6550 100644 --- a/libraries/BLE/src/BLEDescriptor.cpp +++ b/libraries/BLE/src/BLEDescriptor.cpp @@ -15,16 +15,7 @@ #include "BLEService.h" #include "BLEDescriptor.h" #include "GeneralUtils.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEDescriptor"; -#endif - - - #define NULL_HANDLE (0xffff) @@ -63,10 +54,10 @@ BLEDescriptor::~BLEDescriptor() { * @param [in] pCharacteristic The characteristic to which to register this descriptor. */ void BLEDescriptor::executeCreate(BLECharacteristic* pCharacteristic) { - ESP_LOGD(LOG_TAG, ">> executeCreate(): %s", toString().c_str()); + log_v(">> executeCreate(): %s", toString().c_str()); if (m_handle != NULL_HANDLE) { - ESP_LOGE(LOG_TAG, "Descriptor already has a handle."); + log_e("Descriptor already has a handle."); return; } @@ -82,12 +73,12 @@ void BLEDescriptor::executeCreate(BLECharacteristic* pCharacteristic) { &m_value, &control); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_add_char_descr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("<< esp_ble_gatts_add_char_descr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } m_semaphoreCreateEvt.wait("executeCreate"); - ESP_LOGD(LOG_TAG, "<< executeCreate"); + log_v("<< executeCreate"); } // executeCreate @@ -213,9 +204,9 @@ void BLEDescriptor::handleGATTServerEvent( * @param [in] pCallbacks An instance of a callback structure used to define any callbacks for the descriptor. */ void BLEDescriptor::setCallbacks(BLEDescriptorCallbacks* pCallback) { - ESP_LOGD(LOG_TAG, ">> setCallbacks: 0x%x", (uint32_t) pCallback); + log_v(">> setCallbacks: 0x%x", (uint32_t) pCallback); m_pCallback = pCallback; - ESP_LOGD(LOG_TAG, "<< setCallbacks"); + log_v("<< setCallbacks"); } // setCallbacks @@ -226,9 +217,9 @@ void BLEDescriptor::setCallbacks(BLEDescriptorCallbacks* pCallback) { * @return N/A. */ void BLEDescriptor::setHandle(uint16_t handle) { - ESP_LOGD(LOG_TAG, ">> setHandle(0x%.2x): Setting descriptor handle to be 0x%.2x", handle, handle); + log_v(">> setHandle(0x%.2x): Setting descriptor handle to be 0x%.2x", handle, handle); m_handle = handle; - ESP_LOGD(LOG_TAG, "<< setHandle()"); + log_v("<< setHandle()"); } // setHandle @@ -239,7 +230,7 @@ void BLEDescriptor::setHandle(uint16_t handle) { */ void BLEDescriptor::setValue(uint8_t* data, size_t length) { if (length > ESP_GATT_MAX_ATTR_LEN) { - ESP_LOGE(LOG_TAG, "Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN); + log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN); return; } m_value.attr_len = length; @@ -278,8 +269,8 @@ BLEDescriptorCallbacks::~BLEDescriptorCallbacks() {} * @param [in] pDescriptor The descriptor that is the source of the event. */ void BLEDescriptorCallbacks::onRead(BLEDescriptor* pDescriptor) { - ESP_LOGD("BLEDescriptorCallbacks", ">> onRead: default"); - ESP_LOGD("BLEDescriptorCallbacks", "<< onRead"); + log_d("BLEDescriptorCallbacks", ">> onRead: default"); + log_d("BLEDescriptorCallbacks", "<< onRead"); } // onRead @@ -288,8 +279,8 @@ void BLEDescriptorCallbacks::onRead(BLEDescriptor* pDescriptor) { * @param [in] pDescriptor The descriptor that is the source of the event. */ void BLEDescriptorCallbacks::onWrite(BLEDescriptor* pDescriptor) { - ESP_LOGD("BLEDescriptorCallbacks", ">> onWrite: default"); - ESP_LOGD("BLEDescriptorCallbacks", "<< onWrite"); + log_d("BLEDescriptorCallbacks", ">> onWrite: default"); + log_d("BLEDescriptorCallbacks", "<< onWrite"); } // onWrite diff --git a/libraries/BLE/src/BLEDevice.cpp b/libraries/BLE/src/BLEDevice.cpp index cb2db41f..819f8226 100644 --- a/libraries/BLE/src/BLEDevice.cpp +++ b/libraries/BLE/src/BLEDevice.cpp @@ -34,7 +34,7 @@ #if defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" + #else #include "esp_log.h" static const char* LOG_TAG = "BLEDevice"; @@ -63,13 +63,13 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @return A new instance of the client. */ /* STATIC */ BLEClient* BLEDevice::createClient() { - ESP_LOGD(LOG_TAG, ">> createClient"); + log_v(">> createClient"); #ifndef CONFIG_GATTC_ENABLE // Check that BLE GATTC is enabled in make menuconfig - ESP_LOGE(LOG_TAG, "BLE GATTC is not enabled - CONFIG_GATTC_ENABLE not defined"); + log_e("BLE GATTC is not enabled - CONFIG_GATTC_ENABLE not defined"); abort(); #endif // CONFIG_GATTC_ENABLE m_pClient = new BLEClient(); - ESP_LOGD(LOG_TAG, "<< createClient"); + log_v("<< createClient"); return m_pClient; } // createClient @@ -79,14 +79,14 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @return A new instance of the server. */ /* STATIC */ BLEServer* BLEDevice::createServer() { - ESP_LOGD(LOG_TAG, ">> createServer"); + log_v(">> createServer"); #ifndef CONFIG_GATTS_ENABLE // Check that BLE GATTS is enabled in make menuconfig - ESP_LOGE(LOG_TAG, "BLE GATTS is not enabled - CONFIG_GATTS_ENABLE not defined"); + log_e("BLE GATTS is not enabled - CONFIG_GATTS_ENABLE not defined"); abort(); #endif // CONFIG_GATTS_ENABLE m_pServer = new BLEServer(); m_pServer->createApp(m_appId++); - ESP_LOGD(LOG_TAG, "<< createServer"); + log_v("<< createServer"); return m_pServer; } // createServer @@ -103,7 +103,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param ) { - ESP_LOGD(LOG_TAG, "gattServerEventHandler [esp_gatt_if: %d] ... %s", + log_d("gattServerEventHandler [esp_gatt_if: %d] ... %s", gatts_if, BLEUtils::gattServerEventTypeToString(event).c_str()); @@ -150,7 +150,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param) { - ESP_LOGD(LOG_TAG, "gattClientEventHandler [esp_gatt_if: %d] ... %s", + log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s", gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str()); BLEUtils::dumpGattClientEvent(event, gattc_if, param); @@ -194,16 +194,16 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; switch(event) { case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */ - ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_OOB_REQ_EVT"); + log_i("ESP_GAP_BLE_OOB_REQ_EVT"); break; case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */ - ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT"); + log_i("ESP_GAP_BLE_LOCAL_IR_EVT"); break; case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */ - ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_LOCAL_ER_EVT"); + log_i("ESP_GAP_BLE_LOCAL_ER_EVT"); break; case ESP_GAP_BLE_NC_REQ_EVT: /* NUMERIC CONFIRMATION */ - ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_NC_REQ_EVT"); + log_i("ESP_GAP_BLE_NC_REQ_EVT"); #ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig if(BLEDevice::m_securityCallbacks != nullptr){ esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onConfirmPIN(param->ble_security.key_notif.passkey)); @@ -211,8 +211,8 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; #endif // CONFIG_BLE_SMP_ENABLE break; case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */ - ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT: "); - // esp_log_buffer_hex(LOG_TAG, m_remote_bda, sizeof(m_remote_bda)); + log_i("ESP_GAP_BLE_PASSKEY_REQ_EVT: "); + // esp_log_buffer_hex(m_remote_bda, sizeof(m_remote_bda)); #ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig if(BLEDevice::m_securityCallbacks != nullptr){ esp_ble_passkey_reply(param->ble_security.ble_req.bd_addr, true, BLEDevice::m_securityCallbacks->onPassKeyRequest()); @@ -225,7 +225,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; case ESP_GAP_BLE_SEC_REQ_EVT: /* send the positive(true) security response to the peer device to accept the security request. If not accept the security request, should sent the security response with negative(false) accept value*/ - ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_SEC_REQ_EVT"); + log_i("ESP_GAP_BLE_SEC_REQ_EVT"); #ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig if(BLEDevice::m_securityCallbacks!=nullptr){ esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onSecurityRequest()); @@ -240,9 +240,9 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; */ case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: //the app will receive this evt when the IO has Output capability and the peer device IO has Input capability. //display the passkey number to the user to input it in the peer deivce within 30 seconds - ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PASSKEY_NOTIF_EVT"); + log_i("ESP_GAP_BLE_PASSKEY_NOTIF_EVT"); #ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - ESP_LOGI(LOG_TAG, "passKey = %d", param->ble_security.key_notif.passkey); + log_i("passKey = %d", param->ble_security.key_notif.passkey); if(BLEDevice::m_securityCallbacks!=nullptr){ BLEDevice::m_securityCallbacks->onPassKeyNotify(param->ble_security.key_notif.passkey); } @@ -250,13 +250,13 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; break; case ESP_GAP_BLE_KEY_EVT: //shows the ble key type info share with peer device to the user. - ESP_LOGD(LOG_TAG, "ESP_GAP_BLE_KEY_EVT"); + log_d("ESP_GAP_BLE_KEY_EVT"); #ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - ESP_LOGI(LOG_TAG, "key type = %s", BLESecurity::esp_key_type_to_str(param->ble_security.ble_key.key_type)); + log_i("key type = %s", BLESecurity::esp_key_type_to_str(param->ble_security.ble_key.key_type)); #endif // CONFIG_BLE_SMP_ENABLE break; case ESP_GAP_BLE_AUTH_CMPL_EVT: - ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_AUTH_CMPL_EVT"); + log_i("ESP_GAP_BLE_AUTH_CMPL_EVT"); #ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig if(BLEDevice::m_securityCallbacks != nullptr){ BLEDevice::m_securityCallbacks->onAuthenticationComplete(param->ble_security.auth_cmpl); @@ -305,12 +305,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * try and release/delete it. */ /* STATIC */ BLEScan* BLEDevice::getScan() { - //ESP_LOGD(LOG_TAG, ">> getScan"); + //log_v(">> getScan"); if (m_pScan == nullptr) { m_pScan = new BLEScan(); - //ESP_LOGD(LOG_TAG, " - creating a new scan object"); + //log_d(" - creating a new scan object"); } - //ESP_LOGD(LOG_TAG, "<< getScan: Returning object at 0x%x", (uint32_t)m_pScan); + //log_v("<< getScan: Returning object at 0x%x", (uint32_t)m_pScan); return m_pScan; } // getScan @@ -322,12 +322,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] characteristicUUID */ /* STATIC */ std::string BLEDevice::getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID) { - ESP_LOGD(LOG_TAG, ">> getValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); + log_v(">> getValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); BLEClient* pClient = createClient(); pClient->connect(bdAddress); std::string ret = pClient->getValue(serviceUUID, characteristicUUID); pClient->disconnect(); - ESP_LOGD(LOG_TAG, "<< getValue"); + log_v("<< getValue"); return ret; } // getValue @@ -349,7 +349,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; #else errRc = ::nvs_flash_init(); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "nvs_flash_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("nvs_flash_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } @@ -359,20 +359,20 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); errRc = esp_bt_controller_init(&bt_cfg); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_bt_controller_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_bt_controller_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } #ifndef CLASSIC_BT_ENABLED errRc = esp_bt_controller_enable(ESP_BT_MODE_BLE); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } #else errRc = esp_bt_controller_enable(ESP_BT_MODE_BTDM); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } #endif @@ -382,7 +382,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED) { errRc = esp_bluedroid_init(); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_bluedroid_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_bluedroid_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } } @@ -390,21 +390,21 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; if (bt_state != ESP_BLUEDROID_STATUS_ENABLED) { errRc = esp_bluedroid_enable(); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_bluedroid_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_bluedroid_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } } errRc = esp_ble_gap_register_callback(BLEDevice::gapEventHandler); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } #ifdef CONFIG_GATTC_ENABLE // Check that BLE client is configured in make menuconfig errRc = esp_ble_gattc_register_callback(BLEDevice::gattClientEventHandler); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } #endif // CONFIG_GATTC_ENABLE @@ -412,14 +412,14 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; #ifdef CONFIG_GATTS_ENABLE // Check that BLE server is configured in make menuconfig errRc = esp_ble_gatts_register_callback(BLEDevice::gattServerEventHandler); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gatts_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gatts_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } #endif // CONFIG_GATTS_ENABLE errRc = ::esp_ble_gap_set_device_name(deviceName.c_str()); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_set_device_name: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_set_device_name: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; }; @@ -427,7 +427,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE; errRc = ::esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t)); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_set_security_param: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_set_security_param: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; }; #endif // CONFIG_BLE_SMP_ENABLE @@ -450,12 +450,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] powerLevel. */ /* STATIC */ void BLEDevice::setPower(esp_power_level_t powerLevel) { - ESP_LOGD(LOG_TAG, ">> setPower: %d", powerLevel); + log_v(">> setPower: %d", powerLevel); esp_err_t errRc = ::esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, powerLevel); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_tx_power_set: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_tx_power_set: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); }; - ESP_LOGD(LOG_TAG, "<< setPower"); + log_v("<< setPower"); } // setPower @@ -466,7 +466,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] characteristicUUID */ /* STATIC */ void BLEDevice::setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value) { - ESP_LOGD(LOG_TAG, ">> setValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); + log_v(">> setValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); BLEClient* pClient = createClient(); pClient->connect(bdAddress); pClient->setValue(serviceUUID, characteristicUUID, value); @@ -490,12 +490,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] address The address to add to the white list. */ void BLEDevice::whiteListAdd(BLEAddress address) { - ESP_LOGD(LOG_TAG, ">> whiteListAdd: %s", address.toString().c_str()); + log_v(">> whiteListAdd: %s", address.toString().c_str()); esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry. if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } - ESP_LOGD(LOG_TAG, "<< whiteListAdd"); + log_v("<< whiteListAdd"); } // whiteListAdd @@ -504,12 +504,12 @@ void BLEDevice::whiteListAdd(BLEAddress address) { * @param [in] address The address to remove from the white list. */ void BLEDevice::whiteListRemove(BLEAddress address) { - ESP_LOGD(LOG_TAG, ">> whiteListRemove: %s", address.toString().c_str()); + log_v(">> whiteListRemove: %s", address.toString().c_str()); esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry. if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } - ESP_LOGD(LOG_TAG, "<< whiteListRemove"); + log_v("<< whiteListRemove"); } // whiteListRemove /* @@ -533,14 +533,14 @@ void BLEDevice::setSecurityCallbacks(BLESecurityCallbacks* callbacks) { * @param [in] mtu Value to set local mtu, should be larger than 23 and lower or equal to 517 */ esp_err_t BLEDevice::setMTU(uint16_t mtu) { - ESP_LOGD(LOG_TAG, ">> setLocalMTU: %d", mtu); + log_v(">> setLocalMTU: %d", mtu); esp_err_t err = esp_ble_gatt_set_local_mtu(mtu); if (err == ESP_OK) { m_localMTU = mtu; } else { - ESP_LOGE(LOG_TAG, "can't set local mtu value: %d", mtu); + log_e("can't set local mtu value: %d", mtu); } - ESP_LOGD(LOG_TAG, "<< setLocalMTU"); + log_v("<< setLocalMTU"); return err; } @@ -558,16 +558,16 @@ bool BLEDevice::getInitialized() { BLEAdvertising* BLEDevice::getAdvertising() { if(m_bleAdvertising == nullptr) { m_bleAdvertising = new BLEAdvertising(); - ESP_LOGI(LOG_TAG, "create advertising"); + log_i("create advertising"); } - ESP_LOGD(LOG_TAG, "get advertising"); + log_d("get advertising"); return m_bleAdvertising; } void BLEDevice::startAdvertising() { - ESP_LOGD(LOG_TAG, ">> startAdvertising"); + log_v(">> startAdvertising"); getAdvertising()->start(); - ESP_LOGD(LOG_TAG, "<< startAdvertising"); + log_v("<< startAdvertising"); } // startAdvertising /* multi connect support */ @@ -581,7 +581,7 @@ BLEClient* BLEDevice::getClientByGattIf(uint16_t conn_id) { } void BLEDevice::updatePeerDevice(void* peer, bool _client, uint16_t conn_id) { - ESP_LOGD(LOG_TAG, "update conn_id: %d, GATT role: %s", conn_id, _client? "client":"server"); + log_d("update conn_id: %d, GATT role: %s", conn_id, _client? "client":"server"); std::map::iterator it = m_connectedClientsMap.find(ESP_GATT_IF_NONE); if (it != m_connectedClientsMap.end()) { std::swap(m_connectedClientsMap[conn_id], it->second); @@ -597,7 +597,7 @@ void BLEDevice::updatePeerDevice(void* peer, bool _client, uint16_t conn_id) { } void BLEDevice::addPeerDevice(void* peer, bool _client, uint16_t conn_id) { - ESP_LOGI(LOG_TAG, "add conn_id: %d, GATT role: %s", conn_id, _client? "client":"server"); + log_i("add conn_id: %d, GATT role: %s", conn_id, _client? "client":"server"); conn_status_t status = { .peer_device = peer, .connected = true, @@ -608,7 +608,7 @@ void BLEDevice::addPeerDevice(void* peer, bool _client, uint16_t conn_id) { } void BLEDevice::removePeerDevice(uint16_t conn_id, bool _client) { - ESP_LOGI(LOG_TAG, "remove: %d, GATT role %s", conn_id, _client?"client":"server"); + log_i("remove: %d, GATT role %s", conn_id, _client?"client":"server"); if(m_connectedClientsMap.find(conn_id) != m_connectedClientsMap.end()) m_connectedClientsMap.erase(conn_id); } diff --git a/libraries/BLE/src/BLEEddystoneTLM.cpp b/libraries/BLE/src/BLEEddystoneTLM.cpp index a92bcdb2..f05c5a3e 100644 --- a/libraries/BLE/src/BLEEddystoneTLM.cpp +++ b/libraries/BLE/src/BLEEddystoneTLM.cpp @@ -8,7 +8,7 @@ #if defined(CONFIG_BT_ENABLED) #include #include -#include +#include "esp32-hal-log.h" #include "BLEEddystoneTLM.h" static const char LOG_TAG[] = "BLEEddystoneTLM"; @@ -117,7 +117,7 @@ std::string BLEEddystoneTLM::toString() { */ void BLEEddystoneTLM::setData(std::string data) { if (data.length() != sizeof(m_eddystoneData)) { - ESP_LOGE(LOG_TAG, "Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_eddystoneData)); + log_e("Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_eddystoneData)); return; } memcpy(&m_eddystoneData, data.data(), data.length()); diff --git a/libraries/BLE/src/BLEEddystoneURL.cpp b/libraries/BLE/src/BLEEddystoneURL.cpp index af3b674c..19a56b28 100644 --- a/libraries/BLE/src/BLEEddystoneURL.cpp +++ b/libraries/BLE/src/BLEEddystoneURL.cpp @@ -7,7 +7,7 @@ #include "sdkconfig.h" #if defined(CONFIG_BT_ENABLED) #include -#include +#include "esp32-hal-log.h" #include "BLEEddystoneURL.h" static const char LOG_TAG[] = "BLEEddystoneURL"; @@ -118,7 +118,7 @@ std::string BLEEddystoneURL::getDecodedURL() { */ void BLEEddystoneURL::setData(std::string data) { if (data.length() > sizeof(m_eddystoneData)) { - ESP_LOGE(LOG_TAG, "Unable to set the data ... length passed in was %d and max expected %d", data.length(), sizeof(m_eddystoneData)); + log_e("Unable to set the data ... length passed in was %d and max expected %d", data.length(), sizeof(m_eddystoneData)); return; } memset(&m_eddystoneData, 0, sizeof(m_eddystoneData)); @@ -136,7 +136,7 @@ void BLEEddystoneURL::setPower(int8_t advertisedTxPower) { void BLEEddystoneURL::setURL(std::string url) { if (url.length() > sizeof(m_eddystoneData.url)) { - ESP_LOGE(LOG_TAG, "Unable to set the url ... length passed in was %d and max expected %d", url.length(), sizeof(m_eddystoneData.url)); + log_e("Unable to set the url ... length passed in was %d and max expected %d", url.length(), sizeof(m_eddystoneData.url)); return; } memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url)); diff --git a/libraries/BLE/src/BLERemoteCharacteristic.cpp b/libraries/BLE/src/BLERemoteCharacteristic.cpp index b6d36d88..e7f59f26 100644 --- a/libraries/BLE/src/BLERemoteCharacteristic.cpp +++ b/libraries/BLE/src/BLERemoteCharacteristic.cpp @@ -18,14 +18,7 @@ #include "BLEUtils.h" #include "GeneralUtils.h" #include "BLERemoteDescriptor.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLERemoteCharacteristic"; // The logging tag for this class. -#endif - /** @@ -40,7 +33,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic( BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService) { - ESP_LOGD(LOG_TAG, ">> BLERemoteCharacteristic: handle: %d 0x%d, uuid: %s", handle, handle, uuid.toString().c_str()); + log_v(">> BLERemoteCharacteristic: handle: %d 0x%d, uuid: %s", handle, handle, uuid.toString().c_str()); m_handle = handle; m_uuid = uuid; m_charProp = charProp; @@ -48,7 +41,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic( m_notifyCallback = nullptr; retrieveDescriptors(); // Get the descriptors for this characteristic - ESP_LOGD(LOG_TAG, "<< BLERemoteCharacteristic"); + log_v("<< BLERemoteCharacteristic"); } // BLERemoteCharacteristic @@ -166,7 +159,7 @@ void BLERemoteCharacteristic::gattClientEventHandler(esp_gattc_cb_event_t event, case ESP_GATTC_NOTIFY_EVT: { if (evtParam->notify.handle != getHandle()) break; if (m_notifyCallback != nullptr) { - ESP_LOGD(LOG_TAG, "Invoking callback for notification on characteristic %s", toString().c_str()); + log_d("Invoking callback for notification on characteristic %s", toString().c_str()); m_notifyCallback(this, evtParam->notify.value, evtParam->notify.value_len, evtParam->notify.is_notify); } // End we have a callback function ... break; @@ -253,7 +246,7 @@ void BLERemoteCharacteristic::gattClientEventHandler(esp_gattc_cb_event_t event, * @brief Populate the descriptors (if any) for this characteristic. */ void BLERemoteCharacteristic::retrieveDescriptors() { - ESP_LOGD(LOG_TAG, ">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str()); + log_v(">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str()); removeDescriptors(); // Remove any existing descriptors. @@ -277,13 +270,13 @@ void BLERemoteCharacteristic::retrieveDescriptors() { } if (status != ESP_GATT_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_get_all_descr: %s", BLEUtils::gattStatusToString(status).c_str()); + log_e("esp_ble_gattc_get_all_descr: %s", BLEUtils::gattStatusToString(status).c_str()); break; } if (count == 0) break; - ESP_LOGD(LOG_TAG, "Found a descriptor: Handle: %d, UUID: %s", result.handle, BLEUUID(result.uuid).toString().c_str()); + log_d("Found a descriptor: Handle: %d, UUID: %s", result.handle, BLEUUID(result.uuid).toString().c_str()); // We now have a new characteristic ... let us add that to our set of known characteristics BLERemoteDescriptor* pNewRemoteDescriptor = new BLERemoteDescriptor( @@ -297,7 +290,7 @@ void BLERemoteCharacteristic::retrieveDescriptors() { offset++; } // while true //m_haveCharacteristics = true; // Remember that we have received the characteristics. - ESP_LOGD(LOG_TAG, "<< retrieveDescriptors(): Found %d descriptors.", offset); + log_v("<< retrieveDescriptors(): Found %d descriptors.", offset); } // getDescriptors @@ -314,8 +307,8 @@ std::map* BLERemoteCharacteristic::getDescrip * @return The handle for this characteristic. */ uint16_t BLERemoteCharacteristic::getHandle() { - //ESP_LOGD(LOG_TAG, ">> getHandle: Characteristic: %s", getUUID().toString().c_str()); - //ESP_LOGD(LOG_TAG, "<< getHandle: %d 0x%.2x", m_handle, m_handle); + //log_v(">> getHandle: Characteristic: %s", getUUID().toString().c_str()); + //log_v("<< getHandle: %d 0x%.2x", m_handle, m_handle); return m_handle; } // getHandle @@ -326,15 +319,15 @@ uint16_t BLERemoteCharacteristic::getHandle() { * @return The Remote descriptor (if present) or null if not present. */ BLERemoteDescriptor* BLERemoteCharacteristic::getDescriptor(BLEUUID uuid) { - ESP_LOGD(LOG_TAG, ">> getDescriptor: uuid: %s", uuid.toString().c_str()); + log_v(">> getDescriptor: uuid: %s", uuid.toString().c_str()); std::string v = uuid.toString(); for (auto &myPair : m_descriptorMap) { if (myPair.first == v) { - ESP_LOGD(LOG_TAG, "<< getDescriptor: found"); + log_v("<< getDescriptor: found"); return myPair.second; } } - ESP_LOGD(LOG_TAG, "<< getDescriptor: Not found"); + log_v("<< getDescriptor: Not found"); return nullptr; } // getDescriptor @@ -401,11 +394,11 @@ uint8_t BLERemoteCharacteristic::readUInt8() { * @return The value of the remote characteristic. */ std::string BLERemoteCharacteristic::readValue() { - ESP_LOGD(LOG_TAG, ">> readValue(): uuid: %s, handle: %d 0x%.2x", getUUID().toString().c_str(), getHandle(), getHandle()); + log_v(">> readValue(): uuid: %s, handle: %d 0x%.2x", getUUID().toString().c_str(), getHandle(), getHandle()); // Check to see that we are connected. if (!getRemoteService()->getClient()->isConnected()) { - ESP_LOGE(LOG_TAG, "Disconnected"); + log_e("Disconnected"); throw BLEDisconnectedException(); } @@ -421,7 +414,7 @@ std::string BLERemoteCharacteristic::readValue() { ESP_GATT_AUTH_REQ_NONE); // Security if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return ""; } @@ -429,7 +422,7 @@ std::string BLERemoteCharacteristic::readValue() { // in m_value will contain our data. m_semaphoreReadCharEvt.wait("readValue"); - ESP_LOGD(LOG_TAG, "<< readValue(): length: %d", m_value.length()); + log_v("<< readValue(): length: %d", m_value.length()); return m_value; } // readValue @@ -441,7 +434,7 @@ std::string BLERemoteCharacteristic::readValue() { * @return N/A. */ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, bool notifications) { - ESP_LOGD(LOG_TAG, ">> registerForNotify(): %s", toString().c_str()); + log_v(">> registerForNotify(): %s", toString().c_str()); m_notifyCallback = notifyCallback; // Save the notification callback. @@ -455,7 +448,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, ); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } uint8_t val[] = {0x01, 0x00}; @@ -471,7 +464,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, ); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_unregister_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_unregister_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } uint8_t val[] = {0x00, 0x00}; @@ -481,7 +474,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, m_semaphoreRegForNotifyEvt.wait("registerForNotify"); - ESP_LOGD(LOG_TAG, "<< registerForNotify()"); + log_v("<< registerForNotify()"); } // registerForNotify @@ -547,11 +540,11 @@ void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) { */ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool response) { // writeValue(std::string((char*)data, length), response); - ESP_LOGD(LOG_TAG, ">> writeValue(), length: %d", length); + log_v(">> writeValue(), length: %d", length); // Check to see that we are connected. if (!getRemoteService()->getClient()->isConnected()) { - ESP_LOGE(LOG_TAG, "Disconnected"); + log_e("Disconnected"); throw BLEDisconnectedException(); } @@ -568,13 +561,13 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp ); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } m_semaphoreWriteCharEvt.wait("writeValue"); - ESP_LOGD(LOG_TAG, "<< writeValue"); + log_v("<< writeValue"); } // writeValue /** diff --git a/libraries/BLE/src/BLERemoteDescriptor.cpp b/libraries/BLE/src/BLERemoteDescriptor.cpp index 96a8a577..3669b636 100644 --- a/libraries/BLE/src/BLERemoteDescriptor.cpp +++ b/libraries/BLE/src/BLERemoteDescriptor.cpp @@ -9,16 +9,7 @@ #include #include "BLERemoteDescriptor.h" #include "GeneralUtils.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLERemoteDescriptor"; -#endif - - - BLERemoteDescriptor::BLERemoteDescriptor( uint16_t handle, @@ -59,11 +50,11 @@ BLEUUID BLERemoteDescriptor::getUUID() { std::string BLERemoteDescriptor::readValue() { - ESP_LOGD(LOG_TAG, ">> readValue: %s", toString().c_str()); + log_v(">> readValue: %s", toString().c_str()); // Check to see that we are connected. if (!getRemoteCharacteristic()->getRemoteService()->getClient()->isConnected()) { - ESP_LOGE(LOG_TAG, "Disconnected"); + log_e("Disconnected"); throw BLEDisconnectedException(); } @@ -77,7 +68,7 @@ std::string BLERemoteDescriptor::readValue() { ESP_GATT_AUTH_REQ_NONE); // Security if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return ""; } @@ -85,7 +76,7 @@ std::string BLERemoteDescriptor::readValue() { // in m_value will contain our data. m_semaphoreReadDescrEvt.wait("readValue"); - ESP_LOGD(LOG_TAG, "<< readValue(): length: %d", m_value.length()); + log_v("<< readValue(): length: %d", m_value.length()); return m_value; } // readValue @@ -135,10 +126,10 @@ std::string BLERemoteDescriptor::toString() { * @param [in] response True if we expect a response. */ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response) { - ESP_LOGD(LOG_TAG, ">> writeValue: %s", toString().c_str()); + log_v(">> writeValue: %s", toString().c_str()); // Check to see that we are connected. if (!getRemoteCharacteristic()->getRemoteService()->getClient()->isConnected()) { - ESP_LOGE(LOG_TAG, "Disconnected"); + log_e("Disconnected"); throw BLEDisconnectedException(); } @@ -152,9 +143,9 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response ESP_GATT_AUTH_REQ_NONE ); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_write_char_descr: %d", errRc); + log_e("esp_ble_gattc_write_char_descr: %d", errRc); } - ESP_LOGD(LOG_TAG, "<< writeValue"); + log_v("<< writeValue"); } // writeValue diff --git a/libraries/BLE/src/BLERemoteService.cpp b/libraries/BLE/src/BLERemoteService.cpp index c2b7d344..87a2c8d6 100644 --- a/libraries/BLE/src/BLERemoteService.cpp +++ b/libraries/BLE/src/BLERemoteService.cpp @@ -12,15 +12,7 @@ #include "BLEUtils.h" #include "GeneralUtils.h" #include -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLERemoteService"; -#endif - - BLERemoteService::BLERemoteService( esp_gatt_id_t srvcId, @@ -29,7 +21,7 @@ BLERemoteService::BLERemoteService( uint16_t endHandle ) { - ESP_LOGD(LOG_TAG, ">> BLERemoteService()"); + log_v(">> BLERemoteService()"); m_srvcId = srvcId; m_pClient = pClient; m_uuid = BLEUUID(m_srvcId); @@ -37,7 +29,7 @@ BLERemoteService::BLERemoteService( m_startHandle = startHandle; m_endHandle = endHandle; - ESP_LOGD(LOG_TAG, "<< BLERemoteService()"); + log_v("<< BLERemoteService()"); } @@ -103,7 +95,7 @@ void BLERemoteService::gattClientEventHandler( &m_srvcId, &evtParam->get_char.char_id); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_get_characteristic: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_get_characteristic: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); break; } @@ -165,7 +157,7 @@ BLERemoteCharacteristic* BLERemoteService::getCharacteristic(BLEUUID uuid) { * @return N/A */ void BLERemoteService::retrieveCharacteristics() { - ESP_LOGD(LOG_TAG, ">> getCharacteristics() for service: %s", getUUID().toString().c_str()); + log_v(">> getCharacteristics() for service: %s", getUUID().toString().c_str()); removeCharacteristics(); // Forget any previous characteristics. @@ -188,7 +180,7 @@ void BLERemoteService::retrieveCharacteristics() { } if (status != ESP_GATT_OK) { // If we got an error, end. - ESP_LOGE(LOG_TAG, "esp_ble_gattc_get_all_char: %s", BLEUtils::gattStatusToString(status).c_str()); + log_e("esp_ble_gattc_get_all_char: %s", BLEUtils::gattStatusToString(status).c_str()); break; } @@ -196,7 +188,7 @@ void BLERemoteService::retrieveCharacteristics() { break; } - ESP_LOGD(LOG_TAG, "Found a characteristic: Handle: %d, UUID: %s", result.char_handle, BLEUUID(result.uuid).toString().c_str()); + log_d("Found a characteristic: Handle: %d, UUID: %s", result.char_handle, BLEUUID(result.uuid).toString().c_str()); // We now have a new characteristic ... let us add that to our set of known characteristics BLERemoteCharacteristic *pNewRemoteCharacteristic = new BLERemoteCharacteristic( @@ -212,7 +204,7 @@ void BLERemoteService::retrieveCharacteristics() { } // Loop forever (until we break inside the loop). m_haveCharacteristics = true; // Remember that we have received the characteristics. - ESP_LOGD(LOG_TAG, "<< getCharacteristics()"); + log_v("<< getCharacteristics()"); } // getCharacteristics @@ -221,14 +213,14 @@ void BLERemoteService::retrieveCharacteristics() { * @return A map of all the characteristics of this service. */ std::map* BLERemoteService::getCharacteristics() { - ESP_LOGD(LOG_TAG, ">> getCharacteristics() for service: %s", getUUID().toString().c_str()); + log_v(">> getCharacteristics() for service: %s", getUUID().toString().c_str()); // If is possible that we have not read the characteristics associated with the service so do that // now. The request to retrieve the characteristics by calling "retrieveCharacteristics" is a blocking // call and does not return until all the characteristics are available. if (!m_haveCharacteristics) { retrieveCharacteristics(); } - ESP_LOGD(LOG_TAG, "<< getCharacteristics() for service: %s", getUUID().toString().c_str()); + log_v("<< getCharacteristics() for service: %s", getUUID().toString().c_str()); return &m_characteristicMap; } // getCharacteristics @@ -265,8 +257,8 @@ uint16_t BLERemoteService::getStartHandle() { uint16_t BLERemoteService::getHandle() { - ESP_LOGD(LOG_TAG, ">> getHandle: service: %s", getUUID().toString().c_str()); - ESP_LOGD(LOG_TAG, "<< getHandle: %d 0x%.2x", getStartHandle(), getStartHandle()); + log_v(">> getHandle: service: %s", getUUID().toString().c_str()); + log_v("<< getHandle: %d 0x%.2x", getStartHandle(), getStartHandle()); return getStartHandle(); } // getHandle @@ -279,9 +271,9 @@ BLEUUID BLERemoteService::getUUID() { * @brief Read the value of a characteristic associated with this service. */ std::string BLERemoteService::getValue(BLEUUID characteristicUuid) { - ESP_LOGD(LOG_TAG, ">> readValue: uuid: %s", characteristicUuid.toString().c_str()); + log_v(">> readValue: uuid: %s", characteristicUuid.toString().c_str()); std::string ret = getCharacteristic(characteristicUuid)->readValue(); - ESP_LOGD(LOG_TAG, "<< readValue"); + log_v("<< readValue"); return ret; } // readValue @@ -314,9 +306,9 @@ void BLERemoteService::removeCharacteristics() { * @throws BLEUuidNotFound */ void BLERemoteService::setValue(BLEUUID characteristicUuid, std::string value) { - ESP_LOGD(LOG_TAG, ">> setValue: uuid: %s", characteristicUuid.toString().c_str()); + log_v(">> setValue: uuid: %s", characteristicUuid.toString().c_str()); getCharacteristic(characteristicUuid)->writeValue(value); - ESP_LOGD(LOG_TAG, "<< setValue"); + log_v("<< setValue"); } // setValue diff --git a/libraries/BLE/src/BLEScan.cpp b/libraries/BLE/src/BLEScan.cpp index d851a47a..cb28dd39 100644 --- a/libraries/BLE/src/BLEScan.cpp +++ b/libraries/BLE/src/BLEScan.cpp @@ -16,16 +16,7 @@ #include "BLEScan.h" #include "BLEUtils.h" #include "GeneralUtils.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEScan"; -#endif - - - /** * Constructor @@ -75,7 +66,7 @@ void BLEScan::handleGAPEvent( // Event that indicates that the duration allowed for the search has completed or that we have been // asked to stop. case ESP_GAP_SEARCH_INQ_CMPL_EVT: { - ESP_LOGW(LOG_TAG, "ESP_GAP_SEARCH_INQ_CMPL_EVT"); + log_w("ESP_GAP_SEARCH_INQ_CMPL_EVT"); m_stopped = true; m_semaphoreScanEnd.give(); if (m_scanCompleteCB != nullptr) { @@ -103,15 +94,15 @@ void BLEScan::handleGAPEvent( } if (found && !m_wantDuplicates) { // If we found a previous entry AND we don't want duplicates, then we are done. - ESP_LOGD(LOG_TAG, "Ignoring %s, already seen it.", advertisedAddress.toString().c_str()); + log_d("Ignoring %s, already seen it.", advertisedAddress.toString().c_str()); vTaskDelay(1); // <--- allow to switch task in case we scan infinity and dont have new devices to report, or we are blocked here break; } // We now construct a model of the advertised device that we have just found for the first // time. - // ESP_LOG_BUFFER_HEXDUMP(LOG_TAG, (uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len, ESP_LOG_DEBUG); - // ESP_LOGW(LOG_TAG, "bytes length: %d + %d, addr type: %d", param->scan_rst.adv_data_len, param->scan_rst.scan_rsp_len, param->scan_rst.ble_addr_type); + // ESP_LOG_BUFFER_HEXDUMP((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len, ESP_LOG_DEBUG); + // log_w("bytes length: %d + %d, addr type: %d", param->scan_rst.adv_data_len, param->scan_rst.scan_rsp_len, param->scan_rst.ble_addr_type); BLEAdvertisedDevice *advertisedDevice = new BLEAdvertisedDevice(); advertisedDevice->setAddress(advertisedAddress); advertisedDevice->setRSSI(param->scan_rst.rssi); @@ -201,7 +192,7 @@ void BLEScan::setWindow(uint16_t windowMSecs) { * @return True if scan started or false if there was an error. */ bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue) { - ESP_LOGD(LOG_TAG, ">> start(duration=%d)", duration); + log_v(">> start(duration=%d)", duration); m_semaphoreScanEnd.take(std::string("start")); m_scanCompleteCB = scanCompleteCB; // Save the callback to be invoked when the scan completes. @@ -218,7 +209,7 @@ bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), b esp_err_t errRc = ::esp_ble_gap_set_scan_params(&m_scan_params); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_set_scan_params: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_set_scan_params: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); m_semaphoreScanEnd.give(); return false; } @@ -226,14 +217,14 @@ bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), b errRc = ::esp_ble_gap_start_scanning(duration); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_start_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_start_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); m_semaphoreScanEnd.give(); return false; } m_stopped = false; - ESP_LOGD(LOG_TAG, "<< start()"); + log_v("<< start()"); return true; } // start @@ -256,7 +247,7 @@ BLEScanResults BLEScan::start(uint32_t duration, bool is_continue) { * @return N/A. */ void BLEScan::stop() { - ESP_LOGD(LOG_TAG, ">> stop()"); + log_v(">> stop()"); esp_err_t errRc = ::esp_ble_gap_stop_scanning(); @@ -264,16 +255,16 @@ void BLEScan::stop() { m_semaphoreScanEnd.give(); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gap_stop_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gap_stop_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); return; } - ESP_LOGD(LOG_TAG, "<< stop()"); + log_v("<< stop()"); } // stop // delete peer device from cache after disconnecting, it is required in case we are connecting to devices with not public address void BLEScan::erase(BLEAddress address) { - ESP_LOGI(LOG_TAG, "erase device: %s", address.toString().c_str()); + log_i("erase device: %s", address.toString().c_str()); BLEAdvertisedDevice *advertisedDevice = m_scanResults.m_vectorAdvertisedDevices.find(address.toString())->second; m_scanResults.m_vectorAdvertisedDevices.erase(address.toString()); delete advertisedDevice; @@ -284,9 +275,9 @@ void BLEScan::erase(BLEAddress address) { * @brief Dump the scan results to the log. */ void BLEScanResults::dump() { - ESP_LOGD(LOG_TAG, ">> Dump scan results:"); + log_v(">> Dump scan results:"); for (int i=0; i #include #include -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEServer"; -#endif - - - /** * @brief Construct a %BLE Server @@ -73,12 +64,12 @@ BLEService* BLEServer::createService(const char* uuid) { * @return A reference to the new service object. */ BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t inst_id) { - ESP_LOGD(LOG_TAG, ">> createService - %s", uuid.toString().c_str()); + log_v(">> createService - %s", uuid.toString().c_str()); m_semaphoreCreateEvt.take("createService"); // Check that a service with the supplied UUID does not already exist. if (m_serviceMap.getByUUID(uuid) != nullptr) { - ESP_LOGW(LOG_TAG, "<< Attempt to create a new service with uuid %s but a service with that UUID already exists.", + log_w("<< Attempt to create a new service with uuid %s but a service with that UUID already exists.", uuid.toString().c_str()); } @@ -89,7 +80,7 @@ BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t m_semaphoreCreateEvt.wait("createService"); - ESP_LOGD(LOG_TAG, "<< createService"); + log_v("<< createService"); return pService; } // createService @@ -149,7 +140,7 @@ uint16_t BLEServer::getGattsIf() { * */ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param) { - ESP_LOGD(LOG_TAG, ">> handleGATTServerEvent: %s", + log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); switch(event) { @@ -277,7 +268,7 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t // Invoke the handler for every Service we have. m_serviceMap.handleGATTServerEvent(event, gatts_if, param); - ESP_LOGD(LOG_TAG, "<< handleGATTServerEvent"); + log_v("<< handleGATTServerEvent"); } // handleGATTServerEvent @@ -287,11 +278,11 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t * @return N/A */ void BLEServer::registerApp(uint16_t m_appId) { - ESP_LOGD(LOG_TAG, ">> registerApp - %d", m_appId); + log_v(">> registerApp - %d", m_appId); m_semaphoreRegisterAppEvt.take("registerApp"); // Take the mutex, will be released by ESP_GATTS_REG_EVT event. ::esp_ble_gatts_app_register(m_appId); m_semaphoreRegisterAppEvt.wait("registerApp"); - ESP_LOGD(LOG_TAG, "<< registerApp"); + log_v("<< registerApp"); } // registerApp @@ -324,9 +315,9 @@ void BLEServer::removeService(BLEService* service) { * retrieving the advertising object and invoking start upon it. */ void BLEServer::startAdvertising() { - ESP_LOGD(LOG_TAG, ">> startAdvertising"); + log_v(">> startAdvertising"); BLEDevice::startAdvertising(); - ESP_LOGD(LOG_TAG, "<< startAdvertising"); + log_v("<< startAdvertising"); } // startAdvertising /** @@ -344,34 +335,34 @@ bool BLEServer::connect(BLEAddress address) { 1 // direct connection ); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return false; } uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete. - ESP_LOGD(LOG_TAG, "<< connect(), rc=%d", rc==ESP_GATT_OK); + log_v("<< connect(), rc=%d", rc==ESP_GATT_OK); return rc == ESP_GATT_OK; } // connect void BLEServerCallbacks::onConnect(BLEServer* pServer) { - ESP_LOGD("BLEServerCallbacks", ">> onConnect(): Default"); - ESP_LOGD("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); - ESP_LOGD("BLEServerCallbacks", "<< onConnect()"); + log_d("BLEServerCallbacks", ">> onConnect(): Default"); + log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); + log_d("BLEServerCallbacks", "<< onConnect()"); } // onConnect void BLEServerCallbacks::onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) { - ESP_LOGD("BLEServerCallbacks", ">> onConnect(): Default"); - ESP_LOGD("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); - ESP_LOGD("BLEServerCallbacks", "<< onConnect()"); + log_d("BLEServerCallbacks", ">> onConnect(): Default"); + log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); + log_d("BLEServerCallbacks", "<< onConnect()"); } // onConnect void BLEServerCallbacks::onDisconnect(BLEServer* pServer) { - ESP_LOGD("BLEServerCallbacks", ">> onDisconnect(): Default"); - ESP_LOGD("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); - ESP_LOGD("BLEServerCallbacks", "<< onDisconnect()"); + log_d("BLEServerCallbacks", ">> onDisconnect(): Default"); + log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); + log_d("BLEServerCallbacks", "<< onDisconnect()"); } // onDisconnect /* multi connect support */ diff --git a/libraries/BLE/src/BLEService.cpp b/libraries/BLE/src/BLEService.cpp index 3034cf18..0fb22b2d 100644 --- a/libraries/BLE/src/BLEService.cpp +++ b/libraries/BLE/src/BLEService.cpp @@ -20,14 +20,7 @@ #include "BLEService.h" #include "BLEUtils.h" #include "GeneralUtils.h" - -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEService"; // Tag for logging. -#endif #define NULL_HANDLE (0xffff) @@ -64,7 +57,7 @@ BLEService::BLEService(BLEUUID uuid, uint16_t numHandles) { */ void BLEService::executeCreate(BLEServer* pServer) { - ESP_LOGD(LOG_TAG, ">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str()); + log_v(">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str()); m_pServer = pServer; m_semaphoreCreateEvt.take("executeCreate"); // Take the mutex and release at event ESP_GATTS_CREATE_EVT @@ -75,12 +68,12 @@ void BLEService::executeCreate(BLEServer* pServer) { esp_err_t errRc = ::esp_ble_gatts_create_service(getServer()->getGattsIf(), &srvc_id, m_numHandles); // The maximum number of handles associated with the service. if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } m_semaphoreCreateEvt.wait("executeCreate"); - ESP_LOGD(LOG_TAG, "<< executeCreate"); + log_v("<< executeCreate"); } // executeCreate @@ -91,18 +84,18 @@ void BLEService::executeCreate(BLEServer* pServer) { */ void BLEService::executeDelete() { - ESP_LOGD(LOG_TAG, ">> executeDelete()"); + log_v(">> executeDelete()"); m_semaphoreDeleteEvt.take("executeDelete"); // Take the mutex and release at event ESP_GATTS_DELETE_EVT esp_err_t errRc = ::esp_ble_gatts_delete_service(getHandle()); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "esp_ble_gatts_delete_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("esp_ble_gatts_delete_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } m_semaphoreDeleteEvt.wait("executeDelete"); - ESP_LOGD(LOG_TAG, "<< executeDelete"); + log_v("<< executeDelete"); } // executeDelete @@ -111,10 +104,10 @@ void BLEService::executeDelete() { * @return N/A. */ void BLEService::dump() { - ESP_LOGD(LOG_TAG, "Service: uuid:%s, handle: 0x%.2x", + log_d("Service: uuid:%s, handle: 0x%.2x", m_uuid.toString().c_str(), m_handle); - ESP_LOGD(LOG_TAG, "Characteristics:\n%s", m_characteristicMap.toString().c_str()); + log_d("Characteristics:\n%s", m_characteristicMap.toString().c_str()); } // dump @@ -138,9 +131,9 @@ void BLEService::start() { // We start the service through its local handle which was returned in the ESP_GATTS_CREATE_EVT event // obtained as a result of calling esp_ble_gatts_create_service(). // - ESP_LOGD(LOG_TAG, ">> start(): Starting service (esp_ble_gatts_start_service): %s", toString().c_str()); + log_v(">> start(): Starting service (esp_ble_gatts_start_service): %s", toString().c_str()); if (m_handle == NULL_HANDLE) { - ESP_LOGE(LOG_TAG, "<< !!! We attempted to start a service but don't know its handle!"); + log_e("<< !!! We attempted to start a service but don't know its handle!"); return; } @@ -158,12 +151,12 @@ void BLEService::start() { esp_err_t errRc = ::esp_ble_gatts_start_service(m_handle); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_start_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("<< esp_ble_gatts_start_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } m_semaphoreStartEvt.wait("start"); - ESP_LOGD(LOG_TAG, "<< start()"); + log_v("<< start()"); } // start @@ -174,9 +167,9 @@ void BLEService::stop() { // We ask the BLE runtime to start the service and then create each of the characteristics. // We start the service through its local handle which was returned in the ESP_GATTS_CREATE_EVT event // obtained as a result of calling esp_ble_gatts_create_service(). - ESP_LOGD(LOG_TAG, ">> stop(): Stopping service (esp_ble_gatts_stop_service): %s", toString().c_str()); + log_v(">> stop(): Stopping service (esp_ble_gatts_stop_service): %s", toString().c_str()); if (m_handle == NULL_HANDLE) { - ESP_LOGE(LOG_TAG, "<< !!! We attempted to stop a service but don't know its handle!"); + log_e("<< !!! We attempted to stop a service but don't know its handle!"); return; } @@ -184,12 +177,12 @@ void BLEService::stop() { esp_err_t errRc = ::esp_ble_gatts_stop_service(m_handle); if (errRc != ESP_OK) { - ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_stop_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + log_e("<< esp_ble_gatts_stop_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } m_semaphoreStopEvt.wait("stop"); - ESP_LOGD(LOG_TAG, "<< stop()"); + log_v("<< stop()"); } // start @@ -198,13 +191,13 @@ void BLEService::stop() { * @param [in] handle The handle associated with the service. */ void BLEService::setHandle(uint16_t handle) { - ESP_LOGD(LOG_TAG, ">> setHandle - Handle=0x%.2x, service UUID=%s)", handle, getUUID().toString().c_str()); + log_v(">> setHandle - Handle=0x%.2x, service UUID=%s)", handle, getUUID().toString().c_str()); if (m_handle != NULL_HANDLE) { - ESP_LOGE(LOG_TAG, "!!! Handle is already set %.2x", m_handle); + log_e("!!! Handle is already set %.2x", m_handle); return; } m_handle = handle; - ESP_LOGD(LOG_TAG, "<< setHandle"); + log_v("<< setHandle"); } // setHandle @@ -226,14 +219,14 @@ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) { // BLECharacteristicMap class instance found in m_characteristicMap. We add the characteristic // to the map and then ask the service to add the characteristic at the BLE level (ESP-IDF). - ESP_LOGD(LOG_TAG, ">> addCharacteristic()"); - ESP_LOGD(LOG_TAG, "Adding characteristic: uuid=%s to service: %s", + log_v(">> addCharacteristic()"); + log_d("Adding characteristic: uuid=%s to service: %s", pCharacteristic->getUUID().toString().c_str(), toString().c_str()); // Check that we don't add the same characteristic twice. if (m_characteristicMap.getByUUID(pCharacteristic->getUUID()) != nullptr) { - ESP_LOGW(LOG_TAG, "<< Adding a new characteristic with the same UUID as a previous one"); + log_w("<< Adding a new characteristic with the same UUID as a previous one"); //return; } @@ -241,7 +234,7 @@ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) { // but not by handle. The handle is allocated to us on the ESP_GATTS_ADD_CHAR_EVT. m_characteristicMap.setByUUID(pCharacteristic, pCharacteristic->getUUID()); - ESP_LOGD(LOG_TAG, "<< addCharacteristic()"); + log_v("<< addCharacteristic()"); } // addCharacteristic @@ -287,7 +280,7 @@ void BLEService::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t if (m_handle == param->add_char.service_handle) { BLECharacteristic *pCharacteristic = getLastCreatedCharacteristic(); if (pCharacteristic == nullptr) { - ESP_LOGE(LOG_TAG, "Expected to find characteristic with UUID: %s, but didnt!", + log_e("Expected to find characteristic with UUID: %s, but didnt!", BLEUUID(param->add_char.char_uuid).toString().c_str()); dump(); break; diff --git a/libraries/BLE/src/BLEUUID.cpp b/libraries/BLE/src/BLEUUID.cpp index 4ddf8fc2..f53a8daa 100644 --- a/libraries/BLE/src/BLEUUID.cpp +++ b/libraries/BLE/src/BLEUUID.cpp @@ -13,15 +13,7 @@ #include #include #include "BLEUUID.h" - -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEUUID"; -#endif - /** * @brief Copy memory from source to target but in reverse order. @@ -121,7 +113,7 @@ BLEUUID::BLEUUID(std::string value) { } } else { - ESP_LOGE(LOG_TAG, "ERROR: UUID value not 2, 4, 16 or 36 bytes"); + log_e("ERROR: UUID value not 2, 4, 16 or 36 bytes"); m_valueSet = false; } } //BLEUUID(std::string) @@ -136,7 +128,7 @@ BLEUUID::BLEUUID(std::string value) { */ BLEUUID::BLEUUID(uint8_t* pData, size_t size, bool msbFirst) { if (size != 16) { - ESP_LOGE(LOG_TAG, "ERROR: UUID length not 16 bytes"); + log_e("ERROR: UUID length not 16 bytes"); return; } m_uuid.len = ESP_UUID_LEN_128; @@ -212,7 +204,7 @@ uint8_t BLEUUID::bitSize() { case ESP_UUID_LEN_128: return 128; default: - ESP_LOGE(LOG_TAG, "Unknown UUID length: %d", m_uuid.len); + log_e("Unknown UUID length: %d", m_uuid.len); return 0; } // End of switch } // bitSize @@ -225,7 +217,7 @@ uint8_t BLEUUID::bitSize() { * @return True if the UUIDs are equal and false otherwise. */ bool BLEUUID::equals(BLEUUID uuid) { - //ESP_LOGD(TAG, "Comparing: %s to %s", toString().c_str(), uuid.toString().c_str()); + //log_d("Comparing: %s to %s", toString().c_str(), uuid.toString().c_str()); if (!m_valueSet || !uuid.m_valueSet) return false; if (uuid.m_uuid.len != m_uuid.len) { @@ -279,12 +271,12 @@ BLEUUID BLEUUID::fromString(std::string _uuid) { * @return The native UUID value or NULL if not set. */ esp_bt_uuid_t* BLEUUID::getNative() { - //ESP_LOGD(TAG, ">> getNative()") + //log_d(">> getNative()") if (m_valueSet == false) { - ESP_LOGD(LOG_TAG, "<< Return of un-initialized UUID!"); + log_v("<< Return of un-initialized UUID!"); return nullptr; } - //ESP_LOGD(TAG, "<< getNative()"); + //log_d("<< getNative()"); return &m_uuid; } // getNative @@ -296,7 +288,7 @@ esp_bt_uuid_t* BLEUUID::getNative() { * will convert 16 or 32 bit representations to the full 128bit. */ BLEUUID BLEUUID::to128() { - //ESP_LOGD(LOG_TAG, ">> toFull() - %s", toString().c_str()); + //log_v(">> toFull() - %s", toString().c_str()); // If we either don't have a value or are already a 128 bit UUID, nothing further to do. if (!m_valueSet || m_uuid.len == ESP_UUID_LEN_128) { @@ -338,7 +330,7 @@ BLEUUID BLEUUID::to128() { m_uuid.uuid.uuid128[0] = 0xfb; m_uuid.len = ESP_UUID_LEN_128; - //ESP_LOGD(TAG, "<< toFull <- %s", toString().c_str()); + //log_d("<< toFull <- %s", toString().c_str()); return *this; } // to128 diff --git a/libraries/BLE/src/BLEUtils.cpp b/libraries/BLE/src/BLEUtils.cpp index 5cd55f93..79a70859 100644 --- a/libraries/BLE/src/BLEUtils.cpp +++ b/libraries/BLE/src/BLEUtils.cpp @@ -23,14 +23,7 @@ #include #include -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "BLEUtils"; // Tag for logging. -#endif - /* static std::map g_addressMap; @@ -744,7 +737,7 @@ const char* BLEUtils::advTypeToString(uint8_t advType) { return "ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE"; #endif default: - ESP_LOGV(LOG_TAG, " adv data type: 0x%x", advType); + log_v(" adv data type: 0x%x", advType); return ""; } // End switch } // advTypeToString @@ -779,7 +772,7 @@ char* BLEUtils::buildHexData(uint8_t* target, uint8_t* source, uint8_t length) { if (target == nullptr) { target = (uint8_t*) malloc(length * 2 + 1); if (target == nullptr) { - ESP_LOGE(LOG_TAG, "buildHexData: malloc failed"); + log_e("buildHexData: malloc failed"); return nullptr; } } @@ -949,7 +942,7 @@ std::string BLEUtils::gattClientEventTypeToString(esp_gattc_cb_event_t eventType return "ESP_GATTC_WRITE_DESCR_EVT"; #endif default: - ESP_LOGV(LOG_TAG, "Unknown GATT Client event type: %d", eventType); + log_v("Unknown GATT Client event type: %d", eventType); return "Unknown"; } } // gattClientEventTypeToString @@ -1047,14 +1040,14 @@ const char* BLEUtils::devTypeToString(esp_bt_dev_type_t type) { void BLEUtils::dumpGapEvent( esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param) { - ESP_LOGV(LOG_TAG, "Received a GAP event: %s", gapEventToString(event)); + log_v("Received a GAP event: %s", gapEventToString(event)); switch (event) { #if CONFIG_LOG_DEFAULT_LEVEL > 4 // ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT // adv_data_cmpl // - esp_bt_status_t case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->adv_data_cmpl.status); + log_v("[status: %d]", param->adv_data_cmpl.status); break; } // ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT @@ -1063,7 +1056,7 @@ void BLEUtils::dumpGapEvent( // adv_data_raw_cmpl // - esp_bt_status_t status case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->adv_data_raw_cmpl.status); + log_v("[status: %d]", param->adv_data_raw_cmpl.status); break; } // ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT @@ -1072,7 +1065,7 @@ void BLEUtils::dumpGapEvent( // adv_start_cmpl // - esp_bt_status_t status case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->adv_start_cmpl.status); + log_v("[status: %d]", param->adv_start_cmpl.status); break; } // ESP_GAP_BLE_ADV_START_COMPLETE_EVT @@ -1081,7 +1074,7 @@ void BLEUtils::dumpGapEvent( // adv_stop_cmpl // - esp_bt_status_t status case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->adv_stop_cmpl.status); + log_v("[status: %d]", param->adv_stop_cmpl.status); break; } // ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT @@ -1096,7 +1089,7 @@ void BLEUtils::dumpGapEvent( // - esp_bd_addr_type_t addr_type // - esp_bt_dev_type_t dev_type case ESP_GAP_BLE_AUTH_CMPL_EVT: { - ESP_LOGV(LOG_TAG, "[bd_addr: %s, key_present: %d, key: ***, key_type: %d, success: %d, fail_reason: %d, addr_type: ***, dev_type: %s]", + log_v("[bd_addr: %s, key_present: %d, key: ***, key_type: %d, success: %d, fail_reason: %d, addr_type: ***, dev_type: %s]", BLEAddress(param->ble_security.auth_cmpl.bd_addr).toString().c_str(), param->ble_security.auth_cmpl.key_present, param->ble_security.auth_cmpl.key_type, @@ -1112,7 +1105,7 @@ void BLEUtils::dumpGapEvent( // clear_bond_dev_cmpl // - esp_bt_status_t status case ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->clear_bond_dev_cmpl.status); + log_v("[status: %d]", param->clear_bond_dev_cmpl.status); break; } // ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT @@ -1128,7 +1121,7 @@ void BLEUtils::dumpGapEvent( // ESP_GAP_BLE_NC_REQ_EVT case ESP_GAP_BLE_NC_REQ_EVT: { - ESP_LOGV(LOG_TAG, "[bd_addr: %s, passkey: %d]", + log_v("[bd_addr: %s, passkey: %d]", BLEAddress(param->ble_security.key_notif.bd_addr).toString().c_str(), param->ble_security.key_notif.passkey); break; @@ -1141,7 +1134,7 @@ void BLEUtils::dumpGapEvent( // - int8_t rssi // - esp_bd_addr_t remote_addr case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d, rssi: %d, remote_addr: %s]", + log_v("[status: %d, rssi: %d, remote_addr: %s]", param->read_rssi_cmpl.status, param->read_rssi_cmpl.rssi, BLEAddress(param->read_rssi_cmpl.remote_addr).toString().c_str() @@ -1154,7 +1147,7 @@ void BLEUtils::dumpGapEvent( // scan_param_cmpl. // - esp_bt_status_t status case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_param_cmpl.status); + log_v("[status: %d]", param->scan_param_cmpl.status); break; } // ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT @@ -1175,7 +1168,7 @@ void BLEUtils::dumpGapEvent( case ESP_GAP_BLE_SCAN_RESULT_EVT: { switch (param->scan_rst.search_evt) { case ESP_GAP_SEARCH_INQ_RES_EVT: { - ESP_LOGV(LOG_TAG, "search_evt: %s, bda: %s, dev_type: %s, ble_addr_type: %s, ble_evt_type: %s, rssi: %d, ble_adv: ??, flag: %d (%s), num_resps: %d, adv_data_len: %d, scan_rsp_len: %d", + log_v("search_evt: %s, bda: %s, dev_type: %s, ble_addr_type: %s, ble_evt_type: %s, rssi: %d, ble_adv: ??, flag: %d (%s), num_resps: %d, adv_data_len: %d, scan_rsp_len: %d", searchEventTypeToString(param->scan_rst.search_evt), BLEAddress(param->scan_rst.bda).toString().c_str(), devTypeToString(param->scan_rst.dev_type), @@ -1192,7 +1185,7 @@ void BLEUtils::dumpGapEvent( } // ESP_GAP_SEARCH_INQ_RES_EVT default: { - ESP_LOGV(LOG_TAG, "search_evt: %s",searchEventTypeToString(param->scan_rst.search_evt)); + log_v("search_evt: %s",searchEventTypeToString(param->scan_rst.search_evt)); break; } } @@ -1204,13 +1197,13 @@ void BLEUtils::dumpGapEvent( // scan_rsp_data_cmpl // - esp_bt_status_t status case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_rsp_data_cmpl.status); + log_v("[status: %d]", param->scan_rsp_data_cmpl.status); break; } // ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT // ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_rsp_data_raw_cmpl.status); + log_v("[status: %d]", param->scan_rsp_data_raw_cmpl.status); break; } // ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT @@ -1219,7 +1212,7 @@ void BLEUtils::dumpGapEvent( // scan_start_cmpl // - esp_bt_status_t status case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_start_cmpl.status); + log_v("[status: %d]", param->scan_start_cmpl.status); break; } // ESP_GAP_BLE_SCAN_START_COMPLETE_EVT @@ -1228,7 +1221,7 @@ void BLEUtils::dumpGapEvent( // scan_stop_cmpl // - esp_bt_status_t status case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_stop_cmpl.status); + log_v("[status: %d]", param->scan_stop_cmpl.status); break; } // ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT @@ -1243,7 +1236,7 @@ void BLEUtils::dumpGapEvent( // - uint16_t conn_int // - uint16_t timeout case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: { - ESP_LOGV(LOG_TAG, "[status: %d, bd_addr: %s, min_int: %d, max_int: %d, latency: %d, conn_int: %d, timeout: %d]", + log_v("[status: %d, bd_addr: %s, min_int: %d, max_int: %d, latency: %d, conn_int: %d, timeout: %d]", param->update_conn_params.status, BLEAddress(param->update_conn_params.bda).toString().c_str(), param->update_conn_params.min_int, @@ -1257,12 +1250,12 @@ void BLEUtils::dumpGapEvent( // ESP_GAP_BLE_SEC_REQ_EVT case ESP_GAP_BLE_SEC_REQ_EVT: { - ESP_LOGV(LOG_TAG, "[bd_addr: %s]", BLEAddress(param->ble_security.ble_req.bd_addr).toString().c_str()); + log_v("[bd_addr: %s]", BLEAddress(param->ble_security.ble_req.bd_addr).toString().c_str()); break; } // ESP_GAP_BLE_SEC_REQ_EVT #endif default: { - ESP_LOGV(LOG_TAG, "*** dumpGapEvent: Logger not coded ***"); + log_v("*** dumpGapEvent: Logger not coded ***"); break; } // default } // switch @@ -1281,7 +1274,7 @@ void BLEUtils::dumpGattClientEvent( esp_ble_gattc_cb_param_t* evtParam) { //esp_ble_gattc_cb_param_t* evtParam = (esp_ble_gattc_cb_param_t*) param; - ESP_LOGV(LOG_TAG, "GATT Event: %s", BLEUtils::gattClientEventTypeToString(event).c_str()); + log_v("GATT Event: %s", BLEUtils::gattClientEventTypeToString(event).c_str()); switch (event) { #if CONFIG_LOG_DEFAULT_LEVEL > 4 // ESP_GATTC_CLOSE_EVT @@ -1292,7 +1285,7 @@ void BLEUtils::dumpGattClientEvent( // - esp_bd_addr_t remote_bda // - esp_gatt_conn_reason_t reason case ESP_GATTC_CLOSE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, reason:%s, conn_id: %d]", + log_v("[status: %s, reason:%s, conn_id: %d]", BLEUtils::gattStatusToString(evtParam->close.status).c_str(), BLEUtils::gattCloseReasonToString(evtParam->close.reason).c_str(), evtParam->close.conn_id); @@ -1306,7 +1299,7 @@ void BLEUtils::dumpGattClientEvent( // - uint16_t conn_id // - esp_bd_addr_t remote_bda case ESP_GATTC_CONNECT_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, remote_bda: %s]", + log_v("[conn_id: %d, remote_bda: %s]", evtParam->connect.conn_id, BLEAddress(evtParam->connect.remote_bda).toString().c_str() ); @@ -1320,7 +1313,7 @@ void BLEUtils::dumpGattClientEvent( // - uint16_t conn_id // - esp_bd_addr_t remote_bda case ESP_GATTC_DISCONNECT_EVT: { - ESP_LOGV(LOG_TAG, "[reason: %s, conn_id: %d, remote_bda: %s]", + log_v("[reason: %s, conn_id: %d, remote_bda: %s]", BLEUtils::gattCloseReasonToString(evtParam->disconnect.reason).c_str(), evtParam->disconnect.conn_id, BLEAddress(evtParam->disconnect.remote_bda).toString().c_str() @@ -1346,7 +1339,7 @@ void BLEUtils::dumpGattClientEvent( if (evtParam->get_char.char_id.uuid.len == ESP_UUID_LEN_16) { description = BLEUtils::gattCharacteristicUUIDToString(evtParam->get_char.char_id.uuid.uuid.uuid16); } - ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, srvc_id: %s, char_id: %s [description: %s]\nchar_prop: %s]", + log_v("[status: %s, conn_id: %d, srvc_id: %s, char_id: %s [description: %s]\nchar_prop: %s]", BLEUtils::gattStatusToString(evtParam->get_char.status).c_str(), evtParam->get_char.conn_id, BLEUtils::gattServiceIdToString(evtParam->get_char.srvc_id).c_str(), @@ -1355,7 +1348,7 @@ void BLEUtils::dumpGattClientEvent( BLEUtils::characteristicPropertiesToString(evtParam->get_char.char_prop).c_str() ); } else { - ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, srvc_id: %s]", + log_v("[status: %s, conn_id: %d, srvc_id: %s]", BLEUtils::gattStatusToString(evtParam->get_char.status).c_str(), evtParam->get_char.conn_id, BLEUtils::gattServiceIdToString(evtParam->get_char.srvc_id).c_str() @@ -1376,7 +1369,7 @@ void BLEUtils::dumpGattClientEvent( // bool is_notify // case ESP_GATTC_NOTIFY_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, remote_bda: %s, handle: %d 0x%.2x, value_len: %d, is_notify: %d]", + log_v("[conn_id: %d, remote_bda: %s, handle: %d 0x%.2x, value_len: %d, is_notify: %d]", evtParam->notify.conn_id, BLEAddress(evtParam->notify.remote_bda).toString().c_str(), evtParam->notify.handle, @@ -1396,7 +1389,7 @@ void BLEUtils::dumpGattClientEvent( // - uint16_t mtu // case ESP_GATTC_OPEN_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, remote_bda: %s, mtu: %d]", + log_v("[status: %s, conn_id: %d, remote_bda: %s, mtu: %d]", BLEUtils::gattStatusToString(evtParam->open.status).c_str(), evtParam->open.conn_id, BLEAddress(evtParam->open.remote_bda).toString().c_str(), @@ -1416,7 +1409,7 @@ void BLEUtils::dumpGattClientEvent( // uint16_t value_type // uint16_t value_len case ESP_GATTC_READ_CHAR_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, handle: %d 0x%.2x, value_len: %d]", + log_v("[status: %s, conn_id: %d, handle: %d 0x%.2x, value_len: %d]", BLEUtils::gattStatusToString(evtParam->read.status).c_str(), evtParam->read.conn_id, evtParam->read.handle, @@ -1427,7 +1420,7 @@ void BLEUtils::dumpGattClientEvent( GeneralUtils::hexDump(evtParam->read.value, evtParam->read.value_len); /* char* pHexData = BLEUtils::buildHexData(nullptr, evtParam->read.value, evtParam->read.value_len); - ESP_LOGV(LOG_TAG, "value: %s \"%s\"", pHexData, BLEUtils::buildPrintData(evtParam->read.value, evtParam->read.value_len).c_str()); + log_v("value: %s \"%s\"", pHexData, BLEUtils::buildPrintData(evtParam->read.value, evtParam->read.value_len).c_str()); free(pHexData); */ } @@ -1440,7 +1433,7 @@ void BLEUtils::dumpGattClientEvent( // - esp_gatt_status_t status // - uint16_t app_id case ESP_GATTC_REG_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, app_id: 0x%x]", + log_v("[status: %s, app_id: 0x%x]", BLEUtils::gattStatusToString(evtParam->reg.status).c_str(), evtParam->reg.app_id); break; @@ -1452,7 +1445,7 @@ void BLEUtils::dumpGattClientEvent( // - esp_gatt_status_t status // - uint16_t handle case ESP_GATTC_REG_FOR_NOTIFY_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, handle: %d 0x%.2x]", + log_v("[status: %s, handle: %d 0x%.2x]", BLEUtils::gattStatusToString(evtParam->reg_for_notify.status).c_str(), evtParam->reg_for_notify.handle, evtParam->reg_for_notify.handle @@ -1466,7 +1459,7 @@ void BLEUtils::dumpGattClientEvent( // - esp_gatt_status_t status // - uint16_t conn_id case ESP_GATTC_SEARCH_CMPL_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d]", + log_v("[status: %s, conn_id: %d]", BLEUtils::gattStatusToString(evtParam->search_cmpl.status).c_str(), evtParam->search_cmpl.conn_id); break; @@ -1480,7 +1473,7 @@ void BLEUtils::dumpGattClientEvent( // - uint16_t end_handle // - esp_gatt_id_t srvc_id case ESP_GATTC_SEARCH_RES_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, start_handle: %d 0x%.2x, end_handle: %d 0x%.2x, srvc_id: %s", + log_v("[conn_id: %d, start_handle: %d 0x%.2x, end_handle: %d 0x%.2x, srvc_id: %s", evtParam->search_res.conn_id, evtParam->search_res.start_handle, evtParam->search_res.start_handle, @@ -1498,7 +1491,7 @@ void BLEUtils::dumpGattClientEvent( // - uint16_t handle // - uint16_t offset case ESP_GATTC_WRITE_CHAR_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, handle: %d 0x%.2x, offset: %d]", + log_v("[status: %s, conn_id: %d, handle: %d 0x%.2x, offset: %d]", BLEUtils::gattStatusToString(evtParam->write.status).c_str(), evtParam->write.conn_id, evtParam->write.handle, @@ -1528,12 +1521,12 @@ void BLEUtils::dumpGattServerEvent( esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* evtParam) { - ESP_LOGV(LOG_TAG, "GATT ServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); + log_v("GATT ServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); switch (event) { #if CONFIG_LOG_DEFAULT_LEVEL > 4 case ESP_GATTS_ADD_CHAR_DESCR_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", + log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", gattStatusToString(evtParam->add_char_descr.status).c_str(), evtParam->add_char_descr.attr_handle, evtParam->add_char_descr.attr_handle, @@ -1545,7 +1538,7 @@ void BLEUtils::dumpGattServerEvent( case ESP_GATTS_ADD_CHAR_EVT: { if (evtParam->add_char.status == ESP_GATT_OK) { - ESP_LOGV(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", + log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", gattStatusToString(evtParam->add_char.status).c_str(), evtParam->add_char.attr_handle, evtParam->add_char.attr_handle, @@ -1553,7 +1546,7 @@ void BLEUtils::dumpGattServerEvent( evtParam->add_char.service_handle, BLEUUID(evtParam->add_char.char_uuid).toString().c_str()); } else { - ESP_LOGE(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", + log_e("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", gattStatusToString(evtParam->add_char.status).c_str(), evtParam->add_char.attr_handle, evtParam->add_char.attr_handle, @@ -1571,7 +1564,7 @@ void BLEUtils::dumpGattServerEvent( // - esp_gatt_status_t status – The status code. // - uint16_t conn_id – The connection used. case ESP_GATTS_CONF_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, conn_id: 0x%.2x]", + log_v("[status: %s, conn_id: 0x%.2x]", gattStatusToString(evtParam->conf.status).c_str(), evtParam->conf.conn_id); break; @@ -1579,21 +1572,21 @@ void BLEUtils::dumpGattServerEvent( case ESP_GATTS_CONGEST_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, congested: %d]", + log_v("[conn_id: %d, congested: %d]", evtParam->congest.conn_id, evtParam->congest.congested); break; } // ESP_GATTS_CONGEST_EVT case ESP_GATTS_CONNECT_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, remote_bda: %s]", + log_v("[conn_id: %d, remote_bda: %s]", evtParam->connect.conn_id, BLEAddress(evtParam->connect.remote_bda).toString().c_str()); break; } // ESP_GATTS_CONNECT_EVT case ESP_GATTS_CREATE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, service_handle: %d 0x%.2x, service_id: [%s]]", + log_v("[status: %s, service_handle: %d 0x%.2x, service_id: [%s]]", gattStatusToString(evtParam->create.status).c_str(), evtParam->create.service_handle, evtParam->create.service_handle, @@ -1602,7 +1595,7 @@ void BLEUtils::dumpGattServerEvent( } // ESP_GATTS_CREATE_EVT case ESP_GATTS_DISCONNECT_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, remote_bda: %s]", + log_v("[conn_id: %d, remote_bda: %s]", evtParam->connect.conn_id, BLEAddress(evtParam->connect.remote_bda).toString().c_str()); break; @@ -1633,7 +1626,7 @@ void BLEUtils::dumpGattServerEvent( break; } - ESP_LOGV(LOG_TAG, "[conn_id: %d, trans_id: %d, bda: %s, exec_write_flag: 0x%.2x=%s]", + log_v("[conn_id: %d, trans_id: %d, bda: %s, exec_write_flag: 0x%.2x=%s]", evtParam->exec_write.conn_id, evtParam->exec_write.trans_id, BLEAddress(evtParam->exec_write.bda).toString().c_str(), @@ -1644,14 +1637,14 @@ void BLEUtils::dumpGattServerEvent( case ESP_GATTS_MTU_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, mtu: %d]", + log_v("[conn_id: %d, mtu: %d]", evtParam->mtu.conn_id, evtParam->mtu.mtu); break; } // ESP_GATTS_MTU_EVT case ESP_GATTS_READ_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, is_long: %d, need_rsp:%d]", + log_v("[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, is_long: %d, need_rsp:%d]", evtParam->read.conn_id, evtParam->read.trans_id, BLEAddress(evtParam->read.bda).toString().c_str(), @@ -1662,14 +1655,14 @@ void BLEUtils::dumpGattServerEvent( } // ESP_GATTS_READ_EVT case ESP_GATTS_RESPONSE_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, handle: 0x%.2x]", + log_v("[status: %s, handle: 0x%.2x]", gattStatusToString(evtParam->rsp.status).c_str(), evtParam->rsp.handle); break; } // ESP_GATTS_RESPONSE_EVT case ESP_GATTS_REG_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, app_id: %d]", + log_v("[status: %s, app_id: %d]", gattStatusToString(evtParam->reg.status).c_str(), evtParam->reg.app_id); break; @@ -1682,7 +1675,7 @@ void BLEUtils::dumpGattServerEvent( // - esp_gatt_status_t status // - uint16_t service_handle case ESP_GATTS_START_EVT: { - ESP_LOGV(LOG_TAG, "[status: %s, service_handle: 0x%.2x]", + log_v("[status: %s, service_handle: 0x%.2x]", gattStatusToString(evtParam->start.status).c_str(), evtParam->start.service_handle); break; @@ -1702,7 +1695,7 @@ void BLEUtils::dumpGattServerEvent( // - uint16_t len – The length of the incoming value part. // - uint8_t* value – The data for this value part. case ESP_GATTS_WRITE_EVT: { - ESP_LOGV(LOG_TAG, "[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, offset: %d, need_rsp: %d, is_prep: %d, len: %d]", + log_v("[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, offset: %d, need_rsp: %d, is_prep: %d, len: %d]", evtParam->write.conn_id, evtParam->write.trans_id, BLEAddress(evtParam->write.bda).toString().c_str(), @@ -1712,13 +1705,13 @@ void BLEUtils::dumpGattServerEvent( evtParam->write.is_prep, evtParam->write.len); char* pHex = buildHexData(nullptr, evtParam->write.value, evtParam->write.len); - ESP_LOGV(LOG_TAG, "[Data: %s]", pHex); + log_v("[Data: %s]", pHex); free(pHex); break; } // ESP_GATTS_WRITE_EVT #endif default: - ESP_LOGV(LOG_TAG, "dumpGattServerEvent: *** NOT CODED ***"); + log_v("dumpGattServerEvent: *** NOT CODED ***"); break; } } // dumpGattServerEvent @@ -1744,7 +1737,7 @@ const char* BLEUtils::eventTypeToString(esp_ble_evt_type_t eventType) { return "ESP_BLE_EVT_SCAN_RSP"; #endif default: - ESP_LOGV(LOG_TAG, "Unknown esp_ble_evt_type_t: %d (0x%.2x)", eventType, eventType); + log_v("Unknown esp_ble_evt_type_t: %d (0x%.2x)", eventType, eventType); return "*** Unknown ***"; } } // eventTypeToString @@ -1815,7 +1808,7 @@ const char* BLEUtils::gapEventToString(uint32_t eventType) { return "ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT"; #endif default: - ESP_LOGV(LOG_TAG, "gapEventToString: Unknown event type %d 0x%.2x", eventType, eventType); + log_v("gapEventToString: Unknown event type %d 0x%.2x", eventType, eventType); return "Unknown event type"; } } // gapEventToString @@ -2025,7 +2018,7 @@ const char* BLEUtils::searchEventTypeToString(esp_gap_search_evt_t searchEvt) { return "ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT"; #endif default: - ESP_LOGV(LOG_TAG, "Unknown event type: 0x%x", searchEvt); + log_v("Unknown event type: 0x%x", searchEvt); return "Unknown event type"; } } // searchEventTypeToString diff --git a/libraries/BLE/src/BLEValue.cpp b/libraries/BLE/src/BLEValue.cpp index ec1e61f5..40f6a20a 100644 --- a/libraries/BLE/src/BLEValue.cpp +++ b/libraries/BLE/src/BLEValue.cpp @@ -7,16 +7,7 @@ #include "sdkconfig.h" #if defined(CONFIG_BT_ENABLED) #include "BLEValue.h" - -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG="BLEValue"; -#endif - - BLEValue::BLEValue() { m_accumulation = ""; @@ -31,7 +22,7 @@ BLEValue::BLEValue() { * @param [in] part A message part being added. */ void BLEValue::addPart(std::string part) { - ESP_LOGD(LOG_TAG, ">> addPart: length=%d", part.length()); + log_v(">> addPart: length=%d", part.length()); m_accumulation += part; } // addPart @@ -43,7 +34,7 @@ void BLEValue::addPart(std::string part) { * @param [in] length The number of bytes being added. */ void BLEValue::addPart(uint8_t* pData, size_t length) { - ESP_LOGD(LOG_TAG, ">> addPart: length=%d", length); + log_v(">> addPart: length=%d", length); m_accumulation += std::string((char*) pData, length); } // addPart @@ -52,7 +43,7 @@ void BLEValue::addPart(uint8_t* pData, size_t length) { * @brief Cancel the current accumulation. */ void BLEValue::cancel() { - ESP_LOGD(LOG_TAG, ">> cancel"); + log_v(">> cancel"); m_accumulation = ""; m_readOffset = 0; } // cancel @@ -65,7 +56,7 @@ void BLEValue::cancel() { * we now have the complete message and commit the change as a unit. */ void BLEValue::commit() { - ESP_LOGD(LOG_TAG, ">> commit"); + log_v(">> commit"); // If there is nothing to commit, do nothing. if (m_accumulation.length() == 0) return; setValue(m_accumulation); diff --git a/libraries/BLE/src/FreeRTOS.cpp b/libraries/BLE/src/FreeRTOS.cpp index 1f12c88a..a5f5ff72 100644 --- a/libraries/BLE/src/FreeRTOS.cpp +++ b/libraries/BLE/src/FreeRTOS.cpp @@ -12,14 +12,7 @@ #include #include "FreeRTOS.h" #include "sdkconfig.h" -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "FreeRTOS"; -#endif - /** * Sleep for the specified number of milliseconds. @@ -67,7 +60,7 @@ uint32_t FreeRTOS::getTimeSinceStart() { * @return The value associated with the semaphore. */ uint32_t FreeRTOS::Semaphore::wait(std::string owner) { - ESP_LOGV(LOG_TAG, ">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str()); + log_v(">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str()); if (m_usePthreads) { pthread_mutex_lock(&m_pthread_mutex); @@ -83,7 +76,7 @@ uint32_t FreeRTOS::Semaphore::wait(std::string owner) { xSemaphoreGive(m_semaphore); } - ESP_LOGV(LOG_TAG, "<< wait: Semaphore released: %s", toString().c_str()); + log_v("<< wait: Semaphore released: %s", toString().c_str()); m_owner = std::string(""); return m_value; } // wait @@ -117,7 +110,7 @@ FreeRTOS::Semaphore::~Semaphore() { * The Semaphore is given. */ void FreeRTOS::Semaphore::give() { - ESP_LOGV(LOG_TAG, "Semaphore giving: %s", toString().c_str()); + log_v("Semaphore giving: %s", toString().c_str()); if (m_usePthreads) { pthread_mutex_unlock(&m_pthread_mutex); } else { @@ -162,7 +155,7 @@ void FreeRTOS::Semaphore::giveFromISR() { * @return True if we took the semaphore. */ bool FreeRTOS::Semaphore::take(std::string owner) { - ESP_LOGD(LOG_TAG, "Semaphore taking: %s for %s", toString().c_str(), owner.c_str()); + log_d("Semaphore taking: %s for %s", toString().c_str(), owner.c_str()); bool rc = false; if (m_usePthreads) { pthread_mutex_lock(&m_pthread_mutex); @@ -171,9 +164,9 @@ bool FreeRTOS::Semaphore::take(std::string owner) { } m_owner = owner; if (rc) { - ESP_LOGD(LOG_TAG, "Semaphore taken: %s", toString().c_str()); + log_d("Semaphore taken: %s", toString().c_str()); } else { - ESP_LOGE(LOG_TAG, "Semaphore NOT taken: %s", toString().c_str()); + log_e("Semaphore NOT taken: %s", toString().c_str()); } return rc; } // Semaphore::take @@ -187,7 +180,7 @@ bool FreeRTOS::Semaphore::take(std::string owner) { * @return True if we took the semaphore. */ bool FreeRTOS::Semaphore::take(uint32_t timeoutMs, std::string owner) { - ESP_LOGV(LOG_TAG, "Semaphore taking: %s for %s", toString().c_str(), owner.c_str()); + log_v("Semaphore taking: %s for %s", toString().c_str(), owner.c_str()); bool rc = false; if (m_usePthreads) { assert(false); // We apparently don't have a timed wait for pthreads. @@ -196,9 +189,9 @@ bool FreeRTOS::Semaphore::take(uint32_t timeoutMs, std::string owner) { } m_owner = owner; if (rc) { - ESP_LOGV(LOG_TAG, "Semaphore taken: %s", toString().c_str()); + log_v("Semaphore taken: %s", toString().c_str()); } else { - ESP_LOGE(LOG_TAG, "Semaphore NOT taken: %s", toString().c_str()); + log_e("Semaphore NOT taken: %s", toString().c_str()); } return rc; } // Semaphore::take diff --git a/libraries/BLE/src/GeneralUtils.cpp b/libraries/BLE/src/GeneralUtils.cpp index 019c81bd..9f4efc3f 100644 --- a/libraries/BLE/src/GeneralUtils.cpp +++ b/libraries/BLE/src/GeneralUtils.cpp @@ -18,15 +18,7 @@ #include #include #include - -#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" -#define LOG_TAG "" -#else -#include "esp_log.h" -static const char* LOG_TAG = "GeneralUtils"; -#endif - static const char kBase64Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" @@ -115,11 +107,11 @@ void GeneralUtils::dumpInfo() { size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_8BIT); esp_chip_info_t chipInfo; esp_chip_info(&chipInfo); - ESP_LOGV(LOG_TAG, "--- dumpInfo ---"); - ESP_LOGV(LOG_TAG, "Free heap: %d", freeHeap); - ESP_LOGV(LOG_TAG, "Chip Info: Model: %d, cores: %d, revision: %d", chipInfo.model, chipInfo.cores, chipInfo.revision); - ESP_LOGV(LOG_TAG, "ESP-IDF version: %s", esp_get_idf_version()); - ESP_LOGV(LOG_TAG, "---"); + log_v("--- dumpInfo ---"); + log_v("Free heap: %d", freeHeap); + log_v("Chip Info: Model: %d, cores: %d, revision: %d", chipInfo.model, chipInfo.cores, chipInfo.revision); + log_v("ESP-IDF version: %s", esp_get_idf_version()); + log_v("---"); } // dumpInfo @@ -237,7 +229,7 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) { if (index % 16 == 0) { strcpy(hexBuf, hex.str().c_str()); strcpy(asciiBuf, ascii.str().c_str()); - ESP_LOGV(tag, "%s %s", hexBuf, asciiBuf); + log_v("%s %s", hexBuf, asciiBuf); hex.str(""); ascii.str(""); } @@ -249,8 +241,8 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) { } strcpy(hexBuf, hex.str().c_str()); strcpy(asciiBuf, ascii.str().c_str()); - ESP_LOGV(tag, "%s %s", hexBuf, asciiBuf); - //ESP_LOGV(tag, "%s %s", hex.str().c_str(), ascii.str().c_str()); + log_v("%s %s", hexBuf, asciiBuf); + //log_v("%s %s", hex.str().c_str(), ascii.str().c_str()); } FreeRTOS::sleep(1000); } @@ -272,7 +264,7 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) { } index++; if (index % 16 == 0) { - ESP_LOGV(tag, "%s %s", hex.str().c_str(), ascii.str().c_str()); + log_v("%s %s", hex.str().c_str(), ascii.str().c_str()); hex.str(""); ascii.str(""); } @@ -282,7 +274,7 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) { hex << " "; index++; } - ESP_LOGV(tag, "%s %s", hex.str().c_str(), ascii.str().c_str()); + log_v("%s %s", hex.str().c_str(), ascii.str().c_str()); } FreeRTOS::sleep(1000); } @@ -302,8 +294,8 @@ void GeneralUtils::hexDump(const uint8_t* pData, uint32_t length) { char tempBuf[80]; uint32_t lineNumber = 0; - ESP_LOGV(LOG_TAG, " 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"); - ESP_LOGV(LOG_TAG, " -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"); + log_v(" 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"); + log_v(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"); strcpy(ascii, ""); strcpy(hex, ""); uint32_t index = 0; @@ -318,7 +310,7 @@ void GeneralUtils::hexDump(const uint8_t* pData, uint32_t length) { strcat(ascii, tempBuf); index++; if (index % 16 == 0) { - ESP_LOGV(LOG_TAG, "%.4x %s %s", lineNumber * 16, hex, ascii); + log_v("%.4x %s %s", lineNumber * 16, hex, ascii); strcpy(ascii, ""); strcpy(hex, ""); lineNumber++; @@ -329,7 +321,7 @@ void GeneralUtils::hexDump(const uint8_t* pData, uint32_t length) { strcat(hex, " "); index++; } - ESP_LOGV(LOG_TAG, "%.4x %s %s", lineNumber * 16, hex, ascii); + log_v("%.4x %s %s", lineNumber * 16, hex, ascii); } } // hexDump diff --git a/libraries/Preferences/src/Preferences.cpp b/libraries/Preferences/src/Preferences.cpp index c2640a87..f06e9d08 100644 --- a/libraries/Preferences/src/Preferences.cpp +++ b/libraries/Preferences/src/Preferences.cpp @@ -291,7 +291,7 @@ int8_t Preferences::getChar(const char* key, const int8_t defaultValue){ } esp_err_t err = nvs_get_i8(_handle, key, &value); if(err){ - log_e("nvs_get_i8 fail: %s %s", key, nvs_error(err)); + log_v("nvs_get_i8 fail: %s %s", key, nvs_error(err)); } return value; } @@ -303,7 +303,7 @@ uint8_t Preferences::getUChar(const char* key, const uint8_t defaultValue){ } esp_err_t err = nvs_get_u8(_handle, key, &value); if(err){ - log_e("nvs_get_u8 fail: %s %s", key, nvs_error(err)); + log_v("nvs_get_u8 fail: %s %s", key, nvs_error(err)); } return value; } @@ -315,7 +315,7 @@ int16_t Preferences::getShort(const char* key, const int16_t defaultValue){ } esp_err_t err = nvs_get_i16(_handle, key, &value); if(err){ - log_e("nvs_get_i16 fail: %s %s", key, nvs_error(err)); + log_v("nvs_get_i16 fail: %s %s", key, nvs_error(err)); } return value; } @@ -327,7 +327,7 @@ uint16_t Preferences::getUShort(const char* key, const uint16_t defaultValue){ } esp_err_t err = nvs_get_u16(_handle, key, &value); if(err){ - log_e("nvs_get_u16 fail: %s %s", key, nvs_error(err)); + log_v("nvs_get_u16 fail: %s %s", key, nvs_error(err)); } return value; } @@ -339,7 +339,7 @@ int32_t Preferences::getInt(const char* key, const int32_t defaultValue){ } esp_err_t err = nvs_get_i32(_handle, key, &value); if(err){ - log_e("nvs_get_i32 fail: %s %s", key, nvs_error(err)); + log_v("nvs_get_i32 fail: %s %s", key, nvs_error(err)); } return value; } @@ -351,7 +351,7 @@ uint32_t Preferences::getUInt(const char* key, const uint32_t defaultValue){ } esp_err_t err = nvs_get_u32(_handle, key, &value); if(err){ - log_e("nvs_get_u32 fail: %s %s", key, nvs_error(err)); + log_v("nvs_get_u32 fail: %s %s", key, nvs_error(err)); } return value; } @@ -371,7 +371,7 @@ int64_t Preferences::getLong64(const char* key, const int64_t defaultValue){ } esp_err_t err = nvs_get_i64(_handle, key, &value); if(err){ - log_e("nvs_get_i64 fail: %s %s", key, nvs_error(err)); + log_v("nvs_get_i64 fail: %s %s", key, nvs_error(err)); } return value; } @@ -383,7 +383,7 @@ uint64_t Preferences::getULong64(const char* key, const uint64_t defaultValue){ } esp_err_t err = nvs_get_u64(_handle, key, &value); if(err){ - log_e("nvs_get_u64 fail: %s %s", key, nvs_error(err)); + log_v("nvs_get_u64 fail: %s %s", key, nvs_error(err)); } return value; }