Skip to content

Commit

Permalink
Added methods to remove service UUID from BLEAdvertising (#8747)
Browse files Browse the repository at this point in the history
* Modified 'BLEAdvertising.h' & 'BLEAdvertising.cpp'

Added three methods for removing service UUID from BLEAdvertised

* Update BLEAdvertising.cpp

Changed 'i' to 'index'

---------

Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com>
  • Loading branch information
dpnebert and P-R-O-C-H-Y committed Nov 29, 2023
1 parent bd39fcf commit c1417e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
35 changes: 35 additions & 0 deletions libraries/BLE/src/BLEAdvertising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,41 @@ void BLEAdvertising::addServiceUUID(const char* serviceUUID) {
} // addServiceUUID


/**
* @brief Remove a service uuid to exposed list of services.
* @param [in] index The index of the service to stop exposing.
*/
bool BLEAdvertising::removeServiceUUID(int index) {

// If index is larger than the size of the
// advertised services, return false
if(index > m_serviceUUIDs.size()) return false;

m_serviceUUIDs.erase(m_serviceUUIDs.begin() + index);
return true;
}

/**
* @brief Remove a service uuid to exposed list of services.
* @param [in] serviceUUID The BLEUUID of the service to stop exposing.
*/
bool BLEAdvertising::removeServiceUUID(BLEUUID serviceUUID) {
for(int i = 0; i < m_serviceUUIDs.size(); i++) {
if(m_serviceUUIDs.at(i).equals(serviceUUID)) {
return removeServiceUUID(i);
}
}
return false;
}

/**
* @brief Remove a service uuid to exposed list of services.
* @param [in] serviceUUID The string of the service to stop exposing.
*/
bool BLEAdvertising::removeServiceUUID(const char* serviceUUID) {
return removeServiceUUID(BLEUUID(serviceUUID));
}

/**
* @brief Set the device appearance in the advertising data.
* The appearance attribute is of type 0x19. The codes for distinct appearances can be found here:
Expand Down
5 changes: 4 additions & 1 deletion libraries/BLE/src/BLEAdvertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class BLEAdvertising {
public:
BLEAdvertising();
void addServiceUUID(BLEUUID serviceUUID);
void addServiceUUID(const char* serviceUUID);
void addServiceUUID(const char* serviceUUID);
bool removeServiceUUID(int index);
bool removeServiceUUID(BLEUUID serviceUUID);
bool removeServiceUUID(const char* serviceUUID);
void start();
void stop();
void setAppearance(uint16_t appearance);
Expand Down

0 comments on commit c1417e9

Please sign in to comment.