mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-01-22 09:20:51 +01:00
Clean up PR
This commit is contained in:
parent
74c6c583d2
commit
310a60a487
5 changed files with 21 additions and 16 deletions
|
@ -632,8 +632,8 @@ NimBLERemoteService* NimBLEClient::getService(const NimBLEUUID& uuid) {
|
|||
NIMBLE_LOGD(LOG_TAG, ">> getService: uuid: %s", uuid.toString().c_str());
|
||||
NimBLERemoteService *pSvc = nullptr;
|
||||
|
||||
NimBLEUtils::getAttr<NimBLERemoteService>(uuid, &pSvc, m_svcVec, [this](const NimBLEUUID* u, NimBLERemoteService** arg) {
|
||||
return retrieveServices(u, arg);
|
||||
NimBLEUtils::getAttr<NimBLERemoteService>(uuid, &pSvc, m_svcVec, [this](const NimBLEUUID* u, NimBLERemoteService** svc) {
|
||||
return retrieveServices(u, svc);
|
||||
});
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< getService: %sfound", !pSvc ? "not " : "");
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
|
||||
# include <climits>
|
||||
|
||||
struct desc_filter_t {
|
||||
const NimBLEUUID* uuid;
|
||||
void* taskData;
|
||||
};
|
||||
typedef struct {
|
||||
const NimBLEUUID* uuid;
|
||||
void* taskData;
|
||||
} desc_filter_t;
|
||||
|
||||
static const char* LOG_TAG = "NimBLERemoteCharacteristic";
|
||||
|
||||
|
@ -99,7 +99,7 @@ bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID* uuidFilte
|
|||
NIMBLE_LOGD(LOG_TAG, ">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str());
|
||||
|
||||
NimBLETaskData taskData(const_cast<NimBLERemoteCharacteristic*>(this));
|
||||
desc_filter_t filter = {uuidFilter, &taskData};
|
||||
desc_filter_t filter = {uuidFilter, &taskData};
|
||||
const uint16_t handle = getHandle();
|
||||
const uint16_t svcHandle = getRemoteService()->getEndHandle();
|
||||
|
||||
|
@ -140,8 +140,8 @@ NimBLERemoteDescriptor* NimBLERemoteCharacteristic::getDescriptor(const NimBLEUU
|
|||
NIMBLE_LOGD(LOG_TAG, ">> getDescriptor: uuid: %s", uuid.toString().c_str());
|
||||
NimBLERemoteDescriptor* pDsc = nullptr;
|
||||
|
||||
NimBLEUtils::getAttr<NimBLERemoteDescriptor>(uuid, &pDsc, m_vDescriptors, [this](const NimBLEUUID* u, NimBLERemoteDescriptor** arg) {
|
||||
return retrieveDescriptors(u, arg);
|
||||
NimBLEUtils::getAttr<NimBLERemoteDescriptor>(uuid, &pDsc, m_vDescriptors, [this](const NimBLEUUID* u, NimBLERemoteDescriptor** dsc) {
|
||||
return retrieveDescriptors(u, dsc);
|
||||
});
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< getDescriptor: %sfound", !pDsc ? "not " : "");
|
||||
|
|
|
@ -78,8 +78,8 @@ NimBLERemoteCharacteristic* NimBLERemoteService::getCharacteristic(const NimBLEU
|
|||
NIMBLE_LOGD(LOG_TAG, ">> getCharacteristic: uuid: %s", uuid.toString().c_str());
|
||||
NimBLERemoteCharacteristic* pChar = nullptr;
|
||||
|
||||
NimBLEUtils::getAttr<NimBLERemoteCharacteristic>(uuid, &pChar, m_vChars, [this](const NimBLEUUID* u, NimBLERemoteCharacteristic** arg) {
|
||||
return retrieveCharacteristics(u, arg);
|
||||
NimBLEUtils::getAttr<NimBLERemoteCharacteristic>(uuid, &pChar, m_vChars, [this](const NimBLEUUID* u, NimBLERemoteCharacteristic** chr) {
|
||||
return retrieveCharacteristics(u, chr);
|
||||
});
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< getCharacteristic: %sfound", !pChar ? "not " : "");
|
||||
|
|
|
@ -578,6 +578,13 @@ NimBLEAddress NimBLEUtils::generateAddr(bool nrpa) {
|
|||
return NimBLEAddress{addr};
|
||||
} // generateAddr
|
||||
|
||||
/**
|
||||
* @brief Get an attribute matching a uuid.
|
||||
* @param [in] uuid Search for this uuid.
|
||||
* @param [in] attr Pointer to hold result.
|
||||
* @param [in] vec Vector to search through before trying to get attribute.
|
||||
* @param [in] getter Attribute getter function to call.
|
||||
*/
|
||||
template <typename T>
|
||||
void NimBLEUtils::getAttr(const NimBLEUUID& uuid, T** attr, const std::vector<T*>& vec, const std::function<bool(const NimBLEUUID*, T**)>& getter) {
|
||||
// Check if already exists.
|
||||
|
@ -587,12 +594,10 @@ void NimBLEUtils::getAttr(const NimBLEUUID& uuid, T** attr, const std::vector<T*
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Exit if request failed or uuid was found.
|
||||
if (!getter(&uuid, attr) || *attr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try again with 128 bit uuid if request succeeded with no uuid found.
|
||||
if (uuid.bitSize() == BLE_UUID_TYPE_16 || uuid.bitSize() == BLE_UUID_TYPE_32) {
|
||||
NimBLEUUID uuid128 = NimBLEUUID(uuid).to128();
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
# include "NimBLEUUID.h"
|
||||
# include "functional"
|
||||
# include <functional>
|
||||
# include <vector>
|
||||
# include <string>
|
||||
|
||||
|
@ -56,9 +56,9 @@ class NimBLEUtils {
|
|||
static NimBLEAddress generateAddr(bool nrpa);
|
||||
static bool taskWait(const NimBLETaskData& taskData, uint32_t timeout);
|
||||
static void taskRelease(const NimBLETaskData& taskData, int rc = 0);
|
||||
|
||||
template <typename T>
|
||||
static void getAttr(const NimBLEUUID& uuid, T** attr, const std::vector<T*>& vec, const std::function<bool(const NimBLEUUID*, T**)>& getter);
|
||||
static void getAttr(const NimBLEUUID& uuid, T** attr, const std::vector<T*>& vec,
|
||||
const std::function<bool(const NimBLEUUID*, T**)>& getter);
|
||||
};
|
||||
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
|
|
Loading…
Add table
Reference in a new issue