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.
Dependents: BLE_HeartRate_IDB0XA1_EPUDEE_Avril2018
Fork of X_NUCLEO_IDB0XA1 by
Revision 236:2a73f3a97452, committed 2016-06-09
- Comitter:
- Andrea Palmieri
- Date:
- Thu Jun 09 17:16:36 2016 +0200
- Parent:
- 235:31b976a40f43
- Child:
- 237:64c2ddbd9329
- Commit message:
- Fix issue on ADV payload de-allocation
Signed-off-by: Andrea Palmieri <andrea.palmieri@st.com>
Changed in this revision
--- a/source/BlueNRGGap.cpp Thu Jun 09 17:15:02 2016 +0200
+++ b/source/BlueNRGGap.cpp Thu Jun 09 17:16:36 2016 +0200
@@ -47,8 +47,6 @@
//Local Variables
//const char *local_name = NULL;
//uint8_t local_name_length = 0;
-const uint8_t *scan_response_payload = NULL;
-uint8_t scan_rsp_length = 0;
/*
* Utility to process GAP specific events (e.g., Advertising timeout)
@@ -111,8 +109,9 @@
local_name_length = 0;
servUuidlength = 0;
AdvLen = 0;
- } else {
- PayloadPtr loadPtr(advData.getPayload(), advData.getPayloadLen());
+ } else {
+ PayloadPtr loadPtr(advData.getPayload(), advData.getPayloadLen());
+
for(uint8_t index=0; index<loadPtr.getPayloadUnitCount(); index++) {
loadPtr.getUnitAtIndex(index);
@@ -157,7 +156,8 @@
}
for(unsigned i=0; i<buffSize; i++) {
- PRINTF("loadPtr.getUnitAtIndex(index).getDataPtr()[%d] = 0x%x\n\r", i, loadPtr.getUnitAtIndex(index).getDataPtr()[i]);
+ PRINTF("loadPtr.getUnitAtIndex(index).getDataPtr()[%d] = 0x%x\n\r",
+ i, loadPtr.getUnitAtIndex(index).getDataPtr()[i]);
}
#endif /* DEBUG */
break;
@@ -224,7 +224,8 @@
}
#ifdef DEBUG
for(int i=0; i<buffSize+1; i++) {
- PRINTF("Advertising type: SERVICE_DATA loadPtr.getUnitAtIndex(index).getDataPtr()[%d] = 0x%x\n\r", i, loadPtr.getUnitAtIndex(index).getDataPtr()[i]);
+ PRINTF("Advertising type: SERVICE_DATA loadPtr.getUnitAtIndex(index).getDataPtr()[%d] = 0x%x\n\r",
+ i, loadPtr.getUnitAtIndex(index).getDataPtr()[i]);
}
#endif
AdvLen = buffSize+2; // the total ADV DATA LEN should include two more bytes: the buffer size byte; and the Service Data Type Value byte
@@ -279,12 +280,15 @@
memcpy(AdvData+2, loadPtr.getUnitAtIndex(index).getDataPtr(), buffSize);
break;
}
-
- }
+ } // end switch
+
+ } //end for
+
+ //Set the SCAN_RSP Payload
+ if(scanResponse.getPayloadLen() > 0) {
+ scan_response_payload = scanResponse.getPayload();
+ scan_rsp_length = scanResponse.getPayloadLen();
}
- //Set the SCAN_RSP Payload
- scan_response_payload = scanResponse.getPayload();
- scan_rsp_length = scanResponse.getPayloadLen();
// Update the ADV data if we are already in ADV mode
if(AdvLen > 0 && state.advertising == 1) {
--- a/source/utils/Payload.cpp Thu Jun 09 17:15:02 2016 +0200
+++ b/source/utils/Payload.cpp Thu Jun 09 17:16:36 2016 +0200
@@ -98,4 +98,21 @@
serializedAdData[i+1] = data[i];
}
return serializedAdData;
-}
+}
+
+Payload::~Payload() {
+ int i = 0;
+
+ if(payload) {
+ while(i<payloadUnitCount) {
+ if(payload->data) {
+ delete[] payload->data;
+ payload->data = NULL;
+ }
+ }
+ delete[] payload;
+ payload = NULL;
+ }
+
+}
+
--- a/x-nucleo-idb0xa1/BlueNRGGap.h Thu Jun 09 17:15:02 2016 +0200
+++ b/x-nucleo-idb0xa1/BlueNRGGap.h Thu Jun 09 17:16:36 2016 +0200
@@ -176,6 +176,9 @@
Timeout advTimeout;
bool AdvToFlag;
+ const uint8_t *scan_response_payload;
+ uint8_t scan_rsp_length;
+
static uint16_t SCAN_DURATION_UNITS_TO_MSEC(uint16_t duration) {
return (duration * 625) / 1000;
}
--- a/x-nucleo-idb0xa1/utils/Payload.h Thu Jun 09 17:15:02 2016 +0200
+++ b/x-nucleo-idb0xa1/utils/Payload.h Thu Jun 09 17:16:36 2016 +0200
@@ -67,6 +67,7 @@
public:
Payload(const uint8_t *tokenString, uint8_t string_ength);
Payload();
+ ~Payload();
uint8_t getPayloadUnitCount();
uint8_t getIDAtIndex(int index);
@@ -180,7 +181,11 @@
int getPayloadUnitCount() { return payloadUnitCount; }
-
+ ~PayloadPtr() {
+ if(unit) delete[] unit;
+
+ unit = NULL;
+ }
};
#endif // __PAYLOAD_H__
