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
Diff: GapAdvertisingData.cpp
- Revision:
- 3:46de446e82ed
- Parent:
- 2:ffc5216bd2cc
- Child:
- 4:50a31ff5f974
diff -r ffc5216bd2cc -r 46de446e82ed GapAdvertisingData.cpp
--- a/GapAdvertisingData.cpp Tue Dec 10 07:32:12 2013 +0000
+++ b/GapAdvertisingData.cpp Wed Dec 11 22:15:59 2013 +0000
@@ -16,6 +16,8 @@
/**************************************************************************/
GapAdvertisingData::GapAdvertisingData(void)
{
+ memset(_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
+ _payloadLen = 0;
}
/**************************************************************************/
@@ -26,3 +28,48 @@
GapAdvertisingData::~GapAdvertisingData(void)
{
}
+
+/**************************************************************************/
+/*!
+ @brief Returns the current payload length (0..31 bytes)
+*/
+/**************************************************************************/
+uint8_t GapAdvertisingData::getPayloadLen(void)
+{
+ return _payloadLen;
+}
+
+/**************************************************************************/
+/*!
+ @brief Adds advertising data based on the specified AD types
+
+ @args[in] adType The advertising data type to add
+ @args[in] payload Pointer to the payload contents
+ @args[in] len Size of the payload in bytes
+
+ @returns ble_error_t
+
+ @retval BLE_ERROR_NONE
+ Everything executed properly
+ @retval BLE_ERROR_BUFFER_OVERFLOW
+ The specified data would cause the advertising buffer
+ to overflow
+
+ @section EXAMPLE
+
+ @code
+
+ @endcode
+*/
+/**************************************************************************/
+ble_error_t GapAdvertisingData::addData(ble_gap_adv_datatype_t adType, uint8_t * payload, uint8_t len)
+{
+ /* ToDo: Make sure we don't exceed the 31 byte payload limit */
+ if (_payloadLen + len >= GAP_ADVERTISING_DATA_MAX_PAYLOAD)
+ return BLE_ERROR_BUFFER_OVERFLOW;
+
+ memcpy(&_payload[_payloadLen], payload, len);
+ _payloadLen += len;
+
+ return BLE_ERROR_NONE;
+}
