Skip to content

Commit c1417e9

Browse files
Added methods to remove service UUID from BLEAdvertising (#8747)
* 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>
1 parent bd39fcf commit c1417e9

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

libraries/BLE/src/BLEAdvertising.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,41 @@ void BLEAdvertising::addServiceUUID(const char* serviceUUID) {
7979
} // addServiceUUID
8080

8181

82+
/**
83+
* @brief Remove a service uuid to exposed list of services.
84+
* @param [in] index The index of the service to stop exposing.
85+
*/
86+
bool BLEAdvertising::removeServiceUUID(int index) {
87+
88+
// If index is larger than the size of the
89+
// advertised services, return false
90+
if(index > m_serviceUUIDs.size()) return false;
91+
92+
m_serviceUUIDs.erase(m_serviceUUIDs.begin() + index);
93+
return true;
94+
}
95+
96+
/**
97+
* @brief Remove a service uuid to exposed list of services.
98+
* @param [in] serviceUUID The BLEUUID of the service to stop exposing.
99+
*/
100+
bool BLEAdvertising::removeServiceUUID(BLEUUID serviceUUID) {
101+
for(int i = 0; i < m_serviceUUIDs.size(); i++) {
102+
if(m_serviceUUIDs.at(i).equals(serviceUUID)) {
103+
return removeServiceUUID(i);
104+
}
105+
}
106+
return false;
107+
}
108+
109+
/**
110+
* @brief Remove a service uuid to exposed list of services.
111+
* @param [in] serviceUUID The string of the service to stop exposing.
112+
*/
113+
bool BLEAdvertising::removeServiceUUID(const char* serviceUUID) {
114+
return removeServiceUUID(BLEUUID(serviceUUID));
115+
}
116+
82117
/**
83118
* @brief Set the device appearance in the advertising data.
84119
* The appearance attribute is of type 0x19. The codes for distinct appearances can be found here:

libraries/BLE/src/BLEAdvertising.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ class BLEAdvertising {
5151
public:
5252
BLEAdvertising();
5353
void addServiceUUID(BLEUUID serviceUUID);
54-
void addServiceUUID(const char* serviceUUID);
54+
void addServiceUUID(const char* serviceUUID);
55+
bool removeServiceUUID(int index);
56+
bool removeServiceUUID(BLEUUID serviceUUID);
57+
bool removeServiceUUID(const char* serviceUUID);
5558
void start();
5659
void stop();
5760
void setAppearance(uint16_t appearance);

0 commit comments

Comments
 (0)