2020-03-30 01:44:20 +02:00
|
|
|
/*
|
|
|
|
* NimBLEDescriptor.h
|
|
|
|
*
|
|
|
|
* Created: on March 10, 2020
|
|
|
|
* Author H2zero
|
2020-05-14 06:03:56 +02:00
|
|
|
*
|
2020-03-30 01:44:20 +02:00
|
|
|
* Originally:
|
|
|
|
*
|
|
|
|
* BLEDescriptor.h
|
|
|
|
*
|
|
|
|
* Created on: Jun 22, 2017
|
|
|
|
* Author: kolban
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MAIN_NIMBLEDESCRIPTOR_H_
|
|
|
|
#define MAIN_NIMBLEDESCRIPTOR_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_PERIPHERAL)
|
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
#include "NimBLECharacteristic.h"
|
|
|
|
#include "NimBLEUUID.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2020-06-08 02:42:28 +02:00
|
|
|
uint16_t attr_max_len; /*!< attribute max value length */
|
|
|
|
uint16_t attr_len; /*!< attribute current value length */
|
|
|
|
uint8_t *attr_value; /*!< the pointer to attribute value */
|
2020-03-30 01:44:20 +02:00
|
|
|
} attr_value_t;
|
|
|
|
|
|
|
|
class NimBLEService;
|
|
|
|
class NimBLECharacteristic;
|
|
|
|
class NimBLEDescriptorCallbacks;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief A model of a %BLE descriptor.
|
|
|
|
*/
|
|
|
|
class NimBLEDescriptor {
|
|
|
|
public:
|
2020-06-08 02:42:28 +02:00
|
|
|
uint16_t getHandle();
|
|
|
|
size_t getLength();
|
|
|
|
NimBLEUUID getUUID();
|
|
|
|
uint8_t* getValue();
|
|
|
|
void setCallbacks(NimBLEDescriptorCallbacks* pCallbacks);
|
|
|
|
void setValue(const uint8_t* data, size_t size);
|
|
|
|
void setValue(const std::string &value);
|
|
|
|
std::string toString();
|
2020-03-30 01:44:20 +02:00
|
|
|
|
2020-07-09 03:27:26 +02:00
|
|
|
/**
|
|
|
|
* @brief Convenience template to set the descriptor value to <type\>val.
|
|
|
|
* @param [in] s The value to set.
|
|
|
|
*/
|
2020-07-02 01:32:41 +02:00
|
|
|
template<typename T>
|
|
|
|
void setValue(const T &s) {
|
|
|
|
setValue((uint8_t*)&s, sizeof(T));
|
|
|
|
}
|
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
private:
|
2020-05-14 06:03:56 +02:00
|
|
|
friend class NimBLECharacteristic;
|
2020-03-30 01:44:20 +02:00
|
|
|
friend class NimBLEService;
|
2020-05-14 06:03:56 +02:00
|
|
|
friend class NimBLE2902;
|
|
|
|
friend class NimBLE2904;
|
|
|
|
|
|
|
|
NimBLEDescriptor(const char* uuid, uint16_t properties,
|
2020-06-08 02:42:28 +02:00
|
|
|
uint16_t max_len,
|
|
|
|
NimBLECharacteristic* pCharacteristic);
|
2020-05-14 06:03:56 +02:00
|
|
|
|
|
|
|
NimBLEDescriptor(NimBLEUUID uuid, uint16_t properties,
|
2020-06-08 02:42:28 +02:00
|
|
|
uint16_t max_len,
|
|
|
|
NimBLECharacteristic* pCharacteristic);
|
|
|
|
|
|
|
|
~NimBLEDescriptor();
|
|
|
|
|
|
|
|
static int handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
|
|
|
|
struct ble_gatt_access_ctxt *ctxt, void *arg);
|
|
|
|
void setHandle(uint16_t handle);
|
2020-05-14 06:03:56 +02:00
|
|
|
|
|
|
|
NimBLEUUID m_uuid;
|
|
|
|
uint16_t m_handle;
|
|
|
|
NimBLEDescriptorCallbacks* m_pCallbacks;
|
|
|
|
NimBLECharacteristic* m_pCharacteristic;
|
|
|
|
uint8_t m_properties;
|
|
|
|
attr_value_t m_value;
|
2020-06-08 02:42:28 +02:00
|
|
|
portMUX_TYPE m_valMux;
|
|
|
|
}; // NimBLEDescriptor
|
2020-03-30 01:44:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Callbacks that can be associated with a %BLE descriptors to inform of events.
|
|
|
|
*
|
|
|
|
* When a server application creates a %BLE descriptor, we may wish to be informed when there is either
|
|
|
|
* a read or write request to the descriptors value. An application can register a
|
|
|
|
* sub-classed instance of this class and will be notified when such an event happens.
|
|
|
|
*/
|
|
|
|
class NimBLEDescriptorCallbacks {
|
|
|
|
public:
|
2020-05-14 06:03:56 +02:00
|
|
|
virtual ~NimBLEDescriptorCallbacks();
|
|
|
|
virtual void onRead(NimBLEDescriptor* pDescriptor);
|
|
|
|
virtual void onWrite(NimBLEDescriptor* pDescriptor);
|
2020-03-30 01:44:20 +02:00
|
|
|
};
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2020-07-09 03:47:32 +02:00
|
|
|
#include "NimBLE2904.h"
|
|
|
|
|
2020-05-14 06:03:56 +02:00
|
|
|
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
2020-03-30 01:44:20 +02:00
|
|
|
#endif /* CONFIG_BT_ENABLED */
|
2020-05-10 15:21:46 +02:00
|
|
|
#endif /* MAIN_NIMBLEDESCRIPTOR_H_ */
|