14
14
* limitations under the License.
15
15
*/
16
16
17
- #ifndef __GATT_ATTRIBUTE_H__
18
- #define __GATT_ATTRIBUTE_H__
17
+ #ifndef MBED_GATT_ATTRIBUTE_H__
18
+ #define MBED_GATT_ATTRIBUTE_H__
19
19
20
20
#include " UUID.h"
21
21
#include " BLETypes.h"
30
30
*/
31
31
32
32
/* *
33
- * Instances of this class encapsulate the data that belongs to a Bluetooth Low
34
- * Energy attribute.
33
+ * Representation of a GattServer attribute.
34
+ *
35
+ * Attributes are the building block of GATT servers: services are attributes,
36
+ * characteristics are groups of attributes and characteristic descriptors are
37
+ * attributes, too.
38
+ *
39
+ * @par Typed values
40
+ *
41
+ * Attributes are typed values composed of a type and its associated value. The
42
+ * attribute type identifies the attribute purpose. A UUID read by the client
43
+ * during the discovery of the GATT server models the attribute type. The value of the
44
+ * attribute is an array of bytes; its length may be fixed or variable.
45
+ *
46
+ * As an example, a primary service is declared by an attribute with the type
47
+ * 0x2800, and the value of the attribute is the UUID of the service.
48
+ *
49
+ * @par Attribute Access
50
+ *
51
+ * The GATT server is an array of attributes in which a unique index identifies
52
+ * each of the attributes within the array. That index is called the attribute
53
+ * handle, and clients use it to access to attributes within the server.
54
+ *
55
+ * @note Attributes do not contain information related to their permissions,
56
+ * grouping or semantic. Higher level specifications define these concepts.
35
57
*/
36
58
class GattAttribute {
37
59
public:
38
60
/* *
39
- * Type for the handle or ID of the attribute in the ATT table. These are
40
- * unique, and the underlying BLE stack usually generates them.
61
+ * Representation of an attribute handle.
62
+ *
63
+ * Each attribute in a GattServer has a unique handle that clients can use
64
+ * to identify the attribute. The underlying BLE stack usually
65
+ * generates and assigns handles to attributes.
41
66
*/
42
67
typedef ble::attribute_handle_t Handle_t;
68
+
43
69
/* *
44
- * Define the value of an invalid attribute handle.
70
+ * Invalid attribute handle.
45
71
*/
46
72
static const Handle_t INVALID_HANDLE = 0x0000 ;
47
73
48
74
public:
49
75
/* *
50
- * @brief Creates a new GattAttribute using the specified
51
- * UUID, value length, and inital value.
52
- *
53
- * @param[in] uuid
54
- * The UUID to use for this attribute.
55
- * @param[in] valuePtr
56
- * The memory holding the initial value.
57
- * @param[in] len
58
- * The length in bytes of this attribute's value.
59
- * @param[in] maxLen
60
- * The max length in bytes of this attribute's value.
61
- * @param[in] hasVariableLen
62
- * Whether the attribute's value length changes over time.
76
+ * Construct an attribute.
63
77
*
64
- * @section EXAMPLE
78
+ * Application code uses attributes to model characteristic descriptors and
79
+ * characteristics values.
65
80
*
66
- * @code
81
+ * @param[in] uuid The type of the attribute.
82
+ * @param[in] valuePtr Pointer to the memory buffer, which contains the
83
+ * initial value of the attribute. The constructor does not make a copy of
84
+ * the attribute buffer; as a consequence, the memory buffer must remain
85
+ * valid during the lifetime of the attribute.
86
+ * @param[in] len The length in bytes of this attribute's value.
87
+ * @param[in] maxLen The length in bytes of the memory buffer containing the
88
+ * attribute value. It must be greater than or equal to @p len.
89
+ * @param[in] hasVariableLen Flag that indicates whether the attribute's value
90
+ * length can change throughout time.
67
91
*
68
- * // UUID = 0x2A19, Min length 2, Max len = 2
69
- * GattAttribute attr = GattAttribute(0x2A19, &someValue, 2, 2);
92
+ * @par Example
70
93
*
71
- * @endcode
72
- */
73
- GattAttribute (const UUID &uuid, uint8_t *valuePtr = NULL , uint16_t len = 0 , uint16_t maxLen = 0 , bool hasVariableLen = true ) :
74
- _uuid (uuid), _valuePtr(valuePtr), _lenMax(maxLen), _len(len), _hasVariableLen(hasVariableLen), _handle() {
75
- /* Empty */
94
+ * @code
95
+ * // declare a value of 2 bytes within a 10 bytes buffer
96
+ * const uint8_t attribute_value[10] = { 10, 50 };
97
+ * GattAttribute attr = GattAttribute(
98
+ * 0x2A19, // attribute type
99
+ * attribute_value,
100
+ * 2, // length of the current value
101
+ * sizeof(attribute_value), // length of the buffer containing the value
102
+ * true // variable length
103
+ * );
104
+ * @endcode
105
+ */
106
+ GattAttribute (
107
+ const UUID &uuid,
108
+ uint8_t *valuePtr = NULL ,
109
+ uint16_t len = 0 ,
110
+ uint16_t maxLen = 0 ,
111
+ bool hasVariableLen = true
112
+ ) : _uuid(uuid),
113
+ _valuePtr (valuePtr),
114
+ _lenMax(maxLen),
115
+ _len(len),
116
+ _hasVariableLen(hasVariableLen),
117
+ _handle() {
76
118
}
77
119
78
120
public:
79
121
/* *
80
122
* Get the attribute's handle in the ATT table.
81
123
*
124
+ * @note The GattServer sets the attribute's handle when services are
125
+ * inserted.
126
+ *
82
127
* @return The attribute's handle.
83
128
*/
84
- Handle_t getHandle (void ) const {
129
+ Handle_t getHandle (void ) const
130
+ {
85
131
return _handle;
86
132
}
87
133
88
134
/* *
89
- * The UUID of the characteristic that this attribute belongs to.
135
+ * Get the UUID of the attribute.
136
+ *
137
+ * The UUID identifies the type of the attribute.
90
138
*
91
- * @return The characteristic's UUID .
139
+ * @return The attribute .
92
140
*/
93
- const UUID &getUUID (void ) const {
141
+ const UUID &getUUID (void ) const
142
+ {
94
143
return _uuid;
95
144
}
96
145
@@ -99,7 +148,8 @@ class GattAttribute {
99
148
*
100
149
* @return The current length of the attribute value.
101
150
*/
102
- uint16_t getLength (void ) const {
151
+ uint16_t getLength (void ) const
152
+ {
103
153
return _len;
104
154
}
105
155
@@ -108,26 +158,33 @@ class GattAttribute {
108
158
*
109
159
* The maximum length of the attribute value.
110
160
*/
111
- uint16_t getMaxLength (void ) const {
161
+ uint16_t getMaxLength (void ) const
162
+ {
112
163
return _lenMax;
113
164
}
114
165
115
166
/* *
116
167
* Get a pointer to the current length of the attribute value.
117
168
*
169
+ * @important note Do not use this function.
170
+ *
118
171
* @return A pointer to the current length of the attribute value.
119
172
*/
120
- uint16_t *getLengthPtr (void ) {
173
+ uint16_t *getLengthPtr (void )
174
+ {
121
175
return &_len;
122
176
}
123
177
124
178
/* *
125
179
* Set the attribute handle.
126
180
*
127
- * @param[in] id
128
- * The new attribute handle.
181
+ * @important The GattServer uses this function internally.
182
+ * Application code must not use it.
183
+ *
184
+ * @param[in] id The new attribute handle.
129
185
*/
130
- void setHandle (Handle_t id) {
186
+ void setHandle (Handle_t id)
187
+ {
131
188
_handle = id;
132
189
}
133
190
@@ -136,44 +193,52 @@ class GattAttribute {
136
193
*
137
194
* @return A pointer to the attribute value.
138
195
*/
139
- uint8_t *getValuePtr (void ) {
196
+ uint8_t *getValuePtr (void )
197
+ {
140
198
return _valuePtr;
141
199
}
142
200
143
201
/* *
144
- * Check whether the length of the attribute's value can change over time.
202
+ * Check whether the length of the attribute's value can change throughout time.
145
203
*
146
- * @return true if the attribute has variable length, false otherwise.
204
+ * @return true if the attribute value has a variable length and false
205
+ * otherwise.
147
206
*/
148
- bool hasVariableLength (void ) const {
207
+ bool hasVariableLength (void ) const
208
+ {
149
209
return _hasVariableLen;
150
210
}
151
211
152
212
private:
153
213
/* *
154
214
* Characteristic's UUID.
155
215
*/
156
- UUID _uuid;
216
+ UUID _uuid;
217
+
157
218
/* *
158
219
* Pointer to the attribute's value.
159
220
*/
160
- uint8_t *_valuePtr;
221
+ uint8_t *_valuePtr;
222
+
161
223
/* *
162
- * Maximum length of the value pointed to by GattAttribute::_valuePtr .
224
+ * Length in byte of the buffer containing the attribute value .
163
225
*/
164
- uint16_t _lenMax;
226
+ uint16_t _lenMax;
227
+
165
228
/* *
166
229
* Current length of the value pointed to by GattAttribute::_valuePtr.
167
230
*/
168
- uint16_t _len;
231
+ uint16_t _len;
232
+
169
233
/* *
170
- * Whether the length of the value can change over time.
234
+ * Whether the length of the value can change throughout time.
171
235
*/
172
- bool _hasVariableLen;
236
+ bool _hasVariableLen;
237
+
173
238
/* *
174
239
* The attribute's handle in the ATT table.
175
240
*/
176
- Handle_t _handle;
241
+ Handle_t _handle;
177
242
178
243
private:
179
244
/* Disallow copy and assignment. */
@@ -187,4 +252,4 @@ class GattAttribute {
187
252
* @}
188
253
*/
189
254
190
- #endif /* ifndef __GATT_ATTRIBUTE_H__ */
255
+ #endif /* ifndef MBED_GATT_ATTRIBUTE_H__ */
0 commit comments