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@106:a20be740075d, 2014-07-23 (annotated)
- Committer:
- Rohit Grover
- Date:
- Wed Jul 23 15:09:23 2014 +0100
- Revision:
- 106:a20be740075d
- Child:
- 108:c85ab5f1eca0
initial re-organization of BLE_API directory structure
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 |
106:a20be740075d | 17 | #include "mbed.h" |
Rohit Grover |
106:a20be740075d | 18 | #include "blecommon.h" |
Rohit Grover |
106:a20be740075d | 19 | #include "Gap.h" |
Rohit Grover |
106:a20be740075d | 20 | #include "GattServer.h" |
Rohit Grover |
106:a20be740075d | 21 | #include "BLEDeviceInstanceBase.hpp" |
Rohit Grover |
106:a20be740075d | 22 | |
Rohit Grover |
106:a20be740075d | 23 | #ifndef __BLE_DEVICE__ |
Rohit Grover |
106:a20be740075d | 24 | #define __BLE_DEVICE__ |
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 |
106:a20be740075d | 44 | * @return |
Rohit Grover |
106:a20be740075d | 45 | */ |
Rohit Grover |
106:a20be740075d | 46 | ble_error_t setAddress(Gap::addr_type_t type, const uint8_t address[6]); |
Rohit Grover |
106:a20be740075d | 47 | |
Rohit Grover |
106:a20be740075d | 48 | /** |
Rohit Grover |
106:a20be740075d | 49 | * @param[in] advType |
Rohit Grover |
106:a20be740075d | 50 | * The GAP advertising mode to use for this device. Valid |
Rohit Grover |
106:a20be740075d | 51 | * values are defined in AdvertisingType: |
Rohit Grover |
106:a20be740075d | 52 | * |
Rohit Grover |
106:a20be740075d | 53 | * \par ADV_NON_CONNECTABLE_UNDIRECTED |
Rohit Grover |
106:a20be740075d | 54 | * All connections to the peripheral device will be refused. |
Rohit Grover |
106:a20be740075d | 55 | * |
Rohit Grover |
106:a20be740075d | 56 | * \par ADV_CONNECTABLE_DIRECTED |
Rohit Grover |
106:a20be740075d | 57 | * Only connections from a pre-defined central device will be |
Rohit Grover |
106:a20be740075d | 58 | * accepted. |
Rohit Grover |
106:a20be740075d | 59 | * |
Rohit Grover |
106:a20be740075d | 60 | * \par ADV_CONNECTABLE_UNDIRECTED |
Rohit Grover |
106:a20be740075d | 61 | * Any central device can connect to this peripheral. |
Rohit Grover |
106:a20be740075d | 62 | * |
Rohit Grover |
106:a20be740075d | 63 | * \par ADV_SCANNABLE_UNDIRECTED |
Rohit Grover |
106:a20be740075d | 64 | * Any central device can connect to this peripheral, and |
Rohit Grover |
106:a20be740075d | 65 | * the secondary Scan Response payload will be included or |
Rohit Grover |
106:a20be740075d | 66 | * available to central devices. |
Rohit Grover |
106:a20be740075d | 67 | * |
Rohit Grover |
106:a20be740075d | 68 | * \par |
Rohit Grover |
106:a20be740075d | 69 | * See Bluetooth Core Specification 4.0 (Vol. 3), Part C, |
Rohit Grover |
106:a20be740075d | 70 | * Section 9.3 and Core Specification 4.0 (Vol. 6), Part B, |
Rohit Grover |
106:a20be740075d | 71 | * Section 2.3.1 for further information on GAP connection |
Rohit Grover |
106:a20be740075d | 72 | * modes |
Rohit Grover |
106:a20be740075d | 73 | */ |
Rohit Grover |
106:a20be740075d | 74 | void setAdvertisingType(GapAdvertisingParams::AdvertisingType); |
Rohit Grover |
106:a20be740075d | 75 | |
Rohit Grover |
106:a20be740075d | 76 | /** |
Rohit Grover |
106:a20be740075d | 77 | * @param[in] interval |
Rohit Grover |
106:a20be740075d | 78 | * Advertising interval between 0x0020 and 0x4000 in 0.625ms |
Rohit Grover |
106:a20be740075d | 79 | * units (20ms to 10.24s). If using non-connectable mode |
Rohit Grover |
106:a20be740075d | 80 | * (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is |
Rohit Grover |
106:a20be740075d | 81 | * 0x00A0 (100ms). To reduce the likelihood of collisions, the |
Rohit Grover |
106:a20be740075d | 82 | * link layer perturbs this interval by a pseudo-random delay |
Rohit Grover |
106:a20be740075d | 83 | * with a range of 0 ms to 10 ms for each advertising event. |
Rohit Grover |
106:a20be740075d | 84 | * |
Rohit Grover |
106:a20be740075d | 85 | * \par |
Rohit Grover |
106:a20be740075d | 86 | * Decreasing this value will allow central devices to detect |
Rohit Grover |
106:a20be740075d | 87 | * your peripheral faster at the expense of more power being |
Rohit Grover |
106:a20be740075d | 88 | * used by the radio due to the higher data transmit rate. |
Rohit Grover |
106:a20be740075d | 89 | * |
Rohit Grover |
106:a20be740075d | 90 | * \par |
Rohit Grover |
106:a20be740075d | 91 | * This field must be set to 0 if connectionMode is equal |
Rohit Grover |
106:a20be740075d | 92 | * to ADV_CONNECTABLE_DIRECTED |
Rohit Grover |
106:a20be740075d | 93 | * |
Rohit Grover |
106:a20be740075d | 94 | * \par |
Rohit Grover |
106:a20be740075d | 95 | * See Bluetooth Core Specification, Vol 3., Part C, |
Rohit Grover |
106:a20be740075d | 96 | * Appendix A for suggested advertising intervals. |
Rohit Grover |
106:a20be740075d | 97 | */ |
Rohit Grover |
106:a20be740075d | 98 | void setAdvertisingInterval(uint16_t interval); |
Rohit Grover |
106:a20be740075d | 99 | |
Rohit Grover |
106:a20be740075d | 100 | /** |
Rohit Grover |
106:a20be740075d | 101 | * @param[in] timeout |
Rohit Grover |
106:a20be740075d | 102 | * Advertising timeout between 0x1 and 0x3FFF (1 and 16383) |
Rohit Grover |
106:a20be740075d | 103 | * in seconds. Enter 0 to disable the advertising timeout. |
Rohit Grover |
106:a20be740075d | 104 | */ |
Rohit Grover |
106:a20be740075d | 105 | void setAdvertisingTimeout(uint16_t timeout); |
Rohit Grover |
106:a20be740075d | 106 | |
Rohit Grover |
106:a20be740075d | 107 | /** |
Rohit Grover |
106:a20be740075d | 108 | * Please refer to the APIs above. |
Rohit Grover |
106:a20be740075d | 109 | */ |
Rohit Grover |
106:a20be740075d | 110 | void setAdvertisingParams(const GapAdvertisingParams &advParams); |
Rohit Grover |
106:a20be740075d | 111 | |
Rohit Grover |
106:a20be740075d | 112 | /** |
Rohit Grover |
106:a20be740075d | 113 | * This API is typically used as an internal helper to udpate the transport |
Rohit Grover |
106:a20be740075d | 114 | * backend with advertising data before starting to advertise. It may also |
Rohit Grover |
106:a20be740075d | 115 | * be explicity used to dynamically reset the accumulated advertising |
Rohit Grover |
106:a20be740075d | 116 | * payload and scanResponse; to do this, the application can clear and re- |
Rohit Grover |
106:a20be740075d | 117 | * accumulate a new advertising payload (and scanResponse) before using this |
Rohit Grover |
106:a20be740075d | 118 | * API. |
Rohit Grover |
106:a20be740075d | 119 | */ |
Rohit Grover |
106:a20be740075d | 120 | ble_error_t setAdvertisingPayload(void); |
Rohit Grover |
106:a20be740075d | 121 | |
Rohit Grover |
106:a20be740075d | 122 | /** |
Rohit Grover |
106:a20be740075d | 123 | * Reset any advertising payload prepared from prior calls to |
Rohit Grover |
106:a20be740075d | 124 | * accumulateAdvertisingPayload(). |
Rohit Grover |
106:a20be740075d | 125 | */ |
Rohit Grover |
106:a20be740075d | 126 | void clearAdvertisingPayload(void); |
Rohit Grover |
106:a20be740075d | 127 | |
Rohit Grover |
106:a20be740075d | 128 | /** |
Rohit Grover |
106:a20be740075d | 129 | * Accumulate an AD structure in the advertising payload. Please note that |
Rohit Grover |
106:a20be740075d | 130 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
Rohit Grover |
106:a20be740075d | 131 | * as an additional 31 bytes if the advertising payload proves to be too |
Rohit Grover |
106:a20be740075d | 132 | * small. |
Rohit Grover |
106:a20be740075d | 133 | * |
Rohit Grover |
106:a20be740075d | 134 | * @param flags |
Rohit Grover |
106:a20be740075d | 135 | * The flags to be added. Multiple flags may be specified in |
Rohit Grover |
106:a20be740075d | 136 | * combination. |
Rohit Grover |
106:a20be740075d | 137 | */ |
Rohit Grover |
106:a20be740075d | 138 | ble_error_t accumulateAdvertisingPayload(uint8_t flags); |
Rohit Grover |
106:a20be740075d | 139 | |
Rohit Grover |
106:a20be740075d | 140 | /** |
Rohit Grover |
106:a20be740075d | 141 | * Accumulate an AD structure in the advertising payload. Please note that |
Rohit Grover |
106:a20be740075d | 142 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
Rohit Grover |
106:a20be740075d | 143 | * as an additional 31 bytes if the advertising payload proves to be too |
Rohit Grover |
106:a20be740075d | 144 | * small. |
Rohit Grover |
106:a20be740075d | 145 | * |
Rohit Grover |
106:a20be740075d | 146 | * @param app |
Rohit Grover |
106:a20be740075d | 147 | * The appearance of the peripheral. |
Rohit Grover |
106:a20be740075d | 148 | */ |
Rohit Grover |
106:a20be740075d | 149 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app); |
Rohit Grover |
106:a20be740075d | 150 | |
Rohit Grover |
106:a20be740075d | 151 | /** |
Rohit Grover |
106:a20be740075d | 152 | * Accumulate an AD structure in the advertising payload. Please note that |
Rohit Grover |
106:a20be740075d | 153 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
Rohit Grover |
106:a20be740075d | 154 | * as an additional 31 bytes if the advertising payload proves to be too |
Rohit Grover |
106:a20be740075d | 155 | * small. |
Rohit Grover |
106:a20be740075d | 156 | * |
Rohit Grover |
106:a20be740075d | 157 | * @param app |
Rohit Grover |
106:a20be740075d | 158 | * The max transmit power to be used by the controller. This is |
Rohit Grover |
106:a20be740075d | 159 | * only a hint. |
Rohit Grover |
106:a20be740075d | 160 | */ |
Rohit Grover |
106:a20be740075d | 161 | ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power); |
Rohit Grover |
106:a20be740075d | 162 | |
Rohit Grover |
106:a20be740075d | 163 | /** |
Rohit Grover |
106:a20be740075d | 164 | * Accumulate a variable length byte-stream as an AD structure in the |
Rohit Grover |
106:a20be740075d | 165 | * advertising payload. Please note that the payload is limited to 31 bytes. |
Rohit Grover |
106:a20be740075d | 166 | * The SCAN_RESPONSE message may be used as an additional 31 bytes if the |
Rohit Grover |
106:a20be740075d | 167 | * advertising payload proves to be too small. |
Rohit Grover |
106:a20be740075d | 168 | * |
Rohit Grover |
106:a20be740075d | 169 | * @param type The type which describes the variable length data. |
Rohit Grover |
106:a20be740075d | 170 | * @param data data bytes. |
Rohit Grover |
106:a20be740075d | 171 | * @param len length of data. |
Rohit Grover |
106:a20be740075d | 172 | */ |
Rohit Grover |
106:a20be740075d | 173 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len); |
Rohit Grover |
106:a20be740075d | 174 | |
Rohit Grover |
106:a20be740075d | 175 | /** |
Rohit Grover |
106:a20be740075d | 176 | * Accumulate a variable length byte-stream as an AD structure in the |
Rohit Grover |
106:a20be740075d | 177 | * scanResponse payload. |
Rohit Grover |
106:a20be740075d | 178 | * |
Rohit Grover |
106:a20be740075d | 179 | * @param type The type which describes the variable length data. |
Rohit Grover |
106:a20be740075d | 180 | * @param data data bytes. |
Rohit Grover |
106:a20be740075d | 181 | * @param len length of data. |
Rohit Grover |
106:a20be740075d | 182 | */ |
Rohit Grover |
106:a20be740075d | 183 | ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len); |
Rohit Grover |
106:a20be740075d | 184 | |
Rohit Grover |
106:a20be740075d | 185 | /** |
Rohit Grover |
106:a20be740075d | 186 | * Start advertising (GAP Discoverable, Connectable modes, Broadcast |
Rohit Grover |
106:a20be740075d | 187 | * Procedure). |
Rohit Grover |
106:a20be740075d | 188 | */ |
Rohit Grover |
106:a20be740075d | 189 | ble_error_t startAdvertising(void); |
Rohit Grover |
106:a20be740075d | 190 | |
Rohit Grover |
106:a20be740075d | 191 | /** |
Rohit Grover |
106:a20be740075d | 192 | * Stop 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 stopAdvertising(void); |
Rohit Grover |
106:a20be740075d | 196 | |
Rohit Grover |
106:a20be740075d | 197 | ble_error_t disconnect(void); |
Rohit Grover |
106:a20be740075d | 198 | |
Rohit Grover |
106:a20be740075d | 199 | /* APIs to set GAP callbacks. */ |
Rohit Grover |
106:a20be740075d | 200 | void onTimeout(Gap::EventCallback_t timeoutCallback); |
Rohit Grover |
106:a20be740075d | 201 | |
Rohit Grover |
106:a20be740075d | 202 | void onConnection(Gap::HandleSpecificEventCallback_t connectionCallback); |
Rohit Grover |
106:a20be740075d | 203 | /** |
Rohit Grover |
106:a20be740075d | 204 | * Used to setup a callback for GAP disconnection. |
Rohit Grover |
106:a20be740075d | 205 | */ |
Rohit Grover |
106:a20be740075d | 206 | void onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback); |
Rohit Grover |
106:a20be740075d | 207 | |
Rohit Grover |
106:a20be740075d | 208 | /** |
Rohit Grover |
106:a20be740075d | 209 | * Setup a callback for the GATT event DATA_SENT. |
Rohit Grover |
106:a20be740075d | 210 | */ |
Rohit Grover |
106:a20be740075d | 211 | void onDataSent(GattServer::ServerEventCallback_t callback); |
Rohit Grover |
106:a20be740075d | 212 | |
Rohit Grover |
106:a20be740075d | 213 | /** |
Rohit Grover |
106:a20be740075d | 214 | * Setup a callback for when a characteristic has its value updated by a |
Rohit Grover |
106:a20be740075d | 215 | * client. |
Rohit Grover |
106:a20be740075d | 216 | */ |
Rohit Grover |
106:a20be740075d | 217 | void onDataWritten(GattServer::EventCallback_t callback); |
Rohit Grover |
106:a20be740075d | 218 | void onUpdatesEnabled(GattServer::EventCallback_t callback); |
Rohit Grover |
106:a20be740075d | 219 | void onUpdatesDisabled(GattServer::EventCallback_t callback); |
Rohit Grover |
106:a20be740075d | 220 | void onConfirmationReceived(GattServer::EventCallback_t callback); |
Rohit Grover |
106:a20be740075d | 221 | |
Rohit Grover |
106:a20be740075d | 222 | /** |
Rohit Grover |
106:a20be740075d | 223 | * Add a service declaration to the local server ATT table. Also add the |
Rohit Grover |
106:a20be740075d | 224 | * characteristics contained within. |
Rohit Grover |
106:a20be740075d | 225 | */ |
Rohit Grover |
106:a20be740075d | 226 | ble_error_t addService(GattService &service); |
Rohit Grover |
106:a20be740075d | 227 | |
Rohit Grover |
106:a20be740075d | 228 | Gap::GapState_t getGapState(void) const; |
Rohit Grover |
106:a20be740075d | 229 | |
Rohit Grover |
106:a20be740075d | 230 | ble_error_t readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP); |
Rohit Grover |
106:a20be740075d | 231 | ble_error_t updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly = false); |
Rohit Grover |
106:a20be740075d | 232 | |
Rohit Grover |
106:a20be740075d | 233 | /** |
Rohit Grover |
106:a20be740075d | 234 | * Yield control to the BLE stack or to other tasks waiting for events. This |
Rohit Grover |
106:a20be740075d | 235 | * is a sleep function which will return when there is an application |
Rohit Grover |
106:a20be740075d | 236 | * specific interrupt, but the MCU might wake up several times before |
Rohit Grover |
106:a20be740075d | 237 | * returning (to service the stack). This is not always interchangeable with |
Rohit Grover |
106:a20be740075d | 238 | * WFE(). |
Rohit Grover |
106:a20be740075d | 239 | */ |
Rohit Grover |
106:a20be740075d | 240 | void waitForEvent(void); |
Rohit Grover |
106:a20be740075d | 241 | |
Rohit Grover |
106:a20be740075d | 242 | ble_error_t getPreferredConnectionParams(Gap::ConnectionParams_t *params); |
Rohit Grover |
106:a20be740075d | 243 | ble_error_t setPreferredConnectionParams(const Gap::ConnectionParams_t *params); |
Rohit Grover |
106:a20be740075d | 244 | ble_error_t updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params); |
Rohit Grover |
106:a20be740075d | 245 | // ble_version_t getVersion(void); |
Rohit Grover |
106:a20be740075d | 246 | |
Rohit Grover |
106:a20be740075d | 247 | public: |
Rohit Grover |
106:a20be740075d | 248 | BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true) { |
Rohit Grover |
106:a20be740075d | 249 | advPayload.clear(); |
Rohit Grover |
106:a20be740075d | 250 | scanResponse.clear(); |
Rohit Grover |
106:a20be740075d | 251 | } |
Rohit Grover |
106:a20be740075d | 252 | |
Rohit Grover |
106:a20be740075d | 253 | private: |
Rohit Grover |
106:a20be740075d | 254 | BLEDeviceInstanceBase *const transport; /* the device specific backend */ |
Rohit Grover |
106:a20be740075d | 255 | |
Rohit Grover |
106:a20be740075d | 256 | GapAdvertisingParams advParams; |
Rohit Grover |
106:a20be740075d | 257 | GapAdvertisingData advPayload; |
Rohit Grover |
106:a20be740075d | 258 | GapAdvertisingData scanResponse; |
Rohit Grover |
106:a20be740075d | 259 | |
Rohit Grover |
106:a20be740075d | 260 | /* Accumulation of AD structures in the advertisement payload should |
Rohit Grover |
106:a20be740075d | 261 | * eventually result in a call to the target's setAdvertisingData() before |
Rohit Grover |
106:a20be740075d | 262 | * the server begins advertising. This flag marks the status of the pending update.*/ |
Rohit Grover |
106:a20be740075d | 263 | bool needToSetAdvPayload; |
Rohit Grover |
106:a20be740075d | 264 | |
Rohit Grover |
106:a20be740075d | 265 | /** |
Rohit Grover |
106:a20be740075d | 266 | * DEPRECATED |
Rohit Grover |
106:a20be740075d | 267 | */ |
Rohit Grover |
106:a20be740075d | 268 | public: |
Rohit Grover |
106:a20be740075d | 269 | ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse); |
Rohit Grover |
106:a20be740075d | 270 | ble_error_t setAdvertisingData(const GapAdvertisingData &ADStructures); |
Rohit Grover |
106:a20be740075d | 271 | |
Rohit Grover |
106:a20be740075d | 272 | ble_error_t startAdvertising(const GapAdvertisingParams &advParams); |
Rohit Grover |
106:a20be740075d | 273 | }; |
Rohit Grover |
106:a20be740075d | 274 | |
Rohit Grover |
106:a20be740075d | 275 | /* BLEDevice methods. Most of these simply forward the calls to the underlying |
Rohit Grover |
106:a20be740075d | 276 | * transport.*/ |
Rohit Grover |
106:a20be740075d | 277 | |
Rohit Grover |
106:a20be740075d | 278 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 279 | BLEDevice::init() |
Rohit Grover |
106:a20be740075d | 280 | { |
Rohit Grover |
106:a20be740075d | 281 | return transport->init(); |
Rohit Grover |
106:a20be740075d | 282 | } |
Rohit Grover |
106:a20be740075d | 283 | |
Rohit Grover |
106:a20be740075d | 284 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 285 | BLEDevice::reset(void) |
Rohit Grover |
106:a20be740075d | 286 | { |
Rohit Grover |
106:a20be740075d | 287 | return transport->reset(); |
Rohit Grover |
106:a20be740075d | 288 | } |
Rohit Grover |
106:a20be740075d | 289 | |
Rohit Grover |
106:a20be740075d | 290 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 291 | BLEDevice::setAddress(Gap::addr_type_t type, const uint8_t address[6]) |
Rohit Grover |
106:a20be740075d | 292 | { |
Rohit Grover |
106:a20be740075d | 293 | return transport->getGap().setAddress(type, address); |
Rohit Grover |
106:a20be740075d | 294 | } |
Rohit Grover |
106:a20be740075d | 295 | |
Rohit Grover |
106:a20be740075d | 296 | inline void |
Rohit Grover |
106:a20be740075d | 297 | BLEDevice::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType) |
Rohit Grover |
106:a20be740075d | 298 | { |
Rohit Grover |
106:a20be740075d | 299 | advParams.setAdvertisingType(advType); |
Rohit Grover |
106:a20be740075d | 300 | } |
Rohit Grover |
106:a20be740075d | 301 | |
Rohit Grover |
106:a20be740075d | 302 | inline void |
Rohit Grover |
106:a20be740075d | 303 | BLEDevice::setAdvertisingInterval(uint16_t interval) |
Rohit Grover |
106:a20be740075d | 304 | { |
Rohit Grover |
106:a20be740075d | 305 | advParams.setInterval(interval); |
Rohit Grover |
106:a20be740075d | 306 | } |
Rohit Grover |
106:a20be740075d | 307 | |
Rohit Grover |
106:a20be740075d | 308 | inline void |
Rohit Grover |
106:a20be740075d | 309 | BLEDevice::setAdvertisingTimeout(uint16_t timeout) |
Rohit Grover |
106:a20be740075d | 310 | { |
Rohit Grover |
106:a20be740075d | 311 | advParams.setTimeout(timeout); |
Rohit Grover |
106:a20be740075d | 312 | } |
Rohit Grover |
106:a20be740075d | 313 | |
Rohit Grover |
106:a20be740075d | 314 | inline void |
Rohit Grover |
106:a20be740075d | 315 | BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams) |
Rohit Grover |
106:a20be740075d | 316 | { |
Rohit Grover |
106:a20be740075d | 317 | advParams = newAdvParams; |
Rohit Grover |
106:a20be740075d | 318 | } |
Rohit Grover |
106:a20be740075d | 319 | |
Rohit Grover |
106:a20be740075d | 320 | inline void |
Rohit Grover |
106:a20be740075d | 321 | BLEDevice::clearAdvertisingPayload(void) |
Rohit Grover |
106:a20be740075d | 322 | { |
Rohit Grover |
106:a20be740075d | 323 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 324 | advPayload.clear(); |
Rohit Grover |
106:a20be740075d | 325 | } |
Rohit Grover |
106:a20be740075d | 326 | |
Rohit Grover |
106:a20be740075d | 327 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 328 | BLEDevice::accumulateAdvertisingPayload(uint8_t flags) |
Rohit Grover |
106:a20be740075d | 329 | { |
Rohit Grover |
106:a20be740075d | 330 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 331 | return advPayload.addFlags(flags); |
Rohit Grover |
106:a20be740075d | 332 | } |
Rohit Grover |
106:a20be740075d | 333 | |
Rohit Grover |
106:a20be740075d | 334 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 335 | BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) |
Rohit Grover |
106:a20be740075d | 336 | { |
Rohit Grover |
106:a20be740075d | 337 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 338 | return advPayload.addAppearance(app); |
Rohit Grover |
106:a20be740075d | 339 | } |
Rohit Grover |
106:a20be740075d | 340 | |
Rohit Grover |
106:a20be740075d | 341 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 342 | BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower) |
Rohit Grover |
106:a20be740075d | 343 | { |
Rohit Grover |
106:a20be740075d | 344 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 345 | return advPayload.addTxPower(txPower); |
Rohit Grover |
106:a20be740075d | 346 | } |
Rohit Grover |
106:a20be740075d | 347 | |
Rohit Grover |
106:a20be740075d | 348 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 349 | BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) |
Rohit Grover |
106:a20be740075d | 350 | { |
Rohit Grover |
106:a20be740075d | 351 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 352 | return advPayload.addData(type, data, len); |
Rohit Grover |
106:a20be740075d | 353 | } |
Rohit Grover |
106:a20be740075d | 354 | |
Rohit Grover |
106:a20be740075d | 355 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 356 | BLEDevice::accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) |
Rohit Grover |
106:a20be740075d | 357 | { |
Rohit Grover |
106:a20be740075d | 358 | needToSetAdvPayload = true; |
Rohit Grover |
106:a20be740075d | 359 | return scanResponse.addData(type, data, len); |
Rohit Grover |
106:a20be740075d | 360 | } |
Rohit Grover |
106:a20be740075d | 361 | |
Rohit Grover |
106:a20be740075d | 362 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 363 | BLEDevice::setAdvertisingPayload(void) { |
Rohit Grover |
106:a20be740075d | 364 | needToSetAdvPayload = false; |
Rohit Grover |
106:a20be740075d | 365 | return transport->getGap().setAdvertisingData(advPayload, scanResponse); |
Rohit Grover |
106:a20be740075d | 366 | } |
Rohit Grover |
106:a20be740075d | 367 | |
Rohit Grover |
106:a20be740075d | 368 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 369 | BLEDevice::startAdvertising(void) |
Rohit Grover |
106:a20be740075d | 370 | { |
Rohit Grover |
106:a20be740075d | 371 | if (needToSetAdvPayload) { |
Rohit Grover |
106:a20be740075d | 372 | ble_error_t rc; |
Rohit Grover |
106:a20be740075d | 373 | if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) { |
Rohit Grover |
106:a20be740075d | 374 | return rc; |
Rohit Grover |
106:a20be740075d | 375 | } |
Rohit Grover |
106:a20be740075d | 376 | } |
Rohit Grover |
106:a20be740075d | 377 | |
Rohit Grover |
106:a20be740075d | 378 | return transport->getGap().startAdvertising(advParams); |
Rohit Grover |
106:a20be740075d | 379 | } |
Rohit Grover |
106:a20be740075d | 380 | |
Rohit Grover |
106:a20be740075d | 381 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 382 | BLEDevice::stopAdvertising(void) |
Rohit Grover |
106:a20be740075d | 383 | { |
Rohit Grover |
106:a20be740075d | 384 | return transport->getGap().stopAdvertising(); |
Rohit Grover |
106:a20be740075d | 385 | } |
Rohit Grover |
106:a20be740075d | 386 | |
Rohit Grover |
106:a20be740075d | 387 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 388 | BLEDevice::disconnect(void) |
Rohit Grover |
106:a20be740075d | 389 | { |
Rohit Grover |
106:a20be740075d | 390 | return transport->getGap().disconnect(); |
Rohit Grover |
106:a20be740075d | 391 | } |
Rohit Grover |
106:a20be740075d | 392 | |
Rohit Grover |
106:a20be740075d | 393 | inline void |
Rohit Grover |
106:a20be740075d | 394 | BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback) |
Rohit Grover |
106:a20be740075d | 395 | { |
Rohit Grover |
106:a20be740075d | 396 | transport->getGap().setOnTimeout(timeoutCallback); |
Rohit Grover |
106:a20be740075d | 397 | } |
Rohit Grover |
106:a20be740075d | 398 | |
Rohit Grover |
106:a20be740075d | 399 | inline void |
Rohit Grover |
106:a20be740075d | 400 | BLEDevice::onConnection(Gap::HandleSpecificEventCallback_t connectionCallback) |
Rohit Grover |
106:a20be740075d | 401 | { |
Rohit Grover |
106:a20be740075d | 402 | transport->getGap().setOnConnection(connectionCallback); |
Rohit Grover |
106:a20be740075d | 403 | } |
Rohit Grover |
106:a20be740075d | 404 | |
Rohit Grover |
106:a20be740075d | 405 | inline void |
Rohit Grover |
106:a20be740075d | 406 | BLEDevice::onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback) |
Rohit Grover |
106:a20be740075d | 407 | { |
Rohit Grover |
106:a20be740075d | 408 | transport->getGap().setOnDisconnection(disconnectionCallback); |
Rohit Grover |
106:a20be740075d | 409 | } |
Rohit Grover |
106:a20be740075d | 410 | |
Rohit Grover |
106:a20be740075d | 411 | inline void |
Rohit Grover |
106:a20be740075d | 412 | BLEDevice::onDataSent(GattServer::ServerEventCallback_t callback) |
Rohit Grover |
106:a20be740075d | 413 | { |
Rohit Grover |
106:a20be740075d | 414 | transport->getGattServer().setOnDataSent(callback); |
Rohit Grover |
106:a20be740075d | 415 | } |
Rohit Grover |
106:a20be740075d | 416 | |
Rohit Grover |
106:a20be740075d | 417 | inline void |
Rohit Grover |
106:a20be740075d | 418 | BLEDevice::onDataWritten(GattServer::EventCallback_t callback) |
Rohit Grover |
106:a20be740075d | 419 | { |
Rohit Grover |
106:a20be740075d | 420 | transport->getGattServer().setOnDataWritten(callback); |
Rohit Grover |
106:a20be740075d | 421 | } |
Rohit Grover |
106:a20be740075d | 422 | |
Rohit Grover |
106:a20be740075d | 423 | inline void |
Rohit Grover |
106:a20be740075d | 424 | BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback) |
Rohit Grover |
106:a20be740075d | 425 | { |
Rohit Grover |
106:a20be740075d | 426 | transport->getGattServer().setOnUpdatesEnabled(callback); |
Rohit Grover |
106:a20be740075d | 427 | } |
Rohit Grover |
106:a20be740075d | 428 | |
Rohit Grover |
106:a20be740075d | 429 | inline void |
Rohit Grover |
106:a20be740075d | 430 | BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback) |
Rohit Grover |
106:a20be740075d | 431 | { |
Rohit Grover |
106:a20be740075d | 432 | transport->getGattServer().setOnUpdatesDisabled(callback); |
Rohit Grover |
106:a20be740075d | 433 | } |
Rohit Grover |
106:a20be740075d | 434 | |
Rohit Grover |
106:a20be740075d | 435 | inline void |
Rohit Grover |
106:a20be740075d | 436 | BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback) |
Rohit Grover |
106:a20be740075d | 437 | { |
Rohit Grover |
106:a20be740075d | 438 | transport->getGattServer().setOnConfirmationReceived(callback); |
Rohit Grover |
106:a20be740075d | 439 | } |
Rohit Grover |
106:a20be740075d | 440 | |
Rohit Grover |
106:a20be740075d | 441 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 442 | BLEDevice::addService(GattService &service) |
Rohit Grover |
106:a20be740075d | 443 | { |
Rohit Grover |
106:a20be740075d | 444 | return transport->getGattServer().addService(service); |
Rohit Grover |
106:a20be740075d | 445 | } |
Rohit Grover |
106:a20be740075d | 446 | |
Rohit Grover |
106:a20be740075d | 447 | inline Gap::GapState_t |
Rohit Grover |
106:a20be740075d | 448 | BLEDevice::getGapState(void) const |
Rohit Grover |
106:a20be740075d | 449 | { |
Rohit Grover |
106:a20be740075d | 450 | return transport->getGap().getState(); |
Rohit Grover |
106:a20be740075d | 451 | } |
Rohit Grover |
106:a20be740075d | 452 | |
Rohit Grover |
106:a20be740075d | 453 | inline ble_error_t BLEDevice::readCharacteristicValue(uint16_t handle, uint8_t *const buffer, uint16_t *const lengthP) |
Rohit Grover |
106:a20be740075d | 454 | { |
Rohit Grover |
106:a20be740075d | 455 | return transport->getGattServer().readValue(handle, buffer, lengthP); |
Rohit Grover |
106:a20be740075d | 456 | } |
Rohit Grover |
106:a20be740075d | 457 | |
Rohit Grover |
106:a20be740075d | 458 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 459 | BLEDevice::updateCharacteristicValue(uint16_t handle, const uint8_t* value, uint16_t size, bool localOnly) |
Rohit Grover |
106:a20be740075d | 460 | { |
Rohit Grover |
106:a20be740075d | 461 | return transport->getGattServer().updateValue(handle, const_cast<uint8_t *>(value), size, localOnly); |
Rohit Grover |
106:a20be740075d | 462 | } |
Rohit Grover |
106:a20be740075d | 463 | |
Rohit Grover |
106:a20be740075d | 464 | inline void |
Rohit Grover |
106:a20be740075d | 465 | BLEDevice::waitForEvent(void) |
Rohit Grover |
106:a20be740075d | 466 | { |
Rohit Grover |
106:a20be740075d | 467 | transport->waitForEvent(); |
Rohit Grover |
106:a20be740075d | 468 | } |
Rohit Grover |
106:a20be740075d | 469 | |
Rohit Grover |
106:a20be740075d | 470 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 471 | BLEDevice::getPreferredConnectionParams(Gap::ConnectionParams_t *params) |
Rohit Grover |
106:a20be740075d | 472 | { |
Rohit Grover |
106:a20be740075d | 473 | return transport->getGap().getPreferredConnectionParams(params); |
Rohit Grover |
106:a20be740075d | 474 | } |
Rohit Grover |
106:a20be740075d | 475 | |
Rohit Grover |
106:a20be740075d | 476 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 477 | BLEDevice::setPreferredConnectionParams(const Gap::ConnectionParams_t *params) |
Rohit Grover |
106:a20be740075d | 478 | { |
Rohit Grover |
106:a20be740075d | 479 | return transport->getGap().setPreferredConnectionParams(params); |
Rohit Grover |
106:a20be740075d | 480 | } |
Rohit Grover |
106:a20be740075d | 481 | |
Rohit Grover |
106:a20be740075d | 482 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 483 | BLEDevice::updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) { |
Rohit Grover |
106:a20be740075d | 484 | return transport->getGap().updateConnectionParams(handle, params); |
Rohit Grover |
106:a20be740075d | 485 | } |
Rohit Grover |
106:a20be740075d | 486 | |
Rohit Grover |
106:a20be740075d | 487 | /* |
Rohit Grover |
106:a20be740075d | 488 | * ALL OF THE FOLLOWING METHODS ARE DEPRECATED |
Rohit Grover |
106:a20be740075d | 489 | */ |
Rohit Grover |
106:a20be740075d | 490 | |
Rohit Grover |
106:a20be740075d | 491 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 492 | BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures, const GapAdvertisingData &scanResponse) |
Rohit Grover |
106:a20be740075d | 493 | { |
Rohit Grover |
106:a20be740075d | 494 | needToSetAdvPayload = false; |
Rohit Grover |
106:a20be740075d | 495 | return transport->getGap().setAdvertisingData(ADStructures, scanResponse); |
Rohit Grover |
106:a20be740075d | 496 | } |
Rohit Grover |
106:a20be740075d | 497 | |
Rohit Grover |
106:a20be740075d | 498 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 499 | BLEDevice::setAdvertisingData(const GapAdvertisingData &ADStructures) |
Rohit Grover |
106:a20be740075d | 500 | { |
Rohit Grover |
106:a20be740075d | 501 | GapAdvertisingData scanResponse; |
Rohit Grover |
106:a20be740075d | 502 | |
Rohit Grover |
106:a20be740075d | 503 | needToSetAdvPayload = false; |
Rohit Grover |
106:a20be740075d | 504 | return transport->getGap().setAdvertisingData(ADStructures, scanResponse); |
Rohit Grover |
106:a20be740075d | 505 | } |
Rohit Grover |
106:a20be740075d | 506 | |
Rohit Grover |
106:a20be740075d | 507 | inline ble_error_t |
Rohit Grover |
106:a20be740075d | 508 | BLEDevice::startAdvertising(const GapAdvertisingParams &_advParams) |
Rohit Grover |
106:a20be740075d | 509 | { |
Rohit Grover |
106:a20be740075d | 510 | return transport->getGap().startAdvertising(_advParams); |
Rohit Grover |
106:a20be740075d | 511 | } |
Rohit Grover |
106:a20be740075d | 512 | |
Rohit Grover |
106:a20be740075d | 513 | #endif // ifndef __BLE_DEVICE__ |