连续签到天数:1天 签到总天数:30天 签到总奖励:159金币
本帖最后由 bluetooth123 于 2020-3-30 23:30 编辑
第一次开机进入idle模式,此时delay的初始值为0,且pskey ps_timers对应的值也为0,也就是delay==0,怎么进入的APP_ENTER_PAIRING_STATE_FROM_IDLE, APP_ENTER_CONNECTABLE_STATE_FROM_IDLE?
if (delay != 0)
{
/* enter connectable or discoverable state if a delay has been configured */
if (BdaddrIsZero(&theSource->ps_config->bdaddr_remote_device) || theSource->inquiry_mode.force_inquiry_mode)
{
/* no device to connect to, go discoverable */
MessageSend(&theSource->app_data.appTask, APP_ENTER_PAIRING_STATE_FROM_IDLE, 0);
}
else
{
/* there is a device to connect to, go connectable */
MessageSend(&theSource->app_data.appTask, APP_ENTER_CONNECTABLE_STATE_FROM_IDLE, 0);
}
} 复制代码
完整代码地方,
static void states_enter_state_idle(SOURCE_STATE_T old_state)
{
uint16 delay = 0; /* default is to have no delay before next connection attempt */
switch (old_state)
{
case SOURCE_STATE_CONNECTING:
{
if (theSource->ps_config->features.connection_max_retries != INVALID_VALUE)
{
/* feature enabled to only try to a remote device a set number of times before giving up */
if ((theSource->connection_data.connection_retries < theSource->ps_config->features.connection_max_retries) ||
theSource->timer_data.timers_stopped)
{
/* if it was connnecting use the connection_idle_timer delay before next connection attempt */
delay = theSource->ps_config->ps_timers.connection_idle_timer;
STATES_DEBUG(("STATE: was connecting, connection attempts:[%d], can continue after delay:[%d secs]\n", theSource->connection_data.connection_retries, delay));
if (!theSource->timer_data.timers_stopped)
{
/* increase number of connections attempted if timers haven't been bypassed */
theSource->connection_data.connection_retries++;
}
}
else
{
/* configured number of connection attempts have been tried - give up connecting! */
delay = TIMER_NO_TIMEOUT;
theSource->connection_data.connection_retries = 0;
STATES_DEBUG(("STATE: was connecting, given up trying to connect\n"));
}
}
else
{
/* if it was connnecting use the connection_idle_timer delay before next connection attempt */
delay = theSource->ps_config->ps_timers.connection_idle_timer;
STATES_DEBUG(("STATE: was connecting, next connect delay:[%d secs]\n", delay));
}
}
break;
case SOURCE_STATE_CONNECTED:
{
/* if it was connnected use the disconnect_idle_timer delay before next connection attempt */
delay = theSource->ps_config->ps_timers.disconnect_idle_timer;
STATES_DEBUG(("STATE: was connected, delay:[%d secs]\n", delay));
}
break;
case SOURCE_STATE_INITIALISING:
case SOURCE_STATE_POWERED_OFF:
{
if (BdaddrIsZero(&theSource->ps_config->bdaddr_remote_device))
{
/* if the device was powered off and no previous connection exists:
use the power_on_discover_idle_timer before first discovery attempt */
delay = theSource->ps_config->ps_timers.power_on_discover_idle_timer;
}
else
{
/* if the device was powered off and a previous connection exists:
use the power_on_connect_idle_timer before first connection attempt */
delay = theSource->ps_config->ps_timers.power_on_connect_idle_timer;
}
}
break;
default:
{
}
break;
}
if (old_state != SOURCE_STATE_CONNECTING)
{
/* reset connection attempts if not currently connecting */
theSource->connection_data.connection_retries = 0;
}
if (delay != 0)
{
/* enter connectable or discoverable state if a delay has been configured */
if (BdaddrIsZero(&theSource->ps_config->bdaddr_remote_device) || theSource->inquiry_mode.force_inquiry_mode)
{
/* no device to connect to, go discoverable */
MessageSend(&theSource->app_data.appTask, APP_ENTER_PAIRING_STATE_FROM_IDLE, 0);
}
else
{
/* there is a device to connect to, go connectable */
MessageSend(&theSource->app_data.appTask, APP_ENTER_CONNECTABLE_STATE_FROM_IDLE, 0);
}
}
if (delay != TIMER_NO_TIMEOUT)
{
STATES_DEBUG(("STATE: IDLE delay before next connection:[%d secs]\n", delay));
/* initialise the connection with the connection manager */
connection_mgr_start_connection_attempt(NULL, AGHFP_PROFILE_IS_ENABLED ? PROFILE_AGHFP : PROFILE_A2DP, delay);
}
else
{
STATES_DEBUG(("STATE: No auto reconnection\n"));
}
} 复制代码
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
楼主热帖