Skip to content

Commit 7b76643

Browse files
committed
Fixed URL and Utils error
1 parent e95b531 commit 7b76643

File tree

5 files changed

+31
-38
lines changed

5 files changed

+31
-38
lines changed

libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
7575
}
7676
Serial.printf("\n");
7777
Serial.printf("Decoded URL: %s\n", EddystoneURL.getDecodedURL().c_str());
78+
Serial.printf("EddystoneURL.getDecodedURL(): %s\n", EddystoneURL.getDecodedURL().c_str());
7879
Serial.printf("TX power %d (Raw 0x%02X)\n", EddystoneURL.getPower(), EddystoneURL.getPower());
7980
Serial.println("\n");
8081
}

libraries/BLE/src/BLECharacteristic.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ BLECharacteristic::~BLECharacteristic() {
6868
* @return N/A.
6969
*/
7070
void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) {
71-
log_v(">> addDescriptor(): Adding %s to %s", pDescriptor->toString()..c_str(), toString()..c_str());
71+
log_v(">> addDescriptor(): Adding %s to %s", pDescriptor->toString().c_str(), toString().c_str());
7272
m_descriptorMap.setByUUID(pDescriptor->getUUID(), pDescriptor);
7373
log_v("<< addDescriptor()");
7474
} // addDescriptor
@@ -89,8 +89,8 @@ void BLECharacteristic::executeCreate(BLEService* pService) {
8989
m_pService = pService; // Save the service to which this characteristic belongs.
9090

9191
log_d("Registering characteristic (esp_ble_gatts_add_char): uuid: %s, service: %s",
92-
getUUID().toString()..c_str(),
93-
m_pService->toString()..c_str());
92+
getUUID().toString().c_str(),
93+
m_pService->toString().c_str());
9494

9595
esp_attr_control_t control;
9696
control.auto_rsp = ESP_GATT_RSP_BY_APP;
@@ -205,7 +205,7 @@ void BLECharacteristic::handleGATTServerEvent(
205205
esp_gatts_cb_event_t event,
206206
esp_gatt_if_t gatts_if,
207207
esp_ble_gatts_cb_param_t* param) {
208-
log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event)..c_str());
208+
log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str());
209209

210210
switch(event) {
211211
// Events handled:
@@ -297,7 +297,7 @@ void BLECharacteristic::handleGATTServerEvent(
297297
}
298298

299299
log_d(" - Response to write event: New value: handle: %.2x, uuid: %s",
300-
getHandle(), getUUID().toString()..c_str());
300+
getHandle(), getUUID().toString().c_str());
301301

302302
char* pHexData = BLEUtils::buildHexData(nullptr, param->write.value, param->write.len);
303303
log_d(" - Data: length: %d, data: %s", param->write.len, pHexData);
@@ -604,7 +604,7 @@ void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) {
604604
* @param [in] handle The handle associated with this characteristic.
605605
*/
606606
void BLECharacteristic::setHandle(uint16_t handle) {
607-
log_v(">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString()..c_str());
607+
log_v(">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString().c_str());
608608
m_handle = handle;
609609
log_v("<< setHandle");
610610
} // setHandle
@@ -659,7 +659,7 @@ void BLECharacteristic::setReadProperty(bool value) {
659659
*/
660660
void BLECharacteristic::setValue(uint8_t* data, size_t length) {
661661
char* pHex = BLEUtils::buildHexData(nullptr, data, length);
662-
log_v(">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString()..c_str());
662+
log_v(">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str());
663663
free(pHex);
664664
if (length > ESP_GATT_MAX_ATTR_LEN) {
665665
log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN);

libraries/BLE/src/BLEEddystoneURL.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,22 @@ String BLEEddystoneURL::getSuffix(){
109109
}
110110

111111
String BLEEddystoneURL::getDecodedURL() {
112-
String decodedURL = "";
113-
decodedURL += String(getPrefix().c_str());
112+
std::string decodedURL = "";
113+
decodedURL += getPrefix().c_str();
114114
if(decodedURL.length() == 0){ // No prefix extracted - interpret byte [0] as character
115-
decodedURL += m_eddystoneData.url[0];
115+
decodedURL += (char)m_eddystoneData.url[0];
116116
}
117-
118-
for (int i = 1; i < lengthURL; i++) {
117+
for(int i = 1; i < lengthURL; i++) {
119118
if (m_eddystoneData.url[i] >= 33 && m_eddystoneData.url[i] < 127) {
120-
decodedURL += m_eddystoneData.url[i];
119+
decodedURL += (char)m_eddystoneData.url[i];
121120
}else{
122121
if(i != lengthURL-1 || m_eddystoneData.url[i] > 0x0D){ // Ignore last Byte and values used for suffix
123122
log_e("Unexpected unprintable char in URL 0x%02X: m_eddystoneData.url[%d]", m_eddystoneData.url[i], i);
124123
}
125124
}
126125
}
127-
decodedURL += String(getSuffix().c_str());
128-
return decodedURL;
126+
decodedURL += getSuffix().c_str();
127+
return String(decodedURL.c_str());
129128
} // getDecodedURL
130129

131130
/**
@@ -234,9 +233,7 @@ int BLEEddystoneURL::setSmartURL(String url) {
234233
uint8_t suffix = 0x0E; // Init with empty string
235234
log_d("Encode url \"%s\" with length %d", url.c_str(), url.length());
236235
for(uint8_t i = 0; i < 4; ++i){
237-
//log_d("check if substr \"%s\" == prefix \"%s\" ", url.substring(0, EDDYSTONE_URL_PREFIX[i].length()), EDDYSTONE_URL_PREFIX[i]);
238236
if(url.substring(0, EDDYSTONE_URL_PREFIX[i].length()) == EDDYSTONE_URL_PREFIX[i]){
239-
//log_d("Found prefix 0x%02X = \"%s\"", i, EDDYSTONE_URL_PREFIX[i]);
240237
m_eddystoneData.url[0] = i;
241238
hasPrefix = true;
242239
break;
@@ -251,7 +248,6 @@ int BLEEddystoneURL::setSmartURL(String url) {
251248
std::string std_url(url.c_str());
252249
std::string std_suffix(EDDYSTONE_URL_SUFFIX[i].c_str());
253250
size_t found_pos = std_url.find(std_suffix);
254-
//log_d("check if in url \"%s\" can find suffix \"%s\": found_pos = %d", std_url.c_str(), std_suffix.c_str(), found_pos);
255251
if(found_pos != std::string::npos){
256252
hasSuffix = true;
257253
suffix = i;

libraries/BLE/src/BLEEddystoneURL.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ class BLEEddystoneURL {
3131
public:
3232
BLEEddystoneURL();
3333
BLEEddystoneURL(BLEAdvertisedDevice *advertisedDevice);
34-
String getData();
35-
String getFrame();
36-
BLEUUID getUUID();
37-
int8_t getPower();
38-
String getURL();
39-
String getPrefix();
40-
String getSuffix();
41-
String getDecodedURL();
42-
void setData(String data);
43-
void setUUID(BLEUUID l_uuid);
44-
void setPower(int8_t advertisedTxPower);
45-
void setPower(esp_power_level_t advertisedTxPower);
46-
void setURL(String url);
47-
int setSmartURL(String url);
34+
String getData();
35+
String getFrame();
36+
BLEUUID getUUID();
37+
int8_t getPower();
38+
String getURL();
39+
String getPrefix();
40+
String getSuffix();
41+
String getDecodedURL();
42+
void setData(String data);
43+
void setUUID(BLEUUID l_uuid);
44+
void setPower(int8_t advertisedTxPower);
45+
void setPower(esp_power_level_t advertisedTxPower);
46+
void setURL(String url);
47+
int setSmartURL(String url);
4848

4949
private:
5050
uint8_t lengthURL; // Describes the length of the URL part including prefix and optional suffix - max 18 B (excluding TX power, frame type and preceding header)

libraries/BLE/src/BLEUtils.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828

2929
#include "esp32-hal-log.h"
3030

31-
/*
32-
static std::map<String, BLEClient*> g_addressMap;
33-
static std::map<uint16_t, BLEClient*> g_connIdMap;
34-
*/
35-
3631
typedef struct {
3732
uint32_t assignedNumber;
3833
const char* name;
@@ -1617,6 +1612,7 @@ void BLEUtils::dumpGattServerEvent(
16171612
// - uint32_t trans_id
16181613
// - esp_bd_addr_t bda
16191614
// - uint8_t exec_write_flag
1615+
#ifdef ARDUHAL_LOG_LEVEL_VERBOSE
16201616
case ESP_GATTS_EXEC_WRITE_EVT: {
16211617
char* pWriteFlagText;
16221618
switch (evtParam->exec_write.exec_write_flag) {
@@ -1643,7 +1639,7 @@ void BLEUtils::dumpGattServerEvent(
16431639
pWriteFlagText);
16441640
break;
16451641
} // ESP_GATTS_DISCONNECT_EVT
1646-
1642+
#endif
16471643

16481644
case ESP_GATTS_MTU_EVT: {
16491645
log_v("[conn_id: %d, mtu: %d]",

0 commit comments

Comments
 (0)