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:
- 4:50a31ff5f974
- Parent:
- 3:46de446e82ed
- Child:
- 5:7635f81a8e09
diff -r 46de446e82ed -r 50a31ff5f974 GapAdvertisingData.cpp
--- a/GapAdvertisingData.cpp Wed Dec 11 22:15:59 2013 +0000
+++ b/GapAdvertisingData.cpp Thu Dec 12 02:20:54 2013 +0000
@@ -31,19 +31,10 @@
/**************************************************************************/
/*!
- @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 type (see
+ \ref DataType)
-/**************************************************************************/
-/*!
- @brief Adds advertising data based on the specified AD types
-
- @args[in] adType The advertising data type to add
+ @args[in] advDataType The Advertising \ref DataType to add
@args[in] payload Pointer to the payload contents
@args[in] len Size of the payload in bytes
@@ -51,6 +42,45 @@
@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(DataType advDataType, uint8_t * payload, uint8_t len)
+{
+ /* ToDo: Check if an AD type already exists and if the existing */
+ /* value is exclusive or not (flags, etc.) */
+
+ /* 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;
+}
+
+/**************************************************************************/
+/*!
+ @brief Helper function to add \ref APPEARANCE data to the advertising
+ payload
+
+ @args[in] appearance The \ref APPEARANCE value to add
+
+ @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
@@ -62,14 +92,93 @@
@endcode
*/
/**************************************************************************/
-ble_error_t GapAdvertisingData::addData(ble_gap_adv_datatype_t adType, uint8_t * payload, uint8_t len)
+ble_error_t GapAdvertisingData::addAppearance(Appearance appearance)
{
- /* 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;
+ return addData(GapAdvertisingData::APPEARANCE, (uint8_t*)&appearance, 2);
+}
+
+/**************************************************************************/
+/*!
+ @brief Helper function to add \ref FLAGS data to the advertising
+ payload
+
+ @args[in] flag The \ref FLAGS value to add
+
+ @para
+ \ref LE_LIMITED_DISCOVERABLE - The peripheral is
+ discoverable for a limited period of time
+
+ @para
+ \ref LE_GENERAL_DISCOVERABLE - The peripheral is
+ permanently discoverable
+
+ @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
- memcpy(&_payload[_payloadLen], payload, len);
- _payloadLen += len;
+ @section EXAMPLE
+
+ @code
+
+ @endcode
+*/
+/**************************************************************************/
+ble_error_t GapAdvertisingData::addFlags(Flags flag)
+{
+ return addData(GapAdvertisingData::FLAGS, (uint8_t*)&flag, 1);
+}
+
+/**************************************************************************/
+/*!
+ @brief Helper function to add \ref TX_POWER_LEVEL data to the
+ advertising payload
+
+ @args[in] flag The \ref TX_POWER_LEVEL value to add
+
+ @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
- return BLE_ERROR_NONE;
+ @section EXAMPLE
+
+ @code
+
+ @endcode
+*/
+/**************************************************************************/
+ble_error_t GapAdvertisingData::addTxPower(int8_t txPower)
+{
+ /* ToDo: Basic error checking to make sure txPower is in range */
+ return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t*)&txPower, 1);
}
+
+/**************************************************************************/
+/*!
+ @brief Clears the payload and resets the payload length counter
+*/
+/**************************************************************************/
+void GapAdvertisingData::clear(void)
+{
+ memset(&_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
+ _payloadLen = 0;
+}
+
+/**************************************************************************/
+/*!
+ @brief Returns the current payload length (0..31 bytes)
+*/
+/**************************************************************************/
+uint8_t GapAdvertisingData::getPayloadLen(void)
+{
+ return _payloadLen;
+}
