mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-22 19:10:46 +01:00
NimBLEClient/ Add getCharacteristic() by handle.
* Add getCharacteristic() by handle. Add a convenience method for getting a characteristic by the 16-bit handle.
This commit is contained in:
parent
d9e11ee630
commit
a331cb05e9
2 changed files with 27 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <string>
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue