Hello,
I've been working on a modified version of the ble_multi_link project from the SDK 10.0.4.66.2 with which I would like to add a scanning function to. So far I have set up a notification that is triggered every second by a timer and callback function, and I am able to get the scanner to run, however my code never reaches the BLE_EVT_GAP_ADV_REPORT case that I added to the BLE_APP_NOTIFY_MASK switch case. Instead my scanner will run for a certain amount of time and then my code will freeze after showing ASSERT_ERROR(0). I had tried turning off advertising and also setting the scanner to turn off at various applicable points in the code, however I still receive this error. If anyone has any advice on this matter, I would greatly appreciate it.
Here are some of the additions I made to the code to implement what I have made so far:
__RETAINED static OS_TIMER sc_scan_tim; //added at the top to set up the 1 second timer
static void sc_scan_cb(OS_TIMER timer) // I added this to the section with all of the other predefined functions
{
OS_TASK task = (OS_TASK)OS_TIMER_GET_TIMER_ID(timer);
OS_TASK_NOTIFY(task, SC_SCANNER_MASK, OS_NOTIFY_SET_BITS);
}
/ /代码添加到ble_multi_link_task函数
ble_gap_role_set(
GAP_PERIPHERAL_ROLE | GAP_CENTRAL_ROLE | GAP_OBSERVER_ROLE); // I also set the GAP_OBSERVER_ROLE to 1 in the config file
sc_scan_tim = OS_TIMER_CREATE("SC_SCAN", OS_MS_2_TICKS(1000), true,
(void *) OS_GET_CURRENT_TASK(), sc_scan_cb);
OS_TIMER_START(sc_scan_tim, OS_TIMER_FOREVER);
////////////////////////////////////////////////////////////////
Inside the BLE_APP_NOTIFY_MASK switch case
//////////////////////////////////////////
case BLE_EVT_GAP_ADV_REPORT:
handle_evt_gap_adv_report(
(ble_evt_gap_adv_report_t *)hdr);
break;
//////////////////////////////////////////////////////////
After the switch case but still within the for loop
//////////////////////////////////////////////////////////
if (notif & SC_SCANNER_MASK) {
ble_error_t status;
ble_gap_adv_stop();
status = ble_gap_scan_start(GAP_SCAN_PASSIVE,
GAP_SCAN_OBSERVER_MODE,
BLE_SCAN_INTERVAL_FROM_MS(2.5),
BLE_SCAN_WINDOW_FROM_MS(0.625),
false, false);
if (status != BLE_STATUS_OK) {
printf("ERROR: scan can not be started (0x%02X)\r\n",
status);
}
printf("Scanning...\r\n");
}
////////////////////////////////////////////////////////////////////////////
If there is anything else I can provide to improve the clarity of my issue, please let me know, and I can do so gladly.
Many thanks,
Steven
Hi all,
As a quick update, I was able to get the ASSERT_ERROR(0) to disappear by getting rid of the stop adv function. However, I am still unable to get the code to reach the BLE_EVT_GAP_ADV_REPORT at which (to my knowledge) a device would be considered discovered. I have been looking at some of the other example codes that utilize a scanner, and have tried many options, but still couldn't trigger the report event. If anyone has any advice on this, I would really appreciate it :)
Many thanks,
Steven
Hi Steven,
Thanks for your question online and apologies for the delay. I am working on this and I will get back to you as soon as possible. Let me check it.
Can you please indicate if you have done any other modifications in the Multi-link project?
Thanks, PM_Dialog
Hi PM,
Thank you for your reply, I appreciate it. I forgot to include that in the ble_common.h file I included the following for the variable SC_SCANNER_MASK:
#define SC_SCANNER_MASK (1 << 1)
Many thanks,
Steven
Hi stevenchick,
An email has been sent in your registered mail address.
Thanks, PM_Dialog