Caching the advertising data and the scan response.

Fork of MaximBLE by Maxim Integrated

Revision:
1:4e764337d5c5
Parent:
0:b562096246b3
diff -r b562096246b3 -r 4e764337d5c5 MaximGap.cpp
--- a/MaximGap.cpp	Thu Mar 03 14:13:21 2016 +0000
+++ b/MaximGap.cpp	Tue Mar 22 18:16:10 2016 +0000
@@ -52,9 +52,11 @@
         return BLE_ERROR_PARAM_OUT_OF_RANGE;
     }
 
-    /* set advertising and scan response data for discoverable mode */
-    DmAdvSetData(DM_DATA_LOC_ADV, advData.getPayloadLen(), (uint8_t*)advData.getPayload());
-    DmAdvSetData(DM_DATA_LOC_SCAN, scanResponse.getPayloadLen(), (uint8_t*)scanResponse.getPayload());
+    /* save advertising and scan response data */
+    advDataLen = advData.getPayloadLen();
+    scanResponseLen = scanResponse.getPayloadLen();
+    memcpy((void*)advDataCache, (void*)advData.getPayload(), advDataLen);
+    memcpy((void*)advDataCache, (void*)advData.getPayload(), scanResponseLen);
 
     return BLE_ERROR_NONE;
 }
@@ -94,6 +96,10 @@
         return BLE_ERROR_PARAM_OUT_OF_RANGE;
     }
 
+    /* set advertising and scan response data for discoverable mode */
+    DmAdvSetData(DM_DATA_LOC_ADV, advDataLen, advDataCache);
+    DmAdvSetData(DM_DATA_LOC_SCAN, scanResponseLen, scanResponseCache);
+
     DmAdvSetInterval(params.getInterval(), params.getInterval());
     DmAdvStart(params.getAdvertisingType(), params.getTimeout());