Skip to content

Commit fb660b5

Browse files
committed
Fixed URL and Utils error
1 parent 4099263 commit fb660b5

File tree

5 files changed

+31
-38
lines changed

5 files changed

+31
-38
lines changed

Diff for: 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
}

Diff for: libraries/BLE/src/BLECharacteristic.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ BLECharacteristic::~BLECharacteristic() {
6565
* @return N/A.
6666
*/
6767
void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) {
68-
log_v(">> addDescriptor(): Adding %s to %s", pDescriptor->toString()..c_str(), toString()..c_str());
68+
log_v(">> addDescriptor(): Adding %s to %s", pDescriptor->toString().c_str(), toString().c_str());
6969
m_descriptorMap.setByUUID(pDescriptor->getUUID(), pDescriptor);
7070
log_v("<< addDescriptor()");
7171
} // addDescriptor
@@ -86,8 +86,8 @@ void BLECharacteristic::executeCreate(BLEService* pService) {
8686
m_pService = pService; // Save the service to which this characteristic belongs.
8787

8888
log_d("Registering characteristic (esp_ble_gatts_add_char): uuid: %s, service: %s",
89-
getUUID().toString()..c_str(),
90-
m_pService->toString()..c_str());
89+
getUUID().toString().c_str(),
90+
m_pService->toString().c_str());
9191

9292
esp_attr_control_t control;
9393
control.auto_rsp = ESP_GATT_RSP_BY_APP;
@@ -202,7 +202,7 @@ void BLECharacteristic::handleGATTServerEvent(
202202
esp_gatts_cb_event_t event,
203203
esp_gatt_if_t gatts_if,
204204
esp_ble_gatts_cb_param_t* param) {
205-
log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event)..c_str());
205+
log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str());
206206

207207
switch(event) {
208208
// Events handled:
@@ -294,7 +294,7 @@ void BLECharacteristic::handleGATTServerEvent(
294294
}
295295

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

299299
char* pHexData = BLEUtils::buildHexData(nullptr, param->write.value, param->write.len);
300300
log_d(" - Data: length: %d, data: %s", param->write.len, pHexData);
@@ -601,7 +601,7 @@ void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) {
601601
* @param [in] handle The handle associated with this characteristic.
602602
*/
603603
void BLECharacteristic::setHandle(uint16_t handle) {
604-
log_v(">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString()..c_str());
604+
log_v(">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString().c_str());
605605
m_handle = handle;
606606
log_v("<< setHandle");
607607
} // setHandle
@@ -656,7 +656,7 @@ void BLECharacteristic::setReadProperty(bool value) {
656656
*/
657657
void BLECharacteristic::setValue(uint8_t* data, size_t length) {
658658
char* pHex = BLEUtils::buildHexData(nullptr, data, length);
659-
log_v(">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString()..c_str());
659+
log_v(">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str());
660660
free(pHex);
661661
if (length > ESP_GATT_MAX_ATTR_LEN) {
662662
log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN);

Diff for: libraries/BLE/src/BLEEddystoneURL.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,22 @@ String BLEEddystoneURL::getSuffix(){
106106
}
107107

108108
String BLEEddystoneURL::getDecodedURL() {
109-
String decodedURL = "";
110-
decodedURL += String(getPrefix().c_str());
109+
std::string decodedURL = "";
110+
decodedURL += getPrefix().c_str();
111111
if(decodedURL.length() == 0){ // No prefix extracted - interpret byte [0] as character
112-
decodedURL += m_eddystoneData.url[0];
112+
decodedURL += (char)m_eddystoneData.url[0];
113113
}
114-
115-
for (int i = 1; i < lengthURL; i++) {
114+
for(int i = 1; i < lengthURL; i++) {
116115
if (m_eddystoneData.url[i] >= 33 && m_eddystoneData.url[i] < 127) {
117-
decodedURL += m_eddystoneData.url[i];
116+
decodedURL += (char)m_eddystoneData.url[i];
118117
}else{
119118
if(i != lengthURL-1 || m_eddystoneData.url[i] > 0x0D){ // Ignore last Byte and values used for suffix
120119
log_e("Unexpected unprintable char in URL 0x%02X: m_eddystoneData.url[%d]", m_eddystoneData.url[i], i);
121120
}
122121
}
123122
}
124-
decodedURL += String(getSuffix().c_str());
125-
return decodedURL;
123+
decodedURL += getSuffix().c_str();
124+
return String(decodedURL.c_str());
126125
} // getDecodedURL
127126

128127
/**
@@ -231,9 +230,7 @@ int BLEEddystoneURL::setSmartURL(String url) {
231230
uint8_t suffix = 0x0E; // Init with empty string
232231
log_d("Encode url \"%s\" with length %d", url.c_str(), url.length());
233232
for(uint8_t i = 0; i < 4; ++i){
234-
//log_d("check if substr \"%s\" == prefix \"%s\" ", url.substring(0, EDDYSTONE_URL_PREFIX[i].length()), EDDYSTONE_URL_PREFIX[i]);
235233
if(url.substring(0, EDDYSTONE_URL_PREFIX[i].length()) == EDDYSTONE_URL_PREFIX[i]){
236-
//log_d("Found prefix 0x%02X = \"%s\"", i, EDDYSTONE_URL_PREFIX[i]);
237234
m_eddystoneData.url[0] = i;
238235
hasPrefix = true;
239236
break;
@@ -248,7 +245,6 @@ int BLEEddystoneURL::setSmartURL(String url) {
248245
std::string std_url(url.c_str());
249246
std::string std_suffix(EDDYSTONE_URL_SUFFIX[i].c_str());
250247
size_t found_pos = std_url.find(std_suffix);
251-
//log_d("check if in url \"%s\" can find suffix \"%s\": found_pos = %d", std_url.c_str(), std_suffix.c_str(), found_pos);
252248
if(found_pos != std::string::npos){
253249
hasSuffix = true;
254250
suffix = i;

Diff for: libraries/BLE/src/BLEEddystoneURL.h

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

4646
private:
4747
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)

Diff for: libraries/BLE/src/BLEUtils.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525

2626
#include "esp32-hal-log.h"
2727

28-
/*
29-
static std::map<String, BLEClient*> g_addressMap;
30-
static std::map<uint16_t, BLEClient*> g_connIdMap;
31-
*/
32-
3328
typedef struct {
3429
uint32_t assignedNumber;
3530
const char* name;
@@ -1614,6 +1609,7 @@ void BLEUtils::dumpGattServerEvent(
16141609
// - uint32_t trans_id
16151610
// - esp_bd_addr_t bda
16161611
// - uint8_t exec_write_flag
1612+
#ifdef ARDUHAL_LOG_LEVEL_VERBOSE
16171613
case ESP_GATTS_EXEC_WRITE_EVT: {
16181614
char* pWriteFlagText;
16191615
switch (evtParam->exec_write.exec_write_flag) {
@@ -1640,7 +1636,7 @@ void BLEUtils::dumpGattServerEvent(
16401636
pWriteFlagText);
16411637
break;
16421638
} // ESP_GATTS_DISCONNECT_EVT
1643-
1639+
#endif
16441640

16451641
case ESP_GATTS_MTU_EVT: {
16461642
log_v("[conn_id: %d, mtu: %d]",

0 commit comments

Comments
 (0)