找回密码
 立即注册

使用微信账号登录

只需一步,快速开始

查看: 3825|回复: 2

[CSR8系列] csr867x source这段代码怎么理解?

[复制链接]
连续签到天数:1天
签到总天数:29天
签到总奖励:154金币
发表于 2020-3-30 23:23:14 | 显示全部楼层 |阅读模式
本帖最后由 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?


  1.     if (delay != 0)
  2.     {
  3.         /* enter connectable or discoverable state if a delay has been configured */
  4.         if (BdaddrIsZero(&theSource->ps_config->bdaddr_remote_device) || theSource->inquiry_mode.force_inquiry_mode)
  5.         {
  6.             /* no device to connect to, go discoverable */
  7.             MessageSend(&theSource->app_data.appTask, APP_ENTER_PAIRING_STATE_FROM_IDLE, 0);
  8.         }
  9.         else
  10.         {
  11.             /* there is a device to connect to, go connectable */
  12.             MessageSend(&theSource->app_data.appTask, APP_ENTER_CONNECTABLE_STATE_FROM_IDLE, 0);
  13.         }
  14.     }
复制代码



完整代码地方,
  1. static void states_enter_state_idle(SOURCE_STATE_T old_state)
  2. {
  3.     uint16 delay = 0; /* default is to have no delay before next connection attempt */

  4.     switch (old_state)
  5.     {
  6.         case SOURCE_STATE_CONNECTING:
  7.         {
  8.             if (theSource->ps_config->features.connection_max_retries != INVALID_VALUE)
  9.             {
  10.                 /* feature enabled to only try to a remote device a set number of times before giving up */
  11.                 if ((theSource->connection_data.connection_retries < theSource->ps_config->features.connection_max_retries) ||
  12.                     theSource->timer_data.timers_stopped)
  13.                 {
  14.                     /* if it was connnecting use the connection_idle_timer delay before next connection attempt */
  15.                     delay = theSource->ps_config->ps_timers.connection_idle_timer;
  16.                     STATES_DEBUG(("STATE: was connecting, connection attempts:[%d], can continue after delay:[%d secs]\n", theSource->connection_data.connection_retries, delay));
  17.                     
  18.                     if (!theSource->timer_data.timers_stopped)
  19.                     {
  20.                         /* increase number of connections attempted if timers haven't been bypassed */
  21.                         theSource->connection_data.connection_retries++;
  22.                     }
  23.                 }
  24.                 else
  25.                 {
  26.                     /* configured number of connection attempts have been tried - give up connecting! */
  27.                     delay = TIMER_NO_TIMEOUT;
  28.                     theSource->connection_data.connection_retries = 0;
  29.                     STATES_DEBUG(("STATE: was connecting, given up trying to connect\n"));
  30.                 }
  31.             }
  32.             else
  33.             {
  34.                 /* if it was connnecting use the connection_idle_timer delay before next connection attempt */
  35.                 delay = theSource->ps_config->ps_timers.connection_idle_timer;
  36.                 STATES_DEBUG(("STATE: was connecting, next connect delay:[%d secs]\n", delay));
  37.             }
  38.         }
  39.         break;
  40.         
  41.         case SOURCE_STATE_CONNECTED:
  42.         {
  43.             /* if it was connnected use the disconnect_idle_timer delay before next connection attempt */
  44.             delay = theSource->ps_config->ps_timers.disconnect_idle_timer;
  45.             STATES_DEBUG(("STATE: was connected, delay:[%d secs]\n", delay));
  46.         }
  47.         break;
  48.         
  49.         case SOURCE_STATE_INITIALISING:
  50.         case SOURCE_STATE_POWERED_OFF:
  51.         {
  52.             if (BdaddrIsZero(&theSource->ps_config->bdaddr_remote_device))
  53.             {
  54.                 /* if the device was powered off and no previous connection exists:
  55.                     use the power_on_discover_idle_timer before first discovery attempt */
  56.                 delay = theSource->ps_config->ps_timers.power_on_discover_idle_timer;
  57.             }
  58.             else
  59.             {
  60.                 /* if the device was powered off and a previous connection exists:
  61.                     use the power_on_connect_idle_timer before first connection attempt */
  62.                 delay = theSource->ps_config->ps_timers.power_on_connect_idle_timer;
  63.             }
  64.         }
  65.         break;
  66.         
  67.         default:
  68.         {
  69.             
  70.         }
  71.         break;            
  72.     }
  73.    
  74.     if (old_state != SOURCE_STATE_CONNECTING)
  75.     {
  76.         /* reset connection attempts if not currently connecting */
  77.         theSource->connection_data.connection_retries = 0;
  78.     }
  79.    
  80.     if (delay != 0)
  81.     {
  82.         /* enter connectable or discoverable state if a delay has been configured */
  83.         if (BdaddrIsZero(&theSource->ps_config->bdaddr_remote_device) || theSource->inquiry_mode.force_inquiry_mode)
  84.         {
  85.             /* no device to connect to, go discoverable */
  86.             MessageSend(&theSource->app_data.appTask, APP_ENTER_PAIRING_STATE_FROM_IDLE, 0);
  87.         }
  88.         else
  89.         {
  90.             /* there is a device to connect to, go connectable */
  91.             MessageSend(&theSource->app_data.appTask, APP_ENTER_CONNECTABLE_STATE_FROM_IDLE, 0);
  92.         }
  93.     }

  94.     if (delay != TIMER_NO_TIMEOUT)
  95.     {
  96.         STATES_DEBUG(("STATE: IDLE delay before next connection:[%d secs]\n", delay));      
  97.         /* initialise the connection with the connection manager */
  98.         connection_mgr_start_connection_attempt(NULL, AGHFP_PROFILE_IS_ENABLED ? PROFILE_AGHFP : PROFILE_A2DP, delay);        
  99.     }
  100.     else
  101.     {
  102.         STATES_DEBUG(("STATE: No auto reconnection\n"));
  103.     }
  104. }
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册  

×
楼主热帖
积分商城 - 让您的金币更有价值!||官方Q群 - 让您的沟通更加及时!
连续签到天数:1天
签到总天数:29天
签到总奖励:154金币
 楼主| 发表于 2020-3-31 11:58:33 | 显示全部楼层
看到了,这里面执行的。
  1. MessageSendLater(app_get_instance(), APP_CONNECT_REQ, message, D_SEC(delay));
复制代码


  1. static void app_connect_req(const APP_CONNECT_REQ_T *message)
  2. {
  3.     APP_MSG_DEBUG(("APP_MSG: app_connect_req\n"));

  4.     /* cancel any other connection requests as they may come from user or be automatically generated */
  5.     MessageCancelAll(app_get_instance(), APP_CONNECT_REQ);
  6.    
  7.     switch (states_get_state())
  8.     {
  9.         case SOURCE_STATE_IDLE:
  10.         case SOURCE_STATE_CONNECTABLE:
  11.         case SOURCE_STATE_DISCOVERABLE:
  12.         case SOURCE_STATE_INQUIRING: /* connect after device found through inquiry */
  13.         case SOURCE_STATE_CONNECTING: /* this will occur when trying to connect further profiles - re-enter state to kick connection */
  14.         case SOURCE_STATE_CONNECTED:
  15.         {
  16.             /* suspend any active audio */
  17.             MessageSend(app_get_instance(), APP_AUDIO_SUSPEND, 0);
  18.             /* connect to remote device */
  19.             if (BdaddrIsZero(connection_mgr_get_remote_address()) || message->force_inquiry_mode)
  20.             {               
  21.                 states_set_state(SOURCE_STATE_INQUIRING);
  22.             }
  23.             else
  24.             {               
  25.                 states_set_state(SOURCE_STATE_CONNECTING);              
  26.             }
  27.         }
  28.         break;
  29.                
  30.         default:
  31.         {
  32.             app_msg_unhandled_state();
  33.         }
  34.         break;
  35.     }
  36. }
复制代码



积分商城 - 让您的金币更有价值!||官方Q群 - 让您的沟通更加及时!
回复 支持 反对

使用道具 举报

连续签到天数:1天
签到总天数:819天
签到总奖励:9195金币
发表于 2020-5-20 18:36:45 | 显示全部楼层
完整代码states_enter_state_idle中的if (delay != 0)代码:

1,如果从关机状态 开机 进入idle模式,如果 delay不等于0,那么执行以下内容:
2,如果无已连接设备记录BdaddrIsZero或者处于强制进入配对模式,那么发送消息APP_ENTER_PAIRING_STATE_FROM_IDLE;否则发送消息APP_ENTER_CONNECTABLE_STATE_FROM_IDLE
积分商城 - 让您的金币更有价值!||官方Q群 - 让您的沟通更加及时!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册  

本版积分规则

小黑屋|手机版|我爱蓝牙网 - 52Bluetooth

GMT+8, 2024-4-29 21:03 , Processed in 0.203738 second(s), 14 queries , Gzip On, MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表