Bizan Nishimura / BLE_API

Dependents:   MiniSteer_BLE

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Fri Jul 11 14:39:17 2014 +0100
Revision:
105:f29ab9f74d7e
Parent:
104:6ef5abef5714
add APIs for working with connectionParams

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 29:011e95ce78b8 1 /* mbed Microcontroller Library
ktownsend 29:011e95ce78b8 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 29:011e95ce78b8 3 *
ktownsend 29:011e95ce78b8 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 29:011e95ce78b8 5 * you may not use this file except in compliance with the License.
ktownsend 29:011e95ce78b8 6 * You may obtain a copy of the License at
ktownsend 29:011e95ce78b8 7 *
ktownsend 29:011e95ce78b8 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 29:011e95ce78b8 9 *
ktownsend 29:011e95ce78b8 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 29:011e95ce78b8 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 29:011e95ce78b8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 29:011e95ce78b8 13 * See the License for the specific language governing permissions and
ktownsend 29:011e95ce78b8 14 * limitations under the License.
ktownsend 29:011e95ce78b8 15 */
Rohit Grover 34:da2ea8cd6216 16
Rohit Grover 81:fd8c6792281b 17 #ifndef __BLE_DEVICE__
Rohit Grover 81:fd8c6792281b 18 #define __BLE_DEVICE__
ktownsend 29:011e95ce78b8 19
ktownsend 29:011e95ce78b8 20 #include "mbed.h"
ktownsend 29:011e95ce78b8 21 #include "blecommon.h"
ktownsend 29:011e95ce78b8 22 #include "hw/Gap.h"
ktownsend 29:011e95ce78b8 23 #include "hw/GattServer.h"
ktownsend 29:011e95ce78b8 24
Rohit Grover 81:fd8c6792281b 25 class BLEDeviceInstanceBase; /* forward declaration */
Rohit Grover 41:7ae5c71cd44c 26
Rohit Grover 41:7ae5c71cd44c 27 /**
Rohit Grover 81:fd8c6792281b 28 * BLEDevice uses composition to hide an interface object encapsulating the
Rohit Grover 41:7ae5c71cd44c 29 * backend transport.
Rohit Grover 41:7ae5c71cd44c 30 *
Rohit Grover 41:7ae5c71cd44c 31 * The following API is used to create the singleton interface object. An
Rohit Grover 41:7ae5c71cd44c 32 * implementation for this function must be provided by the device-specific
Rohit Grover 41:7ae5c71cd44c 33 * library, otherwise there will be a linker error.
Rohit Grover 41:7ae5c71cd44c 34 */
Rohit Grover 81:fd8c6792281b 35 extern BLEDeviceInstanceBase *createBLEDeviceInstance(void);
Rohit Grover 41:7ae5c71cd44c 36
Rohit Grover 41:7ae5c71cd44c 37 /**
Rohit Grover 41:7ae5c71cd44c 38 * The base class used to abstract away BLE capable radio transceivers or SOCs,
Rohit Grover 41:7ae5c71cd44c 39 * to enable this BLE API to work with any radio transparently.
Rohit Grover 41:7ae5c71cd44c 40 */
Rohit Grover 81:fd8c6792281b 41 class BLEDevice
ktownsend 29:011e95ce78b8 42 {
Rohit Grover 34:da2ea8cd6216 43 public:
Rohit Grover 95:5d2102351bf4 44 /**
Rohit Grover 95:5d2102351bf4 45 * Initialize the BLE controller. This should be called before using
Rohit Grover 95:5d2102351bf4 46 * anything else in the BLE_API.
Rohit Grover 95:5d2102351bf4 47 */
Rohit Grover 41:7ae5c71cd44c 48 ble_error_t init();
Rohit Grover 41:7ae5c71cd44c 49 ble_error_t reset(void);
Rohit Grover 35:f3b0c1192cf7 50
Rohit Grover 35:f3b0c1192cf7 51 /* GAP specific APIs */
Rohit Grover 35:f3b0c1192cf7 52 public:
Rohit Grover 37:7e8de07642e0 53 /**
Rohit Grover 37:7e8de07642e0 54 * Set the BTLE MAC address and type.
Rohit Grover 37:7e8de07642e0 55 * @return
Rohit Grover 37:7e8de07642e0 56 */
Rohit Grover 38:02cf26a2a4db 57 ble_error_t setAddress(Gap::addr_type_t type, const uint8_t address[6]);
Rohit Grover 35:f3b0c1192cf7 58
Rohit Grover 46:33d87f468a0d 59 /**
Rohit Grover 46:33d87f468a0d 60 * @param[in] advType
Rohit Grover 46:33d87f468a0d 61 * The GAP advertising mode to use for this device. Valid
Rohit Grover 46:33d87f468a0d 62 * values are defined in AdvertisingType:
Rohit Grover 46:33d87f468a0d 63 *
Rohit Grover 46:33d87f468a0d 64 * \par ADV_NON_CONNECTABLE_UNDIRECTED
Rohit Grover 46:33d87f468a0d 65 * All connections to the peripheral device will be refused.
Rohit Grover 46:33d87f468a0d 66 *
Rohit Grover 46:33d87f468a0d 67 * \par ADV_CONNECTABLE_DIRECTED
Rohit Grover 46:33d87f468a0d 68 * Only connections from a pre-defined central device will be
Rohit Grover 46:33d87f468a0d 69 * accepted.
Rohit Grover 46:33d87f468a0d 70 *
Rohit Grover 46:33d87f468a0d 71 * \par ADV_CONNECTABLE_UNDIRECTED
Rohit Grover 46:33d87f468a0d 72 * Any central device can connect to this peripheral.
Rohit Grover 46:33d87f468a0d 73 *
Rohit Grover 46:33d87f468a0d 74 * \par ADV_SCANNABLE_UNDIRECTED
Rohit Grover 46:33d87f468a0d 75 * Any central device can connect to this peripheral, and
Rohit Grover 46:33d87f468a0d 76 * the secondary Scan Response payload will be included or
Rohit Grover 46:33d87f468a0d 77 * available to central devices.
Rohit Grover 46:33d87f468a0d 78 *
Rohit Grover 46:33d87f468a0d 79 * \par
Rohit Grover 46:33d87f468a0d 80 * See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
Rohit Grover 46:33d87f468a0d 81 * Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
Rohit Grover 46:33d87f468a0d 82 * Section 2.3.1 for further information on GAP connection
Rohit Grover 46:33d87f468a0d 83 * modes
Rohit Grover 46:33d87f468a0d 84 */
Rohit Grover 46:33d87f468a0d 85 void setAdvertisingType(GapAdvertisingParams::AdvertisingType);
Rohit Grover 46:33d87f468a0d 86
Rohit Grover 46:33d87f468a0d 87 /**
Rohit Grover 46:33d87f468a0d 88 * @param[in] interval
Rohit Grover 46:33d87f468a0d 89 * Advertising interval between 0x0020 and 0x4000 in 0.625ms
Rohit Grover 46:33d87f468a0d 90 * units (20ms to 10.24s). If using non-connectable mode
Rohit Grover 46:33d87f468a0d 91 * (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is
Rohit Grover 46:33d87f468a0d 92 * 0x00A0 (100ms). To reduce the likelihood of collisions, the
Rohit Grover 46:33d87f468a0d 93 * link layer perturbs this interval by a pseudo-random delay
Rohit Grover 46:33d87f468a0d 94 * with a range of 0 ms to 10 ms for each advertising event.
Rohit Grover 46:33d87f468a0d 95 *
Rohit Grover 46:33d87f468a0d 96 * \par
Rohit Grover 46:33d87f468a0d 97 * Decreasing this value will allow central devices to detect
Rohit Grover 46:33d87f468a0d 98 * your peripheral faster at the expense of more power being
Rohit Grover 46:33d87f468a0d 99 * used by the radio due to the higher data transmit rate.
Rohit Grover 46:33d87f468a0d 100 *
Rohit Grover 46:33d87f468a0d 101 * \par
Rohit Grover 46:33d87f468a0d 102 * This field must be set to 0 if connectionMode is equal
Rohit Grover 46:33d87f468a0d 103 * to ADV_CONNECTABLE_DIRECTED
Rohit Grover 46:33d87f468a0d 104 *
Rohit Grover 46:33d87f468a0d 105 * \par
Rohit Grover 46:33d87f468a0d 106 * See Bluetooth Core Specification, Vol 3., Part C,
Rohit Grover 46:33d87f468a0d 107 * Appendix A for suggested advertising intervals.
Rohit Grover 46:33d87f468a0d 108 */
Rohit Grover 46:33d87f468a0d 109 void setAdvertisingInterval(uint16_t interval);
Rohit Grover 46:33d87f468a0d 110
Rohit Grover 46:33d87f468a0d 111 /**
Rohit Grover 46:33d87f468a0d 112 * @param[in] timeout
Rohit Grover 46:33d87f468a0d 113 * Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
Rohit Grover 46:33d87f468a0d 114 * in seconds. Enter 0 to disable the advertising timeout.
Rohit Grover 46:33d87f468a0d 115 */
Rohit Grover 46:33d87f468a0d 116 void setAdvertisingTimeout(uint16_t timeout);
Rohit Grover 46:33d87f468a0d 117
Rohit Grover 46:33d87f468a0d 118 /**
Rohit Grover 46:33d87f468a0d 119 * Please refer to the APIs above.
Rohit Grover 46:33d87f468a0d 120 */
Rohit Grover 46:33d87f468a0d 121 void setAdvertisingParams(const GapAdvertisingParams &advParams);
Rohit Grover 46:33d87f468a0d 122
Rohit Grover 95:5d2102351bf4 123 /**
Rohit Grover 102:39e30ac179a7 124 * This API is typically used as an internal helper to udpate the transport
Rohit Grover 102:39e30ac179a7 125 * backend with advertising data before starting to advertise. It may also
Rohit Grover 102:39e30ac179a7 126 * be explicity used to dynamically reset the accumulated advertising
Rohit Grover 102:39e30ac179a7 127 * payload and scanResponse; to do this, the application can clear and re-
Rohit Grover 102:39e30ac179a7 128 * accumulate a new advertising payload (and scanResponse) before using this
Rohit Grover 102:39e30ac179a7 129 * API.
Rohit Grover 102:39e30ac179a7 130 */
Rohit Grover 102:39e30ac179a7 131 ble_error_t setAdvertisingPayload(void);
Rohit Grover 102:39e30ac179a7 132
Rohit Grover 102:39e30ac179a7 133 /**
Rohit Grover 95:5d2102351bf4 134 * Reset any advertising payload prepared from prior calls to
Rohit Grover 95:5d2102351bf4 135 * accumulateAdvertisingPayload().
Rohit Grover 95:5d2102351bf4 136 */
Rohit Grover 49:03a51f0006f8 137 void clearAdvertisingPayload(void);
Rohit Grover 95:5d2102351bf4 138
Rohit Grover 95:5d2102351bf4 139 /**
Rohit Grover 95:5d2102351bf4 140 * Accumulate an AD structure in the advertising payload. Please note that
Rohit Grover 95:5d2102351bf4 141 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
Rohit Grover 95:5d2102351bf4 142 * as an additional 31 bytes if the advertising payload proves to be too
Rohit Grover 95:5d2102351bf4 143 * small.
Rohit Grover 95:5d2102351bf4 144 *
Rohit Grover 95:5d2102351bf4 145 * @param flags
Rohit Grover 100:1e80e8032c13 146 * The flags to be added. Multiple flags may be specified in
Rohit Grover 100:1e80e8032c13 147 * combination.
Rohit Grover 95:5d2102351bf4 148 */
Rohit Grover 100:1e80e8032c13 149 ble_error_t accumulateAdvertisingPayload(uint8_t flags);
Rohit Grover 95:5d2102351bf4 150
Rohit Grover 95:5d2102351bf4 151 /**
Rohit Grover 95:5d2102351bf4 152 * Accumulate an AD structure in the advertising payload. Please note that
Rohit Grover 95:5d2102351bf4 153 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
Rohit Grover 95:5d2102351bf4 154 * as an additional 31 bytes if the advertising payload proves to be too
Rohit Grover 95:5d2102351bf4 155 * small.
Rohit Grover 95:5d2102351bf4 156 *
Rohit Grover 95:5d2102351bf4 157 * @param app
Rohit Grover 95:5d2102351bf4 158 * The appearance of the peripheral.
Rohit Grover 95:5d2102351bf4 159 */
Rohit Grover 49:03a51f0006f8 160 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app);
Rohit Grover 95:5d2102351bf4 161
Rohit Grover 95:5d2102351bf4 162 /**
Rohit Grover 95:5d2102351bf4 163 * Accumulate an AD structure in the advertising payload. Please note that
Rohit Grover 95:5d2102351bf4 164 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
Rohit Grover 95:5d2102351bf4 165 * as an additional 31 bytes if the advertising payload proves to be too
Rohit Grover 95:5d2102351bf4 166 * small.
Rohit Grover 95:5d2102351bf4 167 *
Rohit Grover 95:5d2102351bf4 168 * @param app
Rohit Grover 95:5d2102351bf4 169 * The max transmit power to be used by the controller. This is
Rohit Grover 95:5d2102351bf4 170 * only a hint.
Rohit Grover 95:5d2102351bf4 171 */
Rohit Grover 49:03a51f0006f8 172 ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power);
Rohit Grover 95:5d2102351bf4 173
Rohit Grover 95:5d2102351bf4 174 /**
Rohit Grover 95:5d2102351bf4 175 * Accumulate a variable length byte-stream as an AD structure in the
Rohit Grover 95:5d2102351bf4 176 * advertising payload. Please note that the payload is limited to 31 bytes.
Rohit Grover 95:5d2102351bf4 177 * The SCAN_RESPONSE message may be used as an additional 31 bytes if the
Rohit Grover 95:5d2102351bf4 178 * advertising payload proves to be too small.
Rohit Grover 95:5d2102351bf4 179 *
Rohit Grover 95:5d2102351bf4 180 * @param type The type which describes the variable length data.
Rohit Grover 95:5d2102351bf4 181 * @param data data bytes.
Rohit Grover 95:5d2102351bf4 182 * @param len length of data.
Rohit Grover 95:5d2102351bf4 183 */
Rohit Grover 74:301042c34cb8 184 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len);
Rohit Grover 49:03a51f0006f8 185
Rohit Grover 95:5d2102351bf4 186 /**
Rohit Grover 103:8890715aaf55 187 * Accumulate a variable length byte-stream as an AD structure in the
Rohit Grover 103:8890715aaf55 188 * scanResponse payload.
Rohit Grover 103:8890715aaf55 189 *
Rohit Grover 103:8890715aaf55 190 * @param type The type which describes the variable length data.
Rohit Grover 103:8890715aaf55 191 * @param data data bytes.
Rohit Grover 103:8890715aaf55 192 * @param len length of data.
Rohit Grover 103:8890715aaf55 193 */
Rohit Grover 103:8890715aaf55 194 ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len);
Rohit Grover 103:8890715aaf55 195
Rohit Grover 103:8890715aaf55 196 /**
Rohit Grover 95:5d2102351bf4 197 * Start advertising (GAP Discoverable, Connectable modes, Broadcast
Rohit Grover 95:5d2102351bf4 198 * Procedure).
Rohit Grover 95:5d2102351bf4 199 */
Rohit Grover 46:33d87f468a0d 200 ble_error_t startAdvertising(void);
Rohit Grover 95:5d2102351bf4 201
Rohit Grover 95:5d2102351bf4 202 /**
Rohit Grover 95:5d2102351bf4 203 * Stop advertising (GAP Discoverable, Connectable modes, Broadcast
Rohit Grover 95:5d2102351bf4 204 * Procedure).
Rohit Grover 95:5d2102351bf4 205 */
Rohit Grover 36:9ec94579bb78 206 ble_error_t stopAdvertising(void);
Rohit Grover 46:33d87f468a0d 207
Rohit Grover 36:9ec94579bb78 208 ble_error_t disconnect(void);
Rohit Grover 35:f3b0c1192cf7 209
Rohit Grover 64:95529f47b782 210 /* APIs to set GAP callbacks. */
Rohit Grover 104:6ef5abef5714 211 void onTimeout(Gap::EventCallback_t timeoutCallback);
Rohit Grover 104:6ef5abef5714 212
Rohit Grover 104:6ef5abef5714 213 void onConnection(Gap::HandleSpecificEventCallback_t connectionCallback);
Rohit Grover 95:5d2102351bf4 214 /**
Rohit Grover 95:5d2102351bf4 215 * Used to setup a callback for GAP disconnection.
Rohit Grover 95:5d2102351bf4 216 */
Rohit Grover 104:6ef5abef5714 217 void onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback);
Rohit Grover 63:653378e782ea 218
Rohit Grover 95:5d2102351bf4 219 /**
Rohit Grover 95:5d2102351bf4 220 * Setup a callback for the GATT event DATA_SENT.
Rohit Grover 95:5d2102351bf4 221 */
Rohit Grover 99:58c47085e816 222 void onDataSent(GattServer::ServerEventCallback_t callback);
Rohit Grover 95:5d2102351bf4 223
Rohit Grover 95:5d2102351bf4 224 /**
Rohit Grover 95:5d2102351bf4 225 * Setup a callback for when a characteristic has its value updated by a
Rohit Grover 95:5d2102351bf4 226 * client.
Rohit Grover 95:5d2102351bf4 227 */
Rohit Grover 64:95529f47b782 228 void onDataWritten(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 229 void onUpdatesEnabled(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 230 void onUpdatesDisabled(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 231 void onConfirmationReceived(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 232
Rohit Grover 95:5d2102351bf4 233 /**
Rohit Grover 95:5d2102351bf4 234 * Add a service declaration to the local server ATT table. Also add the
Rohit Grover 95:5d2102351bf4 235 * characteristics contained within.
Rohit Grover 95:5d2102351bf4 236 */
Rohit Grover 72:bd485a3b18c5 237 ble_error_t addService(GattService &service);
Rohit Grover 72:bd485a3b18c5 238
Rohit Grover 73:eeb1ac3545e9 239 Gap::GapState_t getGapState(void) const;
Rohit Grover 94:455363a6eb90 240
Rohit Grover 94:455363a6eb90 241 ble_error_t readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP);
Rohit Grover 94:455363a6eb90 242 ble_error_t updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly = false);
Rohit Grover 73:eeb1ac3545e9 243
Rohit Grover 78:5d356ef94347 244 /**
Rohit Grover 79:b6284f5928bb 245 * Yield control to the BLE stack or to other tasks waiting for events. This
Rohit Grover 79:b6284f5928bb 246 * is a sleep function which will return when there is an application
Rohit Grover 79:b6284f5928bb 247 * specific interrupt, but the MCU might wake up several times before
Rohit Grover 80:e2c50c4a1e9a 248 * returning (to service the stack). This is not always interchangeable with
Rohit Grover 80:e2c50c4a1e9a 249 * WFE().
Rohit Grover 78:5d356ef94347 250 */
Rohit Grover 78:5d356ef94347 251 void waitForEvent(void);
Rohit Grover 78:5d356ef94347 252
Rohit Grover 105:f29ab9f74d7e 253 ble_error_t getPreferredConnectionParams(Gap::ConnectionParams_t *params);
Rohit Grover 105:f29ab9f74d7e 254 ble_error_t setPreferredConnectionParams(const Gap::ConnectionParams_t *params);
Rohit Grover 105:f29ab9f74d7e 255 ble_error_t updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params);
Rohit Grover 105:f29ab9f74d7e 256 // ble_version_t getVersion(void);
Rohit Grover 105:f29ab9f74d7e 257
Rohit Grover 41:7ae5c71cd44c 258 public:
Rohit Grover 98:d751acb2543f 259 BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true) {
Rohit Grover 49:03a51f0006f8 260 advPayload.clear();
Rohit Grover 49:03a51f0006f8 261 scanResponse.clear();
Rohit Grover 41:7ae5c71cd44c 262 }
Rohit Grover 41:7ae5c71cd44c 263
Rohit Grover 41:7ae5c71cd44c 264 private:
Rohit Grover 81:fd8c6792281b 265 BLEDeviceInstanceBase *const transport; /* the device specific backend */
Rohit Grover 46:33d87f468a0d 266
Rohit Grover 49:03a51f0006f8 267 GapAdvertisingParams advParams;
Rohit Grover 49:03a51f0006f8 268 GapAdvertisingData advPayload;
Rohit Grover 49:03a51f0006f8 269 GapAdvertisingData scanResponse;
Rohit Grover 75:d08bdef22500 270
Rohit Grover 75:d08bdef22500 271 /* Accumulation of AD structures in the advertisement payload should
Rohit Grover 75:d08bdef22500 272 * eventually result in a call to the target's setAdvertisingData() before
Rohit Grover 95:5d2102351bf4 273 * the server begins advertising. This flag marks the status of the pending update.*/
Rohit Grover 98:d751acb2543f 274 bool needToSetAdvPayload;
Rohit Grover 98:d751acb2543f 275
Rohit Grover 46:33d87f468a0d 276 /**
Rohit Grover 46:33d87f468a0d 277 * DEPRECATED
Rohit Grover 46:33d87f468a0d 278 */
Rohit Grover 46:33d87f468a0d 279 public:
Rohit Grover 75:d08bdef22500 280 ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse);
Rohit Grover 48:ec0c28e62abf 281 ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures);
Rohit Grover 48:ec0c28e62abf 282
Rohit Grover 46:33d87f468a0d 283 ble_error_t startAdvertising(const GapAdvertisingParams &advParams);
Rohit Grover 41:7ae5c71cd44c 284 };
Rohit Grover 41:7ae5c71cd44c 285
Rohit Grover 41:7ae5c71cd44c 286 /**
Rohit Grover 41:7ae5c71cd44c 287 * The interface for the transport object to be created by the target library's
Rohit Grover 81:fd8c6792281b 288 * createBLEDeviceInstance().
Rohit Grover 41:7ae5c71cd44c 289 */
Rohit Grover 81:fd8c6792281b 290 class BLEDeviceInstanceBase
Rohit Grover 41:7ae5c71cd44c 291 {
Rohit Grover 41:7ae5c71cd44c 292 public:
Rohit Grover 78:5d356ef94347 293 virtual Gap& getGap() = 0;
Rohit Grover 78:5d356ef94347 294 virtual GattServer& getGattServer() = 0;
Rohit Grover 78:5d356ef94347 295 virtual ble_error_t init(void) = 0;
Rohit Grover 78:5d356ef94347 296 virtual ble_error_t reset(void) = 0;
Rohit Grover 78:5d356ef94347 297 virtual void waitForEvent(void) = 0;
ktownsend 29:011e95ce78b8 298 };
ktownsend 29:011e95ce78b8 299
Rohit Grover 41:7ae5c71cd44c 300
Rohit Grover 81:fd8c6792281b 301 /* BLEDevice methods. Most of these simply forward the calls to the underlying
Rohit Grover 41:7ae5c71cd44c 302 * transport.*/
Rohit Grover 41:7ae5c71cd44c 303
Rohit Grover 41:7ae5c71cd44c 304 inline ble_error_t
Rohit Grover 81:fd8c6792281b 305 BLEDevice::init()
Rohit Grover 77:1436ecf09583 306 {
Rohit Grover 41:7ae5c71cd44c 307 return transport->init();
Rohit Grover 41:7ae5c71cd44c 308 }
Rohit Grover 41:7ae5c71cd44c 309
Rohit Grover 41:7ae5c71cd44c 310 inline ble_error_t
Rohit Grover 81:fd8c6792281b 311 BLEDevice::reset(void)
Rohit Grover 77:1436ecf09583 312 {
Rohit Grover 41:7ae5c71cd44c 313 return transport->reset();
Rohit Grover 41:7ae5c71cd44c 314 }
Rohit Grover 41:7ae5c71cd44c 315
Rohit Grover 39:a57137537521 316 inline ble_error_t
Rohit Grover 81:fd8c6792281b 317 BLEDevice::setAddress(Gap::addr_type_t type, const uint8_t address[6])
Rohit Grover 77:1436ecf09583 318 {
Rohit Grover 41:7ae5c71cd44c 319 return transport->getGap().setAddress(type, address);
Rohit Grover 36:9ec94579bb78 320 }
Rohit Grover 36:9ec94579bb78 321
Rohit Grover 46:33d87f468a0d 322 inline void
Rohit Grover 81:fd8c6792281b 323 BLEDevice::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType)
Rohit Grover 77:1436ecf09583 324 {
Rohit Grover 46:33d87f468a0d 325 advParams.setAdvertisingType(advType);
Rohit Grover 46:33d87f468a0d 326 }
Rohit Grover 46:33d87f468a0d 327
Rohit Grover 46:33d87f468a0d 328 inline void
Rohit Grover 81:fd8c6792281b 329 BLEDevice::setAdvertisingInterval(uint16_t interval)
Rohit Grover 77:1436ecf09583 330 {
Rohit Grover 46:33d87f468a0d 331 advParams.setInterval(interval);
Rohit Grover 46:33d87f468a0d 332 }
Rohit Grover 46:33d87f468a0d 333
Rohit Grover 46:33d87f468a0d 334 inline void
Rohit Grover 81:fd8c6792281b 335 BLEDevice::setAdvertisingTimeout(uint16_t timeout)
Rohit Grover 77:1436ecf09583 336 {
Rohit Grover 46:33d87f468a0d 337 advParams.setTimeout(timeout);
Rohit Grover 46:33d87f468a0d 338 }
Rohit Grover 46:33d87f468a0d 339
Rohit Grover 46:33d87f468a0d 340 inline void
Rohit Grover 81:fd8c6792281b 341 BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams)
Rohit Grover 77:1436ecf09583 342 {
Rohit Grover 46:33d87f468a0d 343 advParams = newAdvParams;
Rohit Grover 46:33d87f468a0d 344 }
Rohit Grover 46:33d87f468a0d 345
Rohit Grover 49:03a51f0006f8 346 inline void
Rohit Grover 81:fd8c6792281b 347 BLEDevice::clearAdvertisingPayload(void)
Rohit Grover 77:1436ecf09583 348 {
Rohit Grover 98:d751acb2543f 349 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 350 advPayload.clear();
Rohit Grover 49:03a51f0006f8 351 }
Rohit Grover 49:03a51f0006f8 352
Rohit Grover 49:03a51f0006f8 353 inline ble_error_t
Rohit Grover 100:1e80e8032c13 354 BLEDevice::accumulateAdvertisingPayload(uint8_t flags)
Rohit Grover 77:1436ecf09583 355 {
Rohit Grover 98:d751acb2543f 356 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 357 return advPayload.addFlags(flags);
Rohit Grover 49:03a51f0006f8 358 }
Rohit Grover 49:03a51f0006f8 359
Rohit Grover 49:03a51f0006f8 360 inline ble_error_t
Rohit Grover 81:fd8c6792281b 361 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app)
Rohit Grover 77:1436ecf09583 362 {
Rohit Grover 98:d751acb2543f 363 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 364 return advPayload.addAppearance(app);
Rohit Grover 49:03a51f0006f8 365 }
Rohit Grover 49:03a51f0006f8 366
Rohit Grover 49:03a51f0006f8 367 inline ble_error_t
Rohit Grover 81:fd8c6792281b 368 BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower)
Rohit Grover 77:1436ecf09583 369 {
Rohit Grover 98:d751acb2543f 370 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 371 return advPayload.addTxPower(txPower);
Rohit Grover 49:03a51f0006f8 372 }
Rohit Grover 49:03a51f0006f8 373
Rohit Grover 49:03a51f0006f8 374 inline ble_error_t
Rohit Grover 103:8890715aaf55 375 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
Rohit Grover 77:1436ecf09583 376 {
Rohit Grover 98:d751acb2543f 377 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 378 return advPayload.addData(type, data, len);
Rohit Grover 49:03a51f0006f8 379 }
Rohit Grover 49:03a51f0006f8 380
Rohit Grover 39:a57137537521 381 inline ble_error_t
Rohit Grover 103:8890715aaf55 382 BLEDevice::accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
Rohit Grover 103:8890715aaf55 383 {
Rohit Grover 103:8890715aaf55 384 needToSetAdvPayload = true;
Rohit Grover 103:8890715aaf55 385 return scanResponse.addData(type, data, len);
Rohit Grover 103:8890715aaf55 386 }
Rohit Grover 103:8890715aaf55 387
Rohit Grover 103:8890715aaf55 388 inline ble_error_t
Rohit Grover 98:d751acb2543f 389 BLEDevice::setAdvertisingPayload(void) {
Rohit Grover 98:d751acb2543f 390 needToSetAdvPayload = false;
Rohit Grover 98:d751acb2543f 391 return transport->getGap().setAdvertisingData(advPayload, scanResponse);
Rohit Grover 98:d751acb2543f 392 }
Rohit Grover 98:d751acb2543f 393
Rohit Grover 98:d751acb2543f 394 inline ble_error_t
Rohit Grover 81:fd8c6792281b 395 BLEDevice::startAdvertising(void)
Rohit Grover 77:1436ecf09583 396 {
Rohit Grover 98:d751acb2543f 397 if (needToSetAdvPayload) {
Rohit Grover 98:d751acb2543f 398 ble_error_t rc;
Rohit Grover 98:d751acb2543f 399 if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) {
Rohit Grover 98:d751acb2543f 400 return rc;
Rohit Grover 98:d751acb2543f 401 }
Rohit Grover 49:03a51f0006f8 402 }
Rohit Grover 49:03a51f0006f8 403
Rohit Grover 41:7ae5c71cd44c 404 return transport->getGap().startAdvertising(advParams);
Rohit Grover 36:9ec94579bb78 405 }
Rohit Grover 36:9ec94579bb78 406
Rohit Grover 39:a57137537521 407 inline ble_error_t
Rohit Grover 81:fd8c6792281b 408 BLEDevice::stopAdvertising(void)
Rohit Grover 77:1436ecf09583 409 {
Rohit Grover 41:7ae5c71cd44c 410 return transport->getGap().stopAdvertising();
Rohit Grover 36:9ec94579bb78 411 }
Rohit Grover 36:9ec94579bb78 412
Rohit Grover 39:a57137537521 413 inline ble_error_t
Rohit Grover 81:fd8c6792281b 414 BLEDevice::disconnect(void)
Rohit Grover 77:1436ecf09583 415 {
Rohit Grover 41:7ae5c71cd44c 416 return transport->getGap().disconnect();
Rohit Grover 36:9ec94579bb78 417 }
Rohit Grover 36:9ec94579bb78 418
Rohit Grover 64:95529f47b782 419 inline void
Rohit Grover 81:fd8c6792281b 420 BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback)
Rohit Grover 77:1436ecf09583 421 {
Rohit Grover 64:95529f47b782 422 transport->getGap().setOnTimeout(timeoutCallback);
Rohit Grover 64:95529f47b782 423 }
Rohit Grover 64:95529f47b782 424
Rohit Grover 64:95529f47b782 425 inline void
Rohit Grover 104:6ef5abef5714 426 BLEDevice::onConnection(Gap::HandleSpecificEventCallback_t connectionCallback)
Rohit Grover 77:1436ecf09583 427 {
Rohit Grover 64:95529f47b782 428 transport->getGap().setOnConnection(connectionCallback);
Rohit Grover 64:95529f47b782 429 }
Rohit Grover 64:95529f47b782 430
Rohit Grover 64:95529f47b782 431 inline void
Rohit Grover 104:6ef5abef5714 432 BLEDevice::onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback)
Rohit Grover 77:1436ecf09583 433 {
Rohit Grover 64:95529f47b782 434 transport->getGap().setOnDisconnection(disconnectionCallback);
Rohit Grover 64:95529f47b782 435 }
Rohit Grover 64:95529f47b782 436
Rohit Grover 64:95529f47b782 437 inline void
Rohit Grover 99:58c47085e816 438 BLEDevice::onDataSent(GattServer::ServerEventCallback_t callback)
Rohit Grover 77:1436ecf09583 439 {
Rohit Grover 64:95529f47b782 440 transport->getGattServer().setOnDataSent(callback);
Rohit Grover 64:95529f47b782 441 }
Rohit Grover 64:95529f47b782 442
Rohit Grover 64:95529f47b782 443 inline void
Rohit Grover 81:fd8c6792281b 444 BLEDevice::onDataWritten(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 445 {
Rohit Grover 64:95529f47b782 446 transport->getGattServer().setOnDataWritten(callback);
Rohit Grover 64:95529f47b782 447 }
Rohit Grover 64:95529f47b782 448
Rohit Grover 64:95529f47b782 449 inline void
Rohit Grover 81:fd8c6792281b 450 BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 451 {
Rohit Grover 64:95529f47b782 452 transport->getGattServer().setOnUpdatesEnabled(callback);
Rohit Grover 64:95529f47b782 453 }
Rohit Grover 64:95529f47b782 454
Rohit Grover 64:95529f47b782 455 inline void
Rohit Grover 81:fd8c6792281b 456 BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 457 {
Rohit Grover 64:95529f47b782 458 transport->getGattServer().setOnUpdatesDisabled(callback);
Rohit Grover 64:95529f47b782 459 }
Rohit Grover 64:95529f47b782 460
Rohit Grover 64:95529f47b782 461 inline void
Rohit Grover 81:fd8c6792281b 462 BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 463 {
Rohit Grover 64:95529f47b782 464 transport->getGattServer().setOnConfirmationReceived(callback);
Rohit Grover 64:95529f47b782 465 }
Rohit Grover 64:95529f47b782 466
Rohit Grover 72:bd485a3b18c5 467 inline ble_error_t
Rohit Grover 81:fd8c6792281b 468 BLEDevice::addService(GattService &service)
Rohit Grover 77:1436ecf09583 469 {
Rohit Grover 72:bd485a3b18c5 470 return transport->getGattServer().addService(service);
Rohit Grover 72:bd485a3b18c5 471 }
Rohit Grover 72:bd485a3b18c5 472
Rohit Grover 73:eeb1ac3545e9 473 inline Gap::GapState_t
Rohit Grover 81:fd8c6792281b 474 BLEDevice::getGapState(void) const
Rohit Grover 77:1436ecf09583 475 {
Rohit Grover 73:eeb1ac3545e9 476 return transport->getGap().getState();
Rohit Grover 73:eeb1ac3545e9 477 }
Rohit Grover 73:eeb1ac3545e9 478
Rohit Grover 94:455363a6eb90 479 inline ble_error_t BLEDevice::readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP)
Rohit Grover 94:455363a6eb90 480 {
Rohit Grover 94:455363a6eb90 481 return transport->getGattServer().readValue(handle, buffer, lengthP);
Rohit Grover 94:455363a6eb90 482 }
Rohit Grover 94:455363a6eb90 483
Rohit Grover 74:301042c34cb8 484 inline ble_error_t
Rohit Grover 81:fd8c6792281b 485 BLEDevice::updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly)
Rohit Grover 77:1436ecf09583 486 {
Rohit Grover 74:301042c34cb8 487 return transport->getGattServer().updateValue(handle, const_cast<uint8_t *>(value), size, localOnly);
Rohit Grover 74:301042c34cb8 488 }
Rohit Grover 74:301042c34cb8 489
Rohit Grover 78:5d356ef94347 490 inline void
Rohit Grover 81:fd8c6792281b 491 BLEDevice::waitForEvent(void)
Rohit Grover 78:5d356ef94347 492 {
Rohit Grover 78:5d356ef94347 493 transport->waitForEvent();
Rohit Grover 78:5d356ef94347 494 }
Rohit Grover 78:5d356ef94347 495
Rohit Grover 105:f29ab9f74d7e 496 inline ble_error_t
Rohit Grover 105:f29ab9f74d7e 497 BLEDevice::getPreferredConnectionParams(Gap::ConnectionParams_t *params)
Rohit Grover 105:f29ab9f74d7e 498 {
Rohit Grover 105:f29ab9f74d7e 499 return transport->getGap().getPreferredConnectionParams(params);
Rohit Grover 105:f29ab9f74d7e 500 }
Rohit Grover 105:f29ab9f74d7e 501
Rohit Grover 105:f29ab9f74d7e 502 inline ble_error_t
Rohit Grover 105:f29ab9f74d7e 503 BLEDevice::setPreferredConnectionParams(const Gap::ConnectionParams_t *params)
Rohit Grover 105:f29ab9f74d7e 504 {
Rohit Grover 105:f29ab9f74d7e 505 return transport->getGap().setPreferredConnectionParams(params);
Rohit Grover 105:f29ab9f74d7e 506 }
Rohit Grover 105:f29ab9f74d7e 507
Rohit Grover 105:f29ab9f74d7e 508 inline ble_error_t
Rohit Grover 105:f29ab9f74d7e 509 BLEDevice::updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) {
Rohit Grover 105:f29ab9f74d7e 510 return transport->getGap().updateConnectionParams(handle, params);
Rohit Grover 105:f29ab9f74d7e 511 }
Rohit Grover 105:f29ab9f74d7e 512
Rohit Grover 48:ec0c28e62abf 513 /*
Rohit Grover 48:ec0c28e62abf 514 * ALL OF THE FOLLOWING METHODS ARE DEPRECATED
Rohit Grover 48:ec0c28e62abf 515 */
Rohit Grover 48:ec0c28e62abf 516
Rohit Grover 48:ec0c28e62abf 517 inline ble_error_t
Rohit Grover 81:fd8c6792281b 518 BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse)
Rohit Grover 77:1436ecf09583 519 {
Rohit Grover 98:d751acb2543f 520 needToSetAdvPayload = false;
Rohit Grover 48:ec0c28e62abf 521 return transport->getGap().setAdvertisingData(ADStructures, scanResponse);
Rohit Grover 48:ec0c28e62abf 522 }
Rohit Grover 48:ec0c28e62abf 523
Rohit Grover 48:ec0c28e62abf 524 inline ble_error_t
Rohit Grover 81:fd8c6792281b 525 BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures)
Rohit Grover 77:1436ecf09583 526 {
Rohit Grover 48:ec0c28e62abf 527 GapAdvertisingData scanResponse;
Rohit Grover 98:d751acb2543f 528
Rohit Grover 98:d751acb2543f 529 needToSetAdvPayload = false;
Rohit Grover 48:ec0c28e62abf 530 return transport->getGap().setAdvertisingData(ADStructures, scanResponse);
Rohit Grover 48:ec0c28e62abf 531 }
Rohit Grover 48:ec0c28e62abf 532
Rohit Grover 46:33d87f468a0d 533 inline ble_error_t
Rohit Grover 81:fd8c6792281b 534 BLEDevice::startAdvertising(const GapAdvertisingParams &_advParams)
Rohit Grover 77:1436ecf09583 535 {
Rohit Grover 46:33d87f468a0d 536 return transport->getGap().startAdvertising(_advParams);
Rohit Grover 46:33d87f468a0d 537 }
Rohit Grover 46:33d87f468a0d 538
Rohit Grover 81:fd8c6792281b 539 #endif // ifndef __BLE_DEVICE__