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 __DISCOVERED_CHARACTERISTIC_H__
|
switches |
0:0e018d759a2a
|
18
|
#define __DISCOVERED_CHARACTERISTIC_H__
|
switches |
0:0e018d759a2a
|
19
|
|
switches |
0:0e018d759a2a
|
20
|
#include "UUID.h"
|
switches |
0:0e018d759a2a
|
21
|
#include "Gap.h"
|
switches |
0:0e018d759a2a
|
22
|
#include "GattAttribute.h"
|
switches |
0:0e018d759a2a
|
23
|
#include "GattClient.h"
|
switches |
0:0e018d759a2a
|
24
|
#include "CharacteristicDescriptorDiscovery.h"
|
switches |
0:0e018d759a2a
|
25
|
#include "ble/DiscoveredCharacteristicDescriptor.h"
|
switches |
0:0e018d759a2a
|
26
|
|
switches |
0:0e018d759a2a
|
27
|
/**
|
switches |
0:0e018d759a2a
|
28
|
* @brief Representation of a characteristic discovered during a GattClient
|
switches |
0:0e018d759a2a
|
29
|
* discovery procedure (see GattClient::launchServiceDiscovery ).
|
switches |
0:0e018d759a2a
|
30
|
*
|
switches |
0:0e018d759a2a
|
31
|
* @details Provide detailed informations about a discovered characteristic like:
|
switches |
0:0e018d759a2a
|
32
|
* - Its UUID (see getUUID()).
|
switches |
0:0e018d759a2a
|
33
|
* - The most important handles of the characteristic definition
|
switches |
0:0e018d759a2a
|
34
|
* (see getDeclHandle(), getValueHandle(), getLastHandle())
|
switches |
0:0e018d759a2a
|
35
|
* - Its properties (see getProperties()).
|
switches |
0:0e018d759a2a
|
36
|
* This class also provide functions to operate on the characteristic:
|
switches |
0:0e018d759a2a
|
37
|
* - Read the characteristic value (see read())
|
switches |
0:0e018d759a2a
|
38
|
* - Writing a characteristic value (see write() or writeWoResponse())
|
switches |
0:0e018d759a2a
|
39
|
* - Discover descriptors inside the characteristic definition. These descriptors
|
switches |
0:0e018d759a2a
|
40
|
* extends the characteristic. More information about descriptor usage is
|
switches |
0:0e018d759a2a
|
41
|
* available in DiscoveredCharacteristicDescriptor class.
|
switches |
0:0e018d759a2a
|
42
|
*/
|
switches |
0:0e018d759a2a
|
43
|
class DiscoveredCharacteristic {
|
switches |
0:0e018d759a2a
|
44
|
public:
|
switches |
0:0e018d759a2a
|
45
|
/**
|
switches |
0:0e018d759a2a
|
46
|
* Structure that encapsulates the properties of a discovered
|
switches |
0:0e018d759a2a
|
47
|
* characteristic.
|
switches |
0:0e018d759a2a
|
48
|
*/
|
switches |
0:0e018d759a2a
|
49
|
struct Properties_t {
|
switches |
0:0e018d759a2a
|
50
|
uint8_t _broadcast :1; /**< Broadcasting the value permitted. */
|
switches |
0:0e018d759a2a
|
51
|
uint8_t _read :1; /**< Reading the value permitted. */
|
switches |
0:0e018d759a2a
|
52
|
uint8_t _writeWoResp :1; /**< Writing the value with Write Command permitted. */
|
switches |
0:0e018d759a2a
|
53
|
uint8_t _write :1; /**< Writing the value with Write Request permitted. */
|
switches |
0:0e018d759a2a
|
54
|
uint8_t _notify :1; /**< Notifications of the value permitted. */
|
switches |
0:0e018d759a2a
|
55
|
uint8_t _indicate :1; /**< Indications of the value permitted. */
|
switches |
0:0e018d759a2a
|
56
|
uint8_t _authSignedWrite :1; /**< Writing the value with Signed Write Command permitted. */
|
switches |
0:0e018d759a2a
|
57
|
|
switches |
0:0e018d759a2a
|
58
|
public:
|
switches |
0:0e018d759a2a
|
59
|
/**
|
switches |
0:0e018d759a2a
|
60
|
* @brief Check if broadcasting is permitted.
|
switches |
0:0e018d759a2a
|
61
|
*
|
switches |
0:0e018d759a2a
|
62
|
* @return true if broadcasting the value is permitted, and false
|
switches |
0:0e018d759a2a
|
63
|
* otherwise.
|
switches |
0:0e018d759a2a
|
64
|
*/
|
switches |
0:0e018d759a2a
|
65
|
bool broadcast(void) const {
|
switches |
0:0e018d759a2a
|
66
|
return _broadcast;
|
switches |
0:0e018d759a2a
|
67
|
}
|
switches |
0:0e018d759a2a
|
68
|
|
switches |
0:0e018d759a2a
|
69
|
/**
|
switches |
0:0e018d759a2a
|
70
|
* @brief Check reading is permitted.
|
switches |
0:0e018d759a2a
|
71
|
*
|
switches |
0:0e018d759a2a
|
72
|
* @return true if reading the value is permitted, and false
|
switches |
0:0e018d759a2a
|
73
|
* otherwise.
|
switches |
0:0e018d759a2a
|
74
|
*/
|
switches |
0:0e018d759a2a
|
75
|
bool read(void) const {
|
switches |
0:0e018d759a2a
|
76
|
return _read;
|
switches |
0:0e018d759a2a
|
77
|
}
|
switches |
0:0e018d759a2a
|
78
|
|
switches |
0:0e018d759a2a
|
79
|
/**
|
switches |
0:0e018d759a2a
|
80
|
* @brief Check if writing with Write Command is permitted.
|
switches |
0:0e018d759a2a
|
81
|
*
|
switches |
0:0e018d759a2a
|
82
|
* @return true if writing the value with Write Command is permitted,
|
switches |
0:0e018d759a2a
|
83
|
* false otherwise.
|
switches |
0:0e018d759a2a
|
84
|
*/
|
switches |
0:0e018d759a2a
|
85
|
bool writeWoResp(void) const {
|
switches |
0:0e018d759a2a
|
86
|
return _writeWoResp;
|
switches |
0:0e018d759a2a
|
87
|
}
|
switches |
0:0e018d759a2a
|
88
|
|
switches |
0:0e018d759a2a
|
89
|
/**
|
switches |
0:0e018d759a2a
|
90
|
* @brief Check if writing with Write Request is permitted.
|
switches |
0:0e018d759a2a
|
91
|
*
|
switches |
0:0e018d759a2a
|
92
|
* @return true if writing the value with Write Request is permitted,
|
switches |
0:0e018d759a2a
|
93
|
* false otherwise.
|
switches |
0:0e018d759a2a
|
94
|
*/
|
switches |
0:0e018d759a2a
|
95
|
bool write(void) const {
|
switches |
0:0e018d759a2a
|
96
|
return _write;
|
switches |
0:0e018d759a2a
|
97
|
}
|
switches |
0:0e018d759a2a
|
98
|
|
switches |
0:0e018d759a2a
|
99
|
/**
|
switches |
0:0e018d759a2a
|
100
|
* @brief Check notifications are permitted.
|
switches |
0:0e018d759a2a
|
101
|
*
|
switches |
0:0e018d759a2a
|
102
|
* @return true if notifications of the value are permitted, false
|
switches |
0:0e018d759a2a
|
103
|
* otherwise.
|
switches |
0:0e018d759a2a
|
104
|
*/
|
switches |
0:0e018d759a2a
|
105
|
bool notify(void) const {
|
switches |
0:0e018d759a2a
|
106
|
return _notify;
|
switches |
0:0e018d759a2a
|
107
|
}
|
switches |
0:0e018d759a2a
|
108
|
|
switches |
0:0e018d759a2a
|
109
|
/**
|
switches |
0:0e018d759a2a
|
110
|
* @brief Check if indications are permitted.
|
switches |
0:0e018d759a2a
|
111
|
*
|
switches |
0:0e018d759a2a
|
112
|
* @return true if indications of the value are permitted, false
|
switches |
0:0e018d759a2a
|
113
|
* otherwise.
|
switches |
0:0e018d759a2a
|
114
|
*/
|
switches |
0:0e018d759a2a
|
115
|
bool indicate(void) const {
|
switches |
0:0e018d759a2a
|
116
|
return _indicate;
|
switches |
0:0e018d759a2a
|
117
|
}
|
switches |
0:0e018d759a2a
|
118
|
|
switches |
0:0e018d759a2a
|
119
|
/**
|
switches |
0:0e018d759a2a
|
120
|
* @brief Check if writing with Signed Write Command is permitted.
|
switches |
0:0e018d759a2a
|
121
|
*
|
switches |
0:0e018d759a2a
|
122
|
* @return true if writing the value with Signed Write Command is
|
switches |
0:0e018d759a2a
|
123
|
* permitted, false otherwise.
|
switches |
0:0e018d759a2a
|
124
|
*/
|
switches |
0:0e018d759a2a
|
125
|
bool authSignedWrite(void) const {
|
switches |
0:0e018d759a2a
|
126
|
return _authSignedWrite;
|
switches |
0:0e018d759a2a
|
127
|
}
|
switches |
0:0e018d759a2a
|
128
|
|
switches |
0:0e018d759a2a
|
129
|
/**
|
switches |
0:0e018d759a2a
|
130
|
* @brief "Equal to" operator for DiscoveredCharacteristic::Properties_t
|
switches |
0:0e018d759a2a
|
131
|
*
|
switches |
0:0e018d759a2a
|
132
|
* @param[in] lhs The left hand side of the equality expression
|
switches |
0:0e018d759a2a
|
133
|
* @param[in] rhs The right hand side of the equality expression
|
switches |
0:0e018d759a2a
|
134
|
*
|
switches |
0:0e018d759a2a
|
135
|
* @return true if operands are equals, false otherwise.
|
switches |
0:0e018d759a2a
|
136
|
*/
|
switches |
0:0e018d759a2a
|
137
|
friend bool operator==(Properties_t lhs, Properties_t rhs) {
|
switches |
0:0e018d759a2a
|
138
|
return lhs._broadcast == rhs._broadcast &&
|
switches |
0:0e018d759a2a
|
139
|
lhs._read == rhs._read &&
|
switches |
0:0e018d759a2a
|
140
|
lhs._writeWoResp == rhs._writeWoResp &&
|
switches |
0:0e018d759a2a
|
141
|
lhs._write == rhs._write &&
|
switches |
0:0e018d759a2a
|
142
|
lhs._notify == rhs._notify &&
|
switches |
0:0e018d759a2a
|
143
|
lhs._indicate == rhs._indicate &&
|
switches |
0:0e018d759a2a
|
144
|
lhs._authSignedWrite == rhs._authSignedWrite;
|
switches |
0:0e018d759a2a
|
145
|
}
|
switches |
0:0e018d759a2a
|
146
|
|
switches |
0:0e018d759a2a
|
147
|
/**
|
switches |
0:0e018d759a2a
|
148
|
* @brief "Not equal to" operator for DiscoveredCharacteristic::Properties_t
|
switches |
0:0e018d759a2a
|
149
|
*
|
switches |
0:0e018d759a2a
|
150
|
* @param lhs The right hand side of the expression
|
switches |
0:0e018d759a2a
|
151
|
* @param rhs The left hand side of the expression
|
switches |
0:0e018d759a2a
|
152
|
*
|
switches |
0:0e018d759a2a
|
153
|
* @return true if operands are not equals, false otherwise.
|
switches |
0:0e018d759a2a
|
154
|
*/
|
switches |
0:0e018d759a2a
|
155
|
friend bool operator!=(Properties_t lhs, Properties_t rhs) {
|
switches |
0:0e018d759a2a
|
156
|
return !(lhs == rhs);
|
switches |
0:0e018d759a2a
|
157
|
}
|
switches |
0:0e018d759a2a
|
158
|
|
switches |
0:0e018d759a2a
|
159
|
private:
|
switches |
0:0e018d759a2a
|
160
|
operator uint8_t() const; /* Disallow implicit conversion into an integer. */
|
switches |
0:0e018d759a2a
|
161
|
operator unsigned() const; /* Disallow implicit conversion into an integer. */
|
switches |
0:0e018d759a2a
|
162
|
};
|
switches |
0:0e018d759a2a
|
163
|
|
switches |
0:0e018d759a2a
|
164
|
/**
|
switches |
0:0e018d759a2a
|
165
|
* Initiate (or continue) a read for the value attribute, optionally at a
|
switches |
0:0e018d759a2a
|
166
|
* given offset. If the characteristic or descriptor to be read is longer
|
switches |
0:0e018d759a2a
|
167
|
* than ATT_MTU - 1, this function must be called multiple times with
|
switches |
0:0e018d759a2a
|
168
|
* appropriate offset to read the complete value.
|
switches |
0:0e018d759a2a
|
169
|
*
|
switches |
0:0e018d759a2a
|
170
|
* @param[in] offset
|
switches |
0:0e018d759a2a
|
171
|
* The position - in the characteristic value bytes stream - where
|
switches |
0:0e018d759a2a
|
172
|
* the read operation begin.
|
switches |
0:0e018d759a2a
|
173
|
*
|
switches |
0:0e018d759a2a
|
174
|
* @return BLE_ERROR_NONE if a read has been initiated, or
|
switches |
0:0e018d759a2a
|
175
|
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
|
switches |
0:0e018d759a2a
|
176
|
* BLE_STACK_BUSY if some client procedure is already in progress, or
|
switches |
0:0e018d759a2a
|
177
|
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
|
switches |
0:0e018d759a2a
|
178
|
*/
|
switches |
0:0e018d759a2a
|
179
|
ble_error_t read(uint16_t offset = 0) const;
|
switches |
0:0e018d759a2a
|
180
|
|
switches |
0:0e018d759a2a
|
181
|
/**
|
switches |
0:0e018d759a2a
|
182
|
* @brief Same as #read(uint16_t) const but allow the user to register a callback
|
switches |
0:0e018d759a2a
|
183
|
* which will be fired once the read is done.
|
switches |
0:0e018d759a2a
|
184
|
*
|
switches |
0:0e018d759a2a
|
185
|
* @param[in] offset
|
switches |
0:0e018d759a2a
|
186
|
* The position - in the characteristic value bytes stream - where
|
switches |
0:0e018d759a2a
|
187
|
* the read operation begin.
|
switches |
0:0e018d759a2a
|
188
|
* @param[in] onRead
|
switches |
0:0e018d759a2a
|
189
|
* Continuation of the read operation
|
switches |
0:0e018d759a2a
|
190
|
*/
|
switches |
0:0e018d759a2a
|
191
|
ble_error_t read(uint16_t offset, const GattClient::ReadCallback_t& onRead) const;
|
switches |
0:0e018d759a2a
|
192
|
|
switches |
0:0e018d759a2a
|
193
|
/**
|
switches |
0:0e018d759a2a
|
194
|
* Perform a write without response procedure.
|
switches |
0:0e018d759a2a
|
195
|
*
|
switches |
0:0e018d759a2a
|
196
|
* @param[in] length
|
switches |
0:0e018d759a2a
|
197
|
* The amount of data being written.
|
switches |
0:0e018d759a2a
|
198
|
* @param[in] value
|
switches |
0:0e018d759a2a
|
199
|
* The bytes being written.
|
switches |
0:0e018d759a2a
|
200
|
*
|
switches |
0:0e018d759a2a
|
201
|
* @note It is important to note that a write without response will generate
|
switches |
0:0e018d759a2a
|
202
|
* an onDataSent() callback when the packet has been transmitted. There
|
switches |
0:0e018d759a2a
|
203
|
* will be a BLE-stack specific limit to the number of pending
|
switches |
0:0e018d759a2a
|
204
|
* writeWoResponse operations; the user may want to use the onDataSent()
|
switches |
0:0e018d759a2a
|
205
|
* callback for flow-control.
|
switches |
0:0e018d759a2a
|
206
|
*
|
switches |
0:0e018d759a2a
|
207
|
* @retval BLE_ERROR_NONE Successfully started the Write procedure, or
|
switches |
0:0e018d759a2a
|
208
|
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
|
switches |
0:0e018d759a2a
|
209
|
* BLE_STACK_BUSY if some client procedure is already in progress, or
|
switches |
0:0e018d759a2a
|
210
|
* BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
|
switches |
0:0e018d759a2a
|
211
|
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
|
switches |
0:0e018d759a2a
|
212
|
*/
|
switches |
0:0e018d759a2a
|
213
|
ble_error_t writeWoResponse(uint16_t length, const uint8_t *value) const;
|
switches |
0:0e018d759a2a
|
214
|
|
switches |
0:0e018d759a2a
|
215
|
/**
|
switches |
0:0e018d759a2a
|
216
|
* Initiate a GATT Characteristic Descriptor Discovery procedure for descriptors within this characteristic.
|
switches |
0:0e018d759a2a
|
217
|
*
|
switches |
0:0e018d759a2a
|
218
|
* @param[in] onDescriptorDiscovered This callback will be called every time a descriptor is discovered
|
switches |
0:0e018d759a2a
|
219
|
* @param[in] onTermination This callback will be called when the discovery process is over.
|
switches |
0:0e018d759a2a
|
220
|
*
|
switches |
0:0e018d759a2a
|
221
|
* @return BLE_ERROR_NONE if descriptor discovery is launched successfully; else an appropriate error.
|
switches |
0:0e018d759a2a
|
222
|
*/
|
switches |
0:0e018d759a2a
|
223
|
ble_error_t discoverDescriptors(const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& onDescriptorDiscovered,
|
switches |
0:0e018d759a2a
|
224
|
const CharacteristicDescriptorDiscovery::TerminationCallback_t& onTermination) const;
|
switches |
0:0e018d759a2a
|
225
|
|
switches |
0:0e018d759a2a
|
226
|
/**
|
switches |
0:0e018d759a2a
|
227
|
* Perform a write procedure.
|
switches |
0:0e018d759a2a
|
228
|
*
|
switches |
0:0e018d759a2a
|
229
|
* @param[in] length
|
switches |
0:0e018d759a2a
|
230
|
* The amount of data being written.
|
switches |
0:0e018d759a2a
|
231
|
* @param[in] value
|
switches |
0:0e018d759a2a
|
232
|
* The bytes being written.
|
switches |
0:0e018d759a2a
|
233
|
*
|
switches |
0:0e018d759a2a
|
234
|
* @note It is important to note that a write will generate
|
switches |
0:0e018d759a2a
|
235
|
* an onDataWritten() callback when the peer acknowledges the request.
|
switches |
0:0e018d759a2a
|
236
|
*
|
switches |
0:0e018d759a2a
|
237
|
* @retval BLE_ERROR_NONE Successfully started the Write procedure, or
|
switches |
0:0e018d759a2a
|
238
|
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
|
switches |
0:0e018d759a2a
|
239
|
* BLE_STACK_BUSY if some client procedure is already in progress, or
|
switches |
0:0e018d759a2a
|
240
|
* BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
|
switches |
0:0e018d759a2a
|
241
|
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
|
switches |
0:0e018d759a2a
|
242
|
*/
|
switches |
0:0e018d759a2a
|
243
|
ble_error_t write(uint16_t length, const uint8_t *value) const;
|
switches |
0:0e018d759a2a
|
244
|
|
switches |
0:0e018d759a2a
|
245
|
/**
|
switches |
0:0e018d759a2a
|
246
|
* Same as write(uint16_t, const uint8_t *) const but register a callback
|
switches |
0:0e018d759a2a
|
247
|
* which will be called once the data has been written.
|
switches |
0:0e018d759a2a
|
248
|
*
|
switches |
0:0e018d759a2a
|
249
|
* @param[in] length
|
switches |
0:0e018d759a2a
|
250
|
* The amount of bytes to write.
|
switches |
0:0e018d759a2a
|
251
|
* @param[in] value
|
switches |
0:0e018d759a2a
|
252
|
* The bytes to write.
|
switches |
0:0e018d759a2a
|
253
|
* @param[in] onWrite
|
switches |
0:0e018d759a2a
|
254
|
* Continuation callback for the write operation
|
switches |
0:0e018d759a2a
|
255
|
*
|
switches |
0:0e018d759a2a
|
256
|
* @retval BLE_ERROR_NONE Successfully started the Write procedure, or
|
switches |
0:0e018d759a2a
|
257
|
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
|
switches |
0:0e018d759a2a
|
258
|
* BLE_STACK_BUSY if some client procedure is already in progress, or
|
switches |
0:0e018d759a2a
|
259
|
* BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
|
switches |
0:0e018d759a2a
|
260
|
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
|
switches |
0:0e018d759a2a
|
261
|
*/
|
switches |
0:0e018d759a2a
|
262
|
ble_error_t write(uint16_t length, const uint8_t *value, const GattClient::WriteCallback_t& onWrite) const;
|
switches |
0:0e018d759a2a
|
263
|
|
switches |
0:0e018d759a2a
|
264
|
void setupLongUUID(UUID::LongUUIDBytes_t longUUID, UUID::ByteOrder_t order = UUID::MSB) {
|
switches |
0:0e018d759a2a
|
265
|
uuid.setupLong(longUUID, order);
|
switches |
0:0e018d759a2a
|
266
|
}
|
switches |
0:0e018d759a2a
|
267
|
|
switches |
0:0e018d759a2a
|
268
|
public:
|
switches |
0:0e018d759a2a
|
269
|
/**
|
switches |
0:0e018d759a2a
|
270
|
* @brief Get the UUID of the discovered characteristic
|
switches |
0:0e018d759a2a
|
271
|
* @return the UUID of this characteristic
|
switches |
0:0e018d759a2a
|
272
|
*/
|
switches |
0:0e018d759a2a
|
273
|
const UUID& getUUID(void) const {
|
switches |
0:0e018d759a2a
|
274
|
return uuid;
|
switches |
0:0e018d759a2a
|
275
|
}
|
switches |
0:0e018d759a2a
|
276
|
|
switches |
0:0e018d759a2a
|
277
|
/**
|
switches |
0:0e018d759a2a
|
278
|
* @brief Get the properties of this characteristic
|
switches |
0:0e018d759a2a
|
279
|
* @return the set of properties of this characteristic
|
switches |
0:0e018d759a2a
|
280
|
*/
|
switches |
0:0e018d759a2a
|
281
|
const Properties_t& getProperties(void) const {
|
switches |
0:0e018d759a2a
|
282
|
return props;
|
switches |
0:0e018d759a2a
|
283
|
}
|
switches |
0:0e018d759a2a
|
284
|
|
switches |
0:0e018d759a2a
|
285
|
/**
|
switches |
0:0e018d759a2a
|
286
|
* @brief Get the declaration handle of this characteristic.
|
switches |
0:0e018d759a2a
|
287
|
* @details The declaration handle is the first handle of a characteristic
|
switches |
0:0e018d759a2a
|
288
|
* definition. The value accessible at this handle contains the following
|
switches |
0:0e018d759a2a
|
289
|
* informations:
|
switches |
0:0e018d759a2a
|
290
|
* - The characteristics properties (see Properties_t). This value can
|
switches |
0:0e018d759a2a
|
291
|
* be accessed by using #getProperties .
|
switches |
0:0e018d759a2a
|
292
|
* - The characteristic value attribute handle. This field can be accessed
|
switches |
0:0e018d759a2a
|
293
|
* by using #getValueHandle .
|
switches |
0:0e018d759a2a
|
294
|
* - The characteristic UUID, this value can be accessed by using the
|
switches |
0:0e018d759a2a
|
295
|
* function #getUUID .
|
switches |
0:0e018d759a2a
|
296
|
* @return the declaration handle of this characteristic.
|
switches |
0:0e018d759a2a
|
297
|
*/
|
switches |
0:0e018d759a2a
|
298
|
GattAttribute::Handle_t getDeclHandle(void) const {
|
switches |
0:0e018d759a2a
|
299
|
return declHandle;
|
switches |
0:0e018d759a2a
|
300
|
}
|
switches |
0:0e018d759a2a
|
301
|
|
switches |
0:0e018d759a2a
|
302
|
/**
|
switches |
0:0e018d759a2a
|
303
|
* @brief Return the handle used to access the value of this characteristic.
|
switches |
0:0e018d759a2a
|
304
|
* @details This handle is the one provided in the characteristic declaration
|
switches |
0:0e018d759a2a
|
305
|
* value. Usually, it is equal to #getDeclHandle() + 1. But it is not always
|
switches |
0:0e018d759a2a
|
306
|
* the case. Anyway, users are allowed to use #getDeclHandle() + 1 to access
|
switches |
0:0e018d759a2a
|
307
|
* the value of a characteristic.
|
switches |
0:0e018d759a2a
|
308
|
* @return The handle to access the value of this characteristic.
|
switches |
0:0e018d759a2a
|
309
|
*/
|
switches |
0:0e018d759a2a
|
310
|
GattAttribute::Handle_t getValueHandle(void) const {
|
switches |
0:0e018d759a2a
|
311
|
return valueHandle;
|
switches |
0:0e018d759a2a
|
312
|
}
|
switches |
0:0e018d759a2a
|
313
|
|
switches |
0:0e018d759a2a
|
314
|
/**
|
switches |
0:0e018d759a2a
|
315
|
* @brief Return the last handle of the characteristic definition.
|
switches |
0:0e018d759a2a
|
316
|
* @details A Characteristic definition can contain a lot of handles:
|
switches |
0:0e018d759a2a
|
317
|
* - one for the declaration (see #getDeclHandle)
|
switches |
0:0e018d759a2a
|
318
|
* - one for the value (see #getValueHandle)
|
switches |
0:0e018d759a2a
|
319
|
* - zero of more for the characteristic descriptors.
|
switches |
0:0e018d759a2a
|
320
|
* This handle is the last handle of the characteristic definition.
|
switches |
0:0e018d759a2a
|
321
|
* @return The last handle of this characteristic definition.
|
switches |
0:0e018d759a2a
|
322
|
*/
|
switches |
0:0e018d759a2a
|
323
|
GattAttribute::Handle_t getLastHandle(void) const {
|
switches |
0:0e018d759a2a
|
324
|
return lastHandle;
|
switches |
0:0e018d759a2a
|
325
|
}
|
switches |
0:0e018d759a2a
|
326
|
|
switches |
0:0e018d759a2a
|
327
|
/**
|
switches |
0:0e018d759a2a
|
328
|
* @brief Return the GattClient which can operate on this characteristic.
|
switches |
0:0e018d759a2a
|
329
|
* @return The GattClient which can operate on this characteristic.
|
switches |
0:0e018d759a2a
|
330
|
*/
|
switches |
0:0e018d759a2a
|
331
|
GattClient* getGattClient() {
|
switches |
0:0e018d759a2a
|
332
|
return gattc;
|
switches |
0:0e018d759a2a
|
333
|
}
|
switches |
0:0e018d759a2a
|
334
|
|
switches |
0:0e018d759a2a
|
335
|
/**
|
switches |
0:0e018d759a2a
|
336
|
* @brief Return the GattClient which can operate on this characteristic.
|
switches |
0:0e018d759a2a
|
337
|
* @return The GattClient which can operate on this characteristic.
|
switches |
0:0e018d759a2a
|
338
|
*/
|
switches |
0:0e018d759a2a
|
339
|
const GattClient* getGattClient() const {
|
switches |
0:0e018d759a2a
|
340
|
return gattc;
|
switches |
0:0e018d759a2a
|
341
|
}
|
switches |
0:0e018d759a2a
|
342
|
|
switches |
0:0e018d759a2a
|
343
|
/**
|
switches |
0:0e018d759a2a
|
344
|
* @brief Return the connection handle to the GattServer which contain
|
switches |
0:0e018d759a2a
|
345
|
* this characteristic.
|
switches |
0:0e018d759a2a
|
346
|
* @return the connection handle to the GattServer which contain
|
switches |
0:0e018d759a2a
|
347
|
* this characteristic.
|
switches |
0:0e018d759a2a
|
348
|
*/
|
switches |
0:0e018d759a2a
|
349
|
Gap::Handle_t getConnectionHandle() const {
|
switches |
0:0e018d759a2a
|
350
|
return connHandle;
|
switches |
0:0e018d759a2a
|
351
|
}
|
switches |
0:0e018d759a2a
|
352
|
|
switches |
0:0e018d759a2a
|
353
|
/**
|
switches |
0:0e018d759a2a
|
354
|
* @brief "Equal to" operator for DiscoveredCharacteristic
|
switches |
0:0e018d759a2a
|
355
|
*
|
switches |
0:0e018d759a2a
|
356
|
* @param[in] lhs
|
switches |
0:0e018d759a2a
|
357
|
* The left hand side of the equality expression
|
switches |
0:0e018d759a2a
|
358
|
* @param[in] rhs
|
switches |
0:0e018d759a2a
|
359
|
* The right hand side of the equality expression
|
switches |
0:0e018d759a2a
|
360
|
*
|
switches |
0:0e018d759a2a
|
361
|
* @return true if operands are equals, false otherwise.
|
switches |
0:0e018d759a2a
|
362
|
*/
|
switches |
0:0e018d759a2a
|
363
|
friend bool operator==(const DiscoveredCharacteristic& lhs, const DiscoveredCharacteristic& rhs) {
|
switches |
0:0e018d759a2a
|
364
|
return lhs.gattc == rhs.gattc &&
|
switches |
0:0e018d759a2a
|
365
|
lhs.uuid == rhs.uuid &&
|
switches |
0:0e018d759a2a
|
366
|
lhs.props == rhs.props &&
|
switches |
0:0e018d759a2a
|
367
|
lhs.declHandle == rhs.declHandle &&
|
switches |
0:0e018d759a2a
|
368
|
lhs.valueHandle == rhs.valueHandle &&
|
switches |
0:0e018d759a2a
|
369
|
lhs.lastHandle == rhs.lastHandle &&
|
switches |
0:0e018d759a2a
|
370
|
lhs.connHandle == rhs.connHandle;
|
switches |
0:0e018d759a2a
|
371
|
}
|
switches |
0:0e018d759a2a
|
372
|
|
switches |
0:0e018d759a2a
|
373
|
/**
|
switches |
0:0e018d759a2a
|
374
|
* @brief "Not equal to" operator for DiscoveredCharacteristic
|
switches |
0:0e018d759a2a
|
375
|
*
|
switches |
0:0e018d759a2a
|
376
|
* @param[in] lhs
|
switches |
0:0e018d759a2a
|
377
|
* The right hand side of the expression
|
switches |
0:0e018d759a2a
|
378
|
* @param[in] rhs
|
switches |
0:0e018d759a2a
|
379
|
* The left hand side of the expression
|
switches |
0:0e018d759a2a
|
380
|
*
|
switches |
0:0e018d759a2a
|
381
|
* @return true if operands are not equal, false otherwise.
|
switches |
0:0e018d759a2a
|
382
|
*/
|
switches |
0:0e018d759a2a
|
383
|
friend bool operator !=(const DiscoveredCharacteristic& lhs, const DiscoveredCharacteristic& rhs) {
|
switches |
0:0e018d759a2a
|
384
|
return !(lhs == rhs);
|
switches |
0:0e018d759a2a
|
385
|
}
|
switches |
0:0e018d759a2a
|
386
|
|
switches |
0:0e018d759a2a
|
387
|
public:
|
switches |
0:0e018d759a2a
|
388
|
DiscoveredCharacteristic() : gattc(NULL),
|
switches |
0:0e018d759a2a
|
389
|
uuid(UUID::ShortUUIDBytes_t(0)),
|
switches |
0:0e018d759a2a
|
390
|
props(),
|
switches |
0:0e018d759a2a
|
391
|
declHandle(GattAttribute::INVALID_HANDLE),
|
switches |
0:0e018d759a2a
|
392
|
valueHandle(GattAttribute::INVALID_HANDLE),
|
switches |
0:0e018d759a2a
|
393
|
lastHandle(GattAttribute::INVALID_HANDLE),
|
switches |
0:0e018d759a2a
|
394
|
connHandle() {
|
switches |
0:0e018d759a2a
|
395
|
/* empty */
|
switches |
0:0e018d759a2a
|
396
|
}
|
switches |
0:0e018d759a2a
|
397
|
|
switches |
0:0e018d759a2a
|
398
|
protected:
|
switches |
0:0e018d759a2a
|
399
|
/**
|
switches |
0:0e018d759a2a
|
400
|
* Pointer to the underlying GattClient for this DiscoveredCharacteristic object.
|
switches |
0:0e018d759a2a
|
401
|
*/
|
switches |
0:0e018d759a2a
|
402
|
GattClient *gattc;
|
switches |
0:0e018d759a2a
|
403
|
|
switches |
0:0e018d759a2a
|
404
|
protected:
|
switches |
0:0e018d759a2a
|
405
|
/**
|
switches |
0:0e018d759a2a
|
406
|
* Discovered characteristic's UUID.
|
switches |
0:0e018d759a2a
|
407
|
*/
|
switches |
0:0e018d759a2a
|
408
|
UUID uuid;
|
switches |
0:0e018d759a2a
|
409
|
/**
|
switches |
0:0e018d759a2a
|
410
|
* Hold the configured properties of the discovered characteristic.
|
switches |
0:0e018d759a2a
|
411
|
* For more information refer to Properties_t.
|
switches |
0:0e018d759a2a
|
412
|
*/
|
switches |
0:0e018d759a2a
|
413
|
Properties_t props;
|
switches |
0:0e018d759a2a
|
414
|
/**
|
switches |
0:0e018d759a2a
|
415
|
* Value handle of the discovered characteristic's declaration attribute.
|
switches |
0:0e018d759a2a
|
416
|
*/
|
switches |
0:0e018d759a2a
|
417
|
GattAttribute::Handle_t declHandle;
|
switches |
0:0e018d759a2a
|
418
|
/**
|
switches |
0:0e018d759a2a
|
419
|
* Value handle of the discovered characteristic's value attribute.
|
switches |
0:0e018d759a2a
|
420
|
*/
|
switches |
0:0e018d759a2a
|
421
|
GattAttribute::Handle_t valueHandle;
|
switches |
0:0e018d759a2a
|
422
|
/**
|
switches |
0:0e018d759a2a
|
423
|
* Value handle of the discovered characteristic's last attribute.
|
switches |
0:0e018d759a2a
|
424
|
*/
|
switches |
0:0e018d759a2a
|
425
|
GattAttribute::Handle_t lastHandle;
|
switches |
0:0e018d759a2a
|
426
|
|
switches |
0:0e018d759a2a
|
427
|
/**
|
switches |
0:0e018d759a2a
|
428
|
* Handle for the connection where the characteristic was discovered.
|
switches |
0:0e018d759a2a
|
429
|
*/
|
switches |
0:0e018d759a2a
|
430
|
Gap::Handle_t connHandle;
|
switches |
0:0e018d759a2a
|
431
|
};
|
switches |
0:0e018d759a2a
|
432
|
|
switches |
0:0e018d759a2a
|
433
|
#endif /*__DISCOVERED_CHARACTERISTIC_H__*/
|