diff --git a/src/NimBLEClient.cpp b/src/NimBLEClient.cpp index 539a7a0..3552bfd 100644 --- a/src/NimBLEClient.cpp +++ b/src/NimBLEClient.cpp @@ -641,6 +641,31 @@ bool NimBLEClient::setValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &cha } // setValue +/** + * @brief Get the remote characteristic with the specified handle. + * @param [in] handle The handle of the desired characteristic. + * @returns The matching remote characteristic, nullptr otherwise. + */ +NimBLERemoteCharacteristic* NimBLEClient::getCharacteristic(const uint16_t handle) +{ + NimBLERemoteService *pService = nullptr; + for(auto it = m_servicesVector.begin(); it != m_servicesVector.end(); ++it) { + if ((*it)->getStartHandle() <= handle && handle <= (*it)->getEndHandle()) { + pService = *it; + break; + } + } + + if (pService != nullptr) { + for (auto it = pService->begin(); it != pService->end(); ++it) { + if ((*it)->getHandle() == handle) { + return *it; + } + } + } + + return nullptr; +} /** * @brief Get the current mtu of this connection. diff --git a/src/NimBLEClient.h b/src/NimBLEClient.h index ddeef3c..b9bb0a5 100644 --- a/src/NimBLEClient.h +++ b/src/NimBLEClient.h @@ -30,6 +30,7 @@ #include class NimBLERemoteService; +class NimBLERemoteCharacteristic; class NimBLEClientCallbacks; class NimBLEAdvertisedDevice; @@ -55,6 +56,7 @@ public: std::string getValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID); bool setValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID, const std::string &value); + NimBLERemoteCharacteristic* getCharacteristic(const uint16_t handle); bool isConnected(); void setClientCallbacks(NimBLEClientCallbacks *pClientCallbacks, bool deleteCallbacks = true);