Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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