Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ec2333d

Browse filesBrowse files
committed
merge upstream
1 parent dcf6f39 commit ec2333d
Copy full SHA for ec2333d
Expand file treeCollapse file tree

30 files changed

+758
-774
lines changed

‎libraries/BLE/src/BLEAddress.cpp

Copy file name to clipboardExpand all lines: libraries/BLE/src/BLEAddress.cpp
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <iomanip>
1414
#include <string.h>
1515
#include <stdio.h>
16-
#include <malloc.h>
1716
#ifdef ARDUINO_ARCH_ESP32
1817
#include "esp32-hal-log.h"
1918
#endif
@@ -84,11 +83,13 @@ esp_bd_addr_t *BLEAddress::getNative() {
8483
* @return The string representation of the address.
8584
*/
8685
std::string BLEAddress::toString() {
87-
auto size = 18;
88-
char *res = (char*)malloc(size);
89-
snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]);
90-
std::string ret(res);
91-
free(res);
92-
return ret;
86+
std::stringstream stream;
87+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[0] << ':';
88+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[1] << ':';
89+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[2] << ':';
90+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[3] << ':';
91+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[4] << ':';
92+
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[5];
93+
return stream.str();
9394
} // toString
9495
#endif

‎libraries/BLE/src/BLEAdvertisedDevice.cpp

Copy file name to clipboardExpand all lines: libraries/BLE/src/BLEAdvertisedDevice.cpp
+24-24Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
#include <sstream>
1717
#include "BLEAdvertisedDevice.h"
1818
#include "BLEUtils.h"
19+
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
1920
#include "esp32-hal-log.h"
21+
#define LOG_TAG ""
22+
#else
23+
#include "esp_log.h"
24+
static const char* LOG_TAG="BLEAdvertisedDevice";
25+
#endif
2026

2127
BLEAdvertisedDevice::BLEAdvertisedDevice() {
2228
m_adFlag = 0;
@@ -243,7 +249,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
243249
length--;
244250

245251
char* pHex = BLEUtils::buildHexData(nullptr, payload, length);
246-
log_d("Type: 0x%.2x (%s), length: %d, data: %s",
252+
ESP_LOGD(LOG_TAG, "Type: 0x%.2x (%s), length: %d, data: %s",
247253
ad_type, BLEUtils::advTypeToString(ad_type), length, pHex);
248254
free(pHex);
249255

@@ -302,7 +308,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
302308

303309
case ESP_BLE_AD_TYPE_SERVICE_DATA: { // Adv Data Type: 0x16 (Service Data) - 2 byte UUID
304310
if (length < 2) {
305-
log_e("Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA");
311+
ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA");
306312
break;
307313
}
308314
uint16_t uuid = *(uint16_t*)payload;
@@ -315,7 +321,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
315321

316322
case ESP_BLE_AD_TYPE_32SERVICE_DATA: { // Adv Data Type: 0x20 (Service Data) - 4 byte UUID
317323
if (length < 4) {
318-
log_e("Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA");
324+
ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA");
319325
break;
320326
}
321327
uint32_t uuid = *(uint32_t*) payload;
@@ -328,7 +334,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
328334

329335
case ESP_BLE_AD_TYPE_128SERVICE_DATA: { // Adv Data Type: 0x21 (Service Data) - 16 byte UUID
330336
if (length < 16) {
331-
log_e("Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA");
337+
ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA");
332338
break;
333339
}
334340

@@ -340,7 +346,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
340346
} //ESP_BLE_AD_TYPE_32SERVICE_DATA
341347

342348
default: {
343-
log_d("Unhandled type: adType: %d - 0x%.2x", ad_type, ad_type);
349+
ESP_LOGD(LOG_TAG, "Unhandled type: adType: %d - 0x%.2x", ad_type, ad_type);
344350
break;
345351
}
346352
} // switch
@@ -380,7 +386,7 @@ void BLEAdvertisedDevice::setAdFlag(uint8_t adFlag) {
380386
void BLEAdvertisedDevice::setAppearance(uint16_t appearance) {
381387
m_appearance = appearance;
382388
m_haveAppearance = true;
383-
log_d("- appearance: %d", m_appearance);
389+
ESP_LOGD(LOG_TAG, "- appearance: %d", m_appearance);
384390
} // setAppearance
385391

386392

@@ -392,7 +398,7 @@ void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) {
392398
m_manufacturerData = manufacturerData;
393399
m_haveManufacturerData = true;
394400
char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*) m_manufacturerData.data(), (uint8_t) m_manufacturerData.length());
395-
log_d("- manufacturer data: %s", pHex);
401+
ESP_LOGD(LOG_TAG, "- manufacturer data: %s", pHex);
396402
free(pHex);
397403
} // setManufacturerData
398404

@@ -404,7 +410,7 @@ void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) {
404410
void BLEAdvertisedDevice::setName(std::string name) {
405411
m_name = name;
406412
m_haveName = true;
407-
log_d("- setName(): name: %s", m_name.c_str());
413+
ESP_LOGD(LOG_TAG, "- setName(): name: %s", m_name.c_str());
408414
} // setName
409415

410416

@@ -415,7 +421,7 @@ void BLEAdvertisedDevice::setName(std::string name) {
415421
void BLEAdvertisedDevice::setRSSI(int rssi) {
416422
m_rssi = rssi;
417423
m_haveRSSI = true;
418-
log_d("- setRSSI(): rssi: %d", m_rssi);
424+
ESP_LOGD(LOG_TAG, "- setRSSI(): rssi: %d", m_rssi);
419425
} // setRSSI
420426

421427

@@ -444,7 +450,7 @@ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) {
444450
void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
445451
m_serviceUUIDs.push_back(serviceUUID);
446452
m_haveServiceUUID = true;
447-
log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
453+
ESP_LOGD(LOG_TAG, "- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
448454
} // setServiceUUID
449455

450456

@@ -475,7 +481,7 @@ void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
475481
void BLEAdvertisedDevice::setTXPower(int8_t txPower) {
476482
m_txPower = txPower;
477483
m_haveTXPower = true;
478-
log_d("- txPower: %d", m_txPower);
484+
ESP_LOGD(LOG_TAG, "- txPower: %d", m_txPower);
479485
} // setTXPower
480486

481487

@@ -484,29 +490,23 @@ void BLEAdvertisedDevice::setTXPower(int8_t txPower) {
484490
* @return A string representation of this device.
485491
*/
486492
std::string BLEAdvertisedDevice::toString() {
487-
std::string res = "Name: " + getName() + ", Address: " + getAddress().toString();
493+
std::stringstream ss;
494+
ss << "Name: " << getName() << ", Address: " << getAddress().toString();
488495
if (haveAppearance()) {
489-
char val[6];
490-
snprintf(val, sizeof(val), "%d", getAppearance());
491-
res += ", appearance: ";
492-
res += val;
496+
ss << ", appearance: " << getAppearance();
493497
}
494498
if (haveManufacturerData()) {
495499
char *pHex = BLEUtils::buildHexData(nullptr, (uint8_t*)getManufacturerData().data(), getManufacturerData().length());
496-
res += ", manufacturer data: ";
497-
res += pHex;
500+
ss << ", manufacturer data: " << pHex;
498501
free(pHex);
499502
}
500503
if (haveServiceUUID()) {
501-
res += ", serviceUUID: " + getServiceUUID().toString();
504+
ss << ", serviceUUID: " << getServiceUUID().toString();
502505
}
503506
if (haveTXPower()) {
504-
char val[4];
505-
snprintf(val, sizeof(val), "%d", getTXPower());
506-
res += ", txPower: ";
507-
res += val;
507+
ss << ", txPower: " << (int)getTXPower();
508508
}
509-
return res;
509+
return ss.str();
510510
} // toString
511511

512512
uint8_t* BLEAdvertisedDevice::getPayload() {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.