Lightly modified version of the BLE stack, that doesn't bring up a DFUService by default... as we have our own.
Fork of BLE_API by
public/BLEDevice.h@146:543877bb1f52, 2014-11-28 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Nov 28 14:11:19 2014 +0000
- Revision:
- 146:543877bb1f52
- Parent:
- 145:a7ded9ad83c8
- Child:
- 147:f772d9b93808
Synchronized with git rev e8e3a7aa
Author: Rohit Grover
add Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rohit Grover |
106:a20be740075d | 1 | /* mbed Microcontroller Library |
Rohit Grover |
106:a20be740075d | 2 | * Copyright (c) 2006-2013 ARM Limited |
Rohit Grover |
106:a20be740075d | 3 | * |
Rohit Grover |
106:a20be740075d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Rohit Grover |
106:a20be740075d | 5 | * you may not use this file except in compliance with the License. |
Rohit Grover |
106:a20be740075d | 6 | * You may obtain a copy of the License at |
Rohit Grover |
106:a20be740075d | 7 | * |
Rohit Grover |
106:a20be740075d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Rohit Grover |
106:a20be740075d | 9 | * |
Rohit Grover |
106:a20be740075d | 10 | * Unless required by applicable law or agreed to in writing, software |
Rohit Grover |
106:a20be740075d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Rohit Grover |
106:a20be740075d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Rohit Grover |
106:a20be740075d | 13 | * See the License for the specific language governing permissions and |
Rohit Grover |
106:a20be740075d | 14 | * limitations under the License. |
Rohit Grover |
106:a20be740075d | 15 | */ |
Rohit Grover |
106:a20be740075d | 16 | |
Rohit Grover |
110:d5a824cee1d3 | 17 | #ifndef __BLE_DEVICE__ |
Rohit Grover |
110:d5a824cee1d3 | 18 | #define __BLE_DEVICE__ |
Rohit Grover |
110:d5a824cee1d3 | 19 | |
rgrover1 | 146:543877bb1f52 | 20 | #include "mbed.h" |
Rohit Grover |
106:a20be740075d | 21 | #include "blecommon.h" |
Rohit Grover |
106:a20be740075d | 22 | #include "Gap.h" |
Rohit Grover |
106:a20be740075d | 23 | #include "GattServer.h" |
Rohit Grover |
111:189ff241dae1 | 24 | #include "BLEDeviceInstanceBase.h" |
Rohit Grover |
106:a20be740075d | 25 | |
Rohit Grover |
106:a20be740075d | 26 | /** |
Rohit Grover |
106:a20be740075d | 27 | * The base class used to abstract away BLE capable radio transceivers or SOCs, |
Rohit Grover |
106:a20be740075d | 28 | * to enable this BLE API to work with any radio transparently. |
Rohit Grover |
106:a20be740075d | 29 | */ |
Rohit Grover |
106:a20be740075d | 30 | class BLEDevice |
Rohit Grover |
106:a20be740075d | 31 | { |
Rohit Grover |
106:a20be740075d | 32 | public: |
Rohit Grover |
106:a20be740075d | 33 | /** |
Rohit Grover |
106:a20be740075d | 34 | * Initialize the BLE controller. This should be called before using |
Rohit Grover |
106:a20be740075d | 35 | * anything else in the BLE_API. |
Rohit Grover |
106:a20be740075d | 36 | */ |
Rohit Grover |
106:a20be740075d | 37 | ble_error_t init(); |
Rohit Grover |
106:a20be740075d | 38 | ble_error_t reset(void); |
Rohit Grover |
106:a20be740075d | 39 | |
Rohit Grover |
106:a20be740075d | 40 | /* GAP specific APIs */ |
Rohit Grover |
106:a20be740075d | 41 | public: |
Rohit Grover |
106:a20be740075d | 42 | /** |
Rohit Grover |
106:a20be740075d | 43 | * Set the BTLE MAC address and type. |
Rohit Grover |
123:fede41ce9407 | 44 | * @return BLE_ERROR_NONE on success. |
Rohit Grover |
106:a20be740075d | 45 | */ |
rgrover1 | 140:407d134c179d | 46 | ble_error_t setAddress(Gap::addr_type_t type, const Gap::address_t address); |
Rohit Grover |
123:fede41ce9407 | 47 | |
Rohit Grover |
123:fede41ce9407 | 48 | /** |
Rohit Grover |
123:fede41ce9407 | 49 | * Fetch the BTLE MAC address and type. |
Rohit Grover |
123:fede41ce9407 | 50 | * @return BLE_ERROR_NONE on success. |
Rohit Grover |
123:fede41ce9407 | 51 | */ |
rgrover1 | 140:407d134c179d | 52 | ble_error_t getAddress(Gap::addr_type_t *typeP, Gap::address_t address); |
Rohit Grover |
106:a20be740075d | 53 | |
Rohit Grover |
106:a20be740075d | 54 | /** |
Rohit Grover |
106:a20be740075d | 55 | * @param[in] advType |
Rohit Grover |
106:a20be740075d | 56 | * The GAP advertising mode to use for this device. Valid |
Rohit Grover |
106:a20be740075d | 57 | * values are defined in AdvertisingType: |
Rohit Grover |
106:a20be740075d | 58 | * |
Rohit Grover |
106:a20be740075d | 59 | * \par ADV_NON_CONNECTABLE_UNDIRECTED |
Rohit Grover |
106:a20be740075d | 60 | * All connections to the peripheral device will be refused. |
Rohit Grover |
106:a20be740075d | 61 | * |
Rohit Grover |
106:a20be740075d | 62 | * \par ADV_CONNECTABLE_DIRECTED |
Rohit Grover |
106:a20be740075d | 63 | * Only connections from a pre-defined central device will be |
Rohit Grover |
106:a20be740075d | 64 | * accepted. |
Rohit Grover |
106:a20be740075d | 65 | * |
Rohit Grover |
106:a20be740075d | 66 | * \par ADV_CONNECTABLE_UNDIRECTED |
Rohit Grover |
106:a20be740075d | 67 | * Any central device can connect to this peripheral. |
Rohit Grover |
106:a20be740075d | 68 | * |
Rohit Grover |
106:a20be740075d | 69 | * \par ADV_SCANNABLE_UNDIRECTED |
Rohit Grover |
106:a20be740075d | 70 | * Any central device can connect to this peripheral, and |
Rohit Grover |
106:a20be740075d | 71 | * the secondary Scan Response payload will be included or |
Rohit Grover |
106:a20be740075d | 72 | * available to central devices. |
Rohit Grover |
106:a20be740075d | 73 | * |
Rohit Grover |
106:a20be740075d | 74 | * \par |
Rohit Grover |
106:a20be740075d | 75 | * See Bluetooth Core Specification 4.0 (Vol. 3), Part C, |
Rohit Grover |
106:a20be740075d | 76 | * Section 9.3 and Core Specification 4.0 (Vol. 6), Part B, |
Rohit Grover |
106:a20be740075d | 77 | * Section 2.3.1 for further information on GAP connection |
Rohit Grover |
106:a20be740075d | 78 | * modes |
Rohit Grover |
106:a20be740075d | 79 | */ |
Rohit Grover |
106:a20be740075d | 80 | void setAdvertisingType(GapAdvertisingParams::AdvertisingType); |
Rohit Grover |
106:a20be740075d | 81 | |
Rohit Grover |
106:a20be740075d | 82 | /** |
Rohit Grover |
106:a20be740075d | 83 | * @param[in] interval |
Rohit Grover |
106:a20be740075d | 84 | * Advertising interval between 0x0020 and 0x4000 in 0.625ms |
Rohit Grover |
106:a20be740075d | 85 | * units (20ms to 10.24s). If using non-connectable mode |
Rohit Grover |
106:a20be740075d | 86 | * (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is |
Rohit Grover |
106:a20be740075d | 87 | * 0x00A0 (100ms). To reduce the likelihood of collisions, the |
Rohit Grover |
106:a20be740075d | 88 | * link layer perturbs this interval by a pseudo-random delay |
Rohit Grover |
106:a20be740075d | 89 | * with a range of 0 ms to 10 ms for each advertising event. |
Rohit Grover |
106:a20be740075d | 90 | * |
Rohit Grover |
106:a20be740075d | 91 | * \par |
Rohit Grover |
106:a20be740075d | 92 | * Decreasing this value will allow central devices to detect |
Rohit Grover |
106:a20be740075d | 93 | * your peripheral faster at the expense of more power being |
Rohit Grover |
106:a20be740075d | 94 | * used by the radio due to the higher data transmit rate. |
Rohit Grover |
106:a20be740075d | 95 | * |
Rohit Grover |
106:a20be740075d | 96 | * \par |
Rohit Grover |
106:a20be740075d | 97 | * This field must be set to 0 if connectionMode is equal |
Rohit Grover |
106:a20be740075d | 98 | * to ADV_CONNECTABLE_DIRECTED |
Rohit Grover |
106:a20be740075d | 99 | * |
Rohit Grover |
106:a20be740075d | 100 | * \par |
Rohit Grover |
106:a20be740075d | 101 | * See Bluetooth Core Specification, Vol 3., Part C, |
Rohit Grover |
106:a20be740075d | 102 | * Appendix A for suggested advertising intervals. |
Rohit Grover |
106:a20be740075d | 103 | */ |
Rohit Grover |
106:a20be740075d | 104 | void setAdvertisingInterval(uint16_t interval); |
Rohit Grover |
106:a20be740075d | 105 | |
Rohit Grover |
106:a20be740075d | 106 | /** |
Rohit Grover |
106:a20be740075d | 107 | * @param[in] timeout |
Rohit Grover |
106:a20be740075d | 108 | * Advertising timeout between 0x1 and 0x3FFF (1 and 16383) |
Rohit Grover |
106:a20be740075d | 109 | * in seconds. Enter 0 to disable the advertising timeout. |
Rohit Grover |
106:a20be740075d | 110 | */ |
Rohit Grover |
106:a20be740075d | 111 | void setAdvertisingTimeout(uint16_t timeout); |
Rohit Grover |
106:a20be740075d | 112 | |
Rohit Grover |
106:a20be740075d | 113 | /** |
Rohit Grover |
106:a20be740075d | 114 | * Please refer to the APIs above. |
Rohit Grover |
106:a20be740075d | 115 | */ |
Rohit Grover |
106:a20be740075d | 116 | void setAdvertisingParams(const GapAdvertisingParams &advParams); |
Rohit Grover |
106:a20be740075d | 117 | |
Rohit Grover |
106:a20be740075d | 118 | /** |
Rohit Grover |
106:a20be740075d | 119 | * This API is typically used as an internal helper to udpate the transport |
Rohit Grover |
106:a20be740075d | 120 | * backend with advertising data before starting to advertise. It may also |
Rohit Grover |
106:a20be740075d | 121 | * be explicity used to dynamically reset the accumulated advertising |
Rohit Grover |
106:a20be740075d | 122 | * payload and scanResponse; to do this, the application can clear and re- |
Rohit Grover |
106:a20be740075d | 123 | * accumulate a new advertising payload (and scanResponse) before using this |
Rohit Grover |
106:a20be740075d | 124 | * API. |
Rohit Grover |
106:a20be740075d | 125 | */ |
Rohit Grover |
106:a20be740075d | 126 | ble_error_t setAdvertisingPayload(void); |
Rohit Grover |
106:a20be740075d | 127 | |
Rohit Grover |
106:a20be740075d | 128 | /** |
Rohit Grover |
106:a20be740075d | 129 | * Reset any advertising payload prepared from prior calls to |
Rohit Grover |
106:a20be740075d | 130 | * accumulateAdvertisingPayload(). |
Rohit Grover |
106:a20be740075d | 131 | */ |
Rohit Grover |
106:a20be740075d | 132 | void clearAdvertisingPayload(void); |
Rohit Grover |
106:a20be740075d | 133 | |
Rohit Grover |
106:a20be740075d | 134 | /** |
Rohit Grover |
106:a20be740075d | 135 | * Accumulate an AD structure in the advertising payload. Please note that |
Rohit Grover |
106:a20be740075d | 136 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
Rohit Grover |
106:a20be740075d | 137 | * as an additional 31 bytes if the advertising payload proves to be too |
Rohit Grover |
106:a20be740075d | 138 | * small. |
Rohit Grover |
106:a20be740075d | 139 | * |
Rohit Grover |
106:a20be740075d | 140 | * @param flags |
Rohit Grover |
106:a20be740075d | 141 | * The flags to be added. Multiple flags may be specified in |
Rohit Grover |
106:a20be740075d | 142 | * combination. |
Rohit Grover |
106:a20be740075d | 143 | */ |
Rohit Grover |
106:a20be740075d | 144 | ble_error_t accumulateAdvertisingPayload(uint8_t flags); |
Rohit Grover |
106:a20be740075d | 145 | |
Rohit Grover |
106:a20be740075d | 146 | /** |
Rohit Grover |
106:a20be740075d | 147 | * Accumulate an AD structure in the advertising payload. Please note that |
Rohit Grover |
106:a20be740075d | 148 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
Rohit Grover |
106:a20be740075d | 149 | * as an additional 31 bytes if the advertising payload proves to be too |
Rohit Grover |
106:a20be740075d | 150 | * small. |
Rohit Grover |
106:a20be740075d | 151 | * |
Rohit Grover |
106:a20be740075d | 152 | * @param app |
Rohit Grover |
106:a20be740075d | 153 | * The appearance of the peripheral. |
Rohit Grover |
106:a20be740075d | 154 | */ |
Rohit Grover |
106:a20be740075d | 155 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app); |
Rohit Grover |
106:a20be740075d | 156 | |
Rohit Grover |
106:a20be740075d | 157 | /** |
Rohit Grover |
106:a20be740075d | 158 | * Accumulate an AD structure in the advertising payload. Please note that |
Rohit Grover |
106:a20be740075d | 159 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
Rohit Grover |
106:a20be740075d | 160 | * as an additional 31 bytes if the advertising payload proves to be too |
Rohit Grover |
106:a20be740075d | 161 | * small. |
Rohit Grover |
106:a20be740075d | 162 | * |
Rohit Grover |
106:a20be740075d | 163 | * @param app |
Rohit Grover |
106:a20be740075d | 164 | * The max transmit power to be used by the controller. This is |
Rohit Grover |
106:a20be740075d | 165 | * only a hint. |
Rohit Grover |
106:a20be740075d | 166 | */ |
Rohit Grover |
106:a20be740075d | 167 | ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power); |
Rohit Grover |
106:a20be740075d | 168 | |
Rohit Grover |
106:a20be740075d | 169 | /** |
Rohit Grover |
106:a20be740075d | 170 | * Accumulate a variable length byte-stream as an AD structure in the |
Rohit Grover |
106:a20be740075d | 171 | * advertising payload. Please note that the payload is limited to 31 bytes. |
Rohit Grover |
106:a20be740075d | 172 | * The SCAN_RESPONSE message may be used as an additional 31 bytes if the |
Rohit Grover |
106:a20be740075d | 173 | * advertising payload proves to be too small. |
Rohit Grover |
106:a20be740075d | 174 | * |
Rohit Grover |
106:a20be740075d | 175 | * @param type The type which describes the variable length data. |
Rohit Grover |
106:a20be740075d | 176 | * @param data data bytes. |
Rohit Grover |
106:a20be740075d | 177 | * @param len length of data. |
Rohit Grover |
106:a20be740075d | 178 | */ |
Rohit Grover |
106:a20be740075d | 179 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len); |
Rohit Grover |
106:a20be740075d | 180 | |
Rohit Grover |
106:a20be740075d | 181 | /** |
Rohit Grover |
106:a20be740075d | 182 | * Accumulate a variable length byte-stream as an AD structure in the |
Rohit Grover |
106:a20be740075d | 183 | * scanResponse payload. |
Rohit Grover |
106:a20be740075d | 184 | * |
Rohit Grover |
106:a20be740075d | 185 | * @param type The type which describes the variable length data. |
Rohit Grover |
106:a20be740075d | 186 | * @param data data bytes. |
Rohit Grover |
106:a20be740075d | 187 | * @param len length of data. |
Rohit Grover |
106:a20be740075d | 188 | */ |
Rohit Grover |
106:a20be740075d | 189 | ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len); |
Rohit Grover |
106:a20be740075d | 190 | |
Rohit Grover |
106:a20be740075d | 191 | /** |
Rohit Grover |
106:a20be740075d | 192 | * Start advertising (GAP Discoverable, Connectable modes, Broadcast |
Rohit Grover |
106:a20be740075d | 193 | * Procedure). |
Rohit Grover |
106:a20be740075d | 194 | */ |
Rohit Grover |
106:a20be740075d | 195 | ble_error_t startAdvertising(void); |
Rohit Grover |
106:a20be740075d | 196 | |
Rohit Grover |
106:a20be740075d | 197 | /** |
Rohit Grover |
106:a20be740075d | 198 | * Stop advertising (GAP Discoverable, Connectable modes, Broadcast |
Rohit Grover |
106:a20be740075d | 199 | * Procedure). |
Rohit Grover |
106:a20be740075d | 200 | */ |
Rohit Grover |
106:a20be740075d | 201 | ble_error_t stopAdvertising(void); |
Rohit Grover |
106:a20be740075d | 202 | |
Rohit Grover |
116:ca826083980e | 203 | ble_error_t disconnect(Gap::DisconnectionReason_t reason); |
Rohit Grover |
106:a20be740075d | 204 | |
Rohit Grover |
106:a20be740075d | 205 | /* APIs to set GAP callbacks. */ |
Rohit Grover |
106:a20be740075d | 206 | void onTimeout(Gap::EventCallback_t timeoutCallback); |
Rohit Grover |
106:a20be740075d | 207 | |
Rohit Grover |
116:ca826083980e | 208 | void onConnection(Gap::ConnectionEventCallback_t connectionCallback); |
Rohit Grover |
106:a20be740075d | 209 | /** |
Rohit Grover |
106:a20be740075d | 210 | * Used to setup a callback for GAP disconnection. |
Rohit Grover |
106:a20be740075d | 211 | */ |
Rohit Grover |
116:ca826083980e | 212 | void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback); |
Rohit Grover |
106:a20be740075d | 213 | |
Rohit Grover |
106:a20be740075d | 214 | /** |
Rohit Grover |
106:a20be740075d | 215 | * Setup a callback for the GATT event DATA_SENT. |
Rohit Grover |
106:a20be740075d | 216 | */ |
Rohit Grover |
116:ca826083980e | 217 | void onDataSent(GattServer::ServerEventCallbackWithCount_t callback); |
Rohit Grover |
106:a20be740075d | 218 | |
Rohit Grover |
106:a20be740075d | 219 | /** |
Rohit Grover |
106:a20be740075d | 220 | * Setup a callback for when a characteristic has its value updated by a |
Rohit Grover |
106:a20be740075d | 221 | * client. |
Rohit Grover |
118:620d28e7a1ba | 222 | * |
Rohit Grover |
118:620d28e7a1ba | 223 | * @Note: it is possible to chain together multiple onDataWritten callbacks |
Rohit Grover |
118:620d28e7a1ba | 224 | * (potentially from different modules of an application) to receive updates |
Rohit Grover |
118:620d28e7a1ba | 225 | * to characteristics. Many services, such as DFU and UART add their own |
Rohit Grover |
118:620d28e7a1ba | 226 | * onDataWritten callbacks behind the scenes to trap interesting events. |
Rohit Grover |
118:620d28e7a1ba | 227 | * |
Rohit Grover |
118:620d28e7a1ba | 228 | * @Note: it is also possible to setup a callback into a member function of |
Rohit Grover |
118:620d28e7a1ba | 229 | * some object. |
Rohit Grover |
106:a20be740075d | 230 | */ |
Rohit Grover |
118:620d28e7a1ba | 231 | void onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)); |
rgrover1 | 140:407d134c179d | 232 | template <typename T> void onDataWritten(T * objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)); |
Rohit Grover |
118:620d28e7a1ba | 233 | |
Rohit Grover |
106:a20be740075d | 234 | void onUpdatesEnabled(GattServer::EventCallback_t callback); |
Rohit Grover |
106:a20be740075d | 235 | void onUpdatesDisabled(GattServer::EventCallback_t callback); |
Rohit Grover |
106:a20be740075d | 236 | void onConfirmationReceived(GattServer::EventCallback_t callback); |
Rohit Grover |
106:a20be740075d | 237 | |
Rohit Grover |
106:a20be740075d | 238 | /** |
Rohit Grover |
106:a20be740075d | 239 | * Add a service declaration to the local server ATT table. Also add the |
Rohit Grover |
106:a20be740075d | 240 | * characteristics contained within. |
Rohit Grover |
106:a20be740075d | 241 | */ |
Rohit Grover |
106:a20be740075d | 242 | ble_error_t addService(GattService &service); |
Rohit Grover |
106:a20be740075d | 243 | |
Rohit Grover |
106:a20be740075d | 244 | Gap::GapState_t getGapState(void) const; |
Rohit Grover |
106:a20be740075d | 245 | |
Rohit Grover |
118:620d28e7a1ba | 246 | /** |
Rohit Grover |
118:620d28e7a1ba | 247 | * @param[in/out] lengthP |
Rohit Grover |
118:620d28e7a1ba | 248 | * input: Length in bytes to be read, |
Rohit Grover |
118:620d28e7a1ba | 249 | * output: Total length of attribute value upon successful return. |
Rohit Grover |
118:620d28e7a1ba | 250 | */ |
Rohit Grover |
106:a20be740075d | 251 | ble_error_t readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP); |
Rohit Grover |
118:620d28e7a1ba | 252 | |
Rohit Grover |
118:620d28e7a1ba | 253 | /** |
Rohit Grover |
118:620d28e7a1ba | 254 | * @param localOnly |
Rohit Grover |
118:620d28e7a1ba | 255 | * Only update the characteristic locally regardless of notify/indicate flags in the CCCD. |
Rohit Grover |
118:620d28e7a1ba | 256 | */ |
rgrover1 | 140:407d134c179d | 257 | ble_error_t updateCharacteristicValue(uint16_t handle, const uint8_t *value, uint16_t size, bool localOnly = false); |
Rohit Grover |
106:a20be740075d | 258 | |
Rohit Grover |
106:a20be740075d | 259 | /** |
Rohit Grover |
106:a20be740075d | 260 | * Yield control to the BLE stack or to other tasks waiting for events. This |
Rohit Grover |
106:a20be740075d | 261 | * is a sleep function which will return when there is an application |
Rohit Grover |
106:a20be740075d | 262 | * specific interrupt, but the MCU might wake up several times before |
Rohit Grover |
106:a20be740075d | 263 | * returning (to service the stack). This is not always interchangeable with |
Rohit Grover |
106:a20be740075d | 264 | * WFE(). |
Rohit Grover |
106:a20be740075d | 265 | */ |
Rohit Grover |
106:a20be740075d | 266 | void waitForEvent(void); |
Rohit Grover |
106:a20be740075d | 267 | |
Rohit Grover |
106:a20be740075d | 268 | ble_error_t getPreferredConnectionParams(Gap::ConnectionParams_t *params); |
Rohit Grover |
106:a20be740075d | 269 | ble_error_t setPreferredConnectionParams(const Gap::ConnectionParams_t *params); |
Rohit Grover |
106:a20be740075d | 270 | ble_error_t updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params); |
Rohit Grover |
108:c85ab5f1eca0 | 271 | |
Rohit Grover |
108:c85ab5f1eca0 | 272 | /** |
Rohit Grover |
108:c85ab5f1eca0 | 273 | * This call allows the application to get the BLE stack version information. |
Rohit Grover |
108:c85ab5f1eca0 | 274 | * |
Rohit Grover |
108:c85ab5f1eca0 | 275 | * @return A pointer to a const string representing the version. |
Rohit Grover |
108:c85ab5f1eca0 | 276 | * Note: The string is owned by the BLE_API. |
Rohit Grover |
108:c85ab5f1eca0 | 277 | */ |
Rohit Grover |
108:c85ab5f1eca0 | 278 | const char *getVersion(void); |
Rohit Grover |
108:c85ab5f1eca0 | 279 | |
rgrover1 | 140:407d134c179d | 280 | /** |
rgrover1 | 140:407d134c179d | 281 | * Set the device name characteristic in the GAP service. |
rgrover1 | 140:407d134c179d | 282 | * @param deviceName The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string. |
rgrover1 | 140:407d134c179d | 283 | */ |
rgrover1 | 140:407d134c179d | 284 | ble_error_t setDeviceName(const uint8_t *deviceName); |
Rohit Grover |
108:c85ab5f1eca0 | 285 | |
rgrover1 | 140:407d134c179d | 286 | /** |
rgrover1 | 140:407d134c179d | 287 | * Get the value of the device name characteristic in the GAP service. |
rgrover1 | 140:407d134c179d | 288 | * @param[out] deviceName Pointer to an empty buffer where the UTF-8 *non NULL- |
rgrover1 | 140:407d134c179d | 289 | * terminated* string will be placed. Set this |
rgrover1 | 140:407d134c179d | 290 | * value to NULL in order to obtain the deviceName-length |
rgrover1 | 140:407d134c179d | 291 | * from the 'length' parameter. |
rgrover1 | 140:407d134c179d | 292 | * |
rgrover1 | 140:407d134c179d | 293 | * @param[in/out] lengthP (on input) Length of the buffer pointed to by deviceName; |
rgrover1 | 140:407d134c179d | 294 | * (on output) the complete device name length (without the |
rgrover1 | 140:407d134c179d | 295 | * null terminator). |
rgrover1 | 140:407d134c179d | 296 | * |
rgrover1 | 140:407d134c179d | 297 | * @note If the device name is longer than the size of the supplied buffer, |
rgrover1 | 140:407d134c179d | 298 | * length will return the complete device name length, |
rgrover1 | 140:407d134c179d | 299 | * and not the number of bytes actually returned in deviceName. |
rgrover1 | 140:407d134c179d | 300 | * The application may use this information to retry with a suitable buffer size. |
rgrover1 | 140:407d134c179d | 301 | * |
rgrover1 | 140:407d134c179d | 302 | * Sample use: |
rgrover1 | 140:407d134c179d | 303 | * uint8_t deviceName[20]; |
rgrover1 | 140:407d134c179d | 304 | * unsigned length = sizeof(deviceName); |
rgrover1 | 140:407d134c179d | 305 | * ble.getDeviceName(deviceName, &length); |
rgrover1 | 140:407d134c179d | 306 | * if (length < sizeof(deviceName)) { |
rgrover1 | 140:407d134c179d | 307 | * deviceName[length] = 0; |
rgrover1 | 140:407d134c179d | 308 | * } |
rgrover1 | 140:407d134c179d | 309 | * DEBUG("length: %u, deviceName: %s\r\n", length, deviceName); |
rgrover1 | 140:407d134c179d | 310 | */ |
rgrover1 | 140:407d134c179d | 311 | ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP); |
Rohit Grover |
108:c85ab5f1eca0 | 312 | |
rgrover1 | 140:407d134c179d | 313 | /** |
rgrover1 | 140:407d134c179d | 314 | * Set the appearance characteristic in the GAP service. |
rgrover1 | 140:407d134c179d | 315 | * @param[in] appearance The new value for the device-appearance. |
rgrover1 | 140:407d134c179d | 316 | */ |
rgrover1 | 140:407d134c179d | 317 | ble_error_t setAppearance(uint16_t appearance); |
Rohit Grover |
108:c85ab5f1eca0 | 318 | |
rgrover1 | 140:407d134c179d | 319 | /** |
rgrover1 | 140:407d134c179d | 320 | * Set the appearance characteristic in the GAP service. |
rgrover1 | 140:407d134c179d | 321 | * @param[out] appearance The new value for the device-appearance. |
rgrover1 | 140:407d134c179d | 322 | */ |
rgrover1 | 140:407d134c179d | 323 | ble_error_t getAppearance(uint16_t *appearanceP); |
Rohit Grover |
108:c85ab5f1eca0 | 324 | |
rgrover1 | 140:407d134c179d | 325 | /** |
rgrover1 | 140:407d134c179d | 326 | * Set the radio's transmit power. |
rgrover1 | 140:407d134c179d | 327 | * @param[in] txPower Radio transmit power in dBm. |
rgrover1 | 140:407d134c179d | 328 | */ |
rgrover1 | 140:407d134c179d | 329 | ble_error_t setTxPower(int8_t txPower); |
Rohit Grover |
106:a20be740075d | 330 | |
Rohit Grover |
106:a20be740075d | 331 | public: |
Rohit Grover |
106:a20be740075d | 332 | BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true) { |
Rohit Grover |
106:a20be740075d | 333 | advPayload.clear(); |
Rohit Grover |
106:a20be740075d | 334 | scanResponse.clear(); |
Rohit Grover |
106:a20be740075d | 335 | } |
Rohit Grover |
106:a20be740075d | 336 | |
Rohit Grover |
106:a20be740075d | 337 | private: |
Rohit Grover |
106:a20be740075d | 338 | BLEDeviceInstanceBase *const transport; /* the device specific backend */ |
Rohit Grover |
106:a20be740075d | 339 | |
Rohit Grover |
106:a20be740075d | 340 | GapAdvertisingParams advParams; |
Rohit Grover |
106:a20be740075d | 341 | GapAdvertisingData advPayload; |
Rohit Grover |
106:a20be740075d | 342 | GapAdvertisingData scanResponse; |
Rohit Grover |
106:a20be740075d | 343 | |
Rohit Grover |
106:a20be740075d | 344 | /* Accumulation of AD structures in the advertisement payload should |
Rohit Grover |
106:a20be740075d | 345 | * eventually result in a call to the target's setAdvertisingData() before |
Rohit Grover |
106:a20be740075d | 346 | * the server begins advertising. This flag marks the status of the pending update.*/ |
Rohit Grover |
106:a20be740075d | 347 | bool needToSetAdvPayload; |
Rohit Grover |
106:a20be740075d | 348 | |
Rohit Grover |
106:a20be740075d | 349 | /** |
Rohit Grover |
106:a20be740075d | 350 | * DEPRECATED |
Rohit Grover |
106:a20be740075d | 351 | */ |
Rohit Grover |
106:a20be740075d | 352 | public: |
Rohit Grover |
106:a20be740075d | 353 | ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse); |
Rohit Grover |
106:a20be740075d | 354 | ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures); |
Rohit Grover |
106:a20be740075d | 355 | |
Rohit Grover |
106:a20be740075d | 356 | ble_error_t startAdvertising(const GapAdvertisingParams &advParams); |
Rohit Grover |
106:a20be740075d | 357 | }; |
Rohit Grover |
106:a20be740075d | 358 | |
Rohit Grover |
106:a20be740075d | 359 | /* BLEDevice methods. Most of these simply forward the calls to the underlying |
Rohit Grover |
106:a20be740075d | 360 | * transport.*/ |
Rohit Grover |
106:a20be740075d | 361 | |
Rohit Grover |
106:a20be740075d | 362 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 363 | BLEDevice::reset(void) |
Rohit Grover |
106:a20be740075d | 364 | { |
Rohit Grover |
106:a20be740075d | 365 | return transport->reset(); |
Rohit Grover |
106:a20be740075d | 366 | } |
Rohit Grover |
106:a20be740075d | 367 | |
Rohit Grover |
106:a20be740075d | 368 | inline ble_error_t |
rgrover1 | 140:407d134c179d | 369 | BLEDevice::setAddress(Gap::addr_type_t type, const Gap::address_t address) |
Rohit Grover |
106:a20be740075d | 370 | { |
Rohit Grover |
106:a20be740075d | 371 | return transport->getGap().setAddress(type, address); |
Rohit Grover |
106:a20be740075d | 372 | } |
Rohit Grover |
106:a20be740075d | 373 | |
Rohit Grover |
123:fede41ce9407 | 374 | inline ble_error_t |
rgrover1 | 140:407d134c179d | 375 | BLEDevice::getAddress(Gap::addr_type_t *typeP, Gap::address_t address) |
Rohit Grover |
123:fede41ce9407 | 376 | { |
Rohit Grover |
123:fede41ce9407 | 377 | return transport->getGap().getAddress(typeP, address); |
Rohit Grover |
123:fede41ce9407 | 378 | } |
Rohit Grover |
123:fede41ce9407 | 379 | |
Rohit Grover |
106:a20be740075d | 380 | inline void |
Rohit Grover |
106:a20be740075d | 381 | BLEDevice::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType) |
Rohit Grover |
106:a20be740075d | 382 | { |
Rohit Grover |
106:a20be740075d | 383 | advParams.setAdvertisingType(advType); |
Rohit Grover |
106:a20be740075d | 384 | } |
Rohit Grover |
106:a20be740075d | 385 | |
Rohit Grover |
106:a20be740075d | 386 | inline void |
Rohit Grover |
106:a20be740075d | 387 | BLEDevice::setAdvertisingInterval(uint16_t interval) |
Rohit Grover |
106:a20be740075d | 388 | { |
Rohit Grover |
106:a20be740075d | 389 | advParams.setInterval(interval); |
Rohit Grover |
106:a20be740075d | 390 | } |
Rohit Grover |
106:a20be740075d | 391 | |
Rohit Grover |
106:a20be740075d | 392 | inline void |
Rohit Grover |
106:a20be740075d | 393 | BLEDevice::setAdvertisingTimeout(uint16_t timeout) |
Rohit Grover |
106:a20be740075d | 394 | { |
Rohit Grover |
106:a20be740075d | 395 | advParams.setTimeout(timeout); |
Rohit Grover |
106:a20be740075d | 396 | } |
Rohit Grover |
106:a20be740075d | 397 | |
Rohit Grover |
106:a20be740075d | 398 | inline void |
Rohit Grover |
106:a20be740075d | 399 | BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams) |
Rohit Grover |
106:a20be740075d | 400 | { |
Rohit Grover |
106:a20be740075d | 401 | advParams = newAdvParams; |
Rohit Grover |
106:a20be740075d | 402 | } |
Rohit Grover |
106:a20be740075d | 403 | |
Rohit Grover |
106:a20be740075d | 404 | inline void |
Rohit Grover |
106:a20be740075d | 405 | BLEDevice::clearAdvertisingPayload(void) |
Rohit Grover |
106:a20be740075d | 406 | { |
Rohit Grover |
106:a20be740075d | 407 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 408 | advPayload.clear(); |
Rohit Grover |
106:a20be740075d | 409 | } |
Rohit Grover |
106:a20be740075d | 410 | |
Rohit Grover |
106:a20be740075d | 411 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 412 | BLEDevice::accumulateAdvertisingPayload(uint8_t flags) |
Rohit Grover |
106:a20be740075d | 413 | { |
Rohit Grover |
106:a20be740075d | 414 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 415 | return advPayload.addFlags(flags); |
Rohit Grover |
106:a20be740075d | 416 | } |
Rohit Grover |
106:a20be740075d | 417 | |
Rohit Grover |
106:a20be740075d | 418 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 419 | BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) |
Rohit Grover |
106:a20be740075d | 420 | { |
Rohit Grover |
106:a20be740075d | 421 | needToSetAdvPayload = true; |
rgrover1 | 140:407d134c179d | 422 | transport->getGap().setAppearance(app); |
Rohit Grover |
106:a20be740075d | 423 | return advPayload.addAppearance(app); |
Rohit Grover |
106:a20be740075d | 424 | } |
Rohit Grover |
106:a20be740075d | 425 | |
Rohit Grover |
106:a20be740075d | 426 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 427 | BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower) |
Rohit Grover |
106:a20be740075d | 428 | { |
Rohit Grover |
106:a20be740075d | 429 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 430 | return advPayload.addTxPower(txPower); |
Rohit Grover |
106:a20be740075d | 431 | } |
Rohit Grover |
106:a20be740075d | 432 | |
Rohit Grover |
106:a20be740075d | 433 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 434 | BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) |
Rohit Grover |
106:a20be740075d | 435 | { |
Rohit Grover |
106:a20be740075d | 436 | needToSetAdvPayload = true; |
rgrover1 | 140:407d134c179d | 437 | if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) { |
rgrover1 | 140:407d134c179d | 438 | transport->getGap().setDeviceName(data); |
rgrover1 | 140:407d134c179d | 439 | } |
Rohit Grover |
106:a20be740075d | 440 | return advPayload.addData(type, data, len); |
Rohit Grover |
106:a20be740075d | 441 | } |
Rohit Grover |
106:a20be740075d | 442 | |
Rohit Grover |
106:a20be740075d | 443 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 444 | BLEDevice::accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) |
Rohit Grover |
106:a20be740075d | 445 | { |
Rohit Grover |
106:a20be740075d | 446 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 447 | return scanResponse.addData(type, data, len); |
Rohit Grover |
106:a20be740075d | 448 | } |
Rohit Grover |
106:a20be740075d | 449 | |
Rohit Grover |
106:a20be740075d | 450 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 451 | BLEDevice::setAdvertisingPayload(void) { |
Rohit Grover |
106:a20be740075d | 452 | needToSetAdvPayload = false; |
Rohit Grover |
106:a20be740075d | 453 | return transport->getGap().setAdvertisingData(advPayload, scanResponse); |
Rohit Grover |
106:a20be740075d | 454 | } |
Rohit Grover |
106:a20be740075d | 455 | |
Rohit Grover |
106:a20be740075d | 456 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 457 | BLEDevice::startAdvertising(void) |
Rohit Grover |
106:a20be740075d | 458 | { |
rgrover1 | 140:407d134c179d | 459 | ble_error_t rc; |
rgrover1 | 140:407d134c179d | 460 | if ((rc = transport->getGattServer().initializeGATTDatabase()) != BLE_ERROR_NONE) { |
rgrover1 | 140:407d134c179d | 461 | return rc; |
rgrover1 | 140:407d134c179d | 462 | } |
Rohit Grover |
106:a20be740075d | 463 | if (needToSetAdvPayload) { |
Rohit Grover |
106:a20be740075d | 464 | if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) { |
Rohit Grover |
106:a20be740075d | 465 | return rc; |
Rohit Grover |
106:a20be740075d | 466 | } |
Rohit Grover |
106:a20be740075d | 467 | } |
Rohit Grover |
106:a20be740075d | 468 | |
Rohit Grover |
106:a20be740075d | 469 | return transport->getGap().startAdvertising(advParams); |
Rohit Grover |
106:a20be740075d | 470 | } |
Rohit Grover |
106:a20be740075d | 471 | |
Rohit Grover |
106:a20be740075d | 472 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 473 | BLEDevice::stopAdvertising(void) |
Rohit Grover |
106:a20be740075d | 474 | { |
Rohit Grover |
106:a20be740075d | 475 | return transport->getGap().stopAdvertising(); |
Rohit Grover |
106:a20be740075d | 476 | } |
Rohit Grover |
106:a20be740075d | 477 | |
Rohit Grover |
106:a20be740075d | 478 | inline ble_error_t |
Rohit Grover |
116:ca826083980e | 479 | BLEDevice::disconnect(Gap::DisconnectionReason_t reason) |
Rohit Grover |
106:a20be740075d | 480 | { |
Rohit Grover |
116:ca826083980e | 481 | return transport->getGap().disconnect(reason); |
Rohit Grover |
106:a20be740075d | 482 | } |
Rohit Grover |
106:a20be740075d | 483 | |
Rohit Grover |
106:a20be740075d | 484 | inline void |
Rohit Grover |
106:a20be740075d | 485 | BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback) |
Rohit Grover |
106:a20be740075d | 486 | { |
Rohit Grover |
106:a20be740075d | 487 | transport->getGap().setOnTimeout(timeoutCallback); |
Rohit Grover |
106:a20be740075d | 488 | } |
Rohit Grover |
106:a20be740075d | 489 | |
Rohit Grover |
106:a20be740075d | 490 | inline void |
Rohit Grover |
116:ca826083980e | 491 | BLEDevice::onConnection(Gap::ConnectionEventCallback_t connectionCallback) |
Rohit Grover |
106:a20be740075d | 492 | { |
Rohit Grover |
106:a20be740075d | 493 | transport->getGap().setOnConnection(connectionCallback); |
Rohit Grover |
106:a20be740075d | 494 | } |
Rohit Grover |
106:a20be740075d | 495 | |
Rohit Grover |
106:a20be740075d | 496 | inline void |
Rohit Grover |
116:ca826083980e | 497 | BLEDevice::onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback) |
Rohit Grover |
106:a20be740075d | 498 | { |
Rohit Grover |
106:a20be740075d | 499 | transport->getGap().setOnDisconnection(disconnectionCallback); |
Rohit Grover |
106:a20be740075d | 500 | } |
Rohit Grover |
106:a20be740075d | 501 | |
Rohit Grover |
106:a20be740075d | 502 | inline void |
Rohit Grover |
116:ca826083980e | 503 | BLEDevice::onDataSent(GattServer::ServerEventCallbackWithCount_t callback) |
Rohit Grover |
106:a20be740075d | 504 | { |
Rohit Grover |
106:a20be740075d | 505 | transport->getGattServer().setOnDataSent(callback); |
Rohit Grover |
106:a20be740075d | 506 | } |
Rohit Grover |
106:a20be740075d | 507 | |
Rohit Grover |
106:a20be740075d | 508 | inline void |
Rohit Grover |
118:620d28e7a1ba | 509 | BLEDevice::onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) { |
Rohit Grover |
106:a20be740075d | 510 | transport->getGattServer().setOnDataWritten(callback); |
Rohit Grover |
106:a20be740075d | 511 | } |
Rohit Grover |
106:a20be740075d | 512 | |
Rohit Grover |
118:620d28e7a1ba | 513 | template <typename T> inline void |
Rohit Grover |
118:620d28e7a1ba | 514 | BLEDevice::onDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) { |
Rohit Grover |
118:620d28e7a1ba | 515 | transport->getGattServer().setOnDataWritten(objPtr, memberPtr); |
Rohit Grover |
118:620d28e7a1ba | 516 | } |
Rohit Grover |
118:620d28e7a1ba | 517 | |
Rohit Grover |
106:a20be740075d | 518 | inline void |
Rohit Grover |
106:a20be740075d | 519 | BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback) |
Rohit Grover |
106:a20be740075d | 520 | { |
Rohit Grover |
106:a20be740075d | 521 | transport->getGattServer().setOnUpdatesEnabled(callback); |
Rohit Grover |
106:a20be740075d | 522 | } |
Rohit Grover |
106:a20be740075d | 523 | |
Rohit Grover |
106:a20be740075d | 524 | inline void |
Rohit Grover |
106:a20be740075d | 525 | BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback) |
Rohit Grover |
106:a20be740075d | 526 | { |
Rohit Grover |
106:a20be740075d | 527 | transport->getGattServer().setOnUpdatesDisabled(callback); |
Rohit Grover |
106:a20be740075d | 528 | } |
Rohit Grover |
106:a20be740075d | 529 | |
Rohit Grover |
106:a20be740075d | 530 | inline void |
Rohit Grover |
106:a20be740075d | 531 | BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback) |
Rohit Grover |
106:a20be740075d | 532 | { |
Rohit Grover |
106:a20be740075d | 533 | transport->getGattServer().setOnConfirmationReceived(callback); |
Rohit Grover |
106:a20be740075d | 534 | } |
Rohit Grover |
106:a20be740075d | 535 | |
Rohit Grover |
106:a20be740075d | 536 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 537 | BLEDevice::addService(GattService &service) |
Rohit Grover |
106:a20be740075d | 538 | { |
Rohit Grover |
106:a20be740075d | 539 | return transport->getGattServer().addService(service); |
Rohit Grover |
106:a20be740075d | 540 | } |
Rohit Grover |
106:a20be740075d | 541 | |
Rohit Grover |
106:a20be740075d | 542 | inline Gap::GapState_t |
Rohit Grover |
106:a20be740075d | 543 | BLEDevice::getGapState(void) const |
Rohit Grover |
106:a20be740075d | 544 | { |
Rohit Grover |
106:a20be740075d | 545 | return transport->getGap().getState(); |
Rohit Grover |
106:a20be740075d | 546 | } |
Rohit Grover |
106:a20be740075d | 547 | |
Rohit Grover |
106:a20be740075d | 548 | inline ble_error_t BLEDevice::readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP) |
Rohit Grover |
106:a20be740075d | 549 | { |
Rohit Grover |
106:a20be740075d | 550 | return transport->getGattServer().readValue(handle, buffer, lengthP); |
Rohit Grover |
106:a20be740075d | 551 | } |
Rohit Grover |
106:a20be740075d | 552 | |
Rohit Grover |
106:a20be740075d | 553 | inline ble_error_t |
rgrover1 | 140:407d134c179d | 554 | BLEDevice::updateCharacteristicValue(uint16_t handle, const uint8_t *value, uint16_t size, bool localOnly) |
Rohit Grover |
106:a20be740075d | 555 | { |
Rohit Grover |
106:a20be740075d | 556 | return transport->getGattServer().updateValue(handle, const_cast<uint8_t *>(value), size, localOnly); |
Rohit Grover |
106:a20be740075d | 557 | } |
Rohit Grover |
106:a20be740075d | 558 | |
Rohit Grover |
106:a20be740075d | 559 | inline void |
Rohit Grover |
106:a20be740075d | 560 | BLEDevice::waitForEvent(void) |
Rohit Grover |
106:a20be740075d | 561 | { |
Rohit Grover |
106:a20be740075d | 562 | transport->waitForEvent(); |
Rohit Grover |
106:a20be740075d | 563 | } |
Rohit Grover |
106:a20be740075d | 564 | |
Rohit Grover |
106:a20be740075d | 565 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 566 | BLEDevice::getPreferredConnectionParams(Gap::ConnectionParams_t *params) |
Rohit Grover |
106:a20be740075d | 567 | { |
Rohit Grover |
106:a20be740075d | 568 | return transport->getGap().getPreferredConnectionParams(params); |
Rohit Grover |
106:a20be740075d | 569 | } |
Rohit Grover |
106:a20be740075d | 570 | |
Rohit Grover |
106:a20be740075d | 571 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 572 | BLEDevice::setPreferredConnectionParams(const Gap::ConnectionParams_t *params) |
Rohit Grover |
106:a20be740075d | 573 | { |
Rohit Grover |
106:a20be740075d | 574 | return transport->getGap().setPreferredConnectionParams(params); |
Rohit Grover |
106:a20be740075d | 575 | } |
Rohit Grover |
106:a20be740075d | 576 | |
Rohit Grover |
106:a20be740075d | 577 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 578 | BLEDevice::updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) { |
Rohit Grover |
106:a20be740075d | 579 | return transport->getGap().updateConnectionParams(handle, params); |
Rohit Grover |
106:a20be740075d | 580 | } |
Rohit Grover |
106:a20be740075d | 581 | |
Rohit Grover |
108:c85ab5f1eca0 | 582 | inline const char * |
Rohit Grover |
108:c85ab5f1eca0 | 583 | BLEDevice::getVersion(void) |
Rohit Grover |
108:c85ab5f1eca0 | 584 | { |
Rohit Grover |
108:c85ab5f1eca0 | 585 | return transport->getVersion(); |
Rohit Grover |
108:c85ab5f1eca0 | 586 | } |
Rohit Grover |
108:c85ab5f1eca0 | 587 | |
Rohit Grover |
108:c85ab5f1eca0 | 588 | inline ble_error_t |
Rohit Grover |
108:c85ab5f1eca0 | 589 | BLEDevice::setDeviceName(const uint8_t *deviceName) |
Rohit Grover |
108:c85ab5f1eca0 | 590 | { |
Rohit Grover |
116:ca826083980e | 591 | return transport->getGap().setDeviceName(deviceName); |
Rohit Grover |
108:c85ab5f1eca0 | 592 | } |
Rohit Grover |
108:c85ab5f1eca0 | 593 | |
Rohit Grover |
108:c85ab5f1eca0 | 594 | inline ble_error_t |
Rohit Grover |
108:c85ab5f1eca0 | 595 | BLEDevice::getDeviceName(uint8_t *deviceName, unsigned *lengthP) |
Rohit Grover |
108:c85ab5f1eca0 | 596 | { |
Rohit Grover |
116:ca826083980e | 597 | return transport->getGap().getDeviceName(deviceName, lengthP); |
Rohit Grover |
108:c85ab5f1eca0 | 598 | } |
Rohit Grover |
108:c85ab5f1eca0 | 599 | |
Rohit Grover |
108:c85ab5f1eca0 | 600 | inline ble_error_t |
Rohit Grover |
108:c85ab5f1eca0 | 601 | BLEDevice::setAppearance(uint16_t appearance) |
Rohit Grover |
108:c85ab5f1eca0 | 602 | { |
Rohit Grover |
116:ca826083980e | 603 | return transport->getGap().setAppearance(appearance); |
Rohit Grover |
108:c85ab5f1eca0 | 604 | } |
Rohit Grover |
108:c85ab5f1eca0 | 605 | |
Rohit Grover |
108:c85ab5f1eca0 | 606 | inline ble_error_t |
Rohit Grover |
108:c85ab5f1eca0 | 607 | BLEDevice::getAppearance(uint16_t *appearanceP) |
Rohit Grover |
108:c85ab5f1eca0 | 608 | { |
Rohit Grover |
116:ca826083980e | 609 | return transport->getGap().getAppearance(appearanceP); |
Rohit Grover |
108:c85ab5f1eca0 | 610 | } |
Rohit Grover |
108:c85ab5f1eca0 | 611 | |
Rohit Grover |
108:c85ab5f1eca0 | 612 | inline ble_error_t |
Rohit Grover |
108:c85ab5f1eca0 | 613 | BLEDevice::setTxPower(int8_t txPower) |
Rohit Grover |
108:c85ab5f1eca0 | 614 | { |
Rohit Grover |
108:c85ab5f1eca0 | 615 | return transport->setTxPower(txPower); |
Rohit Grover |
108:c85ab5f1eca0 | 616 | } |
Rohit Grover |
108:c85ab5f1eca0 | 617 | |
Rohit Grover |
106:a20be740075d | 618 | /* |
Rohit Grover |
106:a20be740075d | 619 | * ALL OF THE FOLLOWING METHODS ARE DEPRECATED |
Rohit Grover |
106:a20be740075d | 620 | */ |
Rohit Grover |
106:a20be740075d | 621 | |
Rohit Grover |
106:a20be740075d | 622 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 623 | BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse) |
Rohit Grover |
106:a20be740075d | 624 | { |
Rohit Grover |
106:a20be740075d | 625 | needToSetAdvPayload = false; |
Rohit Grover |
106:a20be740075d | 626 | return transport->getGap().setAdvertisingData(ADStructures, scanResponse); |
Rohit Grover |
106:a20be740075d | 627 | } |
Rohit Grover |
106:a20be740075d | 628 | |
Rohit Grover |
106:a20be740075d | 629 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 630 | BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures) |
Rohit Grover |
106:a20be740075d | 631 | { |
Rohit Grover |
106:a20be740075d | 632 | GapAdvertisingData scanResponse; |
Rohit Grover |
106:a20be740075d | 633 | |
Rohit Grover |
106:a20be740075d | 634 | needToSetAdvPayload = false; |
Rohit Grover |
106:a20be740075d | 635 | return transport->getGap().setAdvertisingData(ADStructures, scanResponse); |
Rohit Grover |
106:a20be740075d | 636 | } |
Rohit Grover |
106:a20be740075d | 637 | |
Rohit Grover |
106:a20be740075d | 638 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 639 | BLEDevice::startAdvertising(const GapAdvertisingParams &_advParams) |
Rohit Grover |
106:a20be740075d | 640 | { |
Rohit Grover |
106:a20be740075d | 641 | return transport->getGap().startAdvertising(_advParams); |
Rohit Grover |
106:a20be740075d | 642 | } |
Rohit Grover |
106:a20be740075d | 643 | |
rgrover1 | 126:fdebe4d5d62f | 644 | #endif // ifndef __BLE_DEVICE__ |