add "LE Device Address" 0x1B to advertising data types

Fork of BLE_API by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Fri Aug 07 15:53:49 2015 +0100
Parent:
762:89ec64c66d94
Child:
764:1e560f0d45e1
Commit message:
Synchronized with git rev 509ffdd1
Author: Xiao Sun
Add a new function updateAdvertisingPayload()

add updateAdvertisingPayload() to update one field of the advertising
payload

Changed in this revision

ble/Gap.h Show annotated file Show diff for this revision Revisions of this file
ble/GapAdvertisingData.h Show annotated file Show diff for this revision Revisions of this file
--- a/ble/Gap.h	Fri Aug 07 15:53:49 2015 +0100
+++ b/ble/Gap.h	Fri Aug 07 15:53:49 2015 +0100
@@ -550,8 +550,8 @@
      * small.
      *
      * @param  app
-     *         The max transmit power to be used by the controller (in dBm).
-     *         This is only a hint.
+     *         The max transmit power to be used by the controller. This is
+     *         only a hint.
      */
     ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power) {
         ble_error_t rc;
@@ -586,6 +586,27 @@
     }
 
     /**
+     * Update the advertising payload filed which has the same adv type as the input
+     * parameter. Total length of the new data must be the same as the old one.
+     *
+     * @param  type The type which describes the variable length data.
+     * @param  data data bytes.
+     * @param  len  length of data.
+     */
+    ble_error_t updateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) {
+        if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) {
+            setDeviceName(data);
+        }
+
+        ble_error_t rc;
+        if ((rc = _advPayload.updateData(type, data, len)) != BLE_ERROR_NONE) {
+            return rc;
+        }
+
+        return setAdvertisingData();
+    }
+
+    /**
      * Setup a particular, user-constructed advertisement payload for the
      * underlying stack. It would be uncommon for this API to be used directly;
      * there are other APIs to build an advertisement payload (see above).
--- a/ble/GapAdvertisingData.h	Fri Aug 07 15:53:49 2015 +0100
+++ b/ble/GapAdvertisingData.h	Fri Aug 07 15:53:49 2015 +0100
@@ -234,6 +234,33 @@
     }
 
     /**
+     * update one advertising data field with the same AD type (see DataType)
+     *
+     * @param  advDataType The Advertising 'DataType' to add
+     * @param  payload     Pointer to the payload contents
+     * @param  len         Size of the payload in bytes
+     *
+     * @return BLE_ERROR_UNSPECIFIED if the specified field is not found, else
+     * BLE_ERROR_NONE.
+     */
+    ble_error_t updateData(DataType advDataType, const uint8_t *payload, uint8_t len)
+     {
+        uint8_t byteIndex = 0;
+        
+        while (byteIndex < _payloadLen) {
+            if (_payload[byteIndex + 1] == advDataType) { /* Check adv type */
+                if (_payload[byteIndex] == (len + 1)) { /* Check adv field length */
+                    memcpy(&_payload[byteIndex + 2], payload, len);
+                }
+                return BLE_ERROR_NONE;
+            }
+            byteIndex += (_payload[byteIndex] + 1);
+        }
+
+        return BLE_ERROR_UNSPECIFIED;
+    }
+
+    /**
      * Helper function to add APPEARANCE data to the advertising payload
      *
      * @param  appearance