Skip to content

Commit 1ea4e4c

Browse files
Merge pull request #5549 from pan-/ble-gatt-server-doc-update
Ble gatt server doc update
2 parents b7a7d4e + 8e7d74c commit 1ea4e4c

File tree

4 files changed

+2304
-925
lines changed

4 files changed

+2304
-925
lines changed

features/FEATURE_BLE/ble/GattAttribute.h

Lines changed: 117 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef __GATT_ATTRIBUTE_H__
18-
#define __GATT_ATTRIBUTE_H__
17+
#ifndef MBED_GATT_ATTRIBUTE_H__
18+
#define MBED_GATT_ATTRIBUTE_H__
1919

2020
#include "UUID.h"
2121
#include "BLETypes.h"
@@ -30,67 +30,116 @@
3030
*/
3131

3232
/**
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.
3557
*/
3658
class GattAttribute {
3759
public:
3860
/**
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.
4166
*/
4267
typedef ble::attribute_handle_t Handle_t;
68+
4369
/**
44-
* Define the value of an invalid attribute handle.
70+
* Invalid attribute handle.
4571
*/
4672
static const Handle_t INVALID_HANDLE = 0x0000;
4773

4874
public:
4975
/**
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.
6377
*
64-
* @section EXAMPLE
78+
* Application code uses attributes to model characteristic descriptors and
79+
* characteristics values.
6580
*
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.
6791
*
68-
* // UUID = 0x2A19, Min length 2, Max len = 2
69-
* GattAttribute attr = GattAttribute(0x2A19, &someValue, 2, 2);
92+
* @par Example
7093
*
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() {
76118
}
77119

78120
public:
79121
/**
80122
* Get the attribute's handle in the ATT table.
81123
*
124+
* @note The GattServer sets the attribute's handle when services are
125+
* inserted.
126+
*
82127
* @return The attribute's handle.
83128
*/
84-
Handle_t getHandle(void) const {
129+
Handle_t getHandle(void) const
130+
{
85131
return _handle;
86132
}
87133

88134
/**
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.
90138
*
91-
* @return The characteristic's UUID.
139+
* @return The attribute.
92140
*/
93-
const UUID &getUUID(void) const {
141+
const UUID &getUUID(void) const
142+
{
94143
return _uuid;
95144
}
96145

@@ -99,7 +148,8 @@ class GattAttribute {
99148
*
100149
* @return The current length of the attribute value.
101150
*/
102-
uint16_t getLength(void) const {
151+
uint16_t getLength(void) const
152+
{
103153
return _len;
104154
}
105155

@@ -108,26 +158,33 @@ class GattAttribute {
108158
*
109159
* The maximum length of the attribute value.
110160
*/
111-
uint16_t getMaxLength(void) const {
161+
uint16_t getMaxLength(void) const
162+
{
112163
return _lenMax;
113164
}
114165

115166
/**
116167
* Get a pointer to the current length of the attribute value.
117168
*
169+
* @important note Do not use this function.
170+
*
118171
* @return A pointer to the current length of the attribute value.
119172
*/
120-
uint16_t *getLengthPtr(void) {
173+
uint16_t *getLengthPtr(void)
174+
{
121175
return &_len;
122176
}
123177

124178
/**
125179
* Set the attribute handle.
126180
*
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.
129185
*/
130-
void setHandle(Handle_t id) {
186+
void setHandle(Handle_t id)
187+
{
131188
_handle = id;
132189
}
133190

@@ -136,44 +193,52 @@ class GattAttribute {
136193
*
137194
* @return A pointer to the attribute value.
138195
*/
139-
uint8_t *getValuePtr(void) {
196+
uint8_t *getValuePtr(void)
197+
{
140198
return _valuePtr;
141199
}
142200

143201
/**
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.
145203
*
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.
147206
*/
148-
bool hasVariableLength(void) const {
207+
bool hasVariableLength(void) const
208+
{
149209
return _hasVariableLen;
150210
}
151211

152212
private:
153213
/**
154214
* Characteristic's UUID.
155215
*/
156-
UUID _uuid;
216+
UUID _uuid;
217+
157218
/**
158219
* Pointer to the attribute's value.
159220
*/
160-
uint8_t *_valuePtr;
221+
uint8_t *_valuePtr;
222+
161223
/**
162-
* Maximum length of the value pointed to by GattAttribute::_valuePtr.
224+
* Length in byte of the buffer containing the attribute value.
163225
*/
164-
uint16_t _lenMax;
226+
uint16_t _lenMax;
227+
165228
/**
166229
* Current length of the value pointed to by GattAttribute::_valuePtr.
167230
*/
168-
uint16_t _len;
231+
uint16_t _len;
232+
169233
/**
170-
* Whether the length of the value can change over time.
234+
* Whether the length of the value can change throughout time.
171235
*/
172-
bool _hasVariableLen;
236+
bool _hasVariableLen;
237+
173238
/**
174239
* The attribute's handle in the ATT table.
175240
*/
176-
Handle_t _handle;
241+
Handle_t _handle;
177242

178243
private:
179244
/* Disallow copy and assignment. */
@@ -187,4 +252,4 @@ class GattAttribute {
187252
* @}
188253
*/
189254

190-
#endif /* ifndef __GATT_ATTRIBUTE_H__ */
255+
#endif /* ifndef MBED_GATT_ATTRIBUTE_H__ */

0 commit comments

Comments
 (0)