大家好,
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:
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:
Please try the steps above and let me know if it is working.
Thanks, 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!
Hi moguilevski,
Glad that me comment helps you and thanks for accepting my answer.
Thanks, PM_Dialog