NimBLE-Arduino 2.1.2
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
30
34class NimBLERemoteCharacteristic : public NimBLERemoteValueAttribute {
35 public:
36 std::string toString() const;
38 void deleteDescriptors() const;
39 size_t deleteDescriptor(const NimBLEUUID& uuid) const;
40 bool canBroadcast() const;
41 bool canRead() const;
42 bool canWriteNoResponse() const;
43 bool canWrite() const;
44 bool canNotify() const;
45 bool canIndicate() const;
46 bool canWriteSigned() const;
47 bool hasExtendedProps() const;
48 NimBLEClient* getClient() const override;
49
50 typedef std::function<void(NimBLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify)> notify_callback;
51
52 bool subscribe(bool notifications = true, const notify_callback notifyCallback = nullptr, bool response = true) const;
53 bool unsubscribe(bool response = true) const;
54
55 std::vector<NimBLERemoteDescriptor*>::iterator begin() const;
56 std::vector<NimBLERemoteDescriptor*>::iterator end() const;
58 const std::vector<NimBLERemoteDescriptor*>& getDescriptors(bool refresh = false) const;
59
60 private:
61 friend class NimBLEClient;
62 friend class NimBLERemoteService;
63
64 NimBLERemoteCharacteristic(const NimBLERemoteService* pRemoteService, const ble_gatt_chr* chr);
66
67 bool setNotify(uint16_t val, notify_callback notifyCallback = nullptr, bool response = true) const;
68 bool retrieveDescriptors(const NimBLEUUID* uuidFilter = nullptr) const;
69
70 static int descriptorDiscCB(
71 uint16_t conn_handle, const ble_gatt_error* error, uint16_t chr_val_handle, const ble_gatt_dsc* dsc, void* arg);
72
73 const NimBLERemoteService* m_pRemoteService{nullptr};
74 uint8_t m_properties{0};
75 mutable notify_callback m_notifyCallback{nullptr};
76 mutable std::vector<NimBLERemoteDescriptor*> m_vDescriptors{};
77
78}; // NimBLERemoteCharacteristic
79
80#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
81#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:34
size_t deleteDescriptor(const NimBLEUUID &uuid) const
Delete descriptor by UUID.
Definition NimBLERemoteCharacteristic.cpp:293
bool canWriteNoResponse() const
Does the characteristic support writing without a response?
Definition NimBLERemoteCharacteristic.cpp:328
bool canBroadcast() const
Does the characteristic support value broadcasting?
Definition NimBLERemoteCharacteristic.cpp:312
std::vector< NimBLERemoteDescriptor * >::iterator begin() const
Get iterator to the beginning of the vector of remote descriptor pointers.
Definition NimBLERemoteCharacteristic.cpp:208
std::vector< NimBLERemoteDescriptor * >::iterator end() const
Get iterator to the end of the vector of remote descriptor pointers.
Definition NimBLERemoteCharacteristic.cpp:216
void deleteDescriptors() const
Delete the descriptors in the descriptor vector.
Definition NimBLERemoteCharacteristic.cpp:277
const NimBLERemoteService * getRemoteService() const
Get the remote service associated with this characteristic.
Definition NimBLERemoteCharacteristic.cpp:224
const std::vector< NimBLERemoteDescriptor * > & getDescriptors(bool refresh=false) const
Get a pointer to the vector of found descriptors.
Definition NimBLERemoteCharacteristic.cpp:195
bool canWrite() const
Does the characteristic support writing?
Definition NimBLERemoteCharacteristic.cpp:336
bool canRead() const
Does the characteristic support reading?
Definition NimBLERemoteCharacteristic.cpp:320
bool unsubscribe(bool response=true) const
Unsubscribe for notifications or indications.
Definition NimBLERemoteCharacteristic.cpp:267
bool canIndicate() const
Does the characteristic support indication?
Definition NimBLERemoteCharacteristic.cpp:352
NimBLERemoteDescriptor * getDescriptor(const NimBLEUUID &uuid) const
Get the descriptor instance with the given UUID that belongs to this characteristic.
Definition NimBLERemoteCharacteristic.cpp:138
std::string toString() const
Convert a NimBLERemoteCharacteristic to a string representation;.
Definition NimBLERemoteCharacteristic.cpp:376
bool subscribe(bool notifications=true, const notify_callback notifyCallback=nullptr, bool response=true) const
Subscribe for notifications or indications.
Definition NimBLERemoteCharacteristic.cpp:258
bool canNotify() const
Does the characteristic support reading with encryption?
Definition NimBLERemoteCharacteristic.cpp:344
bool canWriteSigned() const
Does the characteristic support signed writing?
Definition NimBLERemoteCharacteristic.cpp:360
bool hasExtendedProps() const
Does the characteristic support extended properties?
Definition NimBLERemoteCharacteristic.cpp:368
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