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
|
|
|
|
*/
|
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
#ifndef NIMBLE_CPP_DESCRIPTOR_H_
|
|
|
|
#define NIMBLE_CPP_DESCRIPTOR_H_
|
2020-03-30 01:44:20 +02:00
|
|
|
|
2020-05-14 06:03:56 +02:00
|
|
|
#include "nimconfig.h"
|
2021-09-07 05:14:43 +02:00
|
|
|
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
class NimBLEDescriptor;
|
2020-03-30 01:44:20 +02:00
|
|
|
class NimBLEDescriptorCallbacks;
|
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
# include "NimBLELocalValueAttribute.h"
|
|
|
|
# include "NimBLECharacteristic.h"
|
|
|
|
# include "NimBLEUUID.h"
|
|
|
|
# include "NimBLEAttValue.h"
|
|
|
|
# include "NimBLEConnInfo.h"
|
|
|
|
|
|
|
|
# include <string>
|
2020-03-30 01:44:20 +02:00
|
|
|
|
|
|
|
/**
|
2024-07-26 22:47:36 +02:00
|
|
|
* @brief A model of a BLE descriptor.
|
2020-03-30 01:44:20 +02:00
|
|
|
*/
|
2024-07-26 22:47:36 +02:00
|
|
|
class NimBLEDescriptor : public NimBLELocalValueAttribute {
|
|
|
|
public:
|
|
|
|
NimBLEDescriptor(const char* uuid, uint16_t properties, uint16_t max_len, NimBLECharacteristic* pCharacteristic = nullptr);
|
2021-05-23 21:07:00 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
NimBLEDescriptor(const NimBLEUUID& uuid,
|
|
|
|
uint16_t properties,
|
|
|
|
uint16_t max_len,
|
2021-05-23 21:07:00 +02:00
|
|
|
NimBLECharacteristic* pCharacteristic = nullptr);
|
2024-07-26 22:47:36 +02:00
|
|
|
~NimBLEDescriptor() = default;
|
2021-05-23 21:07:00 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
std::string toString() const;
|
2021-05-23 21:07:00 +02:00
|
|
|
void setCallbacks(NimBLEDescriptorCallbacks* pCallbacks);
|
2024-07-26 22:47:36 +02:00
|
|
|
NimBLECharacteristic* getCharacteristic() const;
|
2021-02-08 16:28:32 +01:00
|
|
|
|
2024-07-26 22:47:36 +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
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
void setCharacteristic(NimBLECharacteristic* pChar);
|
|
|
|
void readEvent(NimBLEConnInfo& connInfo) override;
|
|
|
|
void writeEvent(const uint8_t* val, uint16_t len, NimBLEConnInfo& connInfo) override;
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
NimBLEDescriptorCallbacks* m_pCallbacks{nullptr};
|
|
|
|
NimBLECharacteristic* m_pCharacteristic{nullptr};
|
2020-06-08 02:42:28 +02:00
|
|
|
}; // 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 {
|
2024-07-26 22:47:36 +02:00
|
|
|
public:
|
|
|
|
virtual ~NimBLEDescriptorCallbacks() = default;
|
2022-08-27 16:28:15 +02:00
|
|
|
virtual void onRead(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo);
|
|
|
|
virtual void onWrite(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo);
|
2020-03-30 01:44:20 +02:00
|
|
|
};
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
# include "NimBLE2904.h"
|
2020-07-09 03:47:32 +02:00
|
|
|
|
2021-09-07 05:14:43 +02:00
|
|
|
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
2024-07-26 22:47:36 +02:00
|
|
|
#endif /* NIMBLE_CPP_DESCRIPTOR_H_ */
|