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