mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-10-22 16:09:44 +02:00
f5541d18de
* Replace all semaphores with task notifications. * use critical sections to prevent concurrent data access. * Ensure scan stop has been called before connecting. * Optimize and cleanup * Add template casting to NimBLERemoteDescriptor::readValue() * Removed storage of the descriptor value read as it did not serve any purpose.
69 lines
2.4 KiB
C++
69 lines
2.4 KiB
C++
/*
|
|
* NimBLERemoteDescriptor.h
|
|
*
|
|
* Created: on Jan 27 2020
|
|
* Author H2zero
|
|
*
|
|
* Originally:
|
|
*
|
|
* BLERemoteDescriptor.h
|
|
*
|
|
* Created on: Jul 8, 2017
|
|
* Author: kolban
|
|
*/
|
|
|
|
#ifndef COMPONENTS_NIMBLEREMOTEDESCRIPTOR_H_
|
|
#define COMPONENTS_NIMBLEREMOTEDESCRIPTOR_H_
|
|
#include "sdkconfig.h"
|
|
#if defined(CONFIG_BT_ENABLED)
|
|
|
|
#include "nimconfig.h"
|
|
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
|
|
|
#include "NimBLERemoteCharacteristic.h"
|
|
|
|
class NimBLERemoteCharacteristic;
|
|
/**
|
|
* @brief A model of remote %BLE descriptor.
|
|
*/
|
|
class NimBLERemoteDescriptor {
|
|
public:
|
|
uint16_t getHandle();
|
|
NimBLERemoteCharacteristic* getRemoteCharacteristic();
|
|
NimBLEUUID getUUID();
|
|
std::string readValue();
|
|
|
|
template<typename T>
|
|
T readValue(bool skipSizeCheck = false) {
|
|
std::string value = readValue();
|
|
if(!skipSizeCheck && value.size() < sizeof(T)) return T();
|
|
const char *pData = value.data();
|
|
return *((T *)pData);
|
|
}
|
|
|
|
uint8_t readUInt8() __attribute__ ((deprecated));
|
|
uint16_t readUInt16() __attribute__ ((deprecated));
|
|
uint32_t readUInt32() __attribute__ ((deprecated));
|
|
std::string toString(void);
|
|
bool writeValue(const uint8_t* data, size_t length, bool response = false);
|
|
bool writeValue(const std::string &newValue, bool response = false);
|
|
bool writeValue(uint8_t newValue, bool response = false);
|
|
|
|
private:
|
|
friend class NimBLERemoteCharacteristic;
|
|
|
|
NimBLERemoteDescriptor (NimBLERemoteCharacteristic* pRemoteCharacteristic,
|
|
const struct ble_gatt_dsc *dsc);
|
|
static int onWriteCB(uint16_t conn_handle, const struct ble_gatt_error *error,
|
|
struct ble_gatt_attr *attr, void *arg);
|
|
static int onReadCB(uint16_t conn_handle, const struct ble_gatt_error *error,
|
|
struct ble_gatt_attr *attr, void *arg);
|
|
|
|
uint16_t m_handle;
|
|
NimBLEUUID m_uuid;
|
|
NimBLERemoteCharacteristic* m_pRemoteCharacteristic;
|
|
};
|
|
|
|
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
|
#endif /* CONFIG_BT_ENABLED */
|
|
#endif /* COMPONENTS_NIMBLEREMOTEDESCRIPTOR_H_ */
|