User | Revision | Line number | New contents of line |
switches |
0:0e018d759a2a
|
1
|
/* mbed Microcontroller Library
|
switches |
0:0e018d759a2a
|
2
|
* Copyright (c) 2006-2013 ARM Limited
|
switches |
0:0e018d759a2a
|
3
|
*
|
switches |
0:0e018d759a2a
|
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
switches |
0:0e018d759a2a
|
5
|
* you may not use this file except in compliance with the License.
|
switches |
0:0e018d759a2a
|
6
|
* You may obtain a copy of the License at
|
switches |
0:0e018d759a2a
|
7
|
*
|
switches |
0:0e018d759a2a
|
8
|
* http://www.apache.org/licenses/LICENSE-2.0
|
switches |
0:0e018d759a2a
|
9
|
*
|
switches |
0:0e018d759a2a
|
10
|
* Unless required by applicable law or agreed to in writing, software
|
switches |
0:0e018d759a2a
|
11
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
switches |
0:0e018d759a2a
|
12
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
switches |
0:0e018d759a2a
|
13
|
* See the License for the specific language governing permissions and
|
switches |
0:0e018d759a2a
|
14
|
* limitations under the License.
|
switches |
0:0e018d759a2a
|
15
|
*/
|
switches |
0:0e018d759a2a
|
16
|
|
switches |
0:0e018d759a2a
|
17
|
#ifndef __GATT_ATTRIBUTE_H__
|
switches |
0:0e018d759a2a
|
18
|
#define __GATT_ATTRIBUTE_H__
|
switches |
0:0e018d759a2a
|
19
|
|
switches |
0:0e018d759a2a
|
20
|
#include "UUID.h"
|
switches |
0:0e018d759a2a
|
21
|
|
switches |
0:0e018d759a2a
|
22
|
/**
|
switches |
0:0e018d759a2a
|
23
|
* Instances of this class encapsulate the data that belongs to a Bluetooth Low
|
switches |
0:0e018d759a2a
|
24
|
* Energy attribute.
|
switches |
0:0e018d759a2a
|
25
|
*/
|
switches |
0:0e018d759a2a
|
26
|
class GattAttribute {
|
switches |
0:0e018d759a2a
|
27
|
public:
|
switches |
0:0e018d759a2a
|
28
|
/**
|
switches |
0:0e018d759a2a
|
29
|
* Type for the handle or ID of the attribute in the ATT table. These are
|
switches |
0:0e018d759a2a
|
30
|
* unique and are usually generated by the underlying BLE stack.
|
switches |
0:0e018d759a2a
|
31
|
*/
|
switches |
0:0e018d759a2a
|
32
|
typedef uint16_t Handle_t;
|
switches |
0:0e018d759a2a
|
33
|
/**
|
switches |
0:0e018d759a2a
|
34
|
* Define the value of an invalid attribute handle.
|
switches |
0:0e018d759a2a
|
35
|
*/
|
switches |
0:0e018d759a2a
|
36
|
static const Handle_t INVALID_HANDLE = 0x0000;
|
switches |
0:0e018d759a2a
|
37
|
|
switches |
0:0e018d759a2a
|
38
|
public:
|
switches |
0:0e018d759a2a
|
39
|
/**
|
switches |
0:0e018d759a2a
|
40
|
* @brief Creates a new GattAttribute using the specified
|
switches |
0:0e018d759a2a
|
41
|
* UUID, value length, and inital value.
|
switches |
0:0e018d759a2a
|
42
|
*
|
switches |
0:0e018d759a2a
|
43
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
44
|
* The UUID to use for this attribute.
|
switches |
0:0e018d759a2a
|
45
|
* @param[in] valuePtr
|
switches |
0:0e018d759a2a
|
46
|
* The memory holding the initial value.
|
switches |
0:0e018d759a2a
|
47
|
* @param[in] len
|
switches |
0:0e018d759a2a
|
48
|
* The length in bytes of this attribute's value.
|
switches |
0:0e018d759a2a
|
49
|
* @param[in] maxLen
|
switches |
0:0e018d759a2a
|
50
|
* The max length in bytes of this attribute's value.
|
switches |
0:0e018d759a2a
|
51
|
* @param[in] hasVariableLen
|
switches |
0:0e018d759a2a
|
52
|
* Whether the attribute's value length changes overtime.
|
switches |
0:0e018d759a2a
|
53
|
*
|
switches |
0:0e018d759a2a
|
54
|
* @section EXAMPLE
|
switches |
0:0e018d759a2a
|
55
|
*
|
switches |
0:0e018d759a2a
|
56
|
* @code
|
switches |
0:0e018d759a2a
|
57
|
*
|
switches |
0:0e018d759a2a
|
58
|
* // UUID = 0x2A19, Min length 2, Max len = 2
|
switches |
0:0e018d759a2a
|
59
|
* GattAttribute attr = GattAttribute(0x2A19, &someValue, 2, 2);
|
switches |
0:0e018d759a2a
|
60
|
*
|
switches |
0:0e018d759a2a
|
61
|
* @endcode
|
switches |
0:0e018d759a2a
|
62
|
*/
|
switches |
0:0e018d759a2a
|
63
|
GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t len = 0, uint16_t maxLen = 0, bool hasVariableLen = true) :
|
switches |
0:0e018d759a2a
|
64
|
_uuid(uuid), _valuePtr(valuePtr), _lenMax(maxLen), _len(len), _hasVariableLen(hasVariableLen), _handle() {
|
switches |
0:0e018d759a2a
|
65
|
/* Empty */
|
switches |
0:0e018d759a2a
|
66
|
}
|
switches |
0:0e018d759a2a
|
67
|
|
switches |
0:0e018d759a2a
|
68
|
public:
|
switches |
0:0e018d759a2a
|
69
|
/**
|
switches |
0:0e018d759a2a
|
70
|
* Get the attribute's handle in the ATT table.
|
switches |
0:0e018d759a2a
|
71
|
*
|
switches |
0:0e018d759a2a
|
72
|
* @return The attribute's handle.
|
switches |
0:0e018d759a2a
|
73
|
*/
|
switches |
0:0e018d759a2a
|
74
|
Handle_t getHandle(void) const {
|
switches |
0:0e018d759a2a
|
75
|
return _handle;
|
switches |
0:0e018d759a2a
|
76
|
}
|
switches |
0:0e018d759a2a
|
77
|
|
switches |
0:0e018d759a2a
|
78
|
/**
|
switches |
0:0e018d759a2a
|
79
|
* The UUID of the characteristic that this attribute belongs to.
|
switches |
0:0e018d759a2a
|
80
|
*
|
switches |
0:0e018d759a2a
|
81
|
* @return The characteristic's UUID.
|
switches |
0:0e018d759a2a
|
82
|
*/
|
switches |
0:0e018d759a2a
|
83
|
const UUID &getUUID(void) const {
|
switches |
0:0e018d759a2a
|
84
|
return _uuid;
|
switches |
0:0e018d759a2a
|
85
|
}
|
switches |
0:0e018d759a2a
|
86
|
|
switches |
0:0e018d759a2a
|
87
|
/**
|
switches |
0:0e018d759a2a
|
88
|
* Get the current length of the attribute value.
|
switches |
0:0e018d759a2a
|
89
|
*
|
switches |
0:0e018d759a2a
|
90
|
* @return The current length of the attribute value.
|
switches |
0:0e018d759a2a
|
91
|
*/
|
switches |
0:0e018d759a2a
|
92
|
uint16_t getLength(void) const {
|
switches |
0:0e018d759a2a
|
93
|
return _len;
|
switches |
0:0e018d759a2a
|
94
|
}
|
switches |
0:0e018d759a2a
|
95
|
|
switches |
0:0e018d759a2a
|
96
|
/**
|
switches |
0:0e018d759a2a
|
97
|
* Get the maximum length of the attribute value.
|
switches |
0:0e018d759a2a
|
98
|
*
|
switches |
0:0e018d759a2a
|
99
|
* The maximum length of the attribute value.
|
switches |
0:0e018d759a2a
|
100
|
*/
|
switches |
0:0e018d759a2a
|
101
|
uint16_t getMaxLength(void) const {
|
switches |
0:0e018d759a2a
|
102
|
return _lenMax;
|
switches |
0:0e018d759a2a
|
103
|
}
|
switches |
0:0e018d759a2a
|
104
|
|
switches |
0:0e018d759a2a
|
105
|
/**
|
switches |
0:0e018d759a2a
|
106
|
* Get a pointer to the current length of the attribute value.
|
switches |
0:0e018d759a2a
|
107
|
*
|
switches |
0:0e018d759a2a
|
108
|
* @return A pointer to the current length of the attribute value.
|
switches |
0:0e018d759a2a
|
109
|
*/
|
switches |
0:0e018d759a2a
|
110
|
uint16_t *getLengthPtr(void) {
|
switches |
0:0e018d759a2a
|
111
|
return &_len;
|
switches |
0:0e018d759a2a
|
112
|
}
|
switches |
0:0e018d759a2a
|
113
|
|
switches |
0:0e018d759a2a
|
114
|
/**
|
switches |
0:0e018d759a2a
|
115
|
* Set the attribute handle.
|
switches |
0:0e018d759a2a
|
116
|
*
|
switches |
0:0e018d759a2a
|
117
|
* @param[in] id
|
switches |
0:0e018d759a2a
|
118
|
* The new attribute handle.
|
switches |
0:0e018d759a2a
|
119
|
*/
|
switches |
0:0e018d759a2a
|
120
|
void setHandle(Handle_t id) {
|
switches |
0:0e018d759a2a
|
121
|
_handle = id;
|
switches |
0:0e018d759a2a
|
122
|
}
|
switches |
0:0e018d759a2a
|
123
|
|
switches |
0:0e018d759a2a
|
124
|
/**
|
switches |
0:0e018d759a2a
|
125
|
* Get a pointer to the attribute value.
|
switches |
0:0e018d759a2a
|
126
|
*
|
switches |
0:0e018d759a2a
|
127
|
* @return A pointer to the attribute value.
|
switches |
0:0e018d759a2a
|
128
|
*/
|
switches |
0:0e018d759a2a
|
129
|
uint8_t *getValuePtr(void) {
|
switches |
0:0e018d759a2a
|
130
|
return _valuePtr;
|
switches |
0:0e018d759a2a
|
131
|
}
|
switches |
0:0e018d759a2a
|
132
|
|
switches |
0:0e018d759a2a
|
133
|
/**
|
switches |
0:0e018d759a2a
|
134
|
* Check whether the length of the attribute's value can change over time.
|
switches |
0:0e018d759a2a
|
135
|
*
|
switches |
0:0e018d759a2a
|
136
|
* @return true if the attribute has variable length, false otherwise.
|
switches |
0:0e018d759a2a
|
137
|
*/
|
switches |
0:0e018d759a2a
|
138
|
bool hasVariableLength(void) const {
|
switches |
0:0e018d759a2a
|
139
|
return _hasVariableLen;
|
switches |
0:0e018d759a2a
|
140
|
}
|
switches |
0:0e018d759a2a
|
141
|
|
switches |
0:0e018d759a2a
|
142
|
private:
|
switches |
0:0e018d759a2a
|
143
|
/**
|
switches |
0:0e018d759a2a
|
144
|
* Characteristic's UUID.
|
switches |
0:0e018d759a2a
|
145
|
*/
|
switches |
0:0e018d759a2a
|
146
|
UUID _uuid;
|
switches |
0:0e018d759a2a
|
147
|
/**
|
switches |
0:0e018d759a2a
|
148
|
* Pointer to the attribute's value.
|
switches |
0:0e018d759a2a
|
149
|
*/
|
switches |
0:0e018d759a2a
|
150
|
uint8_t *_valuePtr;
|
switches |
0:0e018d759a2a
|
151
|
/**
|
switches |
0:0e018d759a2a
|
152
|
* Maximum length of the value pointed to by GattAttribute::_valuePtr.
|
switches |
0:0e018d759a2a
|
153
|
*/
|
switches |
0:0e018d759a2a
|
154
|
uint16_t _lenMax;
|
switches |
0:0e018d759a2a
|
155
|
/**
|
switches |
0:0e018d759a2a
|
156
|
* Current length of the value pointed to by GattAttribute::_valuePtr.
|
switches |
0:0e018d759a2a
|
157
|
*/
|
switches |
0:0e018d759a2a
|
158
|
uint16_t _len;
|
switches |
0:0e018d759a2a
|
159
|
/**
|
switches |
0:0e018d759a2a
|
160
|
* Whether the length of the value can change over time.
|
switches |
0:0e018d759a2a
|
161
|
*/
|
switches |
0:0e018d759a2a
|
162
|
bool _hasVariableLen;
|
switches |
0:0e018d759a2a
|
163
|
/**
|
switches |
0:0e018d759a2a
|
164
|
* The attribute's handle in the ATT table.
|
switches |
0:0e018d759a2a
|
165
|
*/
|
switches |
0:0e018d759a2a
|
166
|
Handle_t _handle;
|
switches |
0:0e018d759a2a
|
167
|
|
switches |
0:0e018d759a2a
|
168
|
private:
|
switches |
0:0e018d759a2a
|
169
|
/* Disallow copy and assignment. */
|
switches |
0:0e018d759a2a
|
170
|
GattAttribute(const GattAttribute &);
|
switches |
0:0e018d759a2a
|
171
|
GattAttribute& operator=(const GattAttribute &);
|
switches |
0:0e018d759a2a
|
172
|
};
|
switches |
0:0e018d759a2a
|
173
|
|
switches |
0:0e018d759a2a
|
174
|
#endif /* ifndef __GATT_ATTRIBUTE_H__ */
|