Clément Bertolini / BLE_API

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Fri Jun 13 11:22:03 2014 +0100
Revision:
94:455363a6eb90
Parent:
81:fd8c6792281b
Child:
95:5d2102351bf4
add BLEDevice::readCharacteristicValue()

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 41:7ae5c71cd44c 44 ble_error_t init();
Rohit Grover 41:7ae5c71cd44c 45 ble_error_t reset(void);
Rohit Grover 35:f3b0c1192cf7 46
Rohit Grover 35:f3b0c1192cf7 47 /* GAP specific APIs */
Rohit Grover 35:f3b0c1192cf7 48 public:
Rohit Grover 37:7e8de07642e0 49 /**
Rohit Grover 37:7e8de07642e0 50 * Set the BTLE MAC address and type.
Rohit Grover 37:7e8de07642e0 51 * @return
Rohit Grover 37:7e8de07642e0 52 */
Rohit Grover 38:02cf26a2a4db 53 ble_error_t setAddress(Gap::addr_type_t type, const uint8_t address[6]);
Rohit Grover 35:f3b0c1192cf7 54
Rohit Grover 46:33d87f468a0d 55 /**
Rohit Grover 46:33d87f468a0d 56 * @param[in] advType
Rohit Grover 46:33d87f468a0d 57 * The GAP advertising mode to use for this device. Valid
Rohit Grover 46:33d87f468a0d 58 * values are defined in AdvertisingType:
Rohit Grover 46:33d87f468a0d 59 *
Rohit Grover 46:33d87f468a0d 60 * \par ADV_NON_CONNECTABLE_UNDIRECTED
Rohit Grover 46:33d87f468a0d 61 * All connections to the peripheral device will be refused.
Rohit Grover 46:33d87f468a0d 62 *
Rohit Grover 46:33d87f468a0d 63 * \par ADV_CONNECTABLE_DIRECTED
Rohit Grover 46:33d87f468a0d 64 * Only connections from a pre-defined central device will be
Rohit Grover 46:33d87f468a0d 65 * accepted.
Rohit Grover 46:33d87f468a0d 66 *
Rohit Grover 46:33d87f468a0d 67 * \par ADV_CONNECTABLE_UNDIRECTED
Rohit Grover 46:33d87f468a0d 68 * Any central device can connect to this peripheral.
Rohit Grover 46:33d87f468a0d 69 *
Rohit Grover 46:33d87f468a0d 70 * \par ADV_SCANNABLE_UNDIRECTED
Rohit Grover 46:33d87f468a0d 71 * Any central device can connect to this peripheral, and
Rohit Grover 46:33d87f468a0d 72 * the secondary Scan Response payload will be included or
Rohit Grover 46:33d87f468a0d 73 * available to central devices.
Rohit Grover 46:33d87f468a0d 74 *
Rohit Grover 46:33d87f468a0d 75 * \par
Rohit Grover 46:33d87f468a0d 76 * See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
Rohit Grover 46:33d87f468a0d 77 * Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
Rohit Grover 46:33d87f468a0d 78 * Section 2.3.1 for further information on GAP connection
Rohit Grover 46:33d87f468a0d 79 * modes
Rohit Grover 46:33d87f468a0d 80 */
Rohit Grover 46:33d87f468a0d 81 void setAdvertisingType(GapAdvertisingParams::AdvertisingType);
Rohit Grover 46:33d87f468a0d 82
Rohit Grover 46:33d87f468a0d 83 /**
Rohit Grover 46:33d87f468a0d 84 * @param[in] interval
Rohit Grover 46:33d87f468a0d 85 * Advertising interval between 0x0020 and 0x4000 in 0.625ms
Rohit Grover 46:33d87f468a0d 86 * units (20ms to 10.24s). If using non-connectable mode
Rohit Grover 46:33d87f468a0d 87 * (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is
Rohit Grover 46:33d87f468a0d 88 * 0x00A0 (100ms). To reduce the likelihood of collisions, the
Rohit Grover 46:33d87f468a0d 89 * link layer perturbs this interval by a pseudo-random delay
Rohit Grover 46:33d87f468a0d 90 * with a range of 0 ms to 10 ms for each advertising event.
Rohit Grover 46:33d87f468a0d 91 *
Rohit Grover 46:33d87f468a0d 92 * \par
Rohit Grover 46:33d87f468a0d 93 * Decreasing this value will allow central devices to detect
Rohit Grover 46:33d87f468a0d 94 * your peripheral faster at the expense of more power being
Rohit Grover 46:33d87f468a0d 95 * used by the radio due to the higher data transmit rate.
Rohit Grover 46:33d87f468a0d 96 *
Rohit Grover 46:33d87f468a0d 97 * \par
Rohit Grover 46:33d87f468a0d 98 * This field must be set to 0 if connectionMode is equal
Rohit Grover 46:33d87f468a0d 99 * to ADV_CONNECTABLE_DIRECTED
Rohit Grover 46:33d87f468a0d 100 *
Rohit Grover 46:33d87f468a0d 101 * \par
Rohit Grover 46:33d87f468a0d 102 * See Bluetooth Core Specification, Vol 3., Part C,
Rohit Grover 46:33d87f468a0d 103 * Appendix A for suggested advertising intervals.
Rohit Grover 46:33d87f468a0d 104 */
Rohit Grover 46:33d87f468a0d 105 void setAdvertisingInterval(uint16_t interval);
Rohit Grover 46:33d87f468a0d 106
Rohit Grover 46:33d87f468a0d 107 /**
Rohit Grover 46:33d87f468a0d 108 * @param[in] timeout
Rohit Grover 46:33d87f468a0d 109 * Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
Rohit Grover 46:33d87f468a0d 110 * in seconds. Enter 0 to disable the advertising timeout.
Rohit Grover 46:33d87f468a0d 111 */
Rohit Grover 46:33d87f468a0d 112 void setAdvertisingTimeout(uint16_t timeout);
Rohit Grover 46:33d87f468a0d 113
Rohit Grover 46:33d87f468a0d 114 /**
Rohit Grover 46:33d87f468a0d 115 * Please refer to the APIs above.
Rohit Grover 46:33d87f468a0d 116 */
Rohit Grover 46:33d87f468a0d 117 void setAdvertisingParams(const GapAdvertisingParams &advParams);
Rohit Grover 46:33d87f468a0d 118
Rohit Grover 49:03a51f0006f8 119 void clearAdvertisingPayload(void);
Rohit Grover 49:03a51f0006f8 120 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Flags flags);
Rohit Grover 49:03a51f0006f8 121 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app);
Rohit Grover 49:03a51f0006f8 122 ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power);
Rohit Grover 74:301042c34cb8 123 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len);
Rohit Grover 49:03a51f0006f8 124
Rohit Grover 46:33d87f468a0d 125 ble_error_t startAdvertising(void);
Rohit Grover 36:9ec94579bb78 126 ble_error_t stopAdvertising(void);
Rohit Grover 46:33d87f468a0d 127
Rohit Grover 36:9ec94579bb78 128 ble_error_t disconnect(void);
Rohit Grover 35:f3b0c1192cf7 129
Rohit Grover 64:95529f47b782 130 /* APIs to set GAP callbacks. */
Rohit Grover 63:653378e782ea 131 void onTimeout(Gap::EventCallback_t timeoutCallback);
Rohit Grover 63:653378e782ea 132 void onConnection(Gap::EventCallback_t connectionCallback);
Rohit Grover 63:653378e782ea 133 void onDisconnection(Gap::EventCallback_t disconnectionCallback);
Rohit Grover 63:653378e782ea 134
Rohit Grover 64:95529f47b782 135 /* APIs to set GATT server callbacks */
Rohit Grover 64:95529f47b782 136 void onDataSent(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 137 void onDataWritten(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 138 void onUpdatesEnabled(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 139 void onUpdatesDisabled(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 140 void onConfirmationReceived(GattServer::EventCallback_t callback);
Rohit Grover 64:95529f47b782 141
Rohit Grover 72:bd485a3b18c5 142 ble_error_t addService(GattService &service);
Rohit Grover 72:bd485a3b18c5 143
Rohit Grover 73:eeb1ac3545e9 144 Gap::GapState_t getGapState(void) const;
Rohit Grover 94:455363a6eb90 145
Rohit Grover 94:455363a6eb90 146 ble_error_t readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP);
Rohit Grover 94:455363a6eb90 147 ble_error_t updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly = false);
Rohit Grover 73:eeb1ac3545e9 148
Rohit Grover 78:5d356ef94347 149 /**
Rohit Grover 79:b6284f5928bb 150 * Yield control to the BLE stack or to other tasks waiting for events. This
Rohit Grover 79:b6284f5928bb 151 * is a sleep function which will return when there is an application
Rohit Grover 79:b6284f5928bb 152 * specific interrupt, but the MCU might wake up several times before
Rohit Grover 80:e2c50c4a1e9a 153 * returning (to service the stack). This is not always interchangeable with
Rohit Grover 80:e2c50c4a1e9a 154 * WFE().
Rohit Grover 78:5d356ef94347 155 */
Rohit Grover 78:5d356ef94347 156 void waitForEvent(void);
Rohit Grover 78:5d356ef94347 157
Rohit Grover 49:03a51f0006f8 158 private:
Rohit Grover 49:03a51f0006f8 159 /**
Rohit Grover 49:03a51f0006f8 160 * Internal helper to udpate the transport backend with advertising data
Rohit Grover 49:03a51f0006f8 161 * before starting to advertise.
Rohit Grover 49:03a51f0006f8 162 */
Rohit Grover 49:03a51f0006f8 163 ble_error_t setAdvertisingDataForTransport(void);
Rohit Grover 49:03a51f0006f8 164
Rohit Grover 41:7ae5c71cd44c 165 public:
Rohit Grover 81:fd8c6792281b 166 BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToUpdateAdvData(true) {
Rohit Grover 49:03a51f0006f8 167 advPayload.clear();
Rohit Grover 49:03a51f0006f8 168 scanResponse.clear();
Rohit Grover 41:7ae5c71cd44c 169 }
Rohit Grover 41:7ae5c71cd44c 170
Rohit Grover 41:7ae5c71cd44c 171 private:
Rohit Grover 81:fd8c6792281b 172 BLEDeviceInstanceBase *const transport; /* the device specific backend */
Rohit Grover 46:33d87f468a0d 173
Rohit Grover 49:03a51f0006f8 174 GapAdvertisingParams advParams;
Rohit Grover 49:03a51f0006f8 175 GapAdvertisingData advPayload;
Rohit Grover 49:03a51f0006f8 176 GapAdvertisingData scanResponse;
Rohit Grover 75:d08bdef22500 177
Rohit Grover 75:d08bdef22500 178 /* Accumulation of AD structures in the advertisement payload should
Rohit Grover 75:d08bdef22500 179 * eventually result in a call to the target's setAdvertisingData() before
Rohit Grover 75:d08bdef22500 180 * the server begins advertising. This flag marks the status of the pending
Rohit Grover 75:d08bdef22500 181 * update.*/
Rohit Grover 75:d08bdef22500 182 bool needToUpdateAdvData;
Rohit Grover 46:33d87f468a0d 183
Rohit Grover 46:33d87f468a0d 184 /**
Rohit Grover 46:33d87f468a0d 185 * DEPRECATED
Rohit Grover 46:33d87f468a0d 186 */
Rohit Grover 46:33d87f468a0d 187 public:
Rohit Grover 75:d08bdef22500 188 ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse);
Rohit Grover 48:ec0c28e62abf 189 ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures);
Rohit Grover 48:ec0c28e62abf 190
Rohit Grover 46:33d87f468a0d 191 ble_error_t startAdvertising(const GapAdvertisingParams &advParams);
Rohit Grover 41:7ae5c71cd44c 192 };
Rohit Grover 41:7ae5c71cd44c 193
Rohit Grover 41:7ae5c71cd44c 194 /**
Rohit Grover 41:7ae5c71cd44c 195 * The interface for the transport object to be created by the target library's
Rohit Grover 81:fd8c6792281b 196 * createBLEDeviceInstance().
Rohit Grover 41:7ae5c71cd44c 197 */
Rohit Grover 81:fd8c6792281b 198 class BLEDeviceInstanceBase
Rohit Grover 41:7ae5c71cd44c 199 {
Rohit Grover 41:7ae5c71cd44c 200 public:
Rohit Grover 78:5d356ef94347 201 virtual Gap& getGap() = 0;
Rohit Grover 78:5d356ef94347 202 virtual GattServer& getGattServer() = 0;
Rohit Grover 78:5d356ef94347 203 virtual ble_error_t init(void) = 0;
Rohit Grover 78:5d356ef94347 204 virtual ble_error_t reset(void) = 0;
Rohit Grover 78:5d356ef94347 205 virtual void waitForEvent(void) = 0;
ktownsend 29:011e95ce78b8 206 };
ktownsend 29:011e95ce78b8 207
Rohit Grover 41:7ae5c71cd44c 208
Rohit Grover 81:fd8c6792281b 209 /* BLEDevice methods. Most of these simply forward the calls to the underlying
Rohit Grover 41:7ae5c71cd44c 210 * transport.*/
Rohit Grover 41:7ae5c71cd44c 211
Rohit Grover 41:7ae5c71cd44c 212 inline ble_error_t
Rohit Grover 81:fd8c6792281b 213 BLEDevice::init()
Rohit Grover 77:1436ecf09583 214 {
Rohit Grover 41:7ae5c71cd44c 215 return transport->init();
Rohit Grover 41:7ae5c71cd44c 216 }
Rohit Grover 41:7ae5c71cd44c 217
Rohit Grover 41:7ae5c71cd44c 218 inline ble_error_t
Rohit Grover 81:fd8c6792281b 219 BLEDevice::reset(void)
Rohit Grover 77:1436ecf09583 220 {
Rohit Grover 41:7ae5c71cd44c 221 return transport->reset();
Rohit Grover 41:7ae5c71cd44c 222 }
Rohit Grover 41:7ae5c71cd44c 223
Rohit Grover 39:a57137537521 224 inline ble_error_t
Rohit Grover 81:fd8c6792281b 225 BLEDevice::setAddress(Gap::addr_type_t type, const uint8_t address[6])
Rohit Grover 77:1436ecf09583 226 {
Rohit Grover 41:7ae5c71cd44c 227 return transport->getGap().setAddress(type, address);
Rohit Grover 36:9ec94579bb78 228 }
Rohit Grover 36:9ec94579bb78 229
Rohit Grover 46:33d87f468a0d 230 inline void
Rohit Grover 81:fd8c6792281b 231 BLEDevice::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType)
Rohit Grover 77:1436ecf09583 232 {
Rohit Grover 46:33d87f468a0d 233 advParams.setAdvertisingType(advType);
Rohit Grover 46:33d87f468a0d 234 }
Rohit Grover 46:33d87f468a0d 235
Rohit Grover 46:33d87f468a0d 236 inline void
Rohit Grover 81:fd8c6792281b 237 BLEDevice::setAdvertisingInterval(uint16_t interval)
Rohit Grover 77:1436ecf09583 238 {
Rohit Grover 46:33d87f468a0d 239 advParams.setInterval(interval);
Rohit Grover 46:33d87f468a0d 240 }
Rohit Grover 46:33d87f468a0d 241
Rohit Grover 46:33d87f468a0d 242 inline void
Rohit Grover 81:fd8c6792281b 243 BLEDevice::setAdvertisingTimeout(uint16_t timeout)
Rohit Grover 77:1436ecf09583 244 {
Rohit Grover 46:33d87f468a0d 245 advParams.setTimeout(timeout);
Rohit Grover 46:33d87f468a0d 246 }
Rohit Grover 46:33d87f468a0d 247
Rohit Grover 46:33d87f468a0d 248 inline void
Rohit Grover 81:fd8c6792281b 249 BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams)
Rohit Grover 77:1436ecf09583 250 {
Rohit Grover 46:33d87f468a0d 251 advParams = newAdvParams;
Rohit Grover 46:33d87f468a0d 252 }
Rohit Grover 46:33d87f468a0d 253
Rohit Grover 49:03a51f0006f8 254 inline void
Rohit Grover 81:fd8c6792281b 255 BLEDevice::clearAdvertisingPayload(void)
Rohit Grover 77:1436ecf09583 256 {
Rohit Grover 49:03a51f0006f8 257 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 258 advPayload.clear();
Rohit Grover 49:03a51f0006f8 259 }
Rohit Grover 49:03a51f0006f8 260
Rohit Grover 49:03a51f0006f8 261 inline ble_error_t
Rohit Grover 81:fd8c6792281b 262 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Flags flags)
Rohit Grover 77:1436ecf09583 263 {
Rohit Grover 49:03a51f0006f8 264 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 265 return advPayload.addFlags(flags);
Rohit Grover 49:03a51f0006f8 266 }
Rohit Grover 49:03a51f0006f8 267
Rohit Grover 49:03a51f0006f8 268 inline ble_error_t
Rohit Grover 81:fd8c6792281b 269 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app)
Rohit Grover 77:1436ecf09583 270 {
Rohit Grover 49:03a51f0006f8 271 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 272 return advPayload.addAppearance(app);
Rohit Grover 49:03a51f0006f8 273 }
Rohit Grover 49:03a51f0006f8 274
Rohit Grover 49:03a51f0006f8 275 inline ble_error_t
Rohit Grover 81:fd8c6792281b 276 BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower)
Rohit Grover 77:1436ecf09583 277 {
Rohit Grover 49:03a51f0006f8 278 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 279 return advPayload.addTxPower(txPower);
Rohit Grover 49:03a51f0006f8 280 }
Rohit Grover 49:03a51f0006f8 281
Rohit Grover 49:03a51f0006f8 282 inline ble_error_t
Rohit Grover 81:fd8c6792281b 283 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
Rohit Grover 77:1436ecf09583 284 {
Rohit Grover 49:03a51f0006f8 285 needToUpdateAdvData = true;
Rohit Grover 49:03a51f0006f8 286 return advPayload.addData(type, data, len);
Rohit Grover 49:03a51f0006f8 287 }
Rohit Grover 49:03a51f0006f8 288
Rohit Grover 39:a57137537521 289 inline ble_error_t
Rohit Grover 81:fd8c6792281b 290 BLEDevice::startAdvertising(void)
Rohit Grover 77:1436ecf09583 291 {
Rohit Grover 49:03a51f0006f8 292 if (needToUpdateAdvData) {
Rohit Grover 49:03a51f0006f8 293 setAdvertisingDataForTransport();
Rohit Grover 49:03a51f0006f8 294 needToUpdateAdvData = false;
Rohit Grover 49:03a51f0006f8 295 }
Rohit Grover 49:03a51f0006f8 296
Rohit Grover 41:7ae5c71cd44c 297 return transport->getGap().startAdvertising(advParams);
Rohit Grover 36:9ec94579bb78 298 }
Rohit Grover 36:9ec94579bb78 299
Rohit Grover 39:a57137537521 300 inline ble_error_t
Rohit Grover 81:fd8c6792281b 301 BLEDevice::stopAdvertising(void)
Rohit Grover 77:1436ecf09583 302 {
Rohit Grover 41:7ae5c71cd44c 303 return transport->getGap().stopAdvertising();
Rohit Grover 36:9ec94579bb78 304 }
Rohit Grover 36:9ec94579bb78 305
Rohit Grover 39:a57137537521 306 inline ble_error_t
Rohit Grover 81:fd8c6792281b 307 BLEDevice::disconnect(void)
Rohit Grover 77:1436ecf09583 308 {
Rohit Grover 41:7ae5c71cd44c 309 return transport->getGap().disconnect();
Rohit Grover 36:9ec94579bb78 310 }
Rohit Grover 36:9ec94579bb78 311
Rohit Grover 49:03a51f0006f8 312 inline ble_error_t
Rohit Grover 81:fd8c6792281b 313 BLEDevice::setAdvertisingDataForTransport(void)
Rohit Grover 77:1436ecf09583 314 {
Rohit Grover 49:03a51f0006f8 315 return transport->getGap().setAdvertisingData(advPayload, scanResponse);
Rohit Grover 49:03a51f0006f8 316 }
Rohit Grover 49:03a51f0006f8 317
Rohit Grover 64:95529f47b782 318 inline void
Rohit Grover 81:fd8c6792281b 319 BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback)
Rohit Grover 77:1436ecf09583 320 {
Rohit Grover 64:95529f47b782 321 transport->getGap().setOnTimeout(timeoutCallback);
Rohit Grover 64:95529f47b782 322 }
Rohit Grover 64:95529f47b782 323
Rohit Grover 64:95529f47b782 324 inline void
Rohit Grover 81:fd8c6792281b 325 BLEDevice::onConnection(Gap::EventCallback_t connectionCallback)
Rohit Grover 77:1436ecf09583 326 {
Rohit Grover 64:95529f47b782 327 transport->getGap().setOnConnection(connectionCallback);
Rohit Grover 64:95529f47b782 328 }
Rohit Grover 64:95529f47b782 329
Rohit Grover 64:95529f47b782 330 inline void
Rohit Grover 81:fd8c6792281b 331 BLEDevice::onDisconnection(Gap::EventCallback_t disconnectionCallback)
Rohit Grover 77:1436ecf09583 332 {
Rohit Grover 64:95529f47b782 333 transport->getGap().setOnDisconnection(disconnectionCallback);
Rohit Grover 64:95529f47b782 334 }
Rohit Grover 64:95529f47b782 335
Rohit Grover 64:95529f47b782 336 inline void
Rohit Grover 81:fd8c6792281b 337 BLEDevice::onDataSent(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 338 {
Rohit Grover 64:95529f47b782 339 transport->getGattServer().setOnDataSent(callback);
Rohit Grover 64:95529f47b782 340 }
Rohit Grover 64:95529f47b782 341
Rohit Grover 64:95529f47b782 342 inline void
Rohit Grover 81:fd8c6792281b 343 BLEDevice::onDataWritten(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 344 {
Rohit Grover 64:95529f47b782 345 transport->getGattServer().setOnDataWritten(callback);
Rohit Grover 64:95529f47b782 346 }
Rohit Grover 64:95529f47b782 347
Rohit Grover 64:95529f47b782 348 inline void
Rohit Grover 81:fd8c6792281b 349 BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 350 {
Rohit Grover 64:95529f47b782 351 transport->getGattServer().setOnUpdatesEnabled(callback);
Rohit Grover 64:95529f47b782 352 }
Rohit Grover 64:95529f47b782 353
Rohit Grover 64:95529f47b782 354 inline void
Rohit Grover 81:fd8c6792281b 355 BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 356 {
Rohit Grover 64:95529f47b782 357 transport->getGattServer().setOnUpdatesDisabled(callback);
Rohit Grover 64:95529f47b782 358 }
Rohit Grover 64:95529f47b782 359
Rohit Grover 64:95529f47b782 360 inline void
Rohit Grover 81:fd8c6792281b 361 BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback)
Rohit Grover 77:1436ecf09583 362 {
Rohit Grover 64:95529f47b782 363 transport->getGattServer().setOnConfirmationReceived(callback);
Rohit Grover 64:95529f47b782 364 }
Rohit Grover 64:95529f47b782 365
Rohit Grover 72:bd485a3b18c5 366 inline ble_error_t
Rohit Grover 81:fd8c6792281b 367 BLEDevice::addService(GattService &service)
Rohit Grover 77:1436ecf09583 368 {
Rohit Grover 72:bd485a3b18c5 369 return transport->getGattServer().addService(service);
Rohit Grover 72:bd485a3b18c5 370 }
Rohit Grover 72:bd485a3b18c5 371
Rohit Grover 73:eeb1ac3545e9 372 inline Gap::GapState_t
Rohit Grover 81:fd8c6792281b 373 BLEDevice::getGapState(void) const
Rohit Grover 77:1436ecf09583 374 {
Rohit Grover 73:eeb1ac3545e9 375 return transport->getGap().getState();
Rohit Grover 73:eeb1ac3545e9 376 }
Rohit Grover 73:eeb1ac3545e9 377
Rohit Grover 94:455363a6eb90 378 inline ble_error_t BLEDevice::readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP)
Rohit Grover 94:455363a6eb90 379 {
Rohit Grover 94:455363a6eb90 380 return transport->getGattServer().readValue(handle, buffer, lengthP);
Rohit Grover 94:455363a6eb90 381 }
Rohit Grover 94:455363a6eb90 382
Rohit Grover 74:301042c34cb8 383 inline ble_error_t
Rohit Grover 81:fd8c6792281b 384 BLEDevice::updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly)
Rohit Grover 77:1436ecf09583 385 {
Rohit Grover 74:301042c34cb8 386 return transport->getGattServer().updateValue(handle, const_cast<uint8_t *>(value), size, localOnly);
Rohit Grover 74:301042c34cb8 387 }
Rohit Grover 74:301042c34cb8 388
Rohit Grover 78:5d356ef94347 389 inline void
Rohit Grover 81:fd8c6792281b 390 BLEDevice::waitForEvent(void)
Rohit Grover 78:5d356ef94347 391 {
Rohit Grover 78:5d356ef94347 392 transport->waitForEvent();
Rohit Grover 78:5d356ef94347 393 }
Rohit Grover 78:5d356ef94347 394
Rohit Grover 48:ec0c28e62abf 395 /*
Rohit Grover 48:ec0c28e62abf 396 * ALL OF THE FOLLOWING METHODS ARE DEPRECATED
Rohit Grover 48:ec0c28e62abf 397 */
Rohit Grover 48:ec0c28e62abf 398
Rohit Grover 48:ec0c28e62abf 399 inline ble_error_t
Rohit Grover 81:fd8c6792281b 400 BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse)
Rohit Grover 77:1436ecf09583 401 {
Rohit Grover 48:ec0c28e62abf 402 return transport->getGap().setAdvertisingData(ADStructures, scanResponse);
Rohit Grover 48:ec0c28e62abf 403 }
Rohit Grover 48:ec0c28e62abf 404
Rohit Grover 48:ec0c28e62abf 405 inline ble_error_t
Rohit Grover 81:fd8c6792281b 406 BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures)
Rohit Grover 77:1436ecf09583 407 {
Rohit Grover 48:ec0c28e62abf 408 GapAdvertisingData scanResponse;
Rohit Grover 48:ec0c28e62abf 409 return transport->getGap().setAdvertisingData(ADStructures, scanResponse);
Rohit Grover 48:ec0c28e62abf 410 }
Rohit Grover 48:ec0c28e62abf 411
Rohit Grover 46:33d87f468a0d 412 inline ble_error_t
Rohit Grover 81:fd8c6792281b 413 BLEDevice::startAdvertising(const GapAdvertisingParams &_advParams)
Rohit Grover 77:1436ecf09583 414 {
Rohit Grover 46:33d87f468a0d 415 return transport->getGap().startAdvertising(_advParams);
Rohit Grover 46:33d87f468a0d 416 }
Rohit Grover 46:33d87f468a0d 417
Rohit Grover 81:fd8c6792281b 418 #endif // ifndef __BLE_DEVICE__