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

Sign up
Appearance settings

refactor(ble): minor BLE library cleanup #11789

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

Merged
me-no-dev merged 3 commits into espressif:master from Kolcha:ble-cleanup
Sep 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions libraries/BLE/src/BLE2902.h
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ This class will be removed in a future version.")]] BLE2902 : public BLEDescript
bool getIndications();
void setNotifications(bool flag);
void setIndications(bool flag);

private:
friend class BLECharacteristic;
}; // BLE2902

#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
Expand Down
2 changes: 0 additions & 2 deletions libraries/BLE/src/BLE2904.h
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ class BLE2904 : public BLEDescriptor {
void setUnit(uint16_t unit);

private:
friend class BLECharacteristic;

/***************************************************************************
* Common private properties *
***************************************************************************/
Expand Down
22 changes: 8 additions & 14 deletions libraries/BLE/src/BLEAddress.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ BLEAddress::BLEAddress() {
* @param [in] otherAddress The other address to compare against.
* @return True if the addresses are equal.
*/
bool BLEAddress::equals(BLEAddress otherAddress) {
#if defined(CONFIG_NIMBLE_ENABLED)
if (m_addrType != otherAddress.m_addrType) {
return false;
}
#endif
return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0;
bool BLEAddress::equals(const BLEAddress &otherAddress) const {
return *this == otherAddress;
}

bool BLEAddress::operator==(const BLEAddress &otherAddress) const {
Expand Down Expand Up @@ -116,9 +111,9 @@ uint8_t *BLEAddress::getNative() {
*
* @return The string representation of the address.
*/
String BLEAddress::toString() {
auto size = 18;
char *res = (char *)malloc(size);
String BLEAddress::toString() const {
constexpr size_t size = 18;
char res[size];

#if defined(CONFIG_BLUEDROID_ENABLED)
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]);
Expand All @@ -129,7 +124,6 @@ String BLEAddress::toString() {
#endif

String ret(res);
free(res);
return ret;
}

Expand Down Expand Up @@ -158,7 +152,7 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) {
*
* @param [in] stringAddress The hex representation of the address.
*/
BLEAddress::BLEAddress(String stringAddress) {
BLEAddress::BLEAddress(const String &stringAddress) {
if (stringAddress.length() != 17) {
return;
}
Expand Down Expand Up @@ -193,7 +187,7 @@ BLEAddress::BLEAddress(ble_addr_t address) {
m_addrType = address.type;
}

uint8_t BLEAddress::getType() {
uint8_t BLEAddress::getType() const {
return m_addrType;
}

Expand All @@ -209,7 +203,7 @@ uint8_t BLEAddress::getType() {
* @param [in] stringAddress The hex representation of the address.
* @param [in] type The address type.
*/
BLEAddress::BLEAddress(String stringAddress, uint8_t type) {
BLEAddress::BLEAddress(const String &stringAddress, uint8_t type) {
if (stringAddress.length() != 17) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions libraries/BLE/src/BLEAddress.h
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ class BLEAddress {
***************************************************************************/

BLEAddress();
bool equals(BLEAddress otherAddress);
bool equals(const BLEAddress &otherAddress) const;
bool operator==(const BLEAddress &otherAddress) const;
bool operator!=(const BLEAddress &otherAddress) const;
bool operator<(const BLEAddress &otherAddress) const;
bool operator<=(const BLEAddress &otherAddress) const;
bool operator>(const BLEAddress &otherAddress) const;
bool operator>=(const BLEAddress &otherAddress) const;
uint8_t *getNative();
String toString();
String toString() const;

/***************************************************************************
* Bluedroid public declarations *
***************************************************************************/

#if defined(CONFIG_BLUEDROID_ENABLED)
BLEAddress(esp_bd_addr_t address);
BLEAddress(String stringAddress);
BLEAddress(const String &stringAddress);
#endif

/***************************************************************************
Expand All @@ -87,9 +87,9 @@ class BLEAddress {

#if defined(CONFIG_NIMBLE_ENABLED)
BLEAddress(ble_addr_t address);
BLEAddress(String stringAddress, uint8_t type = BLE_ADDR_PUBLIC);
BLEAddress(const String &stringAddress, uint8_t type = BLE_ADDR_PUBLIC);
BLEAddress(uint8_t address[ESP_BD_ADDR_LEN], uint8_t type = BLE_ADDR_PUBLIC);
uint8_t getType();
uint8_t getType() const;
#endif

private:
Expand Down
2 changes: 1 addition & 1 deletion libraries/BLE/src/BLEBeacon.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int8_t BLEBeacon::getSignalPower() {
return m_beaconData.signalPower;
}

void BLEBeacon::setData(String data) {
void BLEBeacon::setData(const String &data) {
if (data.length() != sizeof(m_beaconData)) {
log_e("Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData));
return;
Expand Down
2 changes: 1 addition & 1 deletion libraries/BLE/src/BLEBeacon.h
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BLEBeacon {
uint16_t getManufacturerId();
BLEUUID getProximityUUID();
int8_t getSignalPower();
void setData(String data);
void setData(const String &data);
void setMajor(uint16_t major);
void setMinor(uint16_t minor);
void setManufacturerId(uint16_t manufacturerId);
Expand Down
20 changes: 10 additions & 10 deletions libraries/BLE/src/BLECharacteristic.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void BLECharacteristic::addDescriptor(BLEDescriptor *pDescriptor) {
* @param [in] descriptorUUID The UUID of the descriptor that we wish to retrieve.
* @return The BLE Descriptor. If no such descriptor is associated with the characteristic, nullptr is returned.
*/
BLEDescriptor *BLECharacteristic::getDescriptorByUUID(const char *descriptorUUID) {
BLEDescriptor *BLECharacteristic::getDescriptorByUUID(const char *descriptorUUID) const {
return m_descriptorMap.getByUUID(BLEUUID(descriptorUUID));
} // getDescriptorByUUID

Expand All @@ -133,15 +133,15 @@ BLEDescriptor *BLECharacteristic::getDescriptorByUUID(const char *descriptorUUID
* @param [in] descriptorUUID The UUID of the descriptor that we wish to retrieve.
* @return The BLE Descriptor. If no such descriptor is associated with the characteristic, nullptr is returned.
*/
BLEDescriptor *BLECharacteristic::getDescriptorByUUID(BLEUUID descriptorUUID) {
BLEDescriptor *BLECharacteristic::getDescriptorByUUID(BLEUUID descriptorUUID) const {
return m_descriptorMap.getByUUID(descriptorUUID);
} // getDescriptorByUUID

/**
* @brief Get the handle of the characteristic.
* @return The handle of the characteristic.
*/
uint16_t BLECharacteristic::getHandle() {
uint16_t BLECharacteristic::getHandle() const {
return m_handle;
} // getHandle

Expand All @@ -151,30 +151,30 @@ void BLECharacteristic::setAccessPermissions(uint16_t perm) {
#endif
}

esp_gatt_char_prop_t BLECharacteristic::getProperties() {
esp_gatt_char_prop_t BLECharacteristic::getProperties() const {
return m_properties;
} // getProperties

/**
* @brief Get the service associated with this characteristic.
*/
BLEService *BLECharacteristic::getService() {
BLEService *BLECharacteristic::getService() const {
return m_pService;
} // getService

/**
* @brief Get the UUID of the characteristic.
* @return The UUID of the characteristic.
*/
BLEUUID BLECharacteristic::getUUID() {
BLEUUID BLECharacteristic::getUUID() const {
return m_bleUUID;
} // getUUID

/**
* @brief Retrieve the current value of the characteristic.
* @return A pointer to storage containing the current characteristic value.
*/
String BLECharacteristic::getValue() {
String BLECharacteristic::getValue() const {
return m_value.getValue();
} // getValue

Expand All @@ -190,7 +190,7 @@ uint8_t *BLECharacteristic::getData() {
* @brief Retrieve the current length of the data of the characteristic.
* @return Amount of databytes of the characteristic.
*/
size_t BLECharacteristic::getLength() {
size_t BLECharacteristic::getLength() const {
return m_value.getLength();
} // getLength

Expand Down Expand Up @@ -425,7 +425,7 @@ void BLECharacteristic::setWriteProperty(bool value) {
* @brief Return a string representation of the characteristic.
* @return A string representation of the characteristic.
*/
String BLECharacteristic::toString() {
String BLECharacteristic::toString() const {
String res = "UUID: " + m_bleUUID.toString() + ", handle : 0x";
char hex[5];
snprintf(hex, sizeof(hex), "%04x", m_handle);
Expand All @@ -452,7 +452,7 @@ String BLECharacteristic::toString() {
return res;
} // toString

BLECharacteristicCallbacks::~BLECharacteristicCallbacks() {}
BLECharacteristicCallbacks::~BLECharacteristicCallbacks() = default;

// Common callbacks
void BLECharacteristicCallbacks::onRead(BLECharacteristic *pCharacteristic) {
Expand Down
28 changes: 14 additions & 14 deletions libraries/BLE/src/BLECharacteristic.h
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ class BLEDescriptorMap {
void setByUUID(const char *uuid, BLEDescriptor *pDescriptor);
void setByUUID(BLEUUID uuid, BLEDescriptor *pDescriptor);
void setByHandle(uint16_t handle, BLEDescriptor *pDescriptor);
BLEDescriptor *getByUUID(const char *uuid);
BLEDescriptor *getByUUID(BLEUUID uuid);
BLEDescriptor *getByHandle(uint16_t handle);
String toString();
BLEDescriptor *getByUUID(const char *uuid) const;
BLEDescriptor *getByUUID(BLEUUID uuid) const;
BLEDescriptor *getByHandle(uint16_t handle) const;
String toString() const;
BLEDescriptor *getFirst();
BLEDescriptor *getNext();
int getRegisteredDescriptorCount();
int getRegisteredDescriptorCount() const;
void removeDescriptor(BLEDescriptor *pDescriptor);

/***************************************************************************
Expand Down Expand Up @@ -181,12 +181,12 @@ class BLECharacteristic {
virtual ~BLECharacteristic();

void addDescriptor(BLEDescriptor *pDescriptor);
BLEDescriptor *getDescriptorByUUID(const char *descriptorUUID);
BLEDescriptor *getDescriptorByUUID(BLEUUID descriptorUUID);
BLEUUID getUUID();
String getValue();
BLEDescriptor *getDescriptorByUUID(const char *descriptorUUID) const;
BLEDescriptor *getDescriptorByUUID(BLEUUID descriptorUUID) const;
BLEUUID getUUID() const;
String getValue() const;
uint8_t *getData();
size_t getLength();
size_t getLength() const;
void indicate();
void notify(bool is_notification = true);
void setCallbacks(BLECharacteristicCallbacks *pCallbacks);
Expand All @@ -197,10 +197,10 @@ class BLECharacteristic {
void setValue(int data32);
void setValue(float data32);
void setValue(double data64);
String toString();
uint16_t getHandle();
String toString() const;
uint16_t getHandle() const;
void setAccessPermissions(uint16_t perm);
esp_gatt_char_prop_t getProperties();
esp_gatt_char_prop_t getProperties() const;
void setReadProperty(bool value);
void setWriteProperty(bool value);
void setNotifyProperty(bool value);
Expand Down Expand Up @@ -253,7 +253,7 @@ class BLECharacteristic {
***************************************************************************/

void executeCreate(BLEService *pService);
BLEService *getService();
BLEService *getService() const;
void setHandle(uint16_t handle);

/***************************************************************************
Expand Down
10 changes: 5 additions & 5 deletions libraries/BLE/src/BLECharacteristicMap.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @param [in] handle The handle to look up the characteristic.
* @return The characteristic.
*/
BLECharacteristic *BLECharacteristicMap::getByHandle(uint16_t handle) {
BLECharacteristic *BLECharacteristicMap::getByHandle(uint16_t handle) const {
return m_handleMap.at(handle);
} // getByHandle

Expand All @@ -45,7 +45,7 @@ BLECharacteristic *BLECharacteristicMap::getByHandle(uint16_t handle) {
* @param [in] UUID The UUID to look up the characteristic.
* @return The characteristic.
*/
BLECharacteristic *BLECharacteristicMap::getByUUID(const char *uuid) {
BLECharacteristic *BLECharacteristicMap::getByUUID(const char *uuid) const {
return getByUUID(BLEUUID(uuid));
}

Expand All @@ -54,7 +54,7 @@ BLECharacteristic *BLECharacteristicMap::getByUUID(const char *uuid) {
* @param [in] UUID The UUID to look up the characteristic.
* @return The characteristic.
*/
BLECharacteristic *BLECharacteristicMap::getByUUID(BLEUUID uuid) {
BLECharacteristic *BLECharacteristicMap::getByUUID(BLEUUID uuid) const {
for (auto &myPair : m_uuidMap) {
if (myPair.first->getUUID().equals(uuid)) {
return myPair.first;
Expand Down Expand Up @@ -95,7 +95,7 @@ BLECharacteristic *BLECharacteristicMap::getNext() {
* @brief Get the number of registered characteristics.
* @return The number of registered characteristics.
*/
int BLECharacteristicMap::getRegisteredCharacteristicCount() {
int BLECharacteristicMap::getRegisteredCharacteristicCount() const {
return m_uuidMap.size();
} // getRegisteredCharacteristicCount

Expand Down Expand Up @@ -133,7 +133,7 @@ void BLECharacteristicMap::setByUUID(BLECharacteristic *pCharacteristic, BLEUUID
* @brief Return a string representation of the characteristic map.
* @return A string representation of the characteristic map.
*/
String BLECharacteristicMap::toString() {
String BLECharacteristicMap::toString() const {
String res;
int count = 0;
char hex[5];
Expand Down
14 changes: 7 additions & 7 deletions libraries/BLE/src/BLEDescriptor.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,38 @@ void BLEDescriptor::executeCreate(BLECharacteristic *pCharacteristic) {
* @brief Get the BLE handle for this descriptor.
* @return The handle for this descriptor.
*/
uint16_t BLEDescriptor::getHandle() {
uint16_t BLEDescriptor::getHandle() const {
return m_handle;
} // getHandle

/**
* @brief Get the length of the value of this descriptor.
* @return The length (in bytes) of the value of this descriptor.
*/
size_t BLEDescriptor::getLength() {
size_t BLEDescriptor::getLength() const {
return m_value.attr_len;
} // getLength

/**
* @brief Get the UUID of the descriptor.
*/
BLEUUID BLEDescriptor::getUUID() {
BLEUUID BLEDescriptor::getUUID() const {
return m_bleUUID;
} // getUUID

/**
* @brief Get the value of this descriptor.
* @return A pointer to the value of this descriptor.
*/
uint8_t *BLEDescriptor::getValue() {
uint8_t *BLEDescriptor::getValue() const {
return m_value.attr_value;
} // getValue

/**
* @brief Get the characteristic this descriptor belongs to.
* @return A pointer to the characteristic this descriptor belongs to.
*/
BLECharacteristic *BLEDescriptor::getCharacteristic() {
BLECharacteristic *BLEDescriptor::getCharacteristic() const {
return m_pCharacteristic;
} // getCharacteristic

Expand Down Expand Up @@ -215,14 +215,14 @@ void BLEDescriptor::setAccessPermissions(uint16_t perm) {
* @brief Return a string representation of the descriptor.
* @return A string representation of the descriptor.
*/
String BLEDescriptor::toString() {
String BLEDescriptor::toString() const {
char hex[5];
snprintf(hex, sizeof(hex), "%04x", m_handle);
String res = "UUID: " + m_bleUUID.toString() + ", handle: 0x" + hex;
return res;
} // toString

BLEDescriptorCallbacks::~BLEDescriptorCallbacks() {}
BLEDescriptorCallbacks::~BLEDescriptorCallbacks() = default;

/**
* @brief Callback function to support a read request.
Expand Down
Loading
Loading

AltStyle によって変換されたページ (->オリジナル) /