Switching the device role

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
4 posts / 0 new
Last post
moguilevski
Offline
Last seen:2 months 2 weeks ago
加入:2019-04-30 12:25
Switching the device role

大家好,

I'm trying to switch the device role from GAP_ROLE_BROADCASTER/GAP_ROLE_ALL to GAP_ROLE_OBSERVER in order to interchange advertising and active scan periodically. Unfortunately, the code execution breaks with the error code 0x43 (GAP_ERR_COMMAND_DISALLOWED) after the code section presented below. Do you have an idea what could be wrong in the re-configuration command? Is there any crucial steps, that should be done before (like changing of the state of the application or of the any other task)?

//create and send a reset msg to a the gap task hanlder struct gapm_reset_cmd* cmd1 = (struct gapm_reset_cmd*)KE_MSG_ALLOC(GAPM_RESET_CMD, TASK_GAPM, TASK_APP, gapm_reset_cmd); cmd1->operation = GAPM_RESET; ke_msg_send(cmd1); //re-configure the device struct gapm_set_dev_config_cmd* cmd2 = KE_MSG_ALLOC(GAPM_SET_DEV_CONFIG_CMD, TASK_GAPM, TASK_APP, gapm_set_dev_config_cmd); cmd2->operation = GAPM_SET_DEV_CONFIG; cmd2->role = GAP_ROLE_OBSERVER; cmd2->max_mtu = 23; cmd2->addr_type = APP_CFG_ADDR_TYPE(USER_CFG_ADDRESS_MODE); cmd2->renew_dur = 15000; nvds_tag_len_t dummy; nvds_get(NVDS_TAG_BD_ADDRESS, &dummy, cmd2->addr.addr); memcpy(cmd2->irk.key, user_gapm_conf.irk, KEY_LEN * sizeof(uint8_t)); cmd2->att_cfg = GAPM_MASK_ATT_SVC_CHG_EN; cmd2->gap_start_hdl = 0; cmd2->gatt_start_hdl = 0; cmd2->max_mps = 0; cmd2->max_txoctets = 0; cmd2->max_txtime = 0; ke_msg_send(cmd2);

Thanks in advance.

Device:
PM_Dialog
Offline
Last seen:1 day 15 hours ago
工作人员
加入:2018-02-08 11:03
Hi moguilevski,

Hi moguilevski,

Since you are using a DA14585, in order to perform role switching, you can set the role in GAP_ROLE_ALL and advertise or scan (you cannot do both at the same time). However, you can advertise and set a timer, upon timer expiration, ou should stop advertising and as soon as it stops you can start scanning and either wait for the scan to complete (if you are scanning in GAP_GEN_DISCOVERY or set an additional timer and cancel the scanning procedure) so as soon as the scanning completes start the advertising again. Please check the steps below in order to perform it in ble_app_peripheral example of the SDK:

  • Change in the user_config.h file the .role member of the user_gapm_conf to GAP_ROLE_ALL.
  • Create a user_scan_start() function in order for the device to start scanning:
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 = GAPM_SCAN_ACTIVE; cmd->op.addr_src = GAPM_STATIC_ADDR; cmd->interval = 16384; cmd->window = 16384; cmd->mode = GAP_GEN_DISCOVERY; cmd->filt_policy = SCAN_ALLOW_ADV_ALL; cmd->filter_duplic = SCAN_FILT_DUPLIC_EN; // Send the message ke_msg_send(cmd); // We are now connectable ke_state_set(TASK_APP, APP_CONNECTABLE); }
  • In the user_app_adv_start() function there is a timer that starts up in order to stop the advertising after about 30 seconds, so we are going to use that in order to stop the advertising.
  • So in the callback of the timer adv_data_update_timer_cb() instead of updating of the advertising string,invoke the app_easy_gap_advertise_stop() function.
  • In the user_app_adv_undirect_complete() function invoke the user_scan_start() function, so that when the device stops advertising to start scanning.
  • In order to stop scanning i won’t use an additional timer in order to cancel the command, but i will use the timeout of the scanning itself.
  • In order to start advertising as soon as the scanning ends create a function user_on_scanning_completed() and from that function invoke the user_app_adv_start();

Please try the steps above and let me know if it is working.

Thanks, PM_Dialog

moguilevski
Offline
Last seen:2 months 2 weeks ago
加入:2019-04-30 12:25
Hi PM-Dialog,

Hi PM-Dialog,

following your instructions the switching between advertising and active scan works fine.

Thank you very much for the detailed answer!

PM_Dialog
Offline
Last seen:1 day 15 hours ago
工作人员
加入:2018-02-08 11:03
Hi moguilevski,

Hi moguilevski,

Glad that me comment helps you and thanks for accepting my answer.

Thanks, PM_Dialog