NimBLE-Arduino 2.3.0
Loading...
Searching...
No Matches
NimBLELocalValueAttribute.h
1/*
2 * Copyright 2020-2025 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_LOCAL_VALUE_ATTRIBUTE_H_
19#define NIMBLE_LOCAL_VALUE_ATTRIBUTE_H_
20
21#include "nimconfig.h"
22#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
23
24# if defined(CONFIG_NIMBLE_CPP_IDF)
25# include "host/ble_hs.h"
26# else
27# include "nimble/nimble/host/include/host/ble_hs.h"
28# endif
29
30/**** FIX COMPILATION ****/
31# undef min
32# undef max
33/**************************/
34
35typedef enum {
36 READ = BLE_GATT_CHR_F_READ,
37 READ_ENC = BLE_GATT_CHR_F_READ_ENC,
38 READ_AUTHEN = BLE_GATT_CHR_F_READ_AUTHEN,
39 READ_AUTHOR = BLE_GATT_CHR_F_READ_AUTHOR,
40 WRITE = BLE_GATT_CHR_F_WRITE,
41 WRITE_NR = BLE_GATT_CHR_F_WRITE_NO_RSP,
42 WRITE_ENC = BLE_GATT_CHR_F_WRITE_ENC,
43 WRITE_AUTHEN = BLE_GATT_CHR_F_WRITE_AUTHEN,
44 WRITE_AUTHOR = BLE_GATT_CHR_F_WRITE_AUTHOR,
45 BROADCAST = BLE_GATT_CHR_F_BROADCAST,
46 NOTIFY = BLE_GATT_CHR_F_NOTIFY,
47 INDICATE = BLE_GATT_CHR_F_INDICATE
48} NIMBLE_PROPERTY;
49
50# include "NimBLELocalAttribute.h"
51# include "NimBLEValueAttribute.h"
52# include "NimBLEAttValue.h"
53# include <vector>
54class NimBLEConnInfo;
55
56class NimBLELocalValueAttribute : public NimBLELocalAttribute, public NimBLEValueAttribute {
57 public:
61 uint16_t getProperties() const { return m_properties; }
62
68 void setValue(const uint8_t* data, size_t size) { m_value.setValue(data, size); }
69
74 void setValue(const char* str) { m_value.setValue(str); }
75
80 void setValue(const std::vector<uint8_t>& vec) { m_value.setValue(vec); }
81
86 template <typename T>
87 void setValue(const T& val) {
88 m_value.setValue<T>(val);
89 }
90
91 protected:
92 friend class NimBLEServer;
93
101 NimBLELocalValueAttribute(const NimBLEUUID& uuid,
102 uint16_t handle,
103 uint16_t maxLen,
104 uint16_t initLen = CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH)
105 : NimBLELocalAttribute(uuid, handle), NimBLEValueAttribute(maxLen, initLen) {}
109 virtual ~NimBLELocalValueAttribute() = default;
110
116 virtual void readEvent(NimBLEConnInfo& connInfo) = 0;
117
125 virtual void writeEvent(const uint8_t* val, uint16_t len, NimBLEConnInfo& connInfo) = 0;
126
132 const NimBLEAttValue& getAttVal() const { return m_value; }
133
138 void setProperties(uint16_t properties) { m_properties = properties; }
139
140 uint16_t m_properties{0};
141};
142
143#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
144#endif // NIMBLE_LOCAL_VALUE_ATTRIBUTE_H_
A specialized container class to hold BLE attribute values.
Definition NimBLEAttValue.h:71
Connection information.
Definition NimBLEConnInfo.h:32
A base class for local BLE attributes.
Definition NimBLELocalAttribute.h:29
The model of a BLE server.
Definition NimBLEServer.h:60
A model of a BLE UUID.
Definition NimBLEUUID.h:41