Microbug / BLE_API

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Fri Jun 13 13:07:46 2014 +0100
Revision:
95:5d2102351bf4
Parent:
94:455363a6eb90
Child:
98:d751acb2543f
add comment headers to the commonly used functions of BLE_API

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 95:5d2102351bf4 124 * Reset any advertising payload prepared from prior calls to
Rohit Grover 95:5d2102351bf4 125 * accumulateAdvertisingPayload().
Rohit Grover 95:5d2102351bf4 126 */
Rohit Grover 49:03a51f0006f8 127 void clearAdvertisingPayload(void);
Rohit Grover 95:5d2102351bf4 128
Rohit Grover 95:5d2102351bf4 129 /**
Rohit Grover 95:5d2102351bf4 130 * Accumulate an AD structure in the advertising payload. Please note that
Rohit Grover 95:5d2102351bf4 131 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
Rohit Grover 95:5d2102351bf4 132 * as an additional 31 bytes if the advertising payload proves to be too
Rohit Grover 95:5d2102351bf4 133 * small.
Rohit Grover 95:5d2102351bf4 134 *
Rohit Grover 95:5d2102351bf4 135 * @param flags
Rohit Grover 95:5d2102351bf4 136 * The flag to be added.
Rohit Grover 95:5d2102351bf4 137 */
Rohit Grover 49:03a51f0006f8 138 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Flags flags);
Rohit Grover 95:5d2102351bf4 139
Rohit Grover 95:5d2102351bf4 140 /**
Rohit Grover 95:5d2102351bf4 141 * Accumulate an AD structure in the advertising payload. Please note that
Rohit Grover 95:5d2102351bf4 142 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
Rohit Grover 95:5d2102351bf4 143 * as an additional 31 bytes if the advertising payload proves to be too
Rohit Grover 95:5d2102351bf4 144 * small.
Rohit Grover 95:5d2102351bf4 145 *
Rohit Grover 95:5d2102351bf4 146 * @param app
Rohit Grover 95:5d2102351bf4 147 * The appearance of the peripheral.
Rohit Grover 95:5d2102351bf4 148 */
Rohit Grover 49:03a51f0006f8 149 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app);
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 max transmit power to be used by the controller. This is
Rohit Grover 95:5d2102351bf4 159 * only a hint.
Rohit Grover 95:5d2102351bf4 160 */
Rohit Grover 49:03a51f0006f8 161 ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power);
Rohit Grover 95:5d2102351bf4 162
Rohit Grover 95:5d2102351bf4 163 /**
Rohit Grover 95:5d2102351bf4 164 * @param app
Rohit Grover 95:5d2102351bf4 165 * The appearance of the peripheral.
Rohit Grover 95:5d2102351bf4 166 */
Rohit Grover 95:5d2102351bf4 167 /**
Rohit Grover 95:5d2102351bf4 168 * Accumulate a variable length byte-stream as an AD structure in the
Rohit Grover 95:5d2102351bf4 169 * advertising payload. Please note that the payload is limited to 31 bytes.
Rohit Grover 95:5d2102351bf4 170 * The SCAN_RESPONSE message may be used as an additional 31 bytes if the
Rohit Grover 95:5d2102351bf4 171 * advertising payload proves to be too small.
Rohit Grover 95:5d2102351bf4 172 *
Rohit Grover 95:5d2102351bf4 173 * @param type The type which describes the variable length data.
Rohit Grover 95:5d2102351bf4 174 * @param data data bytes.
Rohit Grover 95:5d2102351bf4 175 * @param len length of data.
Rohit Grover 95:5d2102351bf4 176 */
Rohit Grover 74:301042c34cb8 177 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len);
Rohit Grover 49:03a51f0006f8 178
Rohit Grover 95:5d2102351bf4 179 /**
Rohit Grover 95:5d2102351bf4 180 * Start advertising (GAP Discoverable, Connectable modes, Broadcast
Rohit Grover 95:5d2102351bf4 181 * Procedure).
Rohit Grover 95:5d2102351bf4 182 */
Rohit Grover 46:33d87f468a0d 183 ble_error_t startAdvertising(void);
Rohit Grover 95:5d2102351bf4 184
Rohit Grover 95:5d2102351bf4 185 /**
Rohit Grover 95:5d2102351bf4 186 * Stop advertising (GAP Discoverable, Connectable modes, Broadcast
Rohit Grover 95:5d2102351bf4 187 * Procedure).
Rohit Grover 95:5d2102351bf4 188 */
Rohit Grover 36:9ec94579bb78 189 ble_error_t stopAdvertising(void);
Rohit Grover 46:33d87f468a0d 190
Rohit Grover 36:9ec94579bb78 191 ble_error_t disconnect(void);
Rohit Grover 35:f3b0c1192cf7 192
Rohit Grover 64:95529f47b782 193 /* APIs to set GAP callbacks. */
Rohit Grover 63:653378e782ea 194 void onTimeout(Gap::EventCallback_t timeoutCallback);
Rohit Grover 63:653378e782ea 195 void onConnection(Gap::EventCallback_t connectionCallback);
Rohit Grover 95:5d2102351bf4 196 /**
Rohit Grover 95:5d2102351bf4 197 * Used to setup a callback for GAP disconnection.
Rohit Grover 95:5d2102351bf4 198 */
Rohit Grover 63:653378e782ea 199 void onDisconnection(Gap::EventCallback_t disconnectionCallback);
Rohit Grover 63:653378e782ea 200
Rohit Grover 95:5d2102351bf4 201 /**
Rohit Grover 95:5d2102351bf4 202 * Setup a callback for the GATT event DATA_SENT.
Rohit Grover 95:5d2102351bf4 203 */
Rohit Grover 64:95529f47b782 204 void onDataSent(GattServer::EventCallback_t callback);
Rohit Grover 95:5d2102351bf4 205
Rohit Grover 95:5d2102351bf4 206 /**
Rohit Grover 95:5d2102351bf4 207 * Setup a callback for when a characteristic has its value updated by a
Rohit Grover 95:5d2102351bf4 208 * client.
Rohit Grover 95:5d2102351bf4 209 */
Rohit Grover 64:95529f47b782 210 void onDataWritten(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 211 void onUpdatesEnabled(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 212 void onUpdatesDisabled(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 213 void onConfirmationReceived(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 214
Rohit Grover 95:5d2102351bf4 215 /**
Rohit Grover 95:5d2102351bf4 216 * Add a service declaration to the local server ATT table. Also add the
Rohit Grover 95:5d2102351bf4 217 * characteristics contained within.
Rohit Grover 95:5d2102351bf4 218 */
Rohit Grover 72:bd485a3b18c5 219 ble_error_t addService(GattService &service);
Rohit Grover 72:bd485a3b18c5 220
Rohit Grover 73:eeb1ac3545e9 221 Gap::GapState_t getGapState(void) const;
Rohit Grover 94:455363a6eb90 222
Rohit Grover 94:455363a6eb90 223 ble_error_t readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP);
Rohit Grover 94:455363a6eb90 224 ble_error_t updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly = false);
Rohit Grover 73:eeb1ac3545e9 225
Rohit Grover 78:5d356ef94347 226 /**
Rohit Grover 79:b6284f5928bb 227 * Yield control to the BLE stack or to other tasks waiting for events. This
Rohit Grover 79:b6284f5928bb 228 * is a sleep function which will return when there is an application
Rohit Grover 79:b6284f5928bb 229 * specific interrupt, but the MCU might wake up several times before
Rohit Grover 80:e2c50c4a1e9a 230 * returning (to service the stack). This is not always interchangeable with
Rohit Grover 80:e2c50c4a1e9a 231 * WFE().
Rohit Grover 78:5d356ef94347 232 */
Rohit Grover 78:5d356ef94347 233 void waitForEvent(void);
Rohit Grover 78:5d356ef94347 234
Rohit Grover 49:03a51f0006f8 235 private:
Rohit Grover 49:03a51f0006f8 236 /**
Rohit Grover 49:03a51f0006f8 237 * Internal helper to udpate the transport backend with advertising data
Rohit Grover 49:03a51f0006f8 238 * before starting to advertise.
Rohit Grover 49:03a51f0006f8 239 */
Rohit Grover 49:03a51f0006f8 240 ble_error_t setAdvertisingDataForTransport(void);
Rohit Grover 49:03a51f0006f8 241
Rohit Grover 41:7ae5c71cd44c 242 public:
Rohit Grover 81:fd8c6792281b 243 BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToUpdateAdvData(true) {
Rohit Grover 49:03a51f0006f8 244 advPayload.clear();
Rohit Grover 49:03a51f0006f8 245 scanResponse.clear();
Rohit Grover 41:7ae5c71cd44c 246 }
Rohit Grover 41:7ae5c71cd44c 247
Rohit Grover 41:7ae5c71cd44c 248 private:
Rohit Grover 81:fd8c6792281b 249 BLEDeviceInstanceBase *const transport; /* the device specific backend */
Rohit Grover 46:33d87f468a0d 250
Rohit Grover 49:03a51f0006f8 251 GapAdvertisingParams advParams;
Rohit Grover 49:03a51f0006f8 252 GapAdvertisingData advPayload;
Rohit Grover 49:03a51f0006f8 253 GapAdvertisingData scanResponse;
Rohit Grover 75:d08bdef22500 254
Rohit Grover 75:d08bdef22500 255 /* Accumulation of AD structures in the advertisement payload should
Rohit Grover 75:d08bdef22500 256 * eventually result in a call to the target's setAdvertisingData() before
Rohit Grover 95:5d2102351bf4 257 * the server begins advertising. This flag marks the status of the pending update.*/
Rohit Grover 75:d08bdef22500 258 bool needToUpdateAdvData;
Rohit Grover 46:33d87f468a0d 259
Rohit Grover 46:33d87f468a0d 260 /**
Rohit Grover 46:33d87f468a0d 261 * DEPRECATED
Rohit Grover 46:33d87f468a0d 262 */
Rohit Grover 46:33d87f468a0d 263 public:
Rohit Grover 75:d08bdef22500 264 ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse);
Rohit Grover 48:ec0c28e62abf 265 ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures);
Rohit Grover 48:ec0c28e62abf 266
Rohit Grover 46:33d87f468a0d 267 ble_error_t startAdvertising(const GapAdvertisingParams &advParams);
Rohit Grover 41:7ae5c71cd44c 268 };
Rohit Grover 41:7ae5c71cd44c 269
Rohit Grover 41:7ae5c71cd44c 270 /**
Rohit Grover 41:7ae5c71cd44c 271 * The interface for the transport object to be created by the target library's
Rohit Grover 81:fd8c6792281b 272 * createBLEDeviceInstance().
Rohit Grover 41:7ae5c71cd44c 273 */
Rohit Grover 81:fd8c6792281b 274 class BLEDeviceInstanceBase
Rohit Grover 41:7ae5c71cd44c 275 {
Rohit Grover 41:7ae5c71cd44c 276 public:
Rohit Grover 78:5d356ef94347 277 virtual Gap& getGap() = 0;
Rohit Grover 78:5d356ef94347 278 virtual GattServer& getGattServer() = 0;
Rohit Grover 78:5d356ef94347 279 virtual ble_error_t init(void) = 0;
Rohit Grover 78:5d356ef94347 280 virtual ble_error_t reset(void) = 0;
Rohit Grover 78:5d356ef94347 281 virtual void waitForEvent(void) = 0;
ktownsend 29:011e95ce78b8 282 };
ktownsend 29:011e95ce78b8 283
Rohit Grover 41:7ae5c71cd44c 284
Rohit Grover 81:fd8c6792281b 285 /* BLEDevice methods. Most of these simply forward the calls to the underlying
Rohit Grover 41:7ae5c71cd44c 286 * transport.*/
Rohit Grover 41:7ae5c71cd44c 287
Rohit Grover 41:7ae5c71cd44c 288 inline ble_error_t
Rohit Grover 81:fd8c6792281b 289 BLEDevice::init()
Rohit Grover 77:1436ecf09583 290 {
Rohit Grover 41:7ae5c71cd44c 291 return transport->init();
Rohit Grover 41:7ae5c71cd44c 292 }
Rohit Grover 41:7ae5c71cd44c 293
Rohit Grover 41:7ae5c71cd44c 294 inline ble_error_t
Rohit Grover 81:fd8c6792281b 295 BLEDevice::reset(void)
Rohit Grover 77:1436ecf09583 296 {
Rohit Grover 41:7ae5c71cd44c 297 return transport->reset();
Rohit Grover 41:7ae5c71cd44c 298 }
Rohit Grover 41:7ae5c71cd44c 299
Rohit Grover 39:a57137537521 300 inline ble_error_t
Rohit Grover 81:fd8c6792281b 301 BLEDevice::setAddress(Gap::addr_type_t type, const uint8_t address[6])
Rohit Grover 77:1436ecf09583 302 {
Rohit Grover 41:7ae5c71cd44c 303 return transport->getGap().setAddress(type, address);
Rohit Grover 36:9ec94579bb78 304 }
Rohit Grover 36:9ec94579bb78 305
Rohit Grover 46:33d87f468a0d 306 inline void
Rohit Grover 81:fd8c6792281b 307 BLEDevice::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType)
Rohit Grover 77:1436ecf09583 308 {
Rohit Grover 46:33d87f468a0d 309 advParams.setAdvertisingType(advType);
Rohit Grover 46:33d87f468a0d 310 }
Rohit Grover 46:33d87f468a0d 311
Rohit Grover 46:33d87f468a0d 312 inline void
Rohit Grover 81:fd8c6792281b 313 BLEDevice::setAdvertisingInterval(uint16_t interval)
Rohit Grover 77:1436ecf09583 314 {
Rohit Grover 46:33d87f468a0d 315 advParams.setInterval(interval);
Rohit Grover 46:33d87f468a0d 316 }
Rohit Grover 46:33d87f468a0d 317
Rohit Grover 46:33d87f468a0d 318 inline void
Rohit Grover 81:fd8c6792281b 319 BLEDevice::setAdvertisingTimeout(uint16_t timeout)
Rohit Grover 77:1436ecf09583 320 {
Rohit Grover 46:33d87f468a0d 321 advParams.setTimeout(timeout);
Rohit Grover 46:33d87f468a0d 322 }
Rohit Grover 46:33d87f468a0d 323
Rohit Grover 46:33d87f468a0d 324 inline void
Rohit Grover 81:fd8c6792281b 325 BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams)
Rohit Grover 77:1436ecf09583 326 {
Rohit Grover 46:33d87f468a0d 327 advParams = newAdvParams;
Rohit Grover 46:33d87f468a0d 328 }
Rohit Grover 46:33d87f468a0d 329
Rohit Grover 49:03a51f0006f8 330 inline void
Rohit Grover 81:fd8c6792281b 331 BLEDevice::clearAdvertisingPayload(void)
Rohit Grover 77:1436ecf09583 332 {
Rohit Grover 49:03a51f0006f8 333 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 334 advPayload.clear();
Rohit Grover 49:03a51f0006f8 335 }
Rohit Grover 49:03a51f0006f8 336
Rohit Grover 49:03a51f0006f8 337 inline ble_error_t
Rohit Grover 81:fd8c6792281b 338 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Flags flags)
Rohit Grover 77:1436ecf09583 339 {
Rohit Grover 49:03a51f0006f8 340 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 341 return advPayload.addFlags(flags);
Rohit Grover 49:03a51f0006f8 342 }
Rohit Grover 49:03a51f0006f8 343
Rohit Grover 49:03a51f0006f8 344 inline ble_error_t
Rohit Grover 81:fd8c6792281b 345 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app)
Rohit Grover 77:1436ecf09583 346 {
Rohit Grover 49:03a51f0006f8 347 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 348 return advPayload.addAppearance(app);
Rohit Grover 49:03a51f0006f8 349 }
Rohit Grover 49:03a51f0006f8 350
Rohit Grover 49:03a51f0006f8 351 inline ble_error_t
Rohit Grover 81:fd8c6792281b 352 BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower)
Rohit Grover 77:1436ecf09583 353 {
Rohit Grover 49:03a51f0006f8 354 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 355 return advPayload.addTxPower(txPower);
Rohit Grover 49:03a51f0006f8 356 }
Rohit Grover 49:03a51f0006f8 357
Rohit Grover 49:03a51f0006f8 358 inline ble_error_t
Rohit Grover 81:fd8c6792281b 359 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
Rohit Grover 77:1436ecf09583 360 {
Rohit Grover 49:03a51f0006f8 361 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 362 return advPayload.addData(type, data, len);
Rohit Grover 49:03a51f0006f8 363 }
Rohit Grover 49:03a51f0006f8 364
Rohit Grover 39:a57137537521 365 inline ble_error_t
Rohit Grover 81:fd8c6792281b 366 BLEDevice::startAdvertising(void)
Rohit Grover 77:1436ecf09583 367 {
Rohit Grover 49:03a51f0006f8 368 if (needToUpdateAdvData) {
Rohit Grover 49:03a51f0006f8 369 setAdvertisingDataForTransport();
Rohit Grover 49:03a51f0006f8 370 needToUpdateAdvData = false;
Rohit Grover 49:03a51f0006f8 371 }
Rohit Grover 49:03a51f0006f8 372
Rohit Grover 41:7ae5c71cd44c 373 return transport->getGap().startAdvertising(advParams);
Rohit Grover 36:9ec94579bb78 374 }
Rohit Grover 36:9ec94579bb78 375
Rohit Grover 39:a57137537521 376 inline ble_error_t
Rohit Grover 81:fd8c6792281b 377 BLEDevice::stopAdvertising(void)
Rohit Grover 77:1436ecf09583 378 {
Rohit Grover 41:7ae5c71cd44c 379 return transport->getGap().stopAdvertising();
Rohit Grover 36:9ec94579bb78 380 }
Rohit Grover 36:9ec94579bb78 381
Rohit Grover 39:a57137537521 382 inline ble_error_t
Rohit Grover 81:fd8c6792281b 383 BLEDevice::disconnect(void)
Rohit Grover 77:1436ecf09583 384 {
Rohit Grover 41:7ae5c71cd44c 385 return transport->getGap().disconnect();
Rohit Grover 36:9ec94579bb78 386 }
Rohit Grover 36:9ec94579bb78 387
Rohit Grover 49:03a51f0006f8 388 inline ble_error_t
Rohit Grover 81:fd8c6792281b 389 BLEDevice::setAdvertisingDataForTransport(void)
Rohit Grover 77:1436ecf09583 390 {
Rohit Grover 49:03a51f0006f8 391 return transport->getGap().setAdvertisingData(advPayload, scanResponse);
Rohit Grover 49:03a51f0006f8 392 }
Rohit Grover 49:03a51f0006f8 393
Rohit Grover 64:95529f47b782 394 inline void
Rohit Grover 81:fd8c6792281b 395 BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback)
Rohit Grover 77:1436ecf09583 396 {
Rohit Grover 64:95529f47b782 397 transport->getGap().setOnTimeout(timeoutCallback);
Rohit Grover 64:95529f47b782 398 }
Rohit Grover 64:95529f47b782 399
Rohit Grover 64:95529f47b782 400 inline void
Rohit Grover 81:fd8c6792281b 401 BLEDevice::onConnection(Gap::EventCallback_t connectionCallback)
Rohit Grover 77:1436ecf09583 402 {
Rohit Grover 64:95529f47b782 403 transport->getGap().setOnConnection(connectionCallback);
Rohit Grover 64:95529f47b782 404 }
Rohit Grover 64:95529f47b782 405
Rohit Grover 64:95529f47b782 406 inline void
Rohit Grover 81:fd8c6792281b 407 BLEDevice::onDisconnection(Gap::EventCallback_t disconnectionCallback)
Rohit Grover 77:1436ecf09583 408 {
Rohit Grover 64:95529f47b782 409 transport->getGap().setOnDisconnection(disconnectionCallback);
Rohit Grover 64:95529f47b782 410 }
Rohit Grover 64:95529f47b782 411
Rohit Grover 64:95529f47b782 412 inline void
Rohit Grover 81:fd8c6792281b 413 BLEDevice::onDataSent(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 414 {
Rohit Grover 64:95529f47b782 415 transport->getGattServer().setOnDataSent(callback);
Rohit Grover 64:95529f47b782 416 }
Rohit Grover 64:95529f47b782 417
Rohit Grover 64:95529f47b782 418 inline void
Rohit Grover 81:fd8c6792281b 419 BLEDevice::onDataWritten(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 420 {
Rohit Grover 64:95529f47b782 421 transport->getGattServer().setOnDataWritten(callback);
Rohit Grover 64:95529f47b782 422 }
Rohit Grover 64:95529f47b782 423
Rohit Grover 64:95529f47b782 424 inline void
Rohit Grover 81:fd8c6792281b 425 BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 426 {
Rohit Grover 64:95529f47b782 427 transport->getGattServer().setOnUpdatesEnabled(callback);
Rohit Grover 64:95529f47b782 428 }
Rohit Grover 64:95529f47b782 429
Rohit Grover 64:95529f47b782 430 inline void
Rohit Grover 81:fd8c6792281b 431 BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 432 {
Rohit Grover 64:95529f47b782 433 transport->getGattServer().setOnUpdatesDisabled(callback);
Rohit Grover 64:95529f47b782 434 }
Rohit Grover 64:95529f47b782 435
Rohit Grover 64:95529f47b782 436 inline void
Rohit Grover 81:fd8c6792281b 437 BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 438 {
Rohit Grover 64:95529f47b782 439 transport->getGattServer().setOnConfirmationReceived(callback);
Rohit Grover 64:95529f47b782 440 }
Rohit Grover 64:95529f47b782 441
Rohit Grover 72:bd485a3b18c5 442 inline ble_error_t
Rohit Grover 81:fd8c6792281b 443 BLEDevice::addService(GattService &service)
Rohit Grover 77:1436ecf09583 444 {
Rohit Grover 72:bd485a3b18c5 445 return transport->getGattServer().addService(service);
Rohit Grover 72:bd485a3b18c5 446 }
Rohit Grover 72:bd485a3b18c5 447
Rohit Grover 73:eeb1ac3545e9 448 inline Gap::GapState_t
Rohit Grover 81:fd8c6792281b 449 BLEDevice::getGapState(void) const
Rohit Grover 77:1436ecf09583 450 {
Rohit Grover 73:eeb1ac3545e9 451 return transport->getGap().getState();
Rohit Grover 73:eeb1ac3545e9 452 }
Rohit Grover 73:eeb1ac3545e9 453
Rohit Grover 94:455363a6eb90 454 inline ble_error_t BLEDevice::readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP)
Rohit Grover 94:455363a6eb90 455 {
Rohit Grover 94:455363a6eb90 456 return transport->getGattServer().readValue(handle, buffer, lengthP);
Rohit Grover 94:455363a6eb90 457 }
Rohit Grover 94:455363a6eb90 458
Rohit Grover 74:301042c34cb8 459 inline ble_error_t
Rohit Grover 81:fd8c6792281b 460 BLEDevice::updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly)
Rohit Grover 77:1436ecf09583 461 {
Rohit Grover 74:301042c34cb8 462 return transport->getGattServer().updateValue(handle, const_cast<uint8_t *>(value), size, localOnly);
Rohit Grover 74:301042c34cb8 463 }
Rohit Grover 74:301042c34cb8 464
Rohit Grover 78:5d356ef94347 465 inline void
Rohit Grover 81:fd8c6792281b 466 BLEDevice::waitForEvent(void)
Rohit Grover 78:5d356ef94347 467 {
Rohit Grover 78:5d356ef94347 468 transport->waitForEvent();
Rohit Grover 78:5d356ef94347 469 }
Rohit Grover 78:5d356ef94347 470
Rohit Grover 48:ec0c28e62abf 471 /*
Rohit Grover 48:ec0c28e62abf 472 * ALL OF THE FOLLOWING METHODS ARE DEPRECATED
Rohit Grover 48:ec0c28e62abf 473 */
Rohit Grover 48:ec0c28e62abf 474
Rohit Grover 48:ec0c28e62abf 475 inline ble_error_t
Rohit Grover 81:fd8c6792281b 476 BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse)
Rohit Grover 77:1436ecf09583 477 {
Rohit Grover 48:ec0c28e62abf 478 return transport->getGap().setAdvertisingData(ADStructures, scanResponse);
Rohit Grover 48:ec0c28e62abf 479 }
Rohit Grover 48:ec0c28e62abf 480
Rohit Grover 48:ec0c28e62abf 481 inline ble_error_t
Rohit Grover 81:fd8c6792281b 482 BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures)
Rohit Grover 77:1436ecf09583 483 {
Rohit Grover 48:ec0c28e62abf 484 GapAdvertisingData scanResponse;
Rohit Grover 48:ec0c28e62abf 485 return transport->getGap().setAdvertisingData(ADStructures, scanResponse);
Rohit Grover 48:ec0c28e62abf 486 }
Rohit Grover 48:ec0c28e62abf 487
Rohit Grover 46:33d87f468a0d 488 inline ble_error_t
Rohit Grover 81:fd8c6792281b 489 BLEDevice::startAdvertising(const GapAdvertisingParams &_advParams)
Rohit Grover 77:1436ecf09583 490 {
Rohit Grover 46:33d87f468a0d 491 return transport->getGap().startAdvertising(_advParams);
Rohit Grover 46:33d87f468a0d 492 }
Rohit Grover 46:33d87f468a0d 493
Rohit Grover 81:fd8c6792281b 494 #endif // ifndef __BLE_DEVICE__