Skip to content

Commit

Permalink
Modified 'BLEAdvertising.h' & 'BLEAdvertising.cpp'
Browse files Browse the repository at this point in the history
Added three methods for removing service UUID from BLEAdvertised
  • Loading branch information
dpnebert authored Oct 9, 2023
1 parent 7e0f892 commit c5a059e
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() + i);
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 c5a059e

Please sign in to comment.