Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLE upgrades #8724

Merged
merged 18 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed URL and Utils error
  • Loading branch information
PilnyTomas authored and me-no-dev committed Oct 5, 2023
commit 6e370e989dec6cd9fa8eae9377b159a3a16f3b50
1 change: 1 addition & 0 deletions libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
}
Serial.printf("\n");
Serial.printf("Decoded URL: %s\n", EddystoneURL.getDecodedURL().c_str());
Serial.printf("EddystoneURL.getDecodedURL(): %s\n", EddystoneURL.getDecodedURL().c_str());
Serial.printf("TX power %d (Raw 0x%02X)\n", EddystoneURL.getPower(), EddystoneURL.getPower());
Serial.println("\n");
}
Expand Down
14 changes: 7 additions & 7 deletions libraries/BLE/src/BLECharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ BLECharacteristic::~BLECharacteristic() {
* @return N/A.
*/
void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) {
log_v(">> 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);
log_v("<< addDescriptor()");
} // addDescriptor
Expand All @@ -89,8 +89,8 @@ void BLECharacteristic::executeCreate(BLEService* pService) {
m_pService = pService; // Save the service to which this characteristic belongs.

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

esp_attr_control_t control;
control.auto_rsp = ESP_GATT_RSP_BY_APP;
Expand Down Expand Up @@ -205,7 +205,7 @@ void BLECharacteristic::handleGATTServerEvent(
esp_gatts_cb_event_t event,
esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t* param) {
log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event)..c_str());
log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str());

switch(event) {
// Events handled:
Expand Down Expand Up @@ -297,7 +297,7 @@ void BLECharacteristic::handleGATTServerEvent(
}

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

char* pHexData = BLEUtils::buildHexData(nullptr, param->write.value, param->write.len);
log_d(" - Data: length: %d, data: %s", param->write.len, pHexData);
Expand Down Expand Up @@ -604,7 +604,7 @@ void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) {
* @param [in] handle The handle associated with this characteristic.
*/
void BLECharacteristic::setHandle(uint16_t handle) {
log_v(">> 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;
log_v("<< setHandle");
} // setHandle
Expand Down Expand Up @@ -659,7 +659,7 @@ void BLECharacteristic::setReadProperty(bool value) {
*/
void BLECharacteristic::setValue(uint8_t* data, size_t length) {
char* pHex = BLEUtils::buildHexData(nullptr, data, length);
log_v(">> 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) {
log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN);
Expand Down
18 changes: 7 additions & 11 deletions libraries/BLE/src/BLEEddystoneURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,22 @@ String BLEEddystoneURL::getSuffix(){
}

String BLEEddystoneURL::getDecodedURL() {
String decodedURL = "";
decodedURL += String(getPrefix().c_str());
std::string decodedURL = "";
decodedURL += getPrefix().c_str();
if(decodedURL.length() == 0){ // No prefix extracted - interpret byte [0] as character
decodedURL += m_eddystoneData.url[0];
decodedURL += (char)m_eddystoneData.url[0];
}

for (int i = 1; i < lengthURL; i++) {
for(int i = 1; i < lengthURL; i++) {
if (m_eddystoneData.url[i] >= 33 && m_eddystoneData.url[i] < 127) {
decodedURL += m_eddystoneData.url[i];
decodedURL += (char)m_eddystoneData.url[i];
}else{
if(i != lengthURL-1 || m_eddystoneData.url[i] > 0x0D){ // Ignore last Byte and values used for suffix
log_e("Unexpected unprintable char in URL 0x%02X: m_eddystoneData.url[%d]", m_eddystoneData.url[i], i);
}
}
}
decodedURL += String(getSuffix().c_str());
return decodedURL;
decodedURL += getSuffix().c_str();
return String(decodedURL.c_str());
} // getDecodedURL

/**
Expand Down Expand Up @@ -234,9 +233,7 @@ int BLEEddystoneURL::setSmartURL(String url) {
uint8_t suffix = 0x0E; // Init with empty string
log_d("Encode url \"%s\" with length %d", url.c_str(), url.length());
for(uint8_t i = 0; i < 4; ++i){
//log_d("check if substr \"%s\" == prefix \"%s\" ", url.substring(0, EDDYSTONE_URL_PREFIX[i].length()), EDDYSTONE_URL_PREFIX[i]);
if(url.substring(0, EDDYSTONE_URL_PREFIX[i].length()) == EDDYSTONE_URL_PREFIX[i]){
//log_d("Found prefix 0x%02X = \"%s\"", i, EDDYSTONE_URL_PREFIX[i]);
m_eddystoneData.url[0] = i;
hasPrefix = true;
break;
Expand All @@ -251,7 +248,6 @@ int BLEEddystoneURL::setSmartURL(String url) {
std::string std_url(url.c_str());
std::string std_suffix(EDDYSTONE_URL_SUFFIX[i].c_str());
size_t found_pos = std_url.find(std_suffix);
//log_d("check if in url \"%s\" can find suffix \"%s\": found_pos = %d", std_url.c_str(), std_suffix.c_str(), found_pos);
if(found_pos != std::string::npos){
hasSuffix = true;
suffix = i;
Expand Down
28 changes: 14 additions & 14 deletions libraries/BLE/src/BLEEddystoneURL.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ class BLEEddystoneURL {
public:
BLEEddystoneURL();
BLEEddystoneURL(BLEAdvertisedDevice *advertisedDevice);
String getData();
String getFrame();
BLEUUID getUUID();
int8_t getPower();
String getURL();
String getPrefix();
String getSuffix();
String getDecodedURL();
void setData(String data);
void setUUID(BLEUUID l_uuid);
void setPower(int8_t advertisedTxPower);
void setPower(esp_power_level_t advertisedTxPower);
void setURL(String url);
int setSmartURL(String url);
String getData();
String getFrame();
BLEUUID getUUID();
int8_t getPower();
String getURL();
String getPrefix();
String getSuffix();
String getDecodedURL();
void setData(String data);
void setUUID(BLEUUID l_uuid);
void setPower(int8_t advertisedTxPower);
void setPower(esp_power_level_t advertisedTxPower);
void setURL(String url);
int setSmartURL(String url);

private:
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)
Expand Down
8 changes: 2 additions & 6 deletions libraries/BLE/src/BLEUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@

#include "esp32-hal-log.h"

/*
static std::map<String, BLEClient*> g_addressMap;
static std::map<uint16_t, BLEClient*> g_connIdMap;
*/

typedef struct {
uint32_t assignedNumber;
const char* name;
Expand Down Expand Up @@ -1617,6 +1612,7 @@ void BLEUtils::dumpGattServerEvent(
// - uint32_t trans_id
// - esp_bd_addr_t bda
// - uint8_t exec_write_flag
#ifdef ARDUHAL_LOG_LEVEL_VERBOSE
case ESP_GATTS_EXEC_WRITE_EVT: {
char* pWriteFlagText;
switch (evtParam->exec_write.exec_write_flag) {
Expand All @@ -1643,7 +1639,7 @@ void BLEUtils::dumpGattServerEvent(
pWriteFlagText);
break;
} // ESP_GATTS_DISCONNECT_EVT

#endif

case ESP_GATTS_MTU_EVT: {
log_v("[conn_id: %d, mtu: %d]",
Expand Down