Skip to content

Added methods to remove service UUID from BLEAdvertising #8747

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
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
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