mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-18 17:20:47 +01:00
6be6a111d0
This allows for adding and removing of characteristics and descriptors after initial setup of the server. When used it will send a service changed notification to all clients. The changes will not take effect until all clients have disconnected and advertising restarted.
118 lines
3.3 KiB
C++
118 lines
3.3 KiB
C++
/*
|
|
* NimBLEDescriptor.h
|
|
*
|
|
* Created: on March 10, 2020
|
|
* Author H2zero
|
|
*
|
|
* 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)
|
|
|
|
#include "nimconfig.h"
|
|
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
|
|
|
#include "NimBLECharacteristic.h"
|
|
#include "NimBLEUUID.h"
|
|
|
|
#include <string>
|
|
|
|
|
|
typedef struct
|
|
{
|
|
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 */
|
|
} attr_value_t;
|
|
|
|
class NimBLEService;
|
|
class NimBLECharacteristic;
|
|
class NimBLEDescriptorCallbacks;
|
|
|
|
|
|
/**
|
|
* @brief A model of a %BLE descriptor.
|
|
*/
|
|
class NimBLEDescriptor {
|
|
public:
|
|
NimBLEDescriptor(const char* uuid, uint16_t properties,
|
|
uint16_t max_len,
|
|
NimBLECharacteristic* pCharacteristic = nullptr);
|
|
|
|
NimBLEDescriptor(NimBLEUUID uuid, uint16_t properties,
|
|
uint16_t max_len,
|
|
NimBLECharacteristic* pCharacteristic = nullptr);
|
|
|
|
~NimBLEDescriptor();
|
|
|
|
uint16_t getHandle();
|
|
NimBLEUUID getUUID();
|
|
std::string toString();
|
|
|
|
void setCallbacks(NimBLEDescriptorCallbacks* pCallbacks);
|
|
|
|
size_t getLength();
|
|
uint8_t* getValue();
|
|
std::string getStringValue();
|
|
|
|
void setValue(const uint8_t* data, size_t size);
|
|
void setValue(const std::string &value);
|
|
NimBLECharacteristic* getCharacteristic();
|
|
|
|
/**
|
|
* @brief Convenience template to set the descriptor value to <type\>val.
|
|
* @param [in] s The value to set.
|
|
*/
|
|
template<typename T>
|
|
void setValue(const T &s) {
|
|
setValue((uint8_t*)&s, sizeof(T));
|
|
}
|
|
|
|
private:
|
|
friend class NimBLECharacteristic;
|
|
friend class NimBLEService;
|
|
friend class NimBLE2904;
|
|
|
|
static int handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
|
|
struct ble_gatt_access_ctxt *ctxt, void *arg);
|
|
void setHandle(uint16_t handle);
|
|
void setCharacteristic(NimBLECharacteristic* pChar);
|
|
|
|
NimBLEUUID m_uuid;
|
|
uint16_t m_handle;
|
|
NimBLEDescriptorCallbacks* m_pCallbacks;
|
|
NimBLECharacteristic* m_pCharacteristic;
|
|
uint8_t m_properties;
|
|
attr_value_t m_value;
|
|
portMUX_TYPE m_valMux;
|
|
uint8_t m_removed;
|
|
}; // NimBLEDescriptor
|
|
|
|
|
|
/**
|
|
* @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:
|
|
virtual ~NimBLEDescriptorCallbacks();
|
|
virtual void onRead(NimBLEDescriptor* pDescriptor);
|
|
virtual void onWrite(NimBLEDescriptor* pDescriptor);
|
|
};
|
|
|
|
#include "NimBLE2904.h"
|
|
|
|
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
|
#endif /* CONFIG_BT_ENABLED */
|
|
#endif /* MAIN_NIMBLEDESCRIPTOR_H_ */
|