test
Dependents: BLE_PowerBank_HeyFaradey
Fork of BLE_API by
ble/GattClient.h@935:e9b595e6b0ed, 2015-11-26 (annotated)
- Committer:
- rgrover1
- Date:
- Thu Nov 26 12:52:06 2015 +0000
- Revision:
- 935:e9b595e6b0ed
- Parent:
- 934:5e3acddfcd82
- Child:
- 937:4932e700daf2
Synchronized with git rev 561358bd
Author: Irit Arkin
Minor edits
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" |
rgrover1 | 716:11b41f651697 | 23 | |
rgrover1 | 716:11b41f651697 | 24 | #include "GattCallbackParamTypes.h" |
rgrover1 | 716:11b41f651697 | 25 | |
rgrover1 | 716:11b41f651697 | 26 | class GattClient { |
rgrover1 | 716:11b41f651697 | 27 | public: |
rgrover1 | 933:3ec277a0d780 | 28 | typedef void (*ReadCallback_t)(const GattReadCallbackParams *params); |
rgrover1 | 716:11b41f651697 | 29 | |
rgrover1 | 716:11b41f651697 | 30 | enum WriteOp_t { |
rgrover1 | 935:e9b595e6b0ed | 31 | GATT_OP_WRITE_REQ = 0x01, /**< Write Request. */ |
rgrover1 | 935:e9b595e6b0ed | 32 | GATT_OP_WRITE_CMD = 0x02, /**< Write Command. */ |
rgrover1 | 716:11b41f651697 | 33 | }; |
rgrover1 | 716:11b41f651697 | 34 | |
rgrover1 | 933:3ec277a0d780 | 35 | typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params); |
rgrover1 | 716:11b41f651697 | 36 | |
rgrover1 | 933:3ec277a0d780 | 37 | typedef void (*HVXCallback_t)(const GattHVXCallbackParams *params); |
rgrover1 | 737:79d95f9b93be | 38 | |
rgrover1 | 716:11b41f651697 | 39 | /* |
rgrover1 | 716:11b41f651697 | 40 | * The following functions are meant to be overridden in the platform-specific sub-class. |
rgrover1 | 716:11b41f651697 | 41 | */ |
rgrover1 | 716:11b41f651697 | 42 | public: |
rgrover1 | 716:11b41f651697 | 43 | /** |
rgrover1 | 728:997ba5e7b3b6 | 44 | * Launch service discovery. Once launched, application callbacks will be |
rgrover1 | 935:e9b595e6b0ed | 45 | * invoked for matching services/characteristics. isServiceDiscoveryActive() |
rgrover1 | 935:e9b595e6b0ed | 46 | * can be used to determine status; and a termination callback (if setup) |
rgrover1 | 935:e9b595e6b0ed | 47 | * will be invoked at the end. Service discovery can be terminated prematurely |
rgrover1 | 935:e9b595e6b0ed | 48 | * if needed using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 49 | * |
rgrover1 | 716:11b41f651697 | 50 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 51 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 52 | * @param sc |
rgrover1 | 935:e9b595e6b0ed | 53 | * This is the application callback for matching service. Taken as |
rgrover1 | 716:11b41f651697 | 54 | * NULL by default. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 55 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 56 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 57 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 935:e9b595e6b0ed | 58 | * may be better to make local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 59 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 60 | * service. |
rgrover1 | 716:11b41f651697 | 61 | * @param cc |
rgrover1 | 935:e9b595e6b0ed | 62 | * This is the application callback for matching characteristic. |
rgrover1 | 716:11b41f651697 | 63 | * Taken as NULL by default. Note: service discovery may still be |
rgrover1 | 716:11b41f651697 | 64 | * active when this callback is issued; calling asynchronous |
rgrover1 | 716:11b41f651697 | 65 | * BLE-stack APIs from within this application callback might cause |
rgrover1 | 716:11b41f651697 | 66 | * the stack to abort service discovery. If this becomes an issue, |
rgrover1 | 935:e9b595e6b0ed | 67 | * it may be better to make local copy of the discoveredCharacteristic |
rgrover1 | 716:11b41f651697 | 68 | * and wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 69 | * characteristic. |
rgrover1 | 716:11b41f651697 | 70 | * @param matchingServiceUUID |
rgrover1 | 935:e9b595e6b0ed | 71 | * UUID based filter for specifying a service in which the application is |
rgrover1 | 716:11b41f651697 | 72 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 716:11b41f651697 | 73 | * in which case it matches all services. If characteristic-UUID |
rgrover1 | 716:11b41f651697 | 74 | * filter (below) is set to the wildcard value, then a service |
rgrover1 | 716:11b41f651697 | 75 | * callback will be invoked for the matching service (or for every |
rgrover1 | 716:11b41f651697 | 76 | * service if the service filter is a wildcard). |
rgrover1 | 716:11b41f651697 | 77 | * @param matchingCharacteristicUUIDIn |
rgrover1 | 935:e9b595e6b0ed | 78 | * UUID based filter for specifying characteristic in which the application |
rgrover1 | 716:11b41f651697 | 79 | * is interested. By default it is set as the wildcard UUID_UKNOWN |
rgrover1 | 716:11b41f651697 | 80 | * to match against any characteristic. If both service-UUID |
rgrover1 | 935:e9b595e6b0ed | 81 | * filter and characteristic-UUID filter are used with non- wildcard |
rgrover1 | 716:11b41f651697 | 82 | * values, then only a single characteristic callback is |
rgrover1 | 716:11b41f651697 | 83 | * invoked for the matching characteristic. |
rgrover1 | 716:11b41f651697 | 84 | * |
rgrover1 | 716:11b41f651697 | 85 | * @note Using wildcard values for both service-UUID and characteristic- |
rgrover1 | 935:e9b595e6b0ed | 86 | * UUID will result in complete service discovery--callbacks being |
rgrover1 | 716:11b41f651697 | 87 | * called for every service and characteristic. |
rgrover1 | 716:11b41f651697 | 88 | * |
rgrover1 | 716:11b41f651697 | 89 | * @note Providing NULL for the characteristic callback will result in |
rgrover1 | 716:11b41f651697 | 90 | * characteristic discovery being skipped for each matching |
rgrover1 | 716:11b41f651697 | 91 | * service. This allows for an inexpensive method to discover only |
rgrover1 | 716:11b41f651697 | 92 | * services. |
rgrover1 | 716:11b41f651697 | 93 | * |
rgrover1 | 716:11b41f651697 | 94 | * @return |
rgrover1 | 716:11b41f651697 | 95 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 96 | */ |
rgrover1 | 716:11b41f651697 | 97 | virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 98 | ServiceDiscovery::ServiceCallback_t sc = NULL, |
rgrover1 | 716:11b41f651697 | 99 | ServiceDiscovery::CharacteristicCallback_t cc = NULL, |
rgrover1 | 716:11b41f651697 | 100 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
rgrover1 | 716:11b41f651697 | 101 | const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
rgrover1 | 935:e9b595e6b0ed | 102 | /* avoid compiler warnings about unused variables */ |
rgrover1 | 734:4872b70437ce | 103 | (void)connectionHandle; |
rgrover1 | 734:4872b70437ce | 104 | (void)sc; |
rgrover1 | 734:4872b70437ce | 105 | (void)cc; |
rgrover1 | 734:4872b70437ce | 106 | (void)matchingServiceUUID; |
rgrover1 | 734:4872b70437ce | 107 | (void)matchingCharacteristicUUIDIn; |
rgrover1 | 734:4872b70437ce | 108 | |
rgrover1 | 935:e9b595e6b0ed | 109 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 110 | } |
rgrover1 | 716:11b41f651697 | 111 | |
rgrover1 | 716:11b41f651697 | 112 | /** |
rgrover1 | 716:11b41f651697 | 113 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 716:11b41f651697 | 114 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 716:11b41f651697 | 115 | * services. isServiceDiscoveryActive() can be used to |
rgrover1 | 935:e9b595e6b0ed | 116 | * determine status; and a termination callback (if setup) will be invoked |
rgrover1 | 935:e9b595e6b0ed | 117 | * at the end. Service discovery can be terminated prematurely if needed |
rgrover1 | 716:11b41f651697 | 118 | * using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 119 | * |
rgrover1 | 716:11b41f651697 | 120 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 121 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 122 | * @param sc |
rgrover1 | 935:e9b595e6b0ed | 123 | * This is the application callback for matching service. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 124 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 125 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 126 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 935:e9b595e6b0ed | 127 | * may be better to make local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 128 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 129 | * service. |
rgrover1 | 716:11b41f651697 | 130 | * @param matchingServiceUUID |
rgrover1 | 935:e9b595e6b0ed | 131 | * UUID based filter for specifying a service in which the application is |
rgrover1 | 716:11b41f651697 | 132 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 716:11b41f651697 | 133 | * in which case it matches all services. |
rgrover1 | 716:11b41f651697 | 134 | * |
rgrover1 | 716:11b41f651697 | 135 | * @return |
rgrover1 | 716:11b41f651697 | 136 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 137 | */ |
rgrover1 | 716:11b41f651697 | 138 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 139 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 716:11b41f651697 | 140 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
rgrover1 | 742:861ed7eb186d | 141 | return launchServiceDiscovery(connectionHandle, callback, NULL, matchingServiceUUID); /* We take advantage of the property |
rgrover1 | 742:861ed7eb186d | 142 | * that providing NULL for the characteristic callback will result in |
rgrover1 | 742:861ed7eb186d | 143 | * characteristic discovery being skipped for each matching |
rgrover1 | 742:861ed7eb186d | 144 | * service. This allows for an inexpensive method to discover only |
rgrover1 | 935:e9b595e6b0ed | 145 | * services. Porter(s) are free to override this. */ |
rgrover1 | 716:11b41f651697 | 146 | } |
rgrover1 | 716:11b41f651697 | 147 | |
rgrover1 | 716:11b41f651697 | 148 | /** |
rgrover1 | 716:11b41f651697 | 149 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 716:11b41f651697 | 150 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 716:11b41f651697 | 151 | * services. isServiceDiscoveryActive() can be used to |
rgrover1 | 935:e9b595e6b0ed | 152 | * determine status; and a termination callback (if setup) will be invoked |
rgrover1 | 935:e9b595e6b0ed | 153 | * at the end. Service discovery can be terminated prematurely if needed |
rgrover1 | 716:11b41f651697 | 154 | * using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 155 | * |
rgrover1 | 716:11b41f651697 | 156 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 157 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 158 | * @param sc |
rgrover1 | 935:e9b595e6b0ed | 159 | * This is the application callback for matching service. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 160 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 161 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 162 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 935:e9b595e6b0ed | 163 | * may be better to make local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 164 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 165 | * service. |
rgrover1 | 716:11b41f651697 | 166 | * @param startHandle, endHandle |
rgrover1 | 935:e9b595e6b0ed | 167 | * Handle range within which to limit the search |
rgrover1 | 716:11b41f651697 | 168 | * |
rgrover1 | 716:11b41f651697 | 169 | * @return |
rgrover1 | 716:11b41f651697 | 170 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 171 | */ |
rgrover1 | 716:11b41f651697 | 172 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 173 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 716:11b41f651697 | 174 | GattAttribute::Handle_t startHandle, |
rgrover1 | 716:11b41f651697 | 175 | GattAttribute::Handle_t endHandle) { |
rgrover1 | 935:e9b595e6b0ed | 176 | /* avoid compiler warnings about unused variables */ |
rgrover1 | 734:4872b70437ce | 177 | (void)connectionHandle; |
rgrover1 | 734:4872b70437ce | 178 | (void)callback; |
rgrover1 | 734:4872b70437ce | 179 | (void)startHandle; |
rgrover1 | 734:4872b70437ce | 180 | (void)endHandle; |
rgrover1 | 734:4872b70437ce | 181 | |
rgrover1 | 935:e9b595e6b0ed | 182 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 183 | } |
rgrover1 | 716:11b41f651697 | 184 | |
rgrover1 | 716:11b41f651697 | 185 | /** |
rgrover1 | 716:11b41f651697 | 186 | * Is service-discovery currently active? |
rgrover1 | 716:11b41f651697 | 187 | */ |
rgrover1 | 716:11b41f651697 | 188 | virtual bool isServiceDiscoveryActive(void) const { |
rgrover1 | 935:e9b595e6b0ed | 189 | return false; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 190 | } |
rgrover1 | 716:11b41f651697 | 191 | |
rgrover1 | 716:11b41f651697 | 192 | /** |
rgrover1 | 935:e9b595e6b0ed | 193 | * Terminate an ongoing service-discovery. This should result in an |
rgrover1 | 935:e9b595e6b0ed | 194 | * invocation of the TerminationCallback if service-discovery is active. |
rgrover1 | 716:11b41f651697 | 195 | */ |
rgrover1 | 716:11b41f651697 | 196 | virtual void terminateServiceDiscovery(void) { |
rgrover1 | 935:e9b595e6b0ed | 197 | /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 198 | } |
rgrover1 | 716:11b41f651697 | 199 | |
rgrover1 | 935:e9b595e6b0ed | 200 | /* Initiate a Gatt Client read procedure by attribute-handle. */ |
rgrover1 | 716:11b41f651697 | 201 | virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const { |
rgrover1 | 935:e9b595e6b0ed | 202 | /* avoid compiler warnings about unused variables */ |
rgrover1 | 734:4872b70437ce | 203 | (void)connHandle; |
rgrover1 | 734:4872b70437ce | 204 | (void)attributeHandle; |
rgrover1 | 734:4872b70437ce | 205 | (void)offset; |
rgrover1 | 734:4872b70437ce | 206 | |
rgrover1 | 935:e9b595e6b0ed | 207 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 208 | } |
rgrover1 | 716:11b41f651697 | 209 | |
rgrover1 | 716:11b41f651697 | 210 | /** |
rgrover1 | 716:11b41f651697 | 211 | * Initiate a GATT Client write procedure. |
rgrover1 | 716:11b41f651697 | 212 | * |
rgrover1 | 716:11b41f651697 | 213 | * @param[in] cmd |
rgrover1 | 935:e9b595e6b0ed | 214 | * Command can be either a write-request (which generates a |
rgrover1 | 935:e9b595e6b0ed | 215 | * matching response from the peripheral), or a write-command, |
rgrover1 | 935:e9b595e6b0ed | 216 | * which doesn't require the connected peer to respond. |
rgrover1 | 716:11b41f651697 | 217 | * @param[in] connHandle |
rgrover1 | 716:11b41f651697 | 218 | * Connection handle. |
rgrover1 | 716:11b41f651697 | 219 | * @param[in] attributeHandle |
rgrover1 | 935:e9b595e6b0ed | 220 | * handle for the target attribtue on the remote GATT server. |
rgrover1 | 716:11b41f651697 | 221 | * @param[in] length |
rgrover1 | 935:e9b595e6b0ed | 222 | * length of the new value. |
rgrover1 | 716:11b41f651697 | 223 | * @param[in] value |
rgrover1 | 935:e9b595e6b0ed | 224 | * new value being written. |
rgrover1 | 716:11b41f651697 | 225 | */ |
rgrover1 | 716:11b41f651697 | 226 | virtual ble_error_t write(GattClient::WriteOp_t cmd, |
rgrover1 | 716:11b41f651697 | 227 | Gap::Handle_t connHandle, |
rgrover1 | 716:11b41f651697 | 228 | GattAttribute::Handle_t attributeHandle, |
rgrover1 | 716:11b41f651697 | 229 | size_t length, |
rgrover1 | 716:11b41f651697 | 230 | const uint8_t *value) const { |
rgrover1 | 935:e9b595e6b0ed | 231 | /* avoid compiler warnings about unused variables */ |
rgrover1 | 734:4872b70437ce | 232 | (void)cmd; |
rgrover1 | 734:4872b70437ce | 233 | (void)connHandle; |
rgrover1 | 734:4872b70437ce | 234 | (void)attributeHandle; |
rgrover1 | 734:4872b70437ce | 235 | (void)length; |
rgrover1 | 734:4872b70437ce | 236 | (void)value; |
rgrover1 | 734:4872b70437ce | 237 | |
rgrover1 | 935:e9b595e6b0ed | 238 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 728:997ba5e7b3b6 | 239 | } |
rgrover1 | 728:997ba5e7b3b6 | 240 | |
rgrover1 | 728:997ba5e7b3b6 | 241 | /* Event callback handlers. */ |
rgrover1 | 728:997ba5e7b3b6 | 242 | public: |
rgrover1 | 728:997ba5e7b3b6 | 243 | /** |
rgrover1 | 935:e9b595e6b0ed | 244 | * Setup a callback for read response events. |
rgrover1 | 728:997ba5e7b3b6 | 245 | */ |
rgrover1 | 728:997ba5e7b3b6 | 246 | void onDataRead(ReadCallback_t callback) { |
rgrover1 | 933:3ec277a0d780 | 247 | onDataReadCallback = callback; |
rgrover1 | 728:997ba5e7b3b6 | 248 | } |
rgrover1 | 728:997ba5e7b3b6 | 249 | |
rgrover1 | 728:997ba5e7b3b6 | 250 | /** |
rgrover1 | 935:e9b595e6b0ed | 251 | * Setup a callback for write response events. |
rgrover1 | 935:e9b595e6b0ed | 252 | * @Note: write commands (issued using writeWoResponse) don't generate a response. |
rgrover1 | 728:997ba5e7b3b6 | 253 | */ |
rgrover1 | 768:8914bea92690 | 254 | void onDataWritten(WriteCallback_t callback) { |
rgrover1 | 933:3ec277a0d780 | 255 | onDataWriteCallback = callback; |
rgrover1 | 768:8914bea92690 | 256 | } |
rgrover1 | 768:8914bea92690 | 257 | |
rgrover1 | 768:8914bea92690 | 258 | /** |
rgrover1 | 935:e9b595e6b0ed | 259 | * Setup a callback for write response events. |
rgrover1 | 935:e9b595e6b0ed | 260 | * @Note: write commands (issued using writeWoResponse) don't generate a response. |
rgrover1 | 768:8914bea92690 | 261 | * |
rgrover1 | 768:8914bea92690 | 262 | * @note: This API is now *deprecated* and will be dropped in the future. |
rgrover1 | 768:8914bea92690 | 263 | * Please use onDataWritten() instead. |
rgrover1 | 768:8914bea92690 | 264 | */ |
rgrover1 | 728:997ba5e7b3b6 | 265 | void onDataWrite(WriteCallback_t callback) { |
rgrover1 | 768:8914bea92690 | 266 | onDataWritten(callback); |
rgrover1 | 720:ce8a760a4504 | 267 | } |
rgrover1 | 720:ce8a760a4504 | 268 | |
rgrover1 | 716:11b41f651697 | 269 | /** |
rgrover1 | 935:e9b595e6b0ed | 270 | * Setup callback for when serviceDiscovery terminates. |
rgrover1 | 716:11b41f651697 | 271 | */ |
rgrover1 | 716:11b41f651697 | 272 | virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { |
rgrover1 | 935:e9b595e6b0ed | 273 | (void)callback; /* avoid compiler warnings about ununsed variables */ |
rgrover1 | 734:4872b70437ce | 274 | |
rgrover1 | 935:e9b595e6b0ed | 275 | /* Requesting action from porter(s): override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 276 | } |
rgrover1 | 716:11b41f651697 | 277 | |
rgrover1 | 737:79d95f9b93be | 278 | /** |
rgrover1 | 935:e9b595e6b0ed | 279 | * Setup a callback for when GattClient receives an update event |
rgrover1 | 935:e9b595e6b0ed | 280 | * corresponding to a change in value of a characteristic on the remote |
rgrover1 | 935:e9b595e6b0ed | 281 | * GattServer. |
rgrover1 | 737:79d95f9b93be | 282 | */ |
rgrover1 | 737:79d95f9b93be | 283 | void onHVX(HVXCallback_t callback) { |
rgrover1 | 933:3ec277a0d780 | 284 | onHVXCallback = callback; |
rgrover1 | 737:79d95f9b93be | 285 | } |
rgrover1 | 737:79d95f9b93be | 286 | |
rgrover1 | 716:11b41f651697 | 287 | protected: |
rgrover1 | 716:11b41f651697 | 288 | GattClient() { |
rgrover1 | 935:e9b595e6b0ed | 289 | /* empty */ |
rgrover1 | 716:11b41f651697 | 290 | } |
rgrover1 | 716:11b41f651697 | 291 | |
rgrover1 | 728:997ba5e7b3b6 | 292 | /* Entry points for the underlying stack to report events back to the user. */ |
rgrover1 | 728:997ba5e7b3b6 | 293 | public: |
rgrover1 | 728:997ba5e7b3b6 | 294 | void processReadResponse(const GattReadCallbackParams *params) { |
rgrover1 | 933:3ec277a0d780 | 295 | if (onDataReadCallback) { |
rgrover1 | 933:3ec277a0d780 | 296 | onDataReadCallback(params); |
rgrover1 | 933:3ec277a0d780 | 297 | } |
rgrover1 | 728:997ba5e7b3b6 | 298 | } |
rgrover1 | 728:997ba5e7b3b6 | 299 | |
rgrover1 | 728:997ba5e7b3b6 | 300 | void processWriteResponse(const GattWriteCallbackParams *params) { |
rgrover1 | 933:3ec277a0d780 | 301 | if (onDataWriteCallback) { |
rgrover1 | 933:3ec277a0d780 | 302 | onDataWriteCallback(params); |
rgrover1 | 933:3ec277a0d780 | 303 | } |
rgrover1 | 728:997ba5e7b3b6 | 304 | } |
rgrover1 | 728:997ba5e7b3b6 | 305 | |
rgrover1 | 737:79d95f9b93be | 306 | void processHVXEvent(const GattHVXCallbackParams *params) { |
rgrover1 | 933:3ec277a0d780 | 307 | if (onHVXCallback) { |
rgrover1 | 933:3ec277a0d780 | 308 | onHVXCallback(params); |
rgrover1 | 737:79d95f9b93be | 309 | } |
rgrover1 | 737:79d95f9b93be | 310 | } |
rgrover1 | 737:79d95f9b93be | 311 | |
rgrover1 | 728:997ba5e7b3b6 | 312 | protected: |
rgrover1 | 933:3ec277a0d780 | 313 | ReadCallback_t onDataReadCallback; |
rgrover1 | 933:3ec277a0d780 | 314 | WriteCallback_t onDataWriteCallback; |
rgrover1 | 933:3ec277a0d780 | 315 | HVXCallback_t onHVXCallback; |
rgrover1 | 728:997ba5e7b3b6 | 316 | |
rgrover1 | 716:11b41f651697 | 317 | private: |
rgrover1 | 935:e9b595e6b0ed | 318 | /* disallow copy and assignment */ |
rgrover1 | 716:11b41f651697 | 319 | GattClient(const GattClient &); |
rgrover1 | 716:11b41f651697 | 320 | GattClient& operator=(const GattClient &); |
rgrover1 | 716:11b41f651697 | 321 | }; |
rgrover1 | 716:11b41f651697 | 322 | |
rgrover1 | 716:11b41f651697 | 323 | #endif // ifndef __GATT_CLIENT_H__ |