实际使用中,连接参数更新是经常用到,影响到连接后的功耗,连接延迟等,现在以6621Cxc的simple示例,介绍连接后更新连接参数的方法: 1) static int gapc_connection_req_ind_handler(ke_msg_id_t const msgid, struct gapc_connection_req_ind const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { app_env.conidx = KE_IDX_GET(src_id); #if(BLE_APP_SEC) bool is_bond = app_sec_get_bond_status_by_addr(param->peer_addr); #endif co_timer_set(&update_param_timer,500, TIMER_ONE_SHOT, update_param_timer_handler, NULL);//定时500ms 后更新连接参数 log_debug("Device type(%d) conidx(%d) connected, ", param->peer_addr_type, app_env.conidx); log_debug_array_ex("ADDR", ¶m->peer_addr, 6); // Check if the received Connection Handle was valid if (app_env.conidx != GAP_INVALID_CONIDX) { // Retrieve the connection info from the parameters app_env.conhdl = param->conhdl; // Send connection confirmation struct gapc_connection_cfm *cfm = KE_MSG_ALLOC(GAPC_CONNECTION_CFM, KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP, gapc_connection_cfm); #if(BLE_APP_SEC) cfm->auth = is_bond ? GAP_AUTH_REQ_NO_MITM_BOND : GAP_AUTH_REQ_NO_MITM_NO_BOND; // TODO [FBE] restore valid data #else // !(BLE_APP_SEC) cfm->auth = GAP_AUTH_REQ_NO_MITM_NO_BOND; #endif // (BLE_APP_SEC) // Send the message ke_msg_send(cfm); 2) static co_timer_t update_param_timer; void update_param_timer_handler(co_timer_t *timer, void *param) { // Requested connection parameters struct gapc_conn_param conn_param; conn_param.intv_min = 0x18;//1.25ms整数倍 conn_param.intv_max = 0x18;//1.25ms整数倍 conn_param.latency = 0;//延迟 conn_param.time_out = 100;//超时10ms整数倍 appm_update_param(&conn_param); log_debug("update_param intv_min(%d),intv_max(%d),latency(%d),time_out(%d) ",conn_param.intv_min,conn_param.intv_max,conn_param.latency,conn_param.time_out); } 3)连接上后,500ms定时到后会调用连接参数更新 |