diff --git a/src/NimBLEHIDDevice.cpp b/src/NimBLEHIDDevice.cpp index 394e763..78c8fea 100644 --- a/src/NimBLEHIDDevice.cpp +++ b/src/NimBLEHIDDevice.cpp @@ -27,7 +27,7 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) { * Here we create mandatory services described in bluetooth specification */ m_deviceInfoService = server->createService(NimBLEUUID((uint16_t) 0x180a)); - m_hidService = server->createService(NimBLEUUID((uint16_t) 0x1812), 40); + m_hidService = server->createService(NimBLEUUID((uint16_t) 0x1812)); m_batteryService = server->createService(NimBLEUUID((uint16_t) 0x180f)); /* diff --git a/src/NimBLEServer.cpp b/src/NimBLEServer.cpp index 3c7060c..e31c81b 100644 --- a/src/NimBLEServer.cpp +++ b/src/NimBLEServer.cpp @@ -80,18 +80,17 @@ NimBLEService* NimBLEServer::createService(const char* uuid) { * to provide inst_id value different for each service. * @return A reference to the new service object. */ -NimBLEService* NimBLEServer::createService(const NimBLEUUID &uuid, uint32_t numHandles, uint8_t inst_id) { +NimBLEService* NimBLEServer::createService(const NimBLEUUID &uuid) { NIMBLE_LOGD(LOG_TAG, ">> createService - %s", uuid.toString().c_str()); - // TODO: add functionality to use inst_id for multiple services with same uuid - (void)inst_id; + // Check that a service with the supplied UUID does not already exist. if(getServiceByUUID(uuid) != nullptr) { NIMBLE_LOGW(LOG_TAG, "Warning creating a duplicate service UUID: %s", std::string(uuid).c_str()); } - NimBLEService* pService = new NimBLEService(uuid, numHandles, this); - m_svcVec.push_back(pService); // Save a reference to this service being on this server. + NimBLEService* pService = new NimBLEService(uuid); + m_svcVec.push_back(pService); serviceChanged(); NIMBLE_LOGD(LOG_TAG, "<< createService"); diff --git a/src/NimBLEServer.h b/src/NimBLEServer.h index a50e189..5054b84 100644 --- a/src/NimBLEServer.h +++ b/src/NimBLEServer.h @@ -41,8 +41,7 @@ class NimBLEServer { public: size_t getConnectedCount(); NimBLEService* createService(const char* uuid); - NimBLEService* createService(const NimBLEUUID &uuid, uint32_t numHandles=15, - uint8_t inst_id=0); + NimBLEService* createService(const NimBLEUUID &uuid); void removeService(NimBLEService* service, bool deleteSvc = false); void addService(NimBLEService* service); NimBLEAdvertising* getAdvertising(); diff --git a/src/NimBLEService.cpp b/src/NimBLEService.cpp index b2e5b07..18e15bc 100644 --- a/src/NimBLEService.cpp +++ b/src/NimBLEService.cpp @@ -17,6 +17,7 @@ #include "nimconfig.h" #if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) +#include "NimBLEDevice.h" #include "NimBLEService.h" #include "NimBLEUtils.h" #include "NimBLELog.h" @@ -31,25 +32,19 @@ static const char* LOG_TAG = "NimBLEService"; // Tag for logging. /** * @brief Construct an instance of the NimBLEService * @param [in] uuid The UUID of the service. - * @param [in] numHandles The maximum number of handles associated with the service. - * @param [in] pServer A pointer to the server instance that this service belongs to. */ -NimBLEService::NimBLEService(const char* uuid, uint16_t numHandles, NimBLEServer* pServer) -: NimBLEService(NimBLEUUID(uuid), numHandles, pServer) { +NimBLEService::NimBLEService(const char* uuid) +: NimBLEService(NimBLEUUID(uuid)) { } /** * @brief Construct an instance of the BLEService * @param [in] uuid The UUID of the service. - * @param [in] numHandles The maximum number of handles associated with the service. - * @param [in] pServer A pointer to the server instance that this service belongs to. */ -NimBLEService::NimBLEService(const NimBLEUUID &uuid, uint16_t numHandles, NimBLEServer* pServer) { +NimBLEService::NimBLEService(const NimBLEUUID &uuid) { m_uuid = uuid; m_handle = NULL_HANDLE; - m_pServer = pServer; - m_numHandles = numHandles; m_pSvcDef = nullptr; m_removed = 0; @@ -426,7 +421,7 @@ std::string NimBLEService::toString() { * @return The BLEServer associated with this service. */ NimBLEServer* NimBLEService::getServer() { - return m_pServer; + return NimBLEDevice::getServer(); }// getServer #endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */ diff --git a/src/NimBLEService.h b/src/NimBLEService.h index 2543428..fbdd2e1 100644 --- a/src/NimBLEService.h +++ b/src/NimBLEService.h @@ -34,8 +34,8 @@ class NimBLECharacteristic; class NimBLEService { public: - NimBLEService(const char* uuid, uint16_t numHandles, NimBLEServer* pServer); - NimBLEService(const NimBLEUUID &uuid, uint16_t numHandles, NimBLEServer* pServer); + NimBLEService(const char* uuid); + NimBLEService(const NimBLEUUID &uuid); ~NimBLEService(); NimBLEServer* getServer(); @@ -74,9 +74,7 @@ private: friend class NimBLEDevice; uint16_t m_handle; - NimBLEServer* m_pServer; NimBLEUUID m_uuid; - uint16_t m_numHandles; ble_gatt_svc_def* m_pSvcDef; uint8_t m_removed; std::vector m_chrVec;