BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Mon Mar 02 11:50:47 2015 +0000
Revision:
292:b5ee2ada4f33
Parent:
290:aafa664ba829
Child:
293:6278354cfd98
Synchronized with git rev 8d1b53ed
Author: Jeremy Brodt
Added callback on characteristic reads

Who changed what in which revision?

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