2020-03-30 01:44:20 +02:00
|
|
|
/*
|
|
|
|
* NimBLERemoteCharacteristic.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:
|
|
|
|
*
|
|
|
|
* BLERemoteCharacteristic.h
|
|
|
|
*
|
|
|
|
* Created on: Jul 8, 2017
|
|
|
|
* Author: kolban
|
|
|
|
*/
|
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
#ifndef NIMBLE_CPP_REMOTE_CHARACTERISTIC_H_
|
|
|
|
#define NIMBLE_CPP_REMOTE_CHARACTERISTIC_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_CENTRAL)
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
# include "NimBLERemoteValueAttribute.h"
|
|
|
|
# include <vector>
|
|
|
|
# include <functional>
|
2020-03-30 01:44:20 +02:00
|
|
|
|
|
|
|
class NimBLERemoteService;
|
|
|
|
class NimBLERemoteDescriptor;
|
|
|
|
|
|
|
|
/**
|
2024-07-26 22:47:36 +02:00
|
|
|
* @brief A model of a remote BLE characteristic.
|
2020-03-30 01:44:20 +02:00
|
|
|
*/
|
2024-07-26 22:47:36 +02:00
|
|
|
class NimBLERemoteCharacteristic : public NimBLERemoteValueAttribute {
|
|
|
|
public:
|
|
|
|
std::string toString() const;
|
|
|
|
const NimBLERemoteService* getRemoteService() const;
|
|
|
|
void deleteDescriptors() const;
|
|
|
|
size_t deleteDescriptor(const NimBLEUUID& uuid) const;
|
|
|
|
bool canBroadcast() const;
|
|
|
|
bool canRead() const;
|
|
|
|
bool canWriteNoResponse() const;
|
|
|
|
bool canWrite() const;
|
|
|
|
bool canNotify() const;
|
|
|
|
bool canIndicate() const;
|
|
|
|
bool canWriteSigned() const;
|
|
|
|
bool hasExtendedProps() const;
|
|
|
|
NimBLEClient* getClient() const override;
|
|
|
|
|
|
|
|
typedef std::function<void(NimBLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify)> notify_callback;
|
|
|
|
|
|
|
|
bool subscribe(bool notifications = true, const notify_callback notifyCallback = nullptr, bool response = true) const;
|
|
|
|
bool unsubscribe(bool response = true) const;
|
|
|
|
|
|
|
|
std::vector<NimBLERemoteDescriptor*>::iterator begin() const;
|
|
|
|
std::vector<NimBLERemoteDescriptor*>::iterator end() const;
|
|
|
|
NimBLERemoteDescriptor* getDescriptor(const NimBLEUUID& uuid) const;
|
|
|
|
const std::vector<NimBLERemoteDescriptor*>& getDescriptors(bool refresh = false) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class NimBLEClient;
|
|
|
|
friend class NimBLERemoteService;
|
|
|
|
|
|
|
|
NimBLERemoteCharacteristic(const NimBLERemoteService* pRemoteService, const ble_gatt_chr* chr);
|
2020-03-30 01:44:20 +02:00
|
|
|
~NimBLERemoteCharacteristic();
|
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
bool setNotify(uint16_t val, notify_callback notifyCallback = nullptr, bool response = true) const;
|
|
|
|
bool retrieveDescriptors(const NimBLEUUID* uuidFilter = nullptr) const;
|
2020-03-30 01:44:20 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
static int descriptorDiscCB(
|
|
|
|
uint16_t conn_handle, const ble_gatt_error* error, uint16_t chr_val_handle, const ble_gatt_dsc* dsc, void* arg);
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
const NimBLERemoteService* m_pRemoteService{nullptr};
|
|
|
|
uint8_t m_properties{0};
|
|
|
|
mutable notify_callback m_notifyCallback{nullptr};
|
|
|
|
mutable std::vector<NimBLERemoteDescriptor*> m_vDescriptors{};
|
2020-03-30 01:44:20 +02:00
|
|
|
|
2020-05-23 18:27:32 +02:00
|
|
|
}; // NimBLERemoteCharacteristic
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2021-09-07 05:14:43 +02:00
|
|
|
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
2024-07-26 22:47:36 +02:00
|
|
|
#endif /* NIMBLE_CPP_REMOTE_CHARACTERISTIC_H_ */
|