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