some problem about BLE scan

12 posts / 0 new
Last post
2455321262
Offline
Last seen:2 years 7 months ago
加入:2017-01-22 06:43
some problem about BLE scan

I set the device role as central,I use the following function
static void user_scan_start(void)
{
struct gapm_start_scan_cmd* cmd = KE_MSG_ALLOC(GAPM_START_SCAN_CMD,
TASK_GAPM, TASK_APP,
gapm_start_scan_cmd);

cmd->op.code = user_scan_conf.code;
cmd->op.addr_src = user_scan_conf.addr_src;
cmd->interval = user_scan_conf.interval;
cmd->window = user_scan_conf.window;
cmd->mode = user_scan_conf.mode;
cmd->filt_policy = user_scan_conf.filt_policy;
cmd->filter_duplic = user_scan_conf.filter_duplic;

// Send the message
ke_msg_send(cmd);

// We are now connectable
ke_state_set(TASK_APP, APP_CONNECTABLE);
}
to cause the device to start scanning.But,It can not be executed to the function of app_on_scanning_completed.(I refer to the project of DSPS)
did i missed something? and i did not find the project of ble_central ?can you tell where can I download?
I want you to tell me how to configure the ble start scan?I think there are some errors on the kernel tasks or omissions.
Thanks in advance

Device:
MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi 2455321262,

Hi 2455321262,

The app_on_scanning_completed callback is the function that is going to be executed when the device stops that scanning procedure, either via the scanning operation timeout (approximatelly 8 seconds) or if you cancel the operation. So if you dont start scanning the callback will never execute thus you wont get your function to execute. After the configuration of your device completes (after the configuration of the device completes the .app_on_set_dev_config_complete callback will occur) this is where you should place the start scanning operation. Also for an example of a central you might want to have a look at the DSPS reference design in the HOST project. You will be able to find the DSPS reference design under the reference design section on the support portal.

Thanks MT_dialog

2455321262
Offline
Last seen:2 years 7 months ago
加入:2017-01-22 06:43
Hi MT_dialog,

Hi MT_dialog,
thanks for your advice,I'm suer i call function start scanning in function .app_on_set_dev_config_complete callback.But my device is unable to implement function .app_on_set_dev_config_complete .I found that my device was able to scan to the surrounding Bluetooth signal,i don't know why the device did not scan timeout,the time of timeout is fixed for 8 seconds?If it not 8 seconds,where can i Configuration it ?
I hope you can help me as soon as possible,Thanks in advance.

chris0409
Offline
Last seen:3 years 10 months ago
加入:2017-01-11 05:59
Hi, 2455321262

Hi, 2455321262
You can start a timer to cancel the scan process, and thus your program can hit the scan-complete callback.
You can cancel the current scan like this.
struct gapm_cancel_cmd *cmd =(struct gapm_cancel_cmd *) KE_MSG_ALLOC(GAPM_CANCEL_CMD, TASK_GAPM, TASK_APP, gapm_cancel_cmd);
cmd->operation = GAPM_SCAN_PASSIVE; // Set GAPM_SCAN_PASSIVE
ke_msg_send(cmd);// Send the message

2455321262
Offline
Last seen:2 years 7 months ago
加入:2017-01-22 06:43
Hi,chrise0409

Hi,chrise0409
I think it's a good idea to solve my problem ,thanks for your advicing.But I still want to know how to configure automatic scan timeout?I think that would do no harm to me.

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi Jerry,

Hi Jerry,

扫描程序扫描b大约8秒y default, there is no option in order to change that, the scanning function when you are scanning in GAP_GEN_DISCOVERY or GAP_LIM_DISCOVERY has this time out, if you dont want this time out you can scan in GAP_OBSERVER_MODE (you will be able to find more info on this in the RW-BLE-GAP-IS). What i dont get is the exact problem, your device scans at the beggining and you dont see the scan function executed when the timeout occurs ? If your device scans that means that somewhere the device executes the scanning procedure (i suppose that this happens in the app_on_set_dev_config). The DSPS starts the scan in the user_on_set_dev_config_complete (.app_on_set_dev_config_complete callback) and when the timeout occurs (timeout not cancelation) the .app_on_scanning_completed gets triggered. Check if at the callback function that you are using at the custom_on_scanning_completed() you make a check if the status of the scanning only GAP_ERR_CANCELED and not timed out (GAP_ERR_TIMEOUT). Also check in the gapm_cmp_evt_handler() in the app_task.c if the callback app_on_scanning_completed() is getting invoked in the project that you are using in order to implement your project.

case GAPM_SCAN_ACTIVE:
case GAPM_SCAN_PASSIVE:
{
EXECUTE_CALLBACK_PARAM(app_on_scanning_completed, param->status);
}
break;

Thanks MT_dialog

2455321262
Offline
Last seen:2 years 7 months ago
加入:2017-01-22 06:43
Hi, MT_dialog,

Hi, MT_dialog,

Thank you very much for your advice, I have told you where to do one by one check, and now my scan has been able to run successfully, really thank you very much

Thanks Jerry

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi Jerry,

Hi Jerry,

I am not sure i understand the question, when you dont handle the app_on_scanning_completed (you provide NULL at your callback) what happens exactly ? If you dont handle completion of the scanning your device will just go into sleep without doing anything. I dont see what Jlink has to do with the fact that you dont handle the scanning completion.

Thanks MT_dialog

2455321262
Offline
Last seen:2 years 7 months ago
加入:2017-01-22 06:43
Hi,MT_dialog,

Hi,MT_dialog,
I am sorry for my bad statement about my question.
I found that my J-LINK did not work properly after wake up in sleep mode.
I'm in debug mode,Someone of predecessors said DA14580 can not be in both sleep mode and debug mode ,I think I have entered the sleep mode successful, but after the implementation of the function arch_resume_from_sleep, my J-LINK will not work, it seems to quit the debug mode?

I find the function as follows:

void BLE_SLP_Handler(void)
{
syscntl_use_highest_amba_clocks();

TOGGLE_GPIO13_SHORT

power_up(); // power-up the BLE core

wakeup_lp_comp = 0; // clear flag for next time

SetBits16(SYS_CTRL_REG, DEBUGGER_ENABLE, 0);

SetBits16(GP_CONTROL_REG, BLE_WAKEUP_REQ, 0);

...................
}
can i comment out the code of SetBits16(SYS_CTRL_REG, DEBUGGER_ENABLE, 0)? or modify as SetBits16(SYS_CTRL_REG, DEBUGGER_ENABLE, 1)?
If I want to enter both debug and sleep mode at the same time , What shuould I do ?

Thanks Jerry

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi Jerry,

Hi Jerry,

In older SDK's you couldn't be in sleep mode and debug at the same time, that feature is added with the SDK5.0.4, so up until 5.0.3 you couldn't debug with keil and be in sleep mode. If the SDK that you are using is the 5.0.3 and you have removed the piece of code that halted the fw in the check_sys_start_up_period() that prevented the device of going to sleep while the debugger was enabled then you can remove the disabling the debugger in the SLP handler (remove the SetBits16(SYS_CTRL_REG, DEBUGGER_ENABLE, 0); ) and you should be able to do what you would like. The reason for what you are experience is exactly the fact that the debugger module of the ARM is disabled while your are in debug mode.

Thanks MT_dialog

wisilica
Offline
Last seen:10 months 4 weeks ago
加入:2015-03-17 08:16
Hi,

Hi,

我想问一些connection with this thread.
When the scanning is performed in general discoverable/ limited discoverable mode, does the timeout happen even if advertisement reports are being received continuosly ? Or, only if no BLE packets are received during the scan mode ?

Thanks
wisilica

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi wisilica,

Hi wisilica,

If the scanning you are performing is either GAP_GEN_DISCOVERY or GAP_LIM_DISCOVERY the operation will timeout automatically regardless the advertising reports, so even if the device doesn't receive any reports the scan procedure will timeout after about 8 seconds.

Thanks MT_dialog