NimBLE-Arduino 2.2.1
Loading...
Searching...
No Matches
NimBLERemoteCharacteristic.h
1/*
2 * Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLE_CPP_REMOTE_CHARACTERISTIC_H_
19#define NIMBLE_CPP_REMOTE_CHARACTERISTIC_H_
20
21#include "nimconfig.h"
22#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
23
24# include "NimBLERemoteValueAttribute.h"
25# include <vector>
26# include <functional>
27
28class NimBLEUUID;
31struct NimBLEDescriptorFilter;
32
36class NimBLERemoteCharacteristic : public NimBLERemoteValueAttribute {
37 public:
38 std::string toString() const;
40 void deleteDescriptors() const;
41 size_t deleteDescriptor(const NimBLEUUID& uuid) const;
42 bool canBroadcast() const;
43 bool canRead() const;
44 bool canWriteNoResponse() const;
45 bool canWrite() const;
46 bool canNotify() const;
47 bool canIndicate() const;
48 bool canWriteSigned() const;
49 bool hasExtendedProps() const;
50 NimBLEClient* getClient() const override;
51
52 typedef std::function<void(NimBLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify)> notify_callback;
53
54 bool subscribe(bool notifications = true, const notify_callback notifyCallback = nullptr, bool response = true) const;
55 bool unsubscribe(bool response = true) const;
56
57 std::vector<NimBLERemoteDescriptor*>::iterator begin() const;
58 std::vector<NimBLERemoteDescriptor*>::iterator end() const;
60 const std::vector<NimBLERemoteDescriptor*>& getDescriptors(bool refresh = false) const;
61
62 private:
63 friend class NimBLEClient;
64 friend class NimBLERemoteService;
65
66 NimBLERemoteCharacteristic(const NimBLERemoteService* pRemoteService, const ble_gatt_chr* chr);
68
69 bool setNotify(uint16_t val, notify_callback notifyCallback = nullptr, bool response = true) const;
70 bool retrieveDescriptors(NimBLEDescriptorFilter* filter = nullptr) const;
71
72 static int descriptorDiscCB(
73 uint16_t connHandle, const ble_gatt_error* error, uint16_t chrHandle, const ble_gatt_dsc* dsc, void* arg);
74
75 const NimBLERemoteService* m_pRemoteService{nullptr};
76 uint8_t m_properties{0};
77 mutable notify_callback m_notifyCallback{nullptr};
78 mutable std::vector<NimBLERemoteDescriptor*> m_vDescriptors{};
79
80}; // NimBLERemoteCharacteristic
81
82#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
83#endif /* NIMBLE_CPP_REMOTE_CHARACTERISTIC_H_ */
A model of a BLE client.
Definition NimBLEClient.h:49
A model of a remote BLE characteristic.
Definition NimBLERemoteCharacteristic.h:36
size_t deleteDescriptor(const NimBLEUUID &uuid) const
Delete descriptor by UUID.
Definition NimBLERemoteCharacteristic.cpp:275
bool canWriteNoResponse() const
Does the characteristic support writing without a response?
Definition NimBLERemoteCharacteristic.cpp:310
bool canBroadcast() const
Does the characteristic support value broadcasting?
Definition NimBLERemoteCharacteristic.cpp:294
std::vector< NimBLERemoteDescriptor * >::iterator begin() const
Get iterator to the beginning of the vector of remote descriptor pointers.
Definition NimBLERemoteCharacteristic.cpp:190
std::vector< NimBLERemoteDescriptor * >::iterator end() const
Get iterator to the end of the vector of remote descriptor pointers.
Definition NimBLERemoteCharacteristic.cpp:198
void deleteDescriptors() const
Delete the descriptors in the descriptor vector.
Definition NimBLERemoteCharacteristic.cpp:259
const NimBLERemoteService * getRemoteService() const
Get the remote service associated with this characteristic.
Definition NimBLERemoteCharacteristic.cpp:206
const std::vector< NimBLERemoteDescriptor * > & getDescriptors(bool refresh=false) const
Get a pointer to the vector of found descriptors.
Definition NimBLERemoteCharacteristic.cpp:177
bool canWrite() const
Does the characteristic support writing?
Definition NimBLERemoteCharacteristic.cpp:318
bool canRead() const
Does the characteristic support reading?
Definition NimBLERemoteCharacteristic.cpp:302
bool unsubscribe(bool response=true) const
Unsubscribe for notifications or indications.
Definition NimBLERemoteCharacteristic.cpp:249
bool canIndicate() const
Does the characteristic support indication?
Definition NimBLERemoteCharacteristic.cpp:334
NimBLERemoteDescriptor * getDescriptor(const NimBLEUUID &uuid) const
Get the descriptor instance with the given UUID that belongs to this characteristic.
Definition NimBLERemoteCharacteristic.cpp:135
std::string toString() const
Convert a NimBLERemoteCharacteristic to a string representation;.
Definition NimBLERemoteCharacteristic.cpp:358
bool subscribe(bool notifications=true, const notify_callback notifyCallback=nullptr, bool response=true) const
Subscribe for notifications or indications.
Definition NimBLERemoteCharacteristic.cpp:240
bool canNotify() const
Does the characteristic support reading with encryption?
Definition NimBLERemoteCharacteristic.cpp:326
bool canWriteSigned() const
Does the characteristic support signed writing?
Definition NimBLERemoteCharacteristic.cpp:342
bool hasExtendedProps() const
Does the characteristic support extended properties?
Definition NimBLERemoteCharacteristic.cpp:350
A model of remote BLE descriptor.
Definition NimBLERemoteDescriptor.h:32
A model of a remote BLE service.
Definition NimBLERemoteService.h:34
A model of a BLE UUID.
Definition NimBLEUUID.h:41