cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 6 MCU

aaartis1
New Contributor II

Hello! I'm currently developing application using Psoc 63 and part of it requires  storing last n scan results in array inside CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT event for further processing.  Part of code so far:

 

 

void StackEventHandler(uint32 event, void *eventParam)
{
cy_stc_ble_gapc_adv_report_param_t * advReport;
cy_stc_ble_gapc_adv_report_param_t * advReport_arr[10]; //Can store 10 devices adv data
uint8_t scanState = Cy_BLE_GetScanState();
switch (event)
{
/* This event is received when the BLE stack is initialized and turned ON.*/
case CY_BLE_EVT_STACK_ON:
{
   printf("CY_BLE_EVT_STACK_ON \r\n");
Cy_BLE_GAPC_StartScan(CY_BLE_SCANNING_FAST,CY_BLE_OBSERVER_CONFIGURATION_0_INDEX);
break;
}

case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
/* scan progress result event occurs
* when it receives any advertisiment packet
* or scan response packet from peer device*/
advReport = (cy_stc_ble_gapc_adv_report_param_t *)eventParam;
advReport_arr[i] = (cy_stc_ble_gapc_adv_report_param_t *)eventParam;
printf("i %i \n",i);
printf("CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:\r\n");
/* PEER Device address type */
printf("peerBdAddr: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",
advReport->peerBdAddr[5u], advReport->peerBdAddr[4u],
advReport->peerBdAddr[3u], advReport->peerBdAddr[2u],
advReport->peerBdAddr[1u], advReport->peerBdAddr[0u]);
if (i == 10){
for (int k = 0; k<10; k++){
printf("i = %ipeerBdAddr: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",k,
advReport_arr[k]->peerBdAddr[5u], advReport_arr[k]->peerBdAddr[4u],
advReport_arr[k]->peerBdAddr[3u], advReport_arr[k]->peerBdAddr[2u],
advReport_arr[k]->peerBdAddr[1u], advReport_arr[k]->peerBdAddr[0u]);
}
i=0;
}
printf("_______________\n");
i++;
break;

 

 

I have defined array cy_stc_ble_gapc_adv_report_param_t * advReport_arr[10] and my understanding is that every time scan progress result event occurs I store result in advReport_arr[i] = (cy_stc_ble_gapc_adv_report_param_t *)eventParam;

after event is complete I increment i. Unfortunately this outputs:

 

 

_______________
i 1 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 71f23d004fdb 
_______________
i 2 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 7d4ce49f4e4e 
_______________
i 3 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 0bbf76ef24ac 
_______________
i 4 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 04602584dce3 
_______________
i 5 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: bc7e8ba0990f 
_______________
i 6 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 71f23d004fdb 
_______________
i 7 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 04602584dce3 
_______________
i 8 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 7d4ce49f4e4e 
_______________
i 9 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 0bbf76ef24ac 
_______________
i 10 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: d0d0030e8f4d 
i = 0peerBdAddr: d0d0030e8f4d 
i = 1peerBdAddr: d0d0030e8f4d 
i = 2peerBdAddr: d0d0030e8f4d 
i = 3peerBdAddr: d0d0030e8f4d 
i = 4peerBdAddr: d0d0030e8f4d 
i = 5peerBdAddr: d0d0030e8f4d 
i = 6peerBdAddr: d0d0030e8f4d 
i = 7peerBdAddr: d0d0030e8f4d 
i = 8peerBdAddr: d0d0030e8f4d 
i = 9peerBdAddr: d0d0030e8f4d 

 

 

I'm getting different advertisement data every CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT, but when i reaches 10 I print entire array but it turns out only last (i=10) peerBdAddr is stored in all elements of array. 

What is problem with my code and what should I do to see last 10 devices when I print advReport_arr ?

Thanks!

0 Likes
3 Replies
VenkataD_41
Moderator
Moderator

Hi,

From the output, it is understood that the peerBdAddr address for the last scanned device is being printed for all the devices.

Please make the following changes to the code and check once:

cy_stc_ble_gapc_adv_report_param_t  advReport;
cy_stc_ble_gapc_adv_report_param_t  advReport_arr[10];
advReport = *(cy_stc_ble_gapc_adv_report_param_t *)eventParam;
advReport_arr[i] = *(cy_stc_ble_gapc_adv_report_param_t *)eventParam;
printf("peerBdAddr: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",
advReport.peerBdAddr[5u], advReport.peerBdAddr[4u],
advReport.peerBdAddr[3u], advReport.peerBdAddr[2u],
advReport.peerBdAddr[1u], advReport.peerBdAddr[0u]);
if (i == 10){
for (int k = 0; k<10; k++){
printf("i = %ipeerBdAddr: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",k,
advReport_arr[k].peerBdAddr[5u], advReport_arr[k].peerBdAddr[4u],
advReport_arr[k].peerBdAddr[3u], advReport_arr[k].peerBdAddr[2u],
advReport_arr[k].peerBdAddr[1u], advReport_arr[k].peerBdAddr[0u]);
}

Please make these changes and check once.

Thanks 

Ganesh

0 Likes
aaartis1
New Contributor II

Thanks for reply! Unfortunately this doesn't solve my issue. Output:

i 1 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 3b125129f476 
_______________
i 2 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 3b125129f476 
_______________
i 3 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 3b125129f476 
_______________
i 4 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 381b7685b544 
_______________
i 5 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 381b7685b544 
_______________
i 6 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 0c817869e60b 
_______________
i 7 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 381b7685b544 
_______________
i 8 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 381b7685b544 
_______________
i 9 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 381b7685b544 
_______________
i 10 
CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
peerBdAddr: 3b125129f476 
i = 0peerBdAddr: 0c817869e60b 
i = 1peerBdAddr: 3b125129f476 
i = 2peerBdAddr: 3b125129f476 
i = 3peerBdAddr: 3b125129f476 
i = 4peerBdAddr: 3b125129f476 
i = 5peerBdAddr: 3b125129f476 
i = 6peerBdAddr: 3b125129f476 
i = 7peerBdAddr: 3b125129f476 
i = 8peerBdAddr: 3b125129f476 
i = 9peerBdAddr: 3b125129f476 
_______________
0 Likes
VenkataD_41
Moderator
Moderator

Hi,

Can you please declare the following two variables as global variables and check once?

cy_stc_ble_gapc_adv_report_param_t  advReport;
cy_stc_ble_gapc_adv_report_param_t  advReport_arr[10];

I guess the issue is because these two variables are declared inside the StackEventHandler which means local variables.

Thanks

Ganesh

0 Likes
Top labels