Wang Xinglu / BLE_API

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Wed Jul 09 09:08:53 2014 +0100
Revision:
103:8890715aaf55
Parent:
102:39e30ac179a7
Child:
104:6ef5abef5714
add accumulateScanResponse() to BLEDevice.h

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