Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
ble/GattClient.h@1048:efb29faf12fc, 2016-01-11 (annotated)
- Committer:
- vcoubard
- Date:
- Mon Jan 11 08:51:28 2016 +0000
- Revision:
- 1048:efb29faf12fc
- Parent:
- 1047:2d66d38d9ac9
- Child:
- 1051:62b44b3be31b
Synchronized with git rev 08978591
Author: Vincent Coubard
Merge remote-tracking branch 'origin/develop' into descriptorDiscovery
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 716:11b41f651697 | 1 | /* mbed Microcontroller Library |
rgrover1 | 716:11b41f651697 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 716:11b41f651697 | 3 | * |
rgrover1 | 716:11b41f651697 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 716:11b41f651697 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 716:11b41f651697 | 6 | * You may obtain a copy of the License at |
rgrover1 | 716:11b41f651697 | 7 | * |
rgrover1 | 716:11b41f651697 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 716:11b41f651697 | 9 | * |
rgrover1 | 716:11b41f651697 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 716:11b41f651697 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 716:11b41f651697 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 716:11b41f651697 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 716:11b41f651697 | 14 | * limitations under the License. |
rgrover1 | 716:11b41f651697 | 15 | */ |
rgrover1 | 716:11b41f651697 | 16 | |
rgrover1 | 716:11b41f651697 | 17 | #ifndef __GATT_CLIENT_H__ |
rgrover1 | 716:11b41f651697 | 18 | #define __GATT_CLIENT_H__ |
rgrover1 | 716:11b41f651697 | 19 | |
rgrover1 | 716:11b41f651697 | 20 | #include "Gap.h" |
rgrover1 | 716:11b41f651697 | 21 | #include "GattAttribute.h" |
rgrover1 | 716:11b41f651697 | 22 | #include "ServiceDiscovery.h" |
vcoubard | 1045:b9d15970040f | 23 | #include "CharacteristicDescriptorDiscovery.h" |
rgrover1 | 716:11b41f651697 | 24 | |
rgrover1 | 716:11b41f651697 | 25 | #include "GattCallbackParamTypes.h" |
rgrover1 | 716:11b41f651697 | 26 | |
rgrover1 | 716:11b41f651697 | 27 | class GattClient { |
rgrover1 | 716:11b41f651697 | 28 | public: |
vcoubard | 1042:21a86ac7f5b1 | 29 | typedef void (*ReadCallback_t)(const GattReadCallbackParams *params); |
rgrover1 | 716:11b41f651697 | 30 | |
rgrover1 | 716:11b41f651697 | 31 | enum WriteOp_t { |
vcoubard | 1048:efb29faf12fc | 32 | GATT_OP_WRITE_REQ = 0x01, /**< Write request. */ |
vcoubard | 1048:efb29faf12fc | 33 | GATT_OP_WRITE_CMD = 0x02, /**< Write command. */ |
rgrover1 | 716:11b41f651697 | 34 | }; |
rgrover1 | 716:11b41f651697 | 35 | |
vcoubard | 1042:21a86ac7f5b1 | 36 | typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params); |
rgrover1 | 716:11b41f651697 | 37 | |
vcoubard | 1042:21a86ac7f5b1 | 38 | typedef void (*HVXCallback_t)(const GattHVXCallbackParams *params); |
rgrover1 | 737:79d95f9b93be | 39 | |
rgrover1 | 716:11b41f651697 | 40 | /* |
rgrover1 | 716:11b41f651697 | 41 | * The following functions are meant to be overridden in the platform-specific sub-class. |
rgrover1 | 716:11b41f651697 | 42 | */ |
rgrover1 | 716:11b41f651697 | 43 | public: |
rgrover1 | 716:11b41f651697 | 44 | /** |
rgrover1 | 728:997ba5e7b3b6 | 45 | * Launch service discovery. Once launched, application callbacks will be |
vcoubard | 1048:efb29faf12fc | 46 | * invoked for matching services or characteristics. isServiceDiscoveryActive() |
vcoubard | 1048:efb29faf12fc | 47 | * can be used to determine status, and a termination callback (if one was set up) |
vcoubard | 1048:efb29faf12fc | 48 | * will be invoked at the end. Service discovery can be terminated prematurely, |
vcoubard | 1048:efb29faf12fc | 49 | * if needed, using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 50 | * |
rgrover1 | 716:11b41f651697 | 51 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 52 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 53 | * @param sc |
vcoubard | 1048:efb29faf12fc | 54 | * This is the application callback for a matching service. Taken as |
rgrover1 | 716:11b41f651697 | 55 | * NULL by default. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 56 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 57 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 58 | * stack to abort service discovery. If this becomes an issue, it |
vcoubard | 1048:efb29faf12fc | 59 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 60 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 61 | * service. |
rgrover1 | 716:11b41f651697 | 62 | * @param cc |
vcoubard | 1048:efb29faf12fc | 63 | * This is the application callback for a matching characteristic. |
rgrover1 | 716:11b41f651697 | 64 | * Taken as NULL by default. Note: service discovery may still be |
rgrover1 | 716:11b41f651697 | 65 | * active when this callback is issued; calling asynchronous |
rgrover1 | 716:11b41f651697 | 66 | * BLE-stack APIs from within this application callback might cause |
rgrover1 | 716:11b41f651697 | 67 | * the stack to abort service discovery. If this becomes an issue, |
vcoubard | 1048:efb29faf12fc | 68 | * it may be better to make a local copy of the discoveredCharacteristic |
rgrover1 | 716:11b41f651697 | 69 | * and wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 70 | * characteristic. |
rgrover1 | 716:11b41f651697 | 71 | * @param matchingServiceUUID |
vcoubard | 1048:efb29faf12fc | 72 | * UUID-based filter for specifying a service in which the application is |
rgrover1 | 716:11b41f651697 | 73 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 716:11b41f651697 | 74 | * in which case it matches all services. If characteristic-UUID |
rgrover1 | 716:11b41f651697 | 75 | * filter (below) is set to the wildcard value, then a service |
rgrover1 | 716:11b41f651697 | 76 | * callback will be invoked for the matching service (or for every |
rgrover1 | 716:11b41f651697 | 77 | * service if the service filter is a wildcard). |
rgrover1 | 716:11b41f651697 | 78 | * @param matchingCharacteristicUUIDIn |
vcoubard | 1048:efb29faf12fc | 79 | * UUID-based filter for specifying characteristic in which the application |
rgrover1 | 716:11b41f651697 | 80 | * is interested. By default it is set as the wildcard UUID_UKNOWN |
rgrover1 | 716:11b41f651697 | 81 | * to match against any characteristic. If both service-UUID |
vcoubard | 1048:efb29faf12fc | 82 | * filter and characteristic-UUID filter are used with non-wildcard |
rgrover1 | 716:11b41f651697 | 83 | * values, then only a single characteristic callback is |
rgrover1 | 716:11b41f651697 | 84 | * invoked for the matching characteristic. |
rgrover1 | 716:11b41f651697 | 85 | * |
rgrover1 | 716:11b41f651697 | 86 | * @note Using wildcard values for both service-UUID and characteristic- |
vcoubard | 1048:efb29faf12fc | 87 | * UUID will result in complete service discovery: callbacks being |
rgrover1 | 716:11b41f651697 | 88 | * called for every service and characteristic. |
rgrover1 | 716:11b41f651697 | 89 | * |
rgrover1 | 716:11b41f651697 | 90 | * @note Providing NULL for the characteristic callback will result in |
rgrover1 | 716:11b41f651697 | 91 | * characteristic discovery being skipped for each matching |
rgrover1 | 716:11b41f651697 | 92 | * service. This allows for an inexpensive method to discover only |
rgrover1 | 716:11b41f651697 | 93 | * services. |
rgrover1 | 716:11b41f651697 | 94 | * |
rgrover1 | 716:11b41f651697 | 95 | * @return |
rgrover1 | 716:11b41f651697 | 96 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 97 | */ |
rgrover1 | 716:11b41f651697 | 98 | virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 99 | ServiceDiscovery::ServiceCallback_t sc = NULL, |
rgrover1 | 716:11b41f651697 | 100 | ServiceDiscovery::CharacteristicCallback_t cc = NULL, |
rgrover1 | 716:11b41f651697 | 101 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
rgrover1 | 716:11b41f651697 | 102 | const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
vcoubard | 1048:efb29faf12fc | 103 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 104 | (void)connectionHandle; |
rgrover1 | 734:4872b70437ce | 105 | (void)sc; |
rgrover1 | 734:4872b70437ce | 106 | (void)cc; |
rgrover1 | 734:4872b70437ce | 107 | (void)matchingServiceUUID; |
rgrover1 | 734:4872b70437ce | 108 | (void)matchingCharacteristicUUIDIn; |
rgrover1 | 734:4872b70437ce | 109 | |
vcoubard | 1048:efb29faf12fc | 110 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 111 | } |
rgrover1 | 716:11b41f651697 | 112 | |
rgrover1 | 716:11b41f651697 | 113 | /** |
rgrover1 | 716:11b41f651697 | 114 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 716:11b41f651697 | 115 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 716:11b41f651697 | 116 | * services. isServiceDiscoveryActive() can be used to |
vcoubard | 1048:efb29faf12fc | 117 | * determine status, and a termination callback (if set up) will be invoked |
vcoubard | 1048:efb29faf12fc | 118 | * at the end. Service discovery can be terminated prematurely, if needed, |
rgrover1 | 716:11b41f651697 | 119 | * using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 120 | * |
rgrover1 | 716:11b41f651697 | 121 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 122 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 123 | * @param sc |
vcoubard | 1048:efb29faf12fc | 124 | * This is the application callback for a matching service. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 125 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 126 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 127 | * stack to abort service discovery. If this becomes an issue, it |
vcoubard | 1048:efb29faf12fc | 128 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 129 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 130 | * service. |
rgrover1 | 716:11b41f651697 | 131 | * @param matchingServiceUUID |
vcoubard | 1048:efb29faf12fc | 132 | * UUID-based filter for specifying a service in which the application is |
rgrover1 | 716:11b41f651697 | 133 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 716:11b41f651697 | 134 | * in which case it matches all services. |
rgrover1 | 716:11b41f651697 | 135 | * |
rgrover1 | 716:11b41f651697 | 136 | * @return |
rgrover1 | 716:11b41f651697 | 137 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 138 | */ |
rgrover1 | 716:11b41f651697 | 139 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 140 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 716:11b41f651697 | 141 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
rgrover1 | 742:861ed7eb186d | 142 | return launchServiceDiscovery(connectionHandle, callback, NULL, matchingServiceUUID); /* We take advantage of the property |
rgrover1 | 742:861ed7eb186d | 143 | * that providing NULL for the characteristic callback will result in |
rgrover1 | 742:861ed7eb186d | 144 | * characteristic discovery being skipped for each matching |
rgrover1 | 742:861ed7eb186d | 145 | * service. This allows for an inexpensive method to discover only |
vcoubard | 1048:efb29faf12fc | 146 | * services. Porters are free to override this. */ |
rgrover1 | 716:11b41f651697 | 147 | } |
rgrover1 | 716:11b41f651697 | 148 | |
rgrover1 | 716:11b41f651697 | 149 | /** |
rgrover1 | 716:11b41f651697 | 150 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 716:11b41f651697 | 151 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 716:11b41f651697 | 152 | * services. isServiceDiscoveryActive() can be used to |
vcoubard | 1048:efb29faf12fc | 153 | * determine status, and a termination callback (if set up) will be invoked |
vcoubard | 1048:efb29faf12fc | 154 | * at the end. Service discovery can be terminated prematurely, if needed, |
rgrover1 | 716:11b41f651697 | 155 | * using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 156 | * |
rgrover1 | 716:11b41f651697 | 157 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 158 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 159 | * @param sc |
vcoubard | 1048:efb29faf12fc | 160 | * This is the application callback for a matching service. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 161 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 162 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 163 | * stack to abort service discovery. If this becomes an issue, it |
vcoubard | 1048:efb29faf12fc | 164 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 165 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 166 | * service. |
rgrover1 | 716:11b41f651697 | 167 | * @param startHandle, endHandle |
vcoubard | 1048:efb29faf12fc | 168 | * Handle range within which to limit the search. |
rgrover1 | 716:11b41f651697 | 169 | * |
rgrover1 | 716:11b41f651697 | 170 | * @return |
rgrover1 | 716:11b41f651697 | 171 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 172 | */ |
rgrover1 | 716:11b41f651697 | 173 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 174 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 716:11b41f651697 | 175 | GattAttribute::Handle_t startHandle, |
rgrover1 | 716:11b41f651697 | 176 | GattAttribute::Handle_t endHandle) { |
vcoubard | 1048:efb29faf12fc | 177 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 178 | (void)connectionHandle; |
rgrover1 | 734:4872b70437ce | 179 | (void)callback; |
rgrover1 | 734:4872b70437ce | 180 | (void)startHandle; |
rgrover1 | 734:4872b70437ce | 181 | (void)endHandle; |
rgrover1 | 734:4872b70437ce | 182 | |
vcoubard | 1048:efb29faf12fc | 183 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 184 | } |
rgrover1 | 716:11b41f651697 | 185 | |
rgrover1 | 716:11b41f651697 | 186 | /** |
rgrover1 | 716:11b41f651697 | 187 | * Is service-discovery currently active? |
rgrover1 | 716:11b41f651697 | 188 | */ |
rgrover1 | 716:11b41f651697 | 189 | virtual bool isServiceDiscoveryActive(void) const { |
vcoubard | 1048:efb29faf12fc | 190 | return false; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 191 | } |
rgrover1 | 716:11b41f651697 | 192 | |
rgrover1 | 716:11b41f651697 | 193 | /** |
vcoubard | 1048:efb29faf12fc | 194 | * Terminate an ongoing service discovery. This should result in an |
vcoubard | 1048:efb29faf12fc | 195 | * invocation of TerminationCallback if service-discovery is active. |
rgrover1 | 716:11b41f651697 | 196 | */ |
rgrover1 | 716:11b41f651697 | 197 | virtual void terminateServiceDiscovery(void) { |
vcoubard | 1048:efb29faf12fc | 198 | /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 199 | } |
rgrover1 | 716:11b41f651697 | 200 | |
vcoubard | 1048:efb29faf12fc | 201 | /* Initiate a GATT Client read procedure by attribute-handle. */ |
rgrover1 | 716:11b41f651697 | 202 | virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const { |
vcoubard | 1048:efb29faf12fc | 203 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 204 | (void)connHandle; |
rgrover1 | 734:4872b70437ce | 205 | (void)attributeHandle; |
rgrover1 | 734:4872b70437ce | 206 | (void)offset; |
rgrover1 | 734:4872b70437ce | 207 | |
vcoubard | 1048:efb29faf12fc | 208 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 209 | } |
rgrover1 | 716:11b41f651697 | 210 | |
rgrover1 | 716:11b41f651697 | 211 | /** |
rgrover1 | 716:11b41f651697 | 212 | * Initiate a GATT Client write procedure. |
rgrover1 | 716:11b41f651697 | 213 | * |
rgrover1 | 716:11b41f651697 | 214 | * @param[in] cmd |
vcoubard | 1048:efb29faf12fc | 215 | * Command can be either a write-request (which generates a |
vcoubard | 1048:efb29faf12fc | 216 | * matching response from the peripheral), or a write-command |
vcoubard | 1048:efb29faf12fc | 217 | * (which doesn't require the connected peer to respond). |
rgrover1 | 716:11b41f651697 | 218 | * @param[in] connHandle |
rgrover1 | 716:11b41f651697 | 219 | * Connection handle. |
rgrover1 | 716:11b41f651697 | 220 | * @param[in] attributeHandle |
vcoubard | 1048:efb29faf12fc | 221 | * Handle for the target attribtue on the remote GATT server. |
rgrover1 | 716:11b41f651697 | 222 | * @param[in] length |
vcoubard | 1048:efb29faf12fc | 223 | * Length of the new value. |
rgrover1 | 716:11b41f651697 | 224 | * @param[in] value |
vcoubard | 1048:efb29faf12fc | 225 | * New value being written. |
rgrover1 | 716:11b41f651697 | 226 | */ |
rgrover1 | 716:11b41f651697 | 227 | virtual ble_error_t write(GattClient::WriteOp_t cmd, |
rgrover1 | 716:11b41f651697 | 228 | Gap::Handle_t connHandle, |
rgrover1 | 716:11b41f651697 | 229 | GattAttribute::Handle_t attributeHandle, |
rgrover1 | 716:11b41f651697 | 230 | size_t length, |
rgrover1 | 716:11b41f651697 | 231 | const uint8_t *value) const { |
vcoubard | 1048:efb29faf12fc | 232 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 233 | (void)cmd; |
rgrover1 | 734:4872b70437ce | 234 | (void)connHandle; |
rgrover1 | 734:4872b70437ce | 235 | (void)attributeHandle; |
rgrover1 | 734:4872b70437ce | 236 | (void)length; |
rgrover1 | 734:4872b70437ce | 237 | (void)value; |
rgrover1 | 734:4872b70437ce | 238 | |
vcoubard | 1048:efb29faf12fc | 239 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 728:997ba5e7b3b6 | 240 | } |
rgrover1 | 728:997ba5e7b3b6 | 241 | |
rgrover1 | 728:997ba5e7b3b6 | 242 | /* Event callback handlers. */ |
rgrover1 | 728:997ba5e7b3b6 | 243 | public: |
rgrover1 | 728:997ba5e7b3b6 | 244 | /** |
vcoubard | 1048:efb29faf12fc | 245 | * Set up a callback for read response events. |
rgrover1 | 728:997ba5e7b3b6 | 246 | */ |
rgrover1 | 728:997ba5e7b3b6 | 247 | void onDataRead(ReadCallback_t callback) { |
vcoubard | 1042:21a86ac7f5b1 | 248 | onDataReadCallback = callback; |
rgrover1 | 728:997ba5e7b3b6 | 249 | } |
rgrover1 | 728:997ba5e7b3b6 | 250 | |
rgrover1 | 728:997ba5e7b3b6 | 251 | /** |
vcoubard | 1048:efb29faf12fc | 252 | * Set up a callback for write response events. |
vcoubard | 1048:efb29faf12fc | 253 | * @Note: Write commands (issued using writeWoResponse) don't generate a response. |
rgrover1 | 728:997ba5e7b3b6 | 254 | */ |
rgrover1 | 768:8914bea92690 | 255 | void onDataWritten(WriteCallback_t callback) { |
vcoubard | 1042:21a86ac7f5b1 | 256 | onDataWriteCallback = callback; |
rgrover1 | 990:53ac0ac3aa39 | 257 | } |
rgrover1 | 990:53ac0ac3aa39 | 258 | |
rgrover1 | 990:53ac0ac3aa39 | 259 | /** |
vcoubard | 1048:efb29faf12fc | 260 | * Set up a callback for write response events. |
vcoubard | 1048:efb29faf12fc | 261 | * @Note: Write commands (issued using writeWoResponse) don't generate a response. |
rgrover1 | 768:8914bea92690 | 262 | * |
rgrover1 | 768:8914bea92690 | 263 | * @note: This API is now *deprecated* and will be dropped in the future. |
rgrover1 | 768:8914bea92690 | 264 | * Please use onDataWritten() instead. |
rgrover1 | 768:8914bea92690 | 265 | */ |
rgrover1 | 728:997ba5e7b3b6 | 266 | void onDataWrite(WriteCallback_t callback) { |
rgrover1 | 768:8914bea92690 | 267 | onDataWritten(callback); |
rgrover1 | 720:ce8a760a4504 | 268 | } |
rgrover1 | 720:ce8a760a4504 | 269 | |
rgrover1 | 716:11b41f651697 | 270 | /** |
vcoubard | 1048:efb29faf12fc | 271 | * Set up a callback for when serviceDiscovery terminates. |
rgrover1 | 716:11b41f651697 | 272 | */ |
rgrover1 | 716:11b41f651697 | 273 | virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { |
vcoubard | 1048:efb29faf12fc | 274 | (void)callback; /* Avoid compiler warnings about ununsed variables. */ |
rgrover1 | 734:4872b70437ce | 275 | |
vcoubard | 1048:efb29faf12fc | 276 | /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 277 | } |
rgrover1 | 716:11b41f651697 | 278 | |
rgrover1 | 737:79d95f9b93be | 279 | /** |
vcoubard | 1045:b9d15970040f | 280 | * @brief launch discovery of descriptors for a given characteristic |
vcoubard | 1045:b9d15970040f | 281 | * @details This function will discover all descriptors available for a |
vcoubard | 1045:b9d15970040f | 282 | * specific characteristic. |
vcoubard | 1045:b9d15970040f | 283 | * |
vcoubard | 1045:b9d15970040f | 284 | * @param characteristic The characteristic targeted by this discovery |
vcoubard | 1045:b9d15970040f | 285 | * @param callback This is the application callback for each descriptors |
vcoubard | 1045:b9d15970040f | 286 | * found. |
vcoubard | 1045:b9d15970040f | 287 | * @note service discovery may still be active when the callback is issued; |
vcoubard | 1045:b9d15970040f | 288 | * calling asynchronous BLE-stack APIs from within this application callback |
vcoubard | 1045:b9d15970040f | 289 | * might cause the stack to abort the discovery. If this becomes an issue, |
vcoubard | 1045:b9d15970040f | 290 | * it may be better to make local copy of the DiscoveredCharacteristicDescriptor |
vcoubard | 1045:b9d15970040f | 291 | * and wait for characteristic descriptor discovery to terminate before |
vcoubard | 1045:b9d15970040f | 292 | * operating on the descriptor. |
vcoubard | 1045:b9d15970040f | 293 | * |
vcoubard | 1045:b9d15970040f | 294 | * @return |
vcoubard | 1045:b9d15970040f | 295 | * BLE_ERROR_NONE if characteristic descriptor discovery is launched |
vcoubard | 1045:b9d15970040f | 296 | * successfully; else an appropriate error. |
vcoubard | 1045:b9d15970040f | 297 | */ |
vcoubard | 1045:b9d15970040f | 298 | virtual ble_error_t discoverCharacteristicDescriptors( |
vcoubard | 1045:b9d15970040f | 299 | const DiscoveredCharacteristic& characteristic, |
vcoubard | 1047:2d66d38d9ac9 | 300 | const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback, |
vcoubard | 1047:2d66d38d9ac9 | 301 | const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback) { |
vcoubard | 1045:b9d15970040f | 302 | (void) characteristic; |
vcoubard | 1045:b9d15970040f | 303 | (void) discoveryCallback; |
vcoubard | 1045:b9d15970040f | 304 | (void) terminationCallback; |
vcoubard | 1045:b9d15970040f | 305 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1045:b9d15970040f | 306 | } |
vcoubard | 1045:b9d15970040f | 307 | |
vcoubard | 1045:b9d15970040f | 308 | /** |
vcoubard | 1045:b9d15970040f | 309 | * Is characteristic descriptor discovery currently active? |
vcoubard | 1045:b9d15970040f | 310 | */ |
vcoubard | 1045:b9d15970040f | 311 | virtual bool isCharacteristicDiscoveryActive(const DiscoveredCharacteristic& characteristic) const { |
vcoubard | 1045:b9d15970040f | 312 | (void) characteristic; |
vcoubard | 1045:b9d15970040f | 313 | return false; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1045:b9d15970040f | 314 | } |
vcoubard | 1045:b9d15970040f | 315 | |
vcoubard | 1045:b9d15970040f | 316 | /** |
vcoubard | 1045:b9d15970040f | 317 | * Terminate an ongoing characteristic descriptor discovery. This should result |
vcoubard | 1045:b9d15970040f | 318 | * in an invocation of the TerminationCallback if characteristic descriptor discovery is active. |
vcoubard | 1045:b9d15970040f | 319 | */ |
vcoubard | 1045:b9d15970040f | 320 | virtual void terminateCharacteristicDiscovery(const DiscoveredCharacteristic& characteristic) { |
vcoubard | 1045:b9d15970040f | 321 | /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1045:b9d15970040f | 322 | (void) characteristic; |
vcoubard | 1045:b9d15970040f | 323 | } |
vcoubard | 1045:b9d15970040f | 324 | |
vcoubard | 1045:b9d15970040f | 325 | /** |
vcoubard | 1048:efb29faf12fc | 326 | * Set up a callback for when the GATT client receives an update event |
vcoubard | 1048:efb29faf12fc | 327 | * corresponding to a change in the value of a characteristic on the remote |
vcoubard | 1048:efb29faf12fc | 328 | * GATT server. |
rgrover1 | 737:79d95f9b93be | 329 | */ |
rgrover1 | 737:79d95f9b93be | 330 | void onHVX(HVXCallback_t callback) { |
vcoubard | 1042:21a86ac7f5b1 | 331 | onHVXCallback = callback; |
rgrover1 | 737:79d95f9b93be | 332 | } |
rgrover1 | 737:79d95f9b93be | 333 | |
rgrover1 | 716:11b41f651697 | 334 | protected: |
rgrover1 | 716:11b41f651697 | 335 | GattClient() { |
vcoubard | 1048:efb29faf12fc | 336 | /* Empty */ |
rgrover1 | 716:11b41f651697 | 337 | } |
rgrover1 | 716:11b41f651697 | 338 | |
rgrover1 | 728:997ba5e7b3b6 | 339 | /* Entry points for the underlying stack to report events back to the user. */ |
rgrover1 | 728:997ba5e7b3b6 | 340 | public: |
rgrover1 | 728:997ba5e7b3b6 | 341 | void processReadResponse(const GattReadCallbackParams *params) { |
vcoubard | 1042:21a86ac7f5b1 | 342 | if (onDataReadCallback) { |
vcoubard | 1042:21a86ac7f5b1 | 343 | onDataReadCallback(params); |
vcoubard | 1042:21a86ac7f5b1 | 344 | } |
rgrover1 | 728:997ba5e7b3b6 | 345 | } |
rgrover1 | 728:997ba5e7b3b6 | 346 | |
rgrover1 | 728:997ba5e7b3b6 | 347 | void processWriteResponse(const GattWriteCallbackParams *params) { |
vcoubard | 1042:21a86ac7f5b1 | 348 | if (onDataWriteCallback) { |
vcoubard | 1042:21a86ac7f5b1 | 349 | onDataWriteCallback(params); |
vcoubard | 1042:21a86ac7f5b1 | 350 | } |
rgrover1 | 728:997ba5e7b3b6 | 351 | } |
rgrover1 | 728:997ba5e7b3b6 | 352 | |
rgrover1 | 737:79d95f9b93be | 353 | void processHVXEvent(const GattHVXCallbackParams *params) { |
vcoubard | 1042:21a86ac7f5b1 | 354 | if (onHVXCallback) { |
vcoubard | 1042:21a86ac7f5b1 | 355 | onHVXCallback(params); |
rgrover1 | 737:79d95f9b93be | 356 | } |
rgrover1 | 737:79d95f9b93be | 357 | } |
rgrover1 | 737:79d95f9b93be | 358 | |
rgrover1 | 728:997ba5e7b3b6 | 359 | protected: |
vcoubard | 1042:21a86ac7f5b1 | 360 | ReadCallback_t onDataReadCallback; |
vcoubard | 1042:21a86ac7f5b1 | 361 | WriteCallback_t onDataWriteCallback; |
vcoubard | 1042:21a86ac7f5b1 | 362 | HVXCallback_t onHVXCallback; |
rgrover1 | 728:997ba5e7b3b6 | 363 | |
rgrover1 | 716:11b41f651697 | 364 | private: |
vcoubard | 1048:efb29faf12fc | 365 | /* Disallow copy and assignment. */ |
rgrover1 | 716:11b41f651697 | 366 | GattClient(const GattClient &); |
rgrover1 | 716:11b41f651697 | 367 | GattClient& operator=(const GattClient &); |
rgrover1 | 716:11b41f651697 | 368 | }; |
rgrover1 | 716:11b41f651697 | 369 | |
rgrover1 | 716:11b41f651697 | 370 | #endif // ifndef __GATT_CLIENT_H__ |