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
GapAdvertisingData.cpp@3:46de446e82ed, 2013-12-11 (annotated)
- Committer:
- ktownsend
- Date:
- Wed Dec 11 22:15:59 2013 +0000
- Revision:
- 3:46de446e82ed
- Parent:
- 2:ffc5216bd2cc
- Child:
- 4:50a31ff5f974
Incremental changes for GAP Advertising API
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ktownsend | 2:ffc5216bd2cc | 1 | #include <stdio.h> |
| ktownsend | 2:ffc5216bd2cc | 2 | #include <string.h> |
| ktownsend | 2:ffc5216bd2cc | 3 | |
| ktownsend | 2:ffc5216bd2cc | 4 | #include "GapAdvertisingData.h" |
| ktownsend | 2:ffc5216bd2cc | 5 | |
| ktownsend | 2:ffc5216bd2cc | 6 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 7 | /*! |
| ktownsend | 2:ffc5216bd2cc | 8 | @brief Creates a new GapAdvertisingData instance |
| ktownsend | 2:ffc5216bd2cc | 9 | |
| ktownsend | 2:ffc5216bd2cc | 10 | @section EXAMPLE |
| ktownsend | 2:ffc5216bd2cc | 11 | |
| ktownsend | 2:ffc5216bd2cc | 12 | @code |
| ktownsend | 2:ffc5216bd2cc | 13 | |
| ktownsend | 2:ffc5216bd2cc | 14 | @endcode |
| ktownsend | 2:ffc5216bd2cc | 15 | */ |
| ktownsend | 2:ffc5216bd2cc | 16 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 17 | GapAdvertisingData::GapAdvertisingData(void) |
| ktownsend | 2:ffc5216bd2cc | 18 | { |
| ktownsend | 3:46de446e82ed | 19 | memset(_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD); |
| ktownsend | 3:46de446e82ed | 20 | _payloadLen = 0; |
| ktownsend | 2:ffc5216bd2cc | 21 | } |
| ktownsend | 2:ffc5216bd2cc | 22 | |
| ktownsend | 2:ffc5216bd2cc | 23 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 24 | /*! |
| ktownsend | 2:ffc5216bd2cc | 25 | Destructor |
| ktownsend | 2:ffc5216bd2cc | 26 | */ |
| ktownsend | 2:ffc5216bd2cc | 27 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 28 | GapAdvertisingData::~GapAdvertisingData(void) |
| ktownsend | 2:ffc5216bd2cc | 29 | { |
| ktownsend | 2:ffc5216bd2cc | 30 | } |
| ktownsend | 3:46de446e82ed | 31 | |
| ktownsend | 3:46de446e82ed | 32 | /**************************************************************************/ |
| ktownsend | 3:46de446e82ed | 33 | /*! |
| ktownsend | 3:46de446e82ed | 34 | @brief Returns the current payload length (0..31 bytes) |
| ktownsend | 3:46de446e82ed | 35 | */ |
| ktownsend | 3:46de446e82ed | 36 | /**************************************************************************/ |
| ktownsend | 3:46de446e82ed | 37 | uint8_t GapAdvertisingData::getPayloadLen(void) |
| ktownsend | 3:46de446e82ed | 38 | { |
| ktownsend | 3:46de446e82ed | 39 | return _payloadLen; |
| ktownsend | 3:46de446e82ed | 40 | } |
| ktownsend | 3:46de446e82ed | 41 | |
| ktownsend | 3:46de446e82ed | 42 | /**************************************************************************/ |
| ktownsend | 3:46de446e82ed | 43 | /*! |
| ktownsend | 3:46de446e82ed | 44 | @brief Adds advertising data based on the specified AD types |
| ktownsend | 3:46de446e82ed | 45 | |
| ktownsend | 3:46de446e82ed | 46 | @args[in] adType The advertising data type to add |
| ktownsend | 3:46de446e82ed | 47 | @args[in] payload Pointer to the payload contents |
| ktownsend | 3:46de446e82ed | 48 | @args[in] len Size of the payload in bytes |
| ktownsend | 3:46de446e82ed | 49 | |
| ktownsend | 3:46de446e82ed | 50 | @returns ble_error_t |
| ktownsend | 3:46de446e82ed | 51 | |
| ktownsend | 3:46de446e82ed | 52 | @retval BLE_ERROR_NONE |
| ktownsend | 3:46de446e82ed | 53 | Everything executed properly |
| ktownsend | 3:46de446e82ed | 54 | @retval BLE_ERROR_BUFFER_OVERFLOW |
| ktownsend | 3:46de446e82ed | 55 | The specified data would cause the advertising buffer |
| ktownsend | 3:46de446e82ed | 56 | to overflow |
| ktownsend | 3:46de446e82ed | 57 | |
| ktownsend | 3:46de446e82ed | 58 | @section EXAMPLE |
| ktownsend | 3:46de446e82ed | 59 | |
| ktownsend | 3:46de446e82ed | 60 | @code |
| ktownsend | 3:46de446e82ed | 61 | |
| ktownsend | 3:46de446e82ed | 62 | @endcode |
| ktownsend | 3:46de446e82ed | 63 | */ |
| ktownsend | 3:46de446e82ed | 64 | /**************************************************************************/ |
| ktownsend | 3:46de446e82ed | 65 | ble_error_t GapAdvertisingData::addData(ble_gap_adv_datatype_t adType, uint8_t * payload, uint8_t len) |
| ktownsend | 3:46de446e82ed | 66 | { |
| ktownsend | 3:46de446e82ed | 67 | /* ToDo: Make sure we don't exceed the 31 byte payload limit */ |
| ktownsend | 3:46de446e82ed | 68 | if (_payloadLen + len >= GAP_ADVERTISING_DATA_MAX_PAYLOAD) |
| ktownsend | 3:46de446e82ed | 69 | return BLE_ERROR_BUFFER_OVERFLOW; |
| ktownsend | 3:46de446e82ed | 70 | |
| ktownsend | 3:46de446e82ed | 71 | memcpy(&_payload[_payloadLen], payload, len); |
| ktownsend | 3:46de446e82ed | 72 | _payloadLen += len; |
| ktownsend | 3:46de446e82ed | 73 | |
| ktownsend | 3:46de446e82ed | 74 | return BLE_ERROR_NONE; |
| ktownsend | 3:46de446e82ed | 75 | } |
