Skip to content

Commit 7911c4c

Browse files
committed
Changed std::string to Arduino String
1 parent 9f522f4 commit 7911c4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1528
-1267
lines changed

libraries/BLE/examples/EddystoneTLM_Beacon/EddystoneTLM_Beacon.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void setBeacon()
5656

5757
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
5858
BLEAdvertisementData oScanResponseData = BLEAdvertisementData();
59-
oScanResponseData.setServiceData(BLEUUID((uint16_t)0xFEAA), std::string(EddystoneTLM.getData().c_str(), EddystoneTLM.getData().length()));
59+
oScanResponseData.setServiceData(BLEUUID((uint16_t)0xFEAA), String(EddystoneTLM.getData().c_str(), EddystoneTLM.getData().length()));
6060

6161
oAdvertisementData.setName("ESP32 TLM Beacon");
6262
pAdvertising->setAdvertisementData(oAdvertisementData);

libraries/BLE/src/BLEAddress.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ esp_bd_addr_t *BLEAddress::getNative() {
109109
*
110110
* @return The string representation of the address.
111111
*/
112-
std::string BLEAddress::toString() {
112+
String BLEAddress::toString() {
113113
auto size = 18;
114114
char *res = (char*)malloc(size);
115115
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]);
116-
std::string ret(res);
116+
String ret(res);
117117
free(res);
118118
return ret;
119119
} // toString

libraries/BLE/src/BLEAddress.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class BLEAddress {
3232
bool operator<=(const BLEAddress& otherAddress) const;
3333
bool operator>(const BLEAddress& otherAddress) const;
3434
bool operator>=(const BLEAddress& otherAddress) const;
35-
esp_bd_addr_t* getNative();
36-
std::string toString();
35+
esp_bd_addr_t* getNative();
36+
String toString();
3737

3838
private:
3939
esp_bd_addr_t m_address;

libraries/BLE/src/BLEAdvertisedDevice.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ uint16_t BLEAdvertisedDevice::getAppearance() {
7272
* @brief Get the manufacturer data.
7373
* @return The manufacturer data of the advertised device.
7474
*/
75-
std::string BLEAdvertisedDevice::getManufacturerData() {
75+
String BLEAdvertisedDevice::getManufacturerData() {
7676
return m_manufacturerData;
7777
} // getManufacturerData
7878

@@ -81,7 +81,7 @@ std::string BLEAdvertisedDevice::getManufacturerData() {
8181
* @brief Get the name.
8282
* @return The name of the advertised device.
8383
*/
84-
std::string BLEAdvertisedDevice::getName() {
84+
String BLEAdvertisedDevice::getName() {
8585
return m_name;
8686
} // getName
8787

@@ -115,15 +115,15 @@ int BLEAdvertisedDevice::getServiceDataCount() {
115115
* @brief Get the service data.
116116
* @return The ServiceData of the advertised device.
117117
*/
118-
std::string BLEAdvertisedDevice::getServiceData() {
119-
return m_serviceData.empty() ? std::string() : m_serviceData.front();
118+
String BLEAdvertisedDevice::getServiceData() {
119+
return m_serviceData.empty() ? String() : m_serviceData.front();
120120
} //getServiceData
121121

122122
/**
123123
* @brief Get the service data.
124124
* @return The ServiceData of the advertised device.
125125
*/
126-
std::string BLEAdvertisedDevice::getServiceData(int i) {
126+
String BLEAdvertisedDevice::getServiceData(int i) {
127127
return m_serviceData[i];
128128
} //getServiceData
129129

@@ -296,7 +296,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
296296

297297
switch(ad_type) {
298298
case ESP_BLE_AD_TYPE_NAME_CMPL: { // Adv Data Type: 0x09
299-
setName(std::string(reinterpret_cast<char*>(payload), length));
299+
setName(String(reinterpret_cast<char*>(payload), length));
300300
break;
301301
} // ESP_BLE_AD_TYPE_NAME_CMPL
302302

@@ -343,7 +343,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
343343

344344
// See CSS Part A 1.4 Manufacturer Specific Data
345345
case ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE: {
346-
setManufacturerData(std::string(reinterpret_cast<char*>(payload), length));
346+
setManufacturerData(String(reinterpret_cast<char*>(payload), length));
347347
break;
348348
} // ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE
349349

@@ -355,7 +355,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
355355
uint16_t uuid = *(uint16_t*)payload;
356356
setServiceDataUUID(BLEUUID(uuid));
357357
if (length > 2) {
358-
setServiceData(std::string(reinterpret_cast<char*>(payload + 2), length - 2));
358+
setServiceData(String(reinterpret_cast<char*>(payload + 2), length - 2));
359359
}
360360
break;
361361
} //ESP_BLE_AD_TYPE_SERVICE_DATA
@@ -368,7 +368,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
368368
uint32_t uuid = *(uint32_t*) payload;
369369
setServiceDataUUID(BLEUUID(uuid));
370370
if (length > 4) {
371-
setServiceData(std::string(reinterpret_cast<char*>(payload + 4), length - 4));
371+
setServiceData(String(reinterpret_cast<char*>(payload + 4), length - 4));
372372
}
373373
break;
374374
} //ESP_BLE_AD_TYPE_32SERVICE_DATA
@@ -381,7 +381,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
381381

382382
setServiceDataUUID(BLEUUID(payload, (size_t)16, false));
383383
if (length > 16) {
384-
setServiceData(std::string(reinterpret_cast<char*>(payload + 16), length - 16));
384+
setServiceData(String(reinterpret_cast<char*>(payload + 16), length - 16));
385385
}
386386
break;
387387
} //ESP_BLE_AD_TYPE_32SERVICE_DATA
@@ -444,10 +444,10 @@ void BLEAdvertisedDevice::setAppearance(uint16_t appearance) {
444444
* @brief Set the manufacturer data for this device.
445445
* @param [in] The discovered manufacturer data.
446446
*/
447-
void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) {
447+
void BLEAdvertisedDevice::setManufacturerData(String manufacturerData) {
448448
m_manufacturerData = manufacturerData;
449449
m_haveManufacturerData = true;
450-
char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*) m_manufacturerData.data(), (uint8_t) m_manufacturerData.length());
450+
char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*) m_manufacturerData.c_str(), (uint8_t) m_manufacturerData.length());
451451
log_d("- manufacturer data: %s", pHex);
452452
free(pHex);
453453
} // setManufacturerData
@@ -457,7 +457,7 @@ void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) {
457457
* @brief Set the name for this device.
458458
* @param [in] name The discovered name.
459459
*/
460-
void BLEAdvertisedDevice::setName(std::string name) {
460+
void BLEAdvertisedDevice::setName(String name) {
461461
m_name = name;
462462
m_haveName = true;
463463
log_d("- setName(): name: %s", m_name.c_str());
@@ -507,7 +507,7 @@ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
507507
* @brief Set the ServiceData value.
508508
* @param [in] data ServiceData value.
509509
*/
510-
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
510+
void BLEAdvertisedDevice::setServiceData(String serviceData) {
511511
m_serviceData.push_back(serviceData); // Save the service data that we received.
512512
} //setServiceData
513513

@@ -537,16 +537,16 @@ void BLEAdvertisedDevice::setTXPower(int8_t txPower) {
537537
* @brief Create a string representation of this device.
538538
* @return A string representation of this device.
539539
*/
540-
std::string BLEAdvertisedDevice::toString() {
541-
std::string res = "Name: " + getName() + ", Address: " + getAddress().toString();
540+
String BLEAdvertisedDevice::toString() {
541+
String res = "Name: " + getName() + ", Address: " + getAddress().toString();
542542
if (haveAppearance()) {
543543
char val[6];
544544
snprintf(val, sizeof(val), "%d", getAppearance());
545545
res += ", appearance: ";
546546
res += val;
547547
}
548548
if (haveManufacturerData()) {
549-
char *pHex = BLEUtils::buildHexData(nullptr, (uint8_t*)getManufacturerData().data(), getManufacturerData().length());
549+
char *pHex = BLEUtils::buildHexData(nullptr, (uint8_t*)getManufacturerData().c_str(), getManufacturerData().length());
550550
res += ", manufacturer data: ";
551551
res += pHex;
552552
free(pHex);

libraries/BLE/src/BLEAdvertisedDevice.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_
1010
#include "soc/soc_caps.h"
1111
#if SOC_BLE_SUPPORTED
12+
1213
#include "sdkconfig.h"
1314
#if defined(CONFIG_BLUEDROID_ENABLED)
1415
#include <esp_gattc_api.h>
@@ -41,12 +42,12 @@ class BLEAdvertisedDevice {
4142

4243
BLEAddress getAddress();
4344
uint16_t getAppearance();
44-
std::string getManufacturerData();
45-
std::string getName();
45+
String getManufacturerData();
46+
String getName();
4647
int getRSSI();
4748
BLEScan* getScan();
48-
std::string getServiceData();
49-
std::string getServiceData(int i);
49+
String getServiceData();
50+
String getServiceData(int i);
5051
BLEUUID getServiceDataUUID();
5152
BLEUUID getServiceDataUUID(int i);
5253
BLEUUID getServiceUUID();
@@ -71,7 +72,7 @@ class BLEAdvertisedDevice {
7172
bool haveServiceUUID();
7273
bool haveTXPower();
7374

74-
std::string toString();
75+
String toString();
7576

7677
private:
7778
friend class BLEScan;
@@ -82,11 +83,11 @@ class BLEAdvertisedDevice {
8283
void setAdFlag(uint8_t adFlag);
8384
void setAdvertizementResult(uint8_t* payload);
8485
void setAppearance(uint16_t appearance);
85-
void setManufacturerData(std::string manufacturerData);
86-
void setName(std::string name);
86+
void setManufacturerData(String manufacturerData);
87+
void setName(String name);
8788
void setRSSI(int rssi);
8889
void setScan(BLEScan* pScan);
89-
void setServiceData(std::string data);
90+
void setServiceData(String data);
9091
void setServiceDataUUID(BLEUUID uuid);
9192
void setServiceUUID(const char* serviceUUID);
9293
void setServiceUUID(BLEUUID serviceUUID);
@@ -103,13 +104,13 @@ class BLEAdvertisedDevice {
103104
uint8_t m_adFlag;
104105
uint16_t m_appearance;
105106
int m_deviceType;
106-
std::string m_manufacturerData;
107-
std::string m_name;
107+
String m_manufacturerData;
108+
String m_name;
108109
BLEScan* m_pScan;
109110
int m_rssi;
110111
std::vector<BLEUUID> m_serviceUUIDs;
111112
int8_t m_txPower;
112-
std::vector<std::string> m_serviceData;
113+
std::vector<String> m_serviceData;
113114
std::vector<BLEUUID> m_serviceDataUUIDs;
114115
uint8_t* m_payload;
115116
size_t m_payloadLength = 0;

0 commit comments

Comments
 (0)