just a fork
Fork of BLE_API by
ble/GattClient.h@710:b2e1a2660ec2, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:53:28 2015 +0100
- Revision:
- 710:b2e1a2660ec2
- Parent:
- public/GattClient.h@564:1d8aa4ad07fe
Synchronized with git rev 7e8977d8
Author: Rohit Grover
Release 0.3.8
=============
This is a minor set of enhancements before we yotta-ize BLE_API.
Enhancements
~~~~~~~~~~~~
* Minor rework for class UUID; added a default and copy constructor; and a != operator.
* Added copy constructor and accessors for GapAdvertisingParams.
* GapScanningParams:: remove unnecessary checks for SCAN_TIMEOUT_MAX.
* Add a comment header block to explain why BLEDevice::init() may not be safe
to call from global static context.
* Introduce GattAttribute::INVALID_HANDLE.
* Replace some deprecated uses of Gap::address_t with Gap::Address_t.
Bugfixes
~~~~~~~~
* None.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 527:493185cebc03 | 1 | /* mbed Microcontroller Library |
rgrover1 | 527:493185cebc03 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 527:493185cebc03 | 3 | * |
rgrover1 | 527:493185cebc03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 527:493185cebc03 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 527:493185cebc03 | 6 | * You may obtain a copy of the License at |
rgrover1 | 527:493185cebc03 | 7 | * |
rgrover1 | 527:493185cebc03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 527:493185cebc03 | 9 | * |
rgrover1 | 527:493185cebc03 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 527:493185cebc03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 527:493185cebc03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 527:493185cebc03 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 527:493185cebc03 | 14 | * limitations under the License. |
rgrover1 | 527:493185cebc03 | 15 | */ |
rgrover1 | 527:493185cebc03 | 16 | |
rgrover1 | 527:493185cebc03 | 17 | #ifndef __GATT_CLIENT_H__ |
rgrover1 | 527:493185cebc03 | 18 | #define __GATT_CLIENT_H__ |
rgrover1 | 527:493185cebc03 | 19 | |
rgrover1 | 527:493185cebc03 | 20 | #include "Gap.h" |
rgrover1 | 527:493185cebc03 | 21 | #include "GattAttribute.h" |
rgrover1 | 527:493185cebc03 | 22 | #include "ServiceDiscovery.h" |
rgrover1 | 527:493185cebc03 | 23 | |
rgrover1 | 527:493185cebc03 | 24 | #include "GattCallbackParamTypes.h" |
rgrover1 | 527:493185cebc03 | 25 | |
rgrover1 | 527:493185cebc03 | 26 | class GattClient { |
rgrover1 | 527:493185cebc03 | 27 | public: |
rgrover1 | 527:493185cebc03 | 28 | typedef void (*ReadCallback_t)(const GattReadCallbackParams *params); |
rgrover1 | 527:493185cebc03 | 29 | |
rgrover1 | 527:493185cebc03 | 30 | enum WriteOp_t { |
rgrover1 | 527:493185cebc03 | 31 | GATT_OP_WRITE_REQ = 0x01, /**< Write Request. */ |
rgrover1 | 527:493185cebc03 | 32 | GATT_OP_WRITE_CMD = 0x02, /**< Write Command. */ |
rgrover1 | 527:493185cebc03 | 33 | }; |
rgrover1 | 527:493185cebc03 | 34 | |
rgrover1 | 527:493185cebc03 | 35 | typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params); |
rgrover1 | 527:493185cebc03 | 36 | |
rgrover1 | 559:1ee5106d3763 | 37 | /* |
rgrover1 | 559:1ee5106d3763 | 38 | * The following functions are meant to be overridden in the platform-specific sub-class. |
rgrover1 | 559:1ee5106d3763 | 39 | */ |
rgrover1 | 527:493185cebc03 | 40 | public: |
rgrover1 | 527:493185cebc03 | 41 | /** |
rgrover1 | 527:493185cebc03 | 42 | * Launch service discovery. Once launched, service discovery will remain |
rgrover1 | 527:493185cebc03 | 43 | * active with callbacks being issued back into the application for matching |
rgrover1 | 540:1fb1e0b809eb | 44 | * services/characteristics. isServiceDiscoveryActive() can be used to |
rgrover1 | 540:1fb1e0b809eb | 45 | * determine status; and a termination callback (if setup) will be invoked |
rgrover1 | 540:1fb1e0b809eb | 46 | * at the end. Service discovery can be terminated prematurely if needed |
rgrover1 | 540:1fb1e0b809eb | 47 | * using terminateServiceDiscovery(). |
rgrover1 | 527:493185cebc03 | 48 | * |
rgrover1 | 527:493185cebc03 | 49 | * @param connectionHandle |
rgrover1 | 527:493185cebc03 | 50 | * Handle for the connection with the peer. |
rgrover1 | 527:493185cebc03 | 51 | * @param sc |
rgrover1 | 540:1fb1e0b809eb | 52 | * This is the application callback for matching service. Taken as |
rgrover1 | 540:1fb1e0b809eb | 53 | * NULL by default. Note: service discovery may still be active |
rgrover1 | 540:1fb1e0b809eb | 54 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 540:1fb1e0b809eb | 55 | * APIs from within this application callback might cause the |
rgrover1 | 540:1fb1e0b809eb | 56 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 540:1fb1e0b809eb | 57 | * may be better to make local copy of the discoveredService and |
rgrover1 | 540:1fb1e0b809eb | 58 | * wait for service discovery to terminate before operating on the |
rgrover1 | 540:1fb1e0b809eb | 59 | * service. |
rgrover1 | 527:493185cebc03 | 60 | * @param cc |
rgrover1 | 527:493185cebc03 | 61 | * This is the application callback for matching characteristic. |
rgrover1 | 540:1fb1e0b809eb | 62 | * Taken as NULL by default. Note: service discovery may still be |
rgrover1 | 540:1fb1e0b809eb | 63 | * active when this callback is issued; calling asynchronous |
rgrover1 | 540:1fb1e0b809eb | 64 | * BLE-stack APIs from within this application callback might cause |
rgrover1 | 540:1fb1e0b809eb | 65 | * the stack to abort service discovery. If this becomes an issue, |
rgrover1 | 540:1fb1e0b809eb | 66 | * it may be better to make local copy of the discoveredCharacteristic |
rgrover1 | 540:1fb1e0b809eb | 67 | * and wait for service discovery to terminate before operating on the |
rgrover1 | 540:1fb1e0b809eb | 68 | * characteristic. |
rgrover1 | 527:493185cebc03 | 69 | * @param matchingServiceUUID |
rgrover1 | 527:493185cebc03 | 70 | * UUID based filter for specifying a service in which the application is |
rgrover1 | 540:1fb1e0b809eb | 71 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 540:1fb1e0b809eb | 72 | * in which case it matches all services. If characteristic-UUID |
rgrover1 | 540:1fb1e0b809eb | 73 | * filter (below) is set to the wildcard value, then a service |
rgrover1 | 540:1fb1e0b809eb | 74 | * callback will be invoked for the matching service (or for every |
rgrover1 | 540:1fb1e0b809eb | 75 | * service if the service filter is a wildcard). |
rgrover1 | 527:493185cebc03 | 76 | * @param matchingCharacteristicUUIDIn |
rgrover1 | 527:493185cebc03 | 77 | * UUID based filter for specifying characteristic in which the application |
rgrover1 | 540:1fb1e0b809eb | 78 | * is interested. By default it is set as the wildcard UUID_UKNOWN |
rgrover1 | 540:1fb1e0b809eb | 79 | * to match against any characteristic. If both service-UUID |
rgrover1 | 540:1fb1e0b809eb | 80 | * filter and characteristic-UUID filter are used with non- wildcard |
rgrover1 | 540:1fb1e0b809eb | 81 | * values, then only a single characteristic callback is |
rgrover1 | 540:1fb1e0b809eb | 82 | * invoked for the matching characteristic. |
rgrover1 | 527:493185cebc03 | 83 | * |
rgrover1 | 540:1fb1e0b809eb | 84 | * @note Using wildcard values for both service-UUID and characteristic- |
rgrover1 | 527:493185cebc03 | 85 | * UUID will result in complete service discovery--callbacks being |
rgrover1 | 527:493185cebc03 | 86 | * called for every service and characteristic. |
rgrover1 | 527:493185cebc03 | 87 | * |
rgrover1 | 540:1fb1e0b809eb | 88 | * @note Providing NULL for the characteristic callback will result in |
rgrover1 | 559:1ee5106d3763 | 89 | * characteristic discovery being skipped for each matching |
rgrover1 | 559:1ee5106d3763 | 90 | * service. This allows for an inexpensive method to discover only |
rgrover1 | 559:1ee5106d3763 | 91 | * services. |
rgrover1 | 540:1fb1e0b809eb | 92 | * |
rgrover1 | 527:493185cebc03 | 93 | * @return |
rgrover1 | 527:493185cebc03 | 94 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 527:493185cebc03 | 95 | */ |
rgrover1 | 527:493185cebc03 | 96 | virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, |
rgrover1 | 527:493185cebc03 | 97 | ServiceDiscovery::ServiceCallback_t sc = NULL, |
rgrover1 | 527:493185cebc03 | 98 | ServiceDiscovery::CharacteristicCallback_t cc = NULL, |
rgrover1 | 527:493185cebc03 | 99 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
rgrover1 | 559:1ee5106d3763 | 100 | const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
rgrover1 | 559:1ee5106d3763 | 101 | return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */ |
rgrover1 | 559:1ee5106d3763 | 102 | } |
rgrover1 | 527:493185cebc03 | 103 | |
rgrover1 | 527:493185cebc03 | 104 | /** |
rgrover1 | 564:1d8aa4ad07fe | 105 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 564:1d8aa4ad07fe | 106 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 564:1d8aa4ad07fe | 107 | * services. isServiceDiscoveryActive() can be used to |
rgrover1 | 564:1d8aa4ad07fe | 108 | * determine status; and a termination callback (if setup) will be invoked |
rgrover1 | 564:1d8aa4ad07fe | 109 | * at the end. Service discovery can be terminated prematurely if needed |
rgrover1 | 564:1d8aa4ad07fe | 110 | * using terminateServiceDiscovery(). |
rgrover1 | 564:1d8aa4ad07fe | 111 | * |
rgrover1 | 564:1d8aa4ad07fe | 112 | * @param connectionHandle |
rgrover1 | 564:1d8aa4ad07fe | 113 | * Handle for the connection with the peer. |
rgrover1 | 564:1d8aa4ad07fe | 114 | * @param sc |
rgrover1 | 564:1d8aa4ad07fe | 115 | * This is the application callback for matching service. Note: service discovery may still be active |
rgrover1 | 564:1d8aa4ad07fe | 116 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 564:1d8aa4ad07fe | 117 | * APIs from within this application callback might cause the |
rgrover1 | 564:1d8aa4ad07fe | 118 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 564:1d8aa4ad07fe | 119 | * may be better to make local copy of the discoveredService and |
rgrover1 | 564:1d8aa4ad07fe | 120 | * wait for service discovery to terminate before operating on the |
rgrover1 | 564:1d8aa4ad07fe | 121 | * service. |
rgrover1 | 564:1d8aa4ad07fe | 122 | * @param matchingServiceUUID |
rgrover1 | 564:1d8aa4ad07fe | 123 | * UUID based filter for specifying a service in which the application is |
rgrover1 | 564:1d8aa4ad07fe | 124 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 564:1d8aa4ad07fe | 125 | * in which case it matches all services. |
rgrover1 | 564:1d8aa4ad07fe | 126 | * |
rgrover1 | 564:1d8aa4ad07fe | 127 | * @return |
rgrover1 | 564:1d8aa4ad07fe | 128 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 564:1d8aa4ad07fe | 129 | */ |
rgrover1 | 564:1d8aa4ad07fe | 130 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 564:1d8aa4ad07fe | 131 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 564:1d8aa4ad07fe | 132 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
rgrover1 | 564:1d8aa4ad07fe | 133 | return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */ |
rgrover1 | 564:1d8aa4ad07fe | 134 | } |
rgrover1 | 564:1d8aa4ad07fe | 135 | |
rgrover1 | 564:1d8aa4ad07fe | 136 | /** |
rgrover1 | 564:1d8aa4ad07fe | 137 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 564:1d8aa4ad07fe | 138 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 564:1d8aa4ad07fe | 139 | * services. isServiceDiscoveryActive() can be used to |
rgrover1 | 564:1d8aa4ad07fe | 140 | * determine status; and a termination callback (if setup) will be invoked |
rgrover1 | 564:1d8aa4ad07fe | 141 | * at the end. Service discovery can be terminated prematurely if needed |
rgrover1 | 564:1d8aa4ad07fe | 142 | * using terminateServiceDiscovery(). |
rgrover1 | 564:1d8aa4ad07fe | 143 | * |
rgrover1 | 564:1d8aa4ad07fe | 144 | * @param connectionHandle |
rgrover1 | 564:1d8aa4ad07fe | 145 | * Handle for the connection with the peer. |
rgrover1 | 564:1d8aa4ad07fe | 146 | * @param sc |
rgrover1 | 564:1d8aa4ad07fe | 147 | * This is the application callback for matching service. Note: service discovery may still be active |
rgrover1 | 564:1d8aa4ad07fe | 148 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 564:1d8aa4ad07fe | 149 | * APIs from within this application callback might cause the |
rgrover1 | 564:1d8aa4ad07fe | 150 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 564:1d8aa4ad07fe | 151 | * may be better to make local copy of the discoveredService and |
rgrover1 | 564:1d8aa4ad07fe | 152 | * wait for service discovery to terminate before operating on the |
rgrover1 | 564:1d8aa4ad07fe | 153 | * service. |
rgrover1 | 564:1d8aa4ad07fe | 154 | * @param startHandle, endHandle |
rgrover1 | 564:1d8aa4ad07fe | 155 | * Handle range within which to limit the search |
rgrover1 | 564:1d8aa4ad07fe | 156 | * |
rgrover1 | 564:1d8aa4ad07fe | 157 | * @return |
rgrover1 | 564:1d8aa4ad07fe | 158 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 564:1d8aa4ad07fe | 159 | */ |
rgrover1 | 564:1d8aa4ad07fe | 160 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 564:1d8aa4ad07fe | 161 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 564:1d8aa4ad07fe | 162 | GattAttribute::Handle_t startHandle, |
rgrover1 | 564:1d8aa4ad07fe | 163 | GattAttribute::Handle_t endHandle) { |
rgrover1 | 564:1d8aa4ad07fe | 164 | return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */ |
rgrover1 | 564:1d8aa4ad07fe | 165 | } |
rgrover1 | 564:1d8aa4ad07fe | 166 | |
rgrover1 | 564:1d8aa4ad07fe | 167 | /** |
rgrover1 | 527:493185cebc03 | 168 | * Is service-discovery currently active? |
rgrover1 | 527:493185cebc03 | 169 | */ |
rgrover1 | 559:1ee5106d3763 | 170 | virtual bool isServiceDiscoveryActive(void) const { |
rgrover1 | 559:1ee5106d3763 | 171 | return false; /* default implementation; override this API if this capability is supported. */ |
rgrover1 | 559:1ee5106d3763 | 172 | } |
rgrover1 | 527:493185cebc03 | 173 | |
rgrover1 | 527:493185cebc03 | 174 | /** |
rgrover1 | 527:493185cebc03 | 175 | * Terminate an ongoing service-discovery. This should result in an |
rgrover1 | 527:493185cebc03 | 176 | * invocation of the TerminationCallback if service-discovery is active. |
rgrover1 | 527:493185cebc03 | 177 | */ |
rgrover1 | 559:1ee5106d3763 | 178 | virtual void terminateServiceDiscovery(void) { |
rgrover1 | 559:1ee5106d3763 | 179 | /* default implementation; override this API if this capability is supported. */ |
rgrover1 | 559:1ee5106d3763 | 180 | } |
rgrover1 | 527:493185cebc03 | 181 | |
rgrover1 | 559:1ee5106d3763 | 182 | /* Initiate a Gatt Client read procedure by attribute-handle. */ |
rgrover1 | 559:1ee5106d3763 | 183 | virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const { |
rgrover1 | 559:1ee5106d3763 | 184 | return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */ |
rgrover1 | 559:1ee5106d3763 | 185 | } |
rgrover1 | 527:493185cebc03 | 186 | |
rgrover1 | 540:1fb1e0b809eb | 187 | /** |
rgrover1 | 540:1fb1e0b809eb | 188 | * Initiate a GATT Client write procedure. |
rgrover1 | 540:1fb1e0b809eb | 189 | * |
rgrover1 | 540:1fb1e0b809eb | 190 | * @param[in] cmd |
rgrover1 | 540:1fb1e0b809eb | 191 | * Command can be either a write-request (which generates a |
rgrover1 | 540:1fb1e0b809eb | 192 | * matching response from the peripheral), or a write-command, |
rgrover1 | 540:1fb1e0b809eb | 193 | * which doesn't require the connected peer to respond. |
rgrover1 | 540:1fb1e0b809eb | 194 | * @param[in] connHandle |
rgrover1 | 540:1fb1e0b809eb | 195 | * Connection handle. |
rgrover1 | 540:1fb1e0b809eb | 196 | * @param[in] attributeHandle |
rgrover1 | 540:1fb1e0b809eb | 197 | * handle for the target attribtue on the remote GATT server. |
rgrover1 | 540:1fb1e0b809eb | 198 | * @param[in] length |
rgrover1 | 540:1fb1e0b809eb | 199 | * length of the new value. |
rgrover1 | 540:1fb1e0b809eb | 200 | * @param[in] value |
rgrover1 | 540:1fb1e0b809eb | 201 | * new value being written. |
rgrover1 | 540:1fb1e0b809eb | 202 | */ |
rgrover1 | 527:493185cebc03 | 203 | virtual ble_error_t write(GattClient::WriteOp_t cmd, |
rgrover1 | 527:493185cebc03 | 204 | Gap::Handle_t connHandle, |
rgrover1 | 527:493185cebc03 | 205 | GattAttribute::Handle_t attributeHandle, |
rgrover1 | 527:493185cebc03 | 206 | size_t length, |
rgrover1 | 559:1ee5106d3763 | 207 | const uint8_t *value) const { |
rgrover1 | 559:1ee5106d3763 | 208 | return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */ |
rgrover1 | 559:1ee5106d3763 | 209 | } |
rgrover1 | 559:1ee5106d3763 | 210 | |
rgrover1 | 559:1ee5106d3763 | 211 | /** |
rgrover1 | 559:1ee5106d3763 | 212 | * Setup callback for when serviceDiscovery terminates. |
rgrover1 | 559:1ee5106d3763 | 213 | */ |
rgrover1 | 559:1ee5106d3763 | 214 | virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { |
rgrover1 | 559:1ee5106d3763 | 215 | /* default implementation; override this API if this capability is supported. */ |
rgrover1 | 559:1ee5106d3763 | 216 | } |
rgrover1 | 527:493185cebc03 | 217 | |
rgrover1 | 527:493185cebc03 | 218 | protected: |
rgrover1 | 527:493185cebc03 | 219 | GattClient() { |
rgrover1 | 527:493185cebc03 | 220 | /* empty */ |
rgrover1 | 527:493185cebc03 | 221 | } |
rgrover1 | 527:493185cebc03 | 222 | |
rgrover1 | 527:493185cebc03 | 223 | private: |
rgrover1 | 527:493185cebc03 | 224 | /* disallow copy and assignment */ |
rgrover1 | 527:493185cebc03 | 225 | GattClient(const GattClient &); |
rgrover1 | 527:493185cebc03 | 226 | GattClient& operator=(const GattClient &); |
rgrover1 | 527:493185cebc03 | 227 | }; |
rgrover1 | 527:493185cebc03 | 228 | |
rgrover1 | 527:493185cebc03 | 229 | #endif // ifndef __GATT_CLIENT_H__ |