Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
BLEDevice.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef __BLE_DEVICE__ 00018 #define __BLE_DEVICE__ 00019 00020 #include "blecommon.h" 00021 #include "Gap.h" 00022 #include "GattServer.h" 00023 #include "BLEDeviceInstanceBase.h" 00024 00025 /** 00026 * The base class used to abstract away BLE capable radio transceivers or SOCs, 00027 * to enable this BLE API to work with any radio transparently. 00028 */ 00029 class BLEDevice 00030 { 00031 public: 00032 /** 00033 * Initialize the BLE controller. This should be called before using 00034 * anything else in the BLE_API. 00035 */ 00036 ble_error_t init(); 00037 ble_error_t reset(void); 00038 00039 /** 00040 * Purge the BLE stack of GATT and GAP state. init() must be called afterwards to re-instate services and GAP state. 00041 */ 00042 ble_error_t shutdown(void); 00043 00044 /* GAP specific APIs */ 00045 public: 00046 /** 00047 * Set the BTLE MAC address and type. 00048 * @return BLE_ERROR_NONE on success. 00049 */ 00050 ble_error_t setAddress(Gap::addr_type_t type, const Gap::address_t address); 00051 00052 /** 00053 * Fetch the BTLE MAC address and type. 00054 * @return BLE_ERROR_NONE on success. 00055 */ 00056 ble_error_t getAddress(Gap::addr_type_t *typeP, Gap::address_t address); 00057 00058 /** 00059 * @param[in] advType 00060 * The GAP advertising mode to use for this device. Valid 00061 * values are defined in AdvertisingType: 00062 * 00063 * \par ADV_NON_CONNECTABLE_UNDIRECTED 00064 * All connections to the peripheral device will be refused. 00065 * 00066 * \par ADV_CONNECTABLE_DIRECTED 00067 * Only connections from a pre-defined central device will be 00068 * accepted. 00069 * 00070 * \par ADV_CONNECTABLE_UNDIRECTED 00071 * Any central device can connect to this peripheral. 00072 * 00073 * \par ADV_SCANNABLE_UNDIRECTED 00074 * Include support for Scan Response payloads. 00075 * 00076 * \par 00077 * See Bluetooth Core Specification 4.0 (Vol. 3), Part C, 00078 * Section 9.3 and Core Specification 4.0 (Vol. 6), Part B, 00079 * Section 2.3.1 for further information on GAP connection 00080 * modes 00081 */ 00082 void setAdvertisingType (GapAdvertisingParams::AdvertisingType); 00083 00084 /** 00085 * @param[in] interval 00086 * Advertising interval in units of milliseconds. Advertising 00087 * is disabled if interval is 0. If interval is smaller than 00088 * the minimum supported value, then the minimum supported 00089 * value is used instead. 00090 * 00091 * \par 00092 * Decreasing this value will allow central devices to detect 00093 * your peripheral faster at the expense of more power being 00094 * used by the radio due to the higher data transmit rate. 00095 * 00096 * \par 00097 * This field must be set to 0 if connectionMode is equal 00098 * to ADV_CONNECTABLE_DIRECTED 00099 * 00100 * \par 00101 * See Bluetooth Core Specification, Vol 3., Part C, 00102 * Appendix A for suggested advertising intervals. 00103 * 00104 * @Note: [WARNING] This API previously used 0.625ms as the unit for its 00105 * 'interval' argument. That required an explicit conversion from 00106 * milliseconds using Gap::MSEC_TO_GAP_DURATION_UNITS(). This conversion is 00107 * no longer required as the new units are milliseconds. Any application 00108 * code depending on the old semantics would need to be updated accordingly. 00109 */ 00110 void setAdvertisingInterval (uint16_t interval); 00111 00112 /** 00113 * @return Minimum Advertising interval in milliseconds. 00114 */ 00115 uint16_t getMinAdvertisingInterval (void) const; 00116 /** 00117 * @return Minimum Advertising interval in milliseconds for non connectible mode. 00118 */ 00119 uint16_t getMinNonConnectableAdvertisingInterval (void) const; 00120 /** 00121 * @return Maximum Advertising interval in milliseconds. 00122 */ 00123 uint16_t getMaxAdvertisingInterval (void) const; 00124 00125 /** 00126 * @param[in] timeout 00127 * Advertising timeout between 0x1 and 0x3FFF (1 and 16383) 00128 * in seconds. Enter 0 to disable the advertising timeout. 00129 */ 00130 void setAdvertisingTimeout (uint16_t timeout); 00131 00132 /** 00133 * Please refer to the APIs above. 00134 */ 00135 void setAdvertisingParams(const GapAdvertisingParams &advParams); 00136 00137 /** 00138 * This API is typically used as an internal helper to udpate the transport 00139 * backend with advertising data before starting to advertise. It may also 00140 * be explicity used to dynamically reset the accumulated advertising 00141 * payload and scanResponse; to do this, the application can clear and re- 00142 * accumulate a new advertising payload (and scanResponse) before using this 00143 * API. 00144 */ 00145 ble_error_t setAdvertisingPayload(void); 00146 00147 /** 00148 * Reset any advertising payload prepared from prior calls to 00149 * accumulateAdvertisingPayload(). 00150 */ 00151 void clearAdvertisingPayload(void); 00152 00153 /** 00154 * Accumulate an AD structure in the advertising payload. Please note that 00155 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used 00156 * as an additional 31 bytes if the advertising payload proves to be too 00157 * small. 00158 * 00159 * @param flags 00160 * The flags to be added. Multiple flags may be specified in 00161 * combination. 00162 */ 00163 ble_error_t accumulateAdvertisingPayload(uint8_t flags); 00164 00165 /** 00166 * Accumulate an AD structure in the advertising payload. Please note that 00167 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used 00168 * as an additional 31 bytes if the advertising payload proves to be too 00169 * small. 00170 * 00171 * @param app 00172 * The appearance of the peripheral. 00173 */ 00174 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app); 00175 00176 /** 00177 * Accumulate an AD structure in the advertising payload. Please note that 00178 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used 00179 * as an additional 31 bytes if the advertising payload proves to be too 00180 * small. 00181 * 00182 * @param app 00183 * The max transmit power to be used by the controller. This is 00184 * only a hint. 00185 */ 00186 ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power); 00187 00188 /** 00189 * Accumulate a variable length byte-stream as an AD structure in the 00190 * advertising payload. Please note that the payload is limited to 31 bytes. 00191 * The SCAN_RESPONSE message may be used as an additional 31 bytes if the 00192 * advertising payload proves to be too small. 00193 * 00194 * @param type The type which describes the variable length data. 00195 * @param data data bytes. 00196 * @param len length of data. 00197 */ 00198 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len); 00199 00200 /** 00201 * Accumulate a variable length byte-stream as an AD structure in the 00202 * scanResponse payload. 00203 * 00204 * @param type The type which describes the variable length data. 00205 * @param data data bytes. 00206 * @param len length of data. 00207 */ 00208 ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len); 00209 00210 /** 00211 * Start advertising (GAP Discoverable, Connectable modes, Broadcast 00212 * Procedure). 00213 */ 00214 ble_error_t startAdvertising(void); 00215 00216 /** 00217 * Stop advertising (GAP Discoverable, Connectable modes, Broadcast 00218 * Procedure). 00219 */ 00220 ble_error_t stopAdvertising(void); 00221 00222 /** 00223 * This call initiates the disconnection procedure, and its completion will 00224 * be communicated to the application with an invocation of the 00225 * onDisconnection callback. 00226 * 00227 * @param reason 00228 * The reason for disconnection to be sent back to the peer. 00229 */ 00230 ble_error_t disconnect(Gap::DisconnectionReason_t reason); 00231 00232 /* APIs to set GAP callbacks. */ 00233 void onTimeout(Gap::EventCallback_t timeoutCallback); 00234 00235 void onConnection(Gap::ConnectionEventCallback_t connectionCallback); 00236 /** 00237 * Used to setup a callback for GAP disconnection. 00238 */ 00239 void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback); 00240 00241 /** 00242 * Append to a chain of callbacks to be invoked upon disconnection; these 00243 * callbacks receive no context and are therefore different from the 00244 * onDisconnection callback. 00245 */ 00246 template<typename T> 00247 void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)); 00248 00249 /** 00250 * Add a callback for the GATT event DATA_SENT (which is triggered when 00251 * updates are sent out by GATT in the form of notifications). 00252 * 00253 * @Note: it is possible to chain together multiple onDataSent callbacks 00254 * (potentially from different modules of an application) to receive updates 00255 * to characteristics. 00256 * 00257 * @Note: it is also possible to setup a callback into a member function of 00258 * some object. 00259 */ 00260 void onDataSent(void (*callback)(unsigned count)); 00261 template <typename T> void onDataSent(T * objPtr, void (T::*memberPtr)(unsigned count)); 00262 00263 /** 00264 * Setup a callback for when a characteristic has its value updated by a 00265 * client. 00266 * 00267 * @Note: it is possible to chain together multiple onDataWritten callbacks 00268 * (potentially from different modules of an application) to receive updates 00269 * to characteristics. Many services, such as DFU and UART add their own 00270 * onDataWritten callbacks behind the scenes to trap interesting events. 00271 * 00272 * @Note: it is also possible to setup a callback into a member function of 00273 * some object. 00274 */ 00275 void onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)); 00276 template <typename T> void onDataWritten(T * objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)); 00277 00278 /** 00279 * Setup a callback for when a characteristic is being read by a client. 00280 * 00281 * @Note: this functionality may not be available on all underlying stacks. 00282 * You could use GattCharacteristic::setReadAuthorizationCallback() as an 00283 * alternative. 00284 * 00285 * @Note: it is possible to chain together multiple onDataRead callbacks 00286 * (potentially from different modules of an application) to receive updates 00287 * to characteristics. Services may add their own onDataRead callbacks 00288 * behind the scenes to trap interesting events. 00289 * 00290 * @Note: it is also possible to setup a callback into a member function of 00291 * some object. 00292 * 00293 * @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available; 00294 * else BLE_ERROR_NONE. 00295 */ 00296 ble_error_t onDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)); 00297 template <typename T> ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)); 00298 00299 void onUpdatesEnabled(GattServer::EventCallback_t callback); 00300 void onUpdatesDisabled(GattServer::EventCallback_t callback); 00301 void onConfirmationReceived(GattServer::EventCallback_t callback); 00302 00303 /** 00304 * Radio Notification is a feature that enables ACTIVE and INACTIVE 00305 * (nACTIVE) signals from the stack that notify the application when the 00306 * radio is in use. The signal is sent using software interrupt. 00307 * 00308 * The ACTIVE signal is sent before the Radio Event starts. The nACTIVE 00309 * signal is sent at the end of the Radio Event. These signals can be used 00310 * by the application programmer to synchronize application logic with radio 00311 * activity. For example, the ACTIVE signal can be used to shut off external 00312 * devices to manage peak current drawn during periods when the radio is on, 00313 * or to trigger sensor data collection for transmission in the Radio Event. 00314 * 00315 * @param callback 00316 * The application handler to be invoked in response to a radio 00317 * ACTIVE/INACTIVE event. 00318 */ 00319 void onRadioNotification(Gap::RadioNotificationEventCallback_t callback); 00320 00321 /** 00322 * Add a service declaration to the local server ATT table. Also add the 00323 * characteristics contained within. 00324 */ 00325 ble_error_t addService(GattService &service); 00326 00327 /** 00328 * Returns the current GAP state of the device using a bitmask which 00329 * describes whether the device is advertising and/or connected. 00330 */ 00331 Gap::GapState_t getGapState(void) const; 00332 00333 /** 00334 * @param[in/out] lengthP 00335 * input: Length in bytes to be read, 00336 * output: Total length of attribute value upon successful return. 00337 */ 00338 ble_error_t readCharacteristicValue (GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP); 00339 00340 /** 00341 * @param localOnly 00342 * Only update the characteristic locally regardless of notify/indicate flags in the CCCD. 00343 */ 00344 ble_error_t updateCharacteristicValue (GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly = false); 00345 00346 /** 00347 * Yield control to the BLE stack or to other tasks waiting for events. This 00348 * is a sleep function which will return when there is an application 00349 * specific interrupt, but the MCU might wake up several times before 00350 * returning (to service the stack). This is not always interchangeable with 00351 * WFE(). 00352 */ 00353 void waitForEvent(void); 00354 00355 ble_error_t getPreferredConnectionParams(Gap::ConnectionParams_t *params); 00356 ble_error_t setPreferredConnectionParams(const Gap::ConnectionParams_t *params); 00357 ble_error_t updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params); 00358 00359 /** 00360 * This call allows the application to get the BLE stack version information. 00361 * 00362 * @return A pointer to a const string representing the version. 00363 * Note: The string is owned by the BLE_API. 00364 */ 00365 const char *getVersion(void); 00366 00367 /** 00368 * Set the device name characteristic in the GAP service. 00369 * @param deviceName The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string. 00370 */ 00371 ble_error_t setDeviceName(const uint8_t *deviceName); 00372 00373 /** 00374 * Get the value of the device name characteristic in the GAP service. 00375 * @param[out] deviceName Pointer to an empty buffer where the UTF-8 *non NULL- 00376 * terminated* string will be placed. Set this 00377 * value to NULL in order to obtain the deviceName-length 00378 * from the 'length' parameter. 00379 * 00380 * @param[in/out] lengthP (on input) Length of the buffer pointed to by deviceName; 00381 * (on output) the complete device name length (without the 00382 * null terminator). 00383 * 00384 * @note If the device name is longer than the size of the supplied buffer, 00385 * length will return the complete device name length, 00386 * and not the number of bytes actually returned in deviceName. 00387 * The application may use this information to retry with a suitable buffer size. 00388 * 00389 * Sample use: 00390 * uint8_t deviceName[20]; 00391 * unsigned length = sizeof(deviceName); 00392 * ble.getDeviceName(deviceName, &length); 00393 * if (length < sizeof(deviceName)) { 00394 * deviceName[length] = 0; 00395 * } 00396 * DEBUG("length: %u, deviceName: %s\r\n", length, deviceName); 00397 */ 00398 ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP); 00399 00400 /** 00401 * Set the appearance characteristic in the GAP service. 00402 * @param[in] appearance The new value for the device-appearance. 00403 */ 00404 ble_error_t setAppearance(uint16_t appearance); 00405 00406 /** 00407 * Set the appearance characteristic in the GAP service. 00408 * @param[out] appearance The new value for the device-appearance. 00409 */ 00410 ble_error_t getAppearance(uint16_t *appearanceP); 00411 00412 /** 00413 * Set the radio's transmit power. 00414 * @param[in] txPower Radio transmit power in dBm. 00415 */ 00416 ble_error_t setTxPower(int8_t txPower); 00417 00418 /** 00419 * Query the underlying stack for permitted arguments for setTxPower(). 00420 * 00421 * @param[out] valueArrayPP 00422 * Out parameter to receive the immutable array of Tx values. 00423 * @param[out] countP 00424 * Out parameter to receive the array's size. 00425 */ 00426 void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP); 00427 00428 public: 00429 BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true) { 00430 advPayload.clear(); 00431 scanResponse.clear(); 00432 } 00433 00434 private: 00435 BLEDeviceInstanceBase *const transport; /* the device specific backend */ 00436 00437 GapAdvertisingParams advParams; 00438 GapAdvertisingData advPayload; 00439 GapAdvertisingData scanResponse; 00440 00441 /* Accumulation of AD structures in the advertisement payload should 00442 * eventually result in a call to the target's setAdvertisingData() before 00443 * the server begins advertising. This flag marks the status of the pending update.*/ 00444 bool needToSetAdvPayload; 00445 }; 00446 00447 /* BLEDevice methods. Most of these simply forward the calls to the underlying 00448 * transport.*/ 00449 00450 inline ble_error_t 00451 BLEDevice::reset(void) 00452 { 00453 return transport->reset(); 00454 } 00455 00456 inline ble_error_t 00457 BLEDevice::shutdown(void) 00458 { 00459 clearAdvertisingPayload(); 00460 return transport->shutdown(); 00461 } 00462 00463 inline ble_error_t 00464 BLEDevice::setAddress(Gap::addr_type_t type, const Gap::address_t address) 00465 { 00466 return transport->getGap().setAddress(type, address); 00467 } 00468 00469 inline ble_error_t 00470 BLEDevice::getAddress(Gap::addr_type_t *typeP, Gap::address_t address) 00471 { 00472 return transport->getGap().getAddress(typeP, address); 00473 } 00474 00475 inline void 00476 BLEDevice::setAdvertisingType (GapAdvertisingParams::AdvertisingType advType) 00477 { 00478 advParams.setAdvertisingType(advType); 00479 } 00480 00481 inline void 00482 BLEDevice::setAdvertisingInterval (uint16_t interval) 00483 { 00484 if (interval == 0) { 00485 stopAdvertising(); 00486 } else if (interval < getMinAdvertisingInterval ()) { 00487 interval = getMinAdvertisingInterval (); 00488 } 00489 advParams.setInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)); 00490 } 00491 00492 inline uint16_t 00493 BLEDevice::getMinAdvertisingInterval (void) const { 00494 return transport->getGap().getMinAdvertisingInterval(); 00495 } 00496 00497 inline uint16_t 00498 BLEDevice::getMinNonConnectableAdvertisingInterval (void) const { 00499 return transport->getGap().getMinNonConnectableAdvertisingInterval(); 00500 } 00501 00502 inline uint16_t 00503 BLEDevice::getMaxAdvertisingInterval (void) const { 00504 return transport->getGap().getMaxAdvertisingInterval(); 00505 } 00506 00507 inline void 00508 BLEDevice::setAdvertisingTimeout (uint16_t timeout) 00509 { 00510 advParams.setTimeout(timeout); 00511 } 00512 00513 inline void 00514 BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams) 00515 { 00516 advParams = newAdvParams; 00517 } 00518 00519 inline void 00520 BLEDevice::clearAdvertisingPayload(void) 00521 { 00522 needToSetAdvPayload = true; 00523 advPayload.clear(); 00524 } 00525 00526 inline ble_error_t 00527 BLEDevice::accumulateAdvertisingPayload(uint8_t flags) 00528 { 00529 needToSetAdvPayload = true; 00530 return advPayload.addFlags(flags); 00531 } 00532 00533 inline ble_error_t 00534 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) 00535 { 00536 needToSetAdvPayload = true; 00537 transport->getGap().setAppearance(app); 00538 return advPayload.addAppearance(app); 00539 } 00540 00541 inline ble_error_t 00542 BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower) 00543 { 00544 needToSetAdvPayload = true; 00545 return advPayload.addTxPower(txPower); 00546 } 00547 00548 inline ble_error_t 00549 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) 00550 { 00551 needToSetAdvPayload = true; 00552 if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) { 00553 transport->getGap().setDeviceName(data); 00554 } 00555 return advPayload.addData(type, data, len); 00556 } 00557 00558 inline ble_error_t 00559 BLEDevice::accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) 00560 { 00561 needToSetAdvPayload = true; 00562 return scanResponse.addData(type, data, len); 00563 } 00564 00565 inline ble_error_t 00566 BLEDevice::setAdvertisingPayload(void) { 00567 needToSetAdvPayload = false; 00568 return transport->getGap().setAdvertisingData(advPayload, scanResponse); 00569 } 00570 00571 inline ble_error_t 00572 BLEDevice::startAdvertising(void) 00573 { 00574 ble_error_t rc; 00575 if ((rc = transport->getGattServer().initializeGATTDatabase()) != BLE_ERROR_NONE) { 00576 return rc; 00577 } 00578 if (needToSetAdvPayload) { 00579 if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) { 00580 return rc; 00581 } 00582 } 00583 00584 return transport->getGap().startAdvertising(advParams); 00585 } 00586 00587 inline ble_error_t 00588 BLEDevice::stopAdvertising(void) 00589 { 00590 return transport->getGap().stopAdvertising(); 00591 } 00592 00593 inline ble_error_t 00594 BLEDevice::disconnect(Gap::DisconnectionReason_t reason) 00595 { 00596 return transport->getGap().disconnect(reason); 00597 } 00598 00599 inline void 00600 BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback) 00601 { 00602 transport->getGap().setOnTimeout(timeoutCallback); 00603 } 00604 00605 inline void 00606 BLEDevice::onConnection(Gap::ConnectionEventCallback_t connectionCallback) 00607 { 00608 transport->getGap().setOnConnection(connectionCallback); 00609 } 00610 00611 inline void 00612 BLEDevice::onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback) 00613 { 00614 transport->getGap().setOnDisconnection(disconnectionCallback); 00615 } 00616 00617 template<typename T> 00618 inline void 00619 BLEDevice::addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) { 00620 transport->getGap().addToDisconnectionCallChain(tptr, mptr); 00621 } 00622 00623 inline void 00624 BLEDevice::onDataSent(void (*callback)(unsigned count)) { 00625 transport->getGattServer().setOnDataSent(callback); 00626 } 00627 00628 template <typename T> inline void 00629 BLEDevice::onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) { 00630 transport->getGattServer().setOnDataSent(objPtr, memberPtr); 00631 } 00632 00633 inline void 00634 BLEDevice::onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) { 00635 transport->getGattServer().setOnDataWritten(callback); 00636 } 00637 00638 template <typename T> inline void 00639 BLEDevice::onDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) { 00640 transport->getGattServer().setOnDataWritten(objPtr, memberPtr); 00641 } 00642 00643 inline ble_error_t 00644 BLEDevice::onDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)) { 00645 return transport->getGattServer().setOnDataRead(callback); 00646 } 00647 00648 template <typename T> inline ble_error_t 00649 BLEDevice::onDataRead(T *objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)) { 00650 return transport->getGattServer().setOnDataRead(objPtr, memberPtr); 00651 } 00652 00653 inline void 00654 BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback) 00655 { 00656 transport->getGattServer().setOnUpdatesEnabled(callback); 00657 } 00658 00659 inline void 00660 BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback) 00661 { 00662 transport->getGattServer().setOnUpdatesDisabled(callback); 00663 } 00664 00665 inline void 00666 BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback) 00667 { 00668 transport->getGattServer().setOnConfirmationReceived(callback); 00669 } 00670 00671 inline void 00672 BLEDevice::onRadioNotification(Gap::RadioNotificationEventCallback_t callback) 00673 { 00674 transport->getGap().setOnRadioNotification(callback); 00675 } 00676 00677 inline ble_error_t 00678 BLEDevice::addService(GattService &service) 00679 { 00680 return transport->getGattServer().addService(service); 00681 } 00682 00683 inline Gap::GapState_t 00684 BLEDevice::getGapState(void) const 00685 { 00686 return transport->getGap().getState(); 00687 } 00688 00689 inline ble_error_t BLEDevice::readCharacteristicValue (GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) 00690 { 00691 return transport->getGattServer().readValue(attributeHandle, buffer, lengthP); 00692 } 00693 00694 inline ble_error_t 00695 BLEDevice::updateCharacteristicValue (GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly) 00696 { 00697 return transport->getGattServer().updateValue(attributeHandle, const_cast<uint8_t *>(value), size, localOnly); 00698 } 00699 00700 inline void 00701 BLEDevice::waitForEvent(void) 00702 { 00703 transport->waitForEvent(); 00704 } 00705 00706 inline ble_error_t 00707 BLEDevice::getPreferredConnectionParams(Gap::ConnectionParams_t *params) 00708 { 00709 return transport->getGap().getPreferredConnectionParams(params); 00710 } 00711 00712 inline ble_error_t 00713 BLEDevice::setPreferredConnectionParams(const Gap::ConnectionParams_t *params) 00714 { 00715 return transport->getGap().setPreferredConnectionParams(params); 00716 } 00717 00718 inline ble_error_t 00719 BLEDevice::updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) { 00720 return transport->getGap().updateConnectionParams(handle, params); 00721 } 00722 00723 inline const char * 00724 BLEDevice::getVersion(void) 00725 { 00726 return transport->getVersion(); 00727 } 00728 00729 inline ble_error_t 00730 BLEDevice::setDeviceName(const uint8_t *deviceName) 00731 { 00732 return transport->getGap().setDeviceName(deviceName); 00733 } 00734 00735 inline ble_error_t 00736 BLEDevice::getDeviceName(uint8_t *deviceName, unsigned *lengthP) 00737 { 00738 return transport->getGap().getDeviceName(deviceName, lengthP); 00739 } 00740 00741 inline ble_error_t 00742 BLEDevice::setAppearance(uint16_t appearance) 00743 { 00744 return transport->getGap().setAppearance(appearance); 00745 } 00746 00747 inline ble_error_t 00748 BLEDevice::getAppearance(uint16_t *appearanceP) 00749 { 00750 return transport->getGap().getAppearance(appearanceP); 00751 } 00752 00753 inline ble_error_t 00754 BLEDevice::setTxPower(int8_t txPower) 00755 { 00756 return transport->setTxPower(txPower); 00757 } 00758 00759 inline void 00760 BLEDevice::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) 00761 { 00762 transport->getPermittedTxPowerValues(valueArrayPP, countP); 00763 } 00764 00765 #endif // ifndef __BLE_DEVICE__
Generated on Tue Jul 12 2022 18:47:13 by
