Bizan Nishimura / BLE_API

Dependents:   MiniSteer_BLE

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Thu Jul 10 12:12:06 2014 +0100
Revision:
104:6ef5abef5714
Parent:
103:8890715aaf55
Child:
105:f29ab9f74d7e
connection and disconnection callbacks need to take a connection handle

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 41:7ae5c71cd44c 253 public:
Rohit Grover 98:d751acb2543f 254 BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true) {
Rohit Grover 49:03a51f0006f8 255 advPayload.clear();
Rohit Grover 49:03a51f0006f8 256 scanResponse.clear();
Rohit Grover 41:7ae5c71cd44c 257 }
Rohit Grover 41:7ae5c71cd44c 258
Rohit Grover 41:7ae5c71cd44c 259 private:
Rohit Grover 81:fd8c6792281b 260 BLEDeviceInstanceBase *const transport; /* the device specific backend */
Rohit Grover 46:33d87f468a0d 261
Rohit Grover 49:03a51f0006f8 262 GapAdvertisingParams advParams;
Rohit Grover 49:03a51f0006f8 263 GapAdvertisingData advPayload;
Rohit Grover 49:03a51f0006f8 264 GapAdvertisingData scanResponse;
Rohit Grover 75:d08bdef22500 265
Rohit Grover 75:d08bdef22500 266 /* Accumulation of AD structures in the advertisement payload should
Rohit Grover 75:d08bdef22500 267 * eventually result in a call to the target's setAdvertisingData() before
Rohit Grover 95:5d2102351bf4 268 * the server begins advertising. This flag marks the status of the pending update.*/
Rohit Grover 98:d751acb2543f 269 bool needToSetAdvPayload;
Rohit Grover 98:d751acb2543f 270
Rohit Grover 46:33d87f468a0d 271 /**
Rohit Grover 46:33d87f468a0d 272 * DEPRECATED
Rohit Grover 46:33d87f468a0d 273 */
Rohit Grover 46:33d87f468a0d 274 public:
Rohit Grover 75:d08bdef22500 275 ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse);
Rohit Grover 48:ec0c28e62abf 276 ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures);
Rohit Grover 48:ec0c28e62abf 277
Rohit Grover 46:33d87f468a0d 278 ble_error_t startAdvertising(const GapAdvertisingParams &advParams);
Rohit Grover 41:7ae5c71cd44c 279 };
Rohit Grover 41:7ae5c71cd44c 280
Rohit Grover 41:7ae5c71cd44c 281 /**
Rohit Grover 41:7ae5c71cd44c 282 * The interface for the transport object to be created by the target library's
Rohit Grover 81:fd8c6792281b 283 * createBLEDeviceInstance().
Rohit Grover 41:7ae5c71cd44c 284 */
Rohit Grover 81:fd8c6792281b 285 class BLEDeviceInstanceBase
Rohit Grover 41:7ae5c71cd44c 286 {
Rohit Grover 41:7ae5c71cd44c 287 public:
Rohit Grover 78:5d356ef94347 288 virtual Gap& getGap() = 0;
Rohit Grover 78:5d356ef94347 289 virtual GattServer& getGattServer() = 0;
Rohit Grover 78:5d356ef94347 290 virtual ble_error_t init(void) = 0;
Rohit Grover 78:5d356ef94347 291 virtual ble_error_t reset(void) = 0;
Rohit Grover 78:5d356ef94347 292 virtual void waitForEvent(void) = 0;
ktownsend 29:011e95ce78b8 293 };
ktownsend 29:011e95ce78b8 294
Rohit Grover 41:7ae5c71cd44c 295
Rohit Grover 81:fd8c6792281b 296 /* BLEDevice methods. Most of these simply forward the calls to the underlying
Rohit Grover 41:7ae5c71cd44c 297 * transport.*/
Rohit Grover 41:7ae5c71cd44c 298
Rohit Grover 41:7ae5c71cd44c 299 inline ble_error_t
Rohit Grover 81:fd8c6792281b 300 BLEDevice::init()
Rohit Grover 77:1436ecf09583 301 {
Rohit Grover 41:7ae5c71cd44c 302 return transport->init();
Rohit Grover 41:7ae5c71cd44c 303 }
Rohit Grover 41:7ae5c71cd44c 304
Rohit Grover 41:7ae5c71cd44c 305 inline ble_error_t
Rohit Grover 81:fd8c6792281b 306 BLEDevice::reset(void)
Rohit Grover 77:1436ecf09583 307 {
Rohit Grover 41:7ae5c71cd44c 308 return transport->reset();
Rohit Grover 41:7ae5c71cd44c 309 }
Rohit Grover 41:7ae5c71cd44c 310
Rohit Grover 39:a57137537521 311 inline ble_error_t
Rohit Grover 81:fd8c6792281b 312 BLEDevice::setAddress(Gap::addr_type_t type, const uint8_t address[6])
Rohit Grover 77:1436ecf09583 313 {
Rohit Grover 41:7ae5c71cd44c 314 return transport->getGap().setAddress(type, address);
Rohit Grover 36:9ec94579bb78 315 }
Rohit Grover 36:9ec94579bb78 316
Rohit Grover 46:33d87f468a0d 317 inline void
Rohit Grover 81:fd8c6792281b 318 BLEDevice::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType)
Rohit Grover 77:1436ecf09583 319 {
Rohit Grover 46:33d87f468a0d 320 advParams.setAdvertisingType(advType);
Rohit Grover 46:33d87f468a0d 321 }
Rohit Grover 46:33d87f468a0d 322
Rohit Grover 46:33d87f468a0d 323 inline void
Rohit Grover 81:fd8c6792281b 324 BLEDevice::setAdvertisingInterval(uint16_t interval)
Rohit Grover 77:1436ecf09583 325 {
Rohit Grover 46:33d87f468a0d 326 advParams.setInterval(interval);
Rohit Grover 46:33d87f468a0d 327 }
Rohit Grover 46:33d87f468a0d 328
Rohit Grover 46:33d87f468a0d 329 inline void
Rohit Grover 81:fd8c6792281b 330 BLEDevice::setAdvertisingTimeout(uint16_t timeout)
Rohit Grover 77:1436ecf09583 331 {
Rohit Grover 46:33d87f468a0d 332 advParams.setTimeout(timeout);
Rohit Grover 46:33d87f468a0d 333 }
Rohit Grover 46:33d87f468a0d 334
Rohit Grover 46:33d87f468a0d 335 inline void
Rohit Grover 81:fd8c6792281b 336 BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams)
Rohit Grover 77:1436ecf09583 337 {
Rohit Grover 46:33d87f468a0d 338 advParams = newAdvParams;
Rohit Grover 46:33d87f468a0d 339 }
Rohit Grover 46:33d87f468a0d 340
Rohit Grover 49:03a51f0006f8 341 inline void
Rohit Grover 81:fd8c6792281b 342 BLEDevice::clearAdvertisingPayload(void)
Rohit Grover 77:1436ecf09583 343 {
Rohit Grover 98:d751acb2543f 344 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 345 advPayload.clear();
Rohit Grover 49:03a51f0006f8 346 }
Rohit Grover 49:03a51f0006f8 347
Rohit Grover 49:03a51f0006f8 348 inline ble_error_t
Rohit Grover 100:1e80e8032c13 349 BLEDevice::accumulateAdvertisingPayload(uint8_t flags)
Rohit Grover 77:1436ecf09583 350 {
Rohit Grover 98:d751acb2543f 351 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 352 return advPayload.addFlags(flags);
Rohit Grover 49:03a51f0006f8 353 }
Rohit Grover 49:03a51f0006f8 354
Rohit Grover 49:03a51f0006f8 355 inline ble_error_t
Rohit Grover 81:fd8c6792281b 356 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app)
Rohit Grover 77:1436ecf09583 357 {
Rohit Grover 98:d751acb2543f 358 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 359 return advPayload.addAppearance(app);
Rohit Grover 49:03a51f0006f8 360 }
Rohit Grover 49:03a51f0006f8 361
Rohit Grover 49:03a51f0006f8 362 inline ble_error_t
Rohit Grover 81:fd8c6792281b 363 BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower)
Rohit Grover 77:1436ecf09583 364 {
Rohit Grover 98:d751acb2543f 365 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 366 return advPayload.addTxPower(txPower);
Rohit Grover 49:03a51f0006f8 367 }
Rohit Grover 49:03a51f0006f8 368
Rohit Grover 49:03a51f0006f8 369 inline ble_error_t
Rohit Grover 103:8890715aaf55 370 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
Rohit Grover 77:1436ecf09583 371 {
Rohit Grover 98:d751acb2543f 372 needToSetAdvPayload = true;
Rohit Grover 49:03a51f0006f8 373 return advPayload.addData(type, data, len);
Rohit Grover 49:03a51f0006f8 374 }
Rohit Grover 49:03a51f0006f8 375
Rohit Grover 39:a57137537521 376 inline ble_error_t
Rohit Grover 103:8890715aaf55 377 BLEDevice::accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
Rohit Grover 103:8890715aaf55 378 {
Rohit Grover 103:8890715aaf55 379 needToSetAdvPayload = true;
Rohit Grover 103:8890715aaf55 380 return scanResponse.addData(type, data, len);
Rohit Grover 103:8890715aaf55 381 }
Rohit Grover 103:8890715aaf55 382
Rohit Grover 103:8890715aaf55 383 inline ble_error_t
Rohit Grover 98:d751acb2543f 384 BLEDevice::setAdvertisingPayload(void) {
Rohit Grover 98:d751acb2543f 385 needToSetAdvPayload = false;
Rohit Grover 98:d751acb2543f 386 return transport->getGap().setAdvertisingData(advPayload, scanResponse);
Rohit Grover 98:d751acb2543f 387 }
Rohit Grover 98:d751acb2543f 388
Rohit Grover 98:d751acb2543f 389 inline ble_error_t
Rohit Grover 81:fd8c6792281b 390 BLEDevice::startAdvertising(void)
Rohit Grover 77:1436ecf09583 391 {
Rohit Grover 98:d751acb2543f 392 if (needToSetAdvPayload) {
Rohit Grover 98:d751acb2543f 393 ble_error_t rc;
Rohit Grover 98:d751acb2543f 394 if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) {
Rohit Grover 98:d751acb2543f 395 return rc;
Rohit Grover 98:d751acb2543f 396 }
Rohit Grover 49:03a51f0006f8 397 }
Rohit Grover 49:03a51f0006f8 398
Rohit Grover 41:7ae5c71cd44c 399 return transport->getGap().startAdvertising(advParams);
Rohit Grover 36:9ec94579bb78 400 }
Rohit Grover 36:9ec94579bb78 401
Rohit Grover 39:a57137537521 402 inline ble_error_t
Rohit Grover 81:fd8c6792281b 403 BLEDevice::stopAdvertising(void)
Rohit Grover 77:1436ecf09583 404 {
Rohit Grover 41:7ae5c71cd44c 405 return transport->getGap().stopAdvertising();
Rohit Grover 36:9ec94579bb78 406 }
Rohit Grover 36:9ec94579bb78 407
Rohit Grover 39:a57137537521 408 inline ble_error_t
Rohit Grover 81:fd8c6792281b 409 BLEDevice::disconnect(void)
Rohit Grover 77:1436ecf09583 410 {
Rohit Grover 41:7ae5c71cd44c 411 return transport->getGap().disconnect();
Rohit Grover 36:9ec94579bb78 412 }
Rohit Grover 36:9ec94579bb78 413
Rohit Grover 64:95529f47b782 414 inline void
Rohit Grover 81:fd8c6792281b 415 BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback)
Rohit Grover 77:1436ecf09583 416 {
Rohit Grover 64:95529f47b782 417 transport->getGap().setOnTimeout(timeoutCallback);
Rohit Grover 64:95529f47b782 418 }
Rohit Grover 64:95529f47b782 419
Rohit Grover 64:95529f47b782 420 inline void
Rohit Grover 104:6ef5abef5714 421 BLEDevice::onConnection(Gap::HandleSpecificEventCallback_t connectionCallback)
Rohit Grover 77:1436ecf09583 422 {
Rohit Grover 64:95529f47b782 423 transport->getGap().setOnConnection(connectionCallback);
Rohit Grover 64:95529f47b782 424 }
Rohit Grover 64:95529f47b782 425
Rohit Grover 64:95529f47b782 426 inline void
Rohit Grover 104:6ef5abef5714 427 BLEDevice::onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback)
Rohit Grover 77:1436ecf09583 428 {
Rohit Grover 64:95529f47b782 429 transport->getGap().setOnDisconnection(disconnectionCallback);
Rohit Grover 64:95529f47b782 430 }
Rohit Grover 64:95529f47b782 431
Rohit Grover 64:95529f47b782 432 inline void
Rohit Grover 99:58c47085e816 433 BLEDevice::onDataSent(GattServer::ServerEventCallback_t callback)
Rohit Grover 77:1436ecf09583 434 {
Rohit Grover 64:95529f47b782 435 transport->getGattServer().setOnDataSent(callback);
Rohit Grover 64:95529f47b782 436 }
Rohit Grover 64:95529f47b782 437
Rohit Grover 64:95529f47b782 438 inline void
Rohit Grover 81:fd8c6792281b 439 BLEDevice::onDataWritten(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 440 {
Rohit Grover 64:95529f47b782 441 transport->getGattServer().setOnDataWritten(callback);
Rohit Grover 64:95529f47b782 442 }
Rohit Grover 64:95529f47b782 443
Rohit Grover 64:95529f47b782 444 inline void
Rohit Grover 81:fd8c6792281b 445 BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 446 {
Rohit Grover 64:95529f47b782 447 transport->getGattServer().setOnUpdatesEnabled(callback);
Rohit Grover 64:95529f47b782 448 }
Rohit Grover 64:95529f47b782 449
Rohit Grover 64:95529f47b782 450 inline void
Rohit Grover 81:fd8c6792281b 451 BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 452 {
Rohit Grover 64:95529f47b782 453 transport->getGattServer().setOnUpdatesDisabled(callback);
Rohit Grover 64:95529f47b782 454 }
Rohit Grover 64:95529f47b782 455
Rohit Grover 64:95529f47b782 456 inline void
Rohit Grover 81:fd8c6792281b 457 BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 458 {
Rohit Grover 64:95529f47b782 459 transport->getGattServer().setOnConfirmationReceived(callback);
Rohit Grover 64:95529f47b782 460 }
Rohit Grover 64:95529f47b782 461
Rohit Grover 72:bd485a3b18c5 462 inline ble_error_t
Rohit Grover 81:fd8c6792281b 463 BLEDevice::addService(GattService &service)
Rohit Grover 77:1436ecf09583 464 {
Rohit Grover 72:bd485a3b18c5 465 return transport->getGattServer().addService(service);
Rohit Grover 72:bd485a3b18c5 466 }
Rohit Grover 72:bd485a3b18c5 467
Rohit Grover 73:eeb1ac3545e9 468 inline Gap::GapState_t
Rohit Grover 81:fd8c6792281b 469 BLEDevice::getGapState(void) const
Rohit Grover 77:1436ecf09583 470 {
Rohit Grover 73:eeb1ac3545e9 471 return transport->getGap().getState();
Rohit Grover 73:eeb1ac3545e9 472 }
Rohit Grover 73:eeb1ac3545e9 473
Rohit Grover 94:455363a6eb90 474 inline ble_error_t BLEDevice::readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP)
Rohit Grover 94:455363a6eb90 475 {
Rohit Grover 94:455363a6eb90 476 return transport->getGattServer().readValue(handle, buffer, lengthP);
Rohit Grover 94:455363a6eb90 477 }
Rohit Grover 94:455363a6eb90 478
Rohit Grover 74:301042c34cb8 479 inline ble_error_t
Rohit Grover 81:fd8c6792281b 480 BLEDevice::updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly)
Rohit Grover 77:1436ecf09583 481 {
Rohit Grover 74:301042c34cb8 482 return transport->getGattServer().updateValue(handle, const_cast<uint8_t *>(value), size, localOnly);
Rohit Grover 74:301042c34cb8 483 }
Rohit Grover 74:301042c34cb8 484
Rohit Grover 78:5d356ef94347 485 inline void
Rohit Grover 81:fd8c6792281b 486 BLEDevice::waitForEvent(void)
Rohit Grover 78:5d356ef94347 487 {
Rohit Grover 78:5d356ef94347 488 transport->waitForEvent();
Rohit Grover 78:5d356ef94347 489 }
Rohit Grover 78:5d356ef94347 490
Rohit Grover 48:ec0c28e62abf 491 /*
Rohit Grover 48:ec0c28e62abf 492 * ALL OF THE FOLLOWING METHODS ARE DEPRECATED
Rohit Grover 48:ec0c28e62abf 493 */
Rohit Grover 48:ec0c28e62abf 494
Rohit Grover 48:ec0c28e62abf 495 inline ble_error_t
Rohit Grover 81:fd8c6792281b 496 BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse)
Rohit Grover 77:1436ecf09583 497 {
Rohit Grover 98:d751acb2543f 498 needToSetAdvPayload = false;
Rohit Grover 48:ec0c28e62abf 499 return transport->getGap().setAdvertisingData(ADStructures, scanResponse);
Rohit Grover 48:ec0c28e62abf 500 }
Rohit Grover 48:ec0c28e62abf 501
Rohit Grover 48:ec0c28e62abf 502 inline ble_error_t
Rohit Grover 81:fd8c6792281b 503 BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures)
Rohit Grover 77:1436ecf09583 504 {
Rohit Grover 48:ec0c28e62abf 505 GapAdvertisingData scanResponse;
Rohit Grover 98:d751acb2543f 506
Rohit Grover 98:d751acb2543f 507 needToSetAdvPayload = false;
Rohit Grover 48:ec0c28e62abf 508 return transport->getGap().setAdvertisingData(ADStructures, scanResponse);
Rohit Grover 48:ec0c28e62abf 509 }
Rohit Grover 48:ec0c28e62abf 510
Rohit Grover 46:33d87f468a0d 511 inline ble_error_t
Rohit Grover 81:fd8c6792281b 512 BLEDevice::startAdvertising(const GapAdvertisingParams &_advParams)
Rohit Grover 77:1436ecf09583 513 {
Rohit Grover 46:33d87f468a0d 514 return transport->getGap().startAdvertising(_advParams);
Rohit Grover 46:33d87f468a0d 515 }
Rohit Grover 46:33d87f468a0d 516
Rohit Grover 81:fd8c6792281b 517 #endif // ifndef __BLE_DEVICE__