8000 multiple services with the same uuid · breadchris/esp32-snippets@eb836aa · GitHub
[go: up one dir, main page]

Skip to content

Commit eb836aa

Browse files
committed
multiple services with the same uuid
1 parent 0d67442 commit eb836aa

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

cpp_utils/BLEServer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,23 @@ BLEService* BLEServer::createService(const char* uuid) {
6969
* of a new service. Every service must have a unique UUID.
7070
* @param [in] uuid The UUID of the new service.
7171
* @param [in] numHandles The maximum number of handles associated with this service.
72+
* @param [in] inst_id With multiple services with the same UUID we need to provide inst_id value different for each service.
7273
* @return A reference to the new service object.
7374
*/
74-
BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles) {
75+
BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t inst_id) {
7576
ESP_LOGD(LOG_TAG, ">> createService - %s", uuid.toString().c_str());
7677
m_semaphoreCreateEvt.take("createService");
7778

78-
BLEService* pService = new BLEService(uuid, numHandles);
7979
// Check that a service with the supplied UUID does not already exist.
8080
if (m_serviceMap.getByUUID(uuid) != nullptr) {
8181
ESP_LOGW(LOG_TAG, "<< Attempt to create a new service with uuid %s but a service with that UUID already exists.",
8282
uuid.toString().c_str());
8383
//m_semaphoreCreateEvt.give();
8484
//return nullptr;
85-
pService->m_id = 1;
8685
}
8786

87+
BLEService* pService = new BLEService(uuid, numHandles);
88+
pService->m_id = inst_id;
8889
m_serviceMap.setByUUID(uuid, pService); // Save a reference to this service being on this server.
8990
pService->executeCreate(this); // Perform the API calls to actually create the service.
9091

cpp_utils/BLEServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ class BLEServer {
5757
public:
5858
uint32_t getConnectedCount();
5959
BLEService* createService(const char* uuid);
60-
BLEService* createService(BLEUUID uuid, uint32_t numHandles=15);
60+
BLEService* createService(BLEUUID uuid, uint32_t numHandles=15, uint8_t inst_id=0);
6161
BLEAdvertising* getAdvertising();
6262
void setCallbacks(BLEServerCallbacks* pCallbacks);
6363
void startAdvertising();
64+
uint16_t getGattsIf();
6465

6566

6667
private:
@@ -81,7 +82,6 @@ class BLEServer {
8182

8283
void createApp(uint16_t appId);
8384
uint16_t getConnId();
84-
uint16_t getGattsIf();
8585
void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
8686
void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
8787
void registerApp();

cpp_utils/BLEService.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ void BLEService::handleGATTServerEvent(
292292
// * - bool is_primary
293293
//
294294
case ESP_GATTS_CREATE_EVT: {
295-
ESP_LOGE(LOG_TAG, "%d", param->create.service_handle);
296295
if (getUUID().equals(BLEUUID(param->create.service_id.id.uuid)) && m_id == param->create.service_id.id.inst_id) {
297296
setHandle(param->create.service_handle);
298297
m_semaphoreCreateEvt.give();

0 commit comments

Comments
 (0)
0