2020-03-30 01:44:20 +02:00
|
|
|
/*
|
|
|
|
* NimBLERemoteDescriptor.h
|
|
|
|
*
|
|
|
|
* Created: on Jan 27 2020
|
|
|
|
* Author H2zero
|
2020-05-14 06:03:56 +02:00
|
|
|
*
|
2020-03-30 01:44:20 +02:00
|
|
|
* 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)
|
|
|
|
|
2020-05-14 06:03:56 +02:00
|
|
|
#include "nimconfig.h"
|
|
|
|
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
#include "NimBLERemoteCharacteristic.h"
|
|
|
|
|
|
|
|
class NimBLERemoteCharacteristic;
|
|
|
|
/**
|
|
|
|
* @brief A model of remote %BLE descriptor.
|
|
|
|
*/
|
|
|
|
class NimBLERemoteDescriptor {
|
|
|
|
public:
|
2020-05-23 18:27:32 +02:00
|
|
|
uint16_t getHandle();
|
2020-03-30 01:44:20 +02:00
|
|
|
NimBLERemoteCharacteristic* getRemoteCharacteristic();
|
2020-05-23 18:27:32 +02:00
|
|
|
NimBLEUUID getUUID();
|
2020-06-22 06:07:01 +02:00
|
|
|
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));
|
2020-05-23 18:27:32 +02:00
|
|
|
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);
|
2020-03-30 01:44:20 +02:00
|
|
|
|
|
|
|
private:
|
2020-05-23 18:27:32 +02:00
|
|
|
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;
|
2020-03-30 01:44:20 +02:00
|
|
|
};
|
2020-05-14 06:03:56 +02:00
|
|
|
|
|
|
|
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
2020-03-30 01:44:20 +02:00
|
|
|
#endif /* CONFIG_BT_ENABLED */
|
|
|
|
#endif /* COMPONENTS_NIMBLEREMOTEDESCRIPTOR_H_ */
|