High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Revision:
3:46de446e82ed
Parent:
2:ffc5216bd2cc
Child:
4:50a31ff5f974
--- 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;
+}