2 posts / 0 new
Last post
craftwizard
Offline
Last seen:3 years 1 month ago
Joined:2014-12-17 05:34
scanner

Hi.
I want to implement the BLE scanner function.
The gapm_adv_report_ind_handler event does not occur.
I implemented the source code as below.
Please check the code.
Is there a simple scanner sample project?

EXTERN const struct ke_msg_handler app_default_state[] =
{
....
{GAPM_ADV_REPORT_IND, (ke_msg_func_t)gapm_adv_report_ind_handler},
...
}

int gapm_adv_report_ind_handler (ke_msg_id_t是否,struct gapm_adv_report_ind *param, ke_task_id_t dest_id, ke_task_id_t src_id)
{
app_adv_report_ind_func(param);
return (KE_MSG_CONSUMED);
}

void app_set_dev_config_complete_func(void)
{

// We are now in Initialization State
ke_state_set(TASK_APP, APP_DB_INIT);

// Add the first required service in the database
/* if (app_db_init())
{
// No service to add in the DB -> Start Advertising
app_adv_start();
}
*/
app_start_scanning();

return;
}

void app_start_scanning(void)
{
arch_printf( "app_start_scanning \n");
struct gapm_start_scan_cmd *msg = KE_MSG_ALLOC(GAPM_START_SCAN_CMD, TASK_GAPM, TASK_APP, gapm_start_scan_cmd);
msg->mode = GAP_OBSERVER_MODE; //GAP_GEN_DISCOVERY;
msg->op.code = GAPM_SCAN_ACTIVE; //GAPM_SCAN_PASSIVE;
msg->op.addr_src = GAPM_PUBLIC_ADDR;
msg->filt_policy = SCAN_ALLOW_ADV_ALL; //SCAN_ALLOW_ADV_WLST; //SCAN_ALLOW_ADV_ALL;
msg->filter_duplic = SCAN_FILT_DUPLIC_EN;
msg->interval = 4000; //10;
msg->window = 4000; //5;
ke_msg_send(msg);
return;
}

//App_scanning_completed_func is called as soon as app_start_scanning is called.
void app_scanning_completed_func(void)
{
arch_printf( "app_scanning_completed_func \n");
// app_start_scanning();
}

int gapm_cmp_evt_handler(ke_msg_id_t const msgid, struct gapm_cmp_evt const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id)
{
switch(param->operation)
{
case GAPM_SCAN_ACTIVE:
case GAPM_SCAN_PASSIVE:
{
app_scanning_completed_func();
break;
}
}
}

Device:
MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi craftwizard,

Hi craftwizard,

There is a scanning function in the DSPS host example and you can check from that project how the scanning procudure is implemented. I dont see anything wrong with the scanning function except from the fact that your scanning interval is the same with your window interval (i dont think that it will cause you any significant issues but the scanning windows should be smaller that the interval). If the advertising indication doesn't occur, make sure that the device is actually scanning (check that the scanning function is executed at some point in your fw or use the power profiler or try to catch after issuing the scanning procedure if there is any GAPM_CMP_EVT for the scanning procdure - GAPM_SCAN_ACTIVE or PASSIVE - that returns with a status of error).

Thanks MT_dialog