peripheralStateNotificationCB

  1 /*********************************************************************
  2  * @fn      peripheralStateNotificationCB 外围设备 状态 通知 回调函数
  3  *
  4  * @brief   Notification from the profile of a state change. 通知来自于profile的状态改变!
  5  *
  6  * @param@param   newState - new state 形参:新状态,类型是一个枚举变量
  7  *
  8  * @return@return  none
  9  */
 10 static void peripheralStateNotificationCB( gaprole_States_t newState )
 11 {
 12 #ifdef PLUS_BROADCASTER //暂时不知 不作任何处理,2016年12月16日15:14:51
 13   static uint8 first_conn_flag = 0;
 14 #endif // PLUS_BROADCASTER
 15   
 16   
 17   switch ( newState )
 18   {
 19     case GAPROLE_STARTED: //GAP 任务 开始,但 并不广播 的状态
 20       {
 21         uint8 ownAddress[B_ADDR_LEN]; //定义一个 存放 设备 地址的 buffer
 22         uint8 systemId[DEVINFO_SYSTEM_ID_LEN];//定义一个存放 设备ID buffer
 23 
 24         //GAP 任务获取 设备 地址放到 ownAddress 临时 buffer中
 25         
 26         GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);
 27 
 28         // use 6 bytes of device address for 8 bytes of system ID value
 29         systemId[0] = ownAddress[0];
 30         systemId[1] = ownAddress[1];
 31         systemId[2] = ownAddress[2];
 32 
 33         // set middle bytes to zero
 34         systemId[4] = 0x00;
 35         systemId[3] = 0x00;
 36 
 37         // shift three bytes up
 38         systemId[7] = ownAddress[5];
 39         systemId[6] = ownAddress[4];
 40         systemId[5] = ownAddress[3];
 41         
 42         //设备信息设置参数 系统ID  为 设备 地址的 前三个字节+00+后三个字节
 43 
 44         DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);
 45 
 46         #if (defined HAL_LCD) && (HAL_LCD == TRUE)
 47           // Display device address
 48           HalLcdWriteString( bdAddr2Str( ownAddress ),  HAL_LCD_LINE_2 );
 49           HalLcdWriteString( "Initialized",  HAL_LCD_LINE_3 );
 50         #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
 51       }
 52       break;
 53 
 54     case GAPROLE_ADVERTISING://GAP 任务 开始广播 的状态
 55       {
 56         #if (defined HAL_LCD) && (HAL_LCD == TRUE)
 57           HalLcdWriteString( "Advertising",  HAL_LCD_LINE_3 );
 58         #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
 59       }
 60       break;
 61 
 62 #ifdef PLUS_BROADCASTER   //暂时不知 不作任何处理,2016年12月16日15:14:51
 63     /* After a connection is dropped a device in PLUS_BROADCASTER will continue
 64      * sending non-connectable advertisements and shall sending this change of 
 65      * state to the application.  These are then disabled here so that sending 
 66      * connectable advertisements can resume.
 67      */
 68     case GAPROLE_ADVERTISING_NONCONN:
 69       {
 70         uint8 advertEnabled = FALSE;
 71       
 72         // Disable non-connectable advertising.
 73         GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8),
 74                            &advertEnabled);
 75         
 76         // Reset flag for next connection.
 77         first_conn_flag = 0;
 78       }
 79       break;
 80 #endif //PLUS_BROADCASTER         
 81       
 82     case GAPROLE_CONNECTED://GAP 任务 已经连接的状态
 83       {        
 84         #if (defined HAL_LCD) && (HAL_LCD == TRUE)
 85           HalLcdWriteString( "Connected",  HAL_LCD_LINE_3 );
 86         #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
 87           
 88 #ifdef PLUS_BROADCASTER
 89         // Only turn advertising on for this state when we first connect
 90         // otherwise, when we go from connected_advertising back to this state
 91         // we will be turning advertising back on.
 92         if ( first_conn_flag == 0 ) 
 93         {
 94             uint8 advertEnabled = FALSE; // Turn on Advertising
 95 
 96             // Disable connectable advertising.
 97             GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8),
 98                                  &advertEnabled);
 99             
100             // Set to true for non-connectabel advertising.
101             advertEnabled = TRUE;
102             
103             // Enable non-connectable advertising.
104             GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8),
105                                  &advertEnabled);
106             
107             first_conn_flag = 1;
108         }
109 #endif // PLUS_BROADCASTER
110       }
111       break;
112 
113     case GAPROLE_CONNECTED_ADV://GAP 任务连接状态下 进行广播 的状态
114       {
115         #if (defined HAL_LCD) && (HAL_LCD == TRUE)
116           HalLcdWriteString( "Connected Advertising",  HAL_LCD_LINE_3 );
117         #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
118       }
119       break;      
120     case GAPROLE_WAITING://GAP 任务 等待进行 周期性广播的  状态
121       {
122         #if (defined HAL_LCD) && (HAL_LCD == TRUE)
123           HalLcdWriteString( "Disconnected",  HAL_LCD_LINE_3 );
124         #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
125           
126 #ifdef PLUS_BROADCASTER                
127         uint8 advertEnabled = TRUE;
128       
129         // Enabled connectable advertising.
130         GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8),
131                              &advertEnabled);
132 #endif //PLUS_BROADCASTER
133       }
134       break;
135 
136     case GAPROLE_WAITING_AFTER_TIMEOUT://GAP 任务  处于连接超时状态, 等待 执行 进行 周期性广播的  状态
137       {
138         #if (defined HAL_LCD) && (HAL_LCD == TRUE)
139           HalLcdWriteString( "Timed Out",  HAL_LCD_LINE_3 );
140         #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
141           
142 #ifdef PLUS_BROADCASTER
143         // Reset flag for next connection.
144         first_conn_flag = 0;
145 #endif //#ifdef (PLUS_BROADCASTER)
146       }
147       break;
148 
149     case GAPROLE_ERROR://GAP 任务处于 无效的状态,暂时不太理解,2016年12月16日15:18:39
150       {
151         #if (defined HAL_LCD) && (HAL_LCD == TRUE)
152           HalLcdWriteString( "Error",  HAL_LCD_LINE_3 );
153         #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
154       }
155       break;
156 
157     default://传入的GAP 状态参数有错
158       {
159         #if (defined HAL_LCD) && (HAL_LCD == TRUE)
160           HalLcdWriteString( "",  HAL_LCD_LINE_3 );
161         #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
162       }
163       break;
164 
165   }
166 
167   gapProfileState = newState;
168 
169 #if !defined( CC2540_MINIDK )
170   VOID gapProfileState;     // added to prevent compiler warning with 添加编译器 警告 事件
171                             // "CC2540 Slave" configurations
172 #endif
173 
174 
175 }

 

 

截图 比较好看一点:

 

 

 

 

posted on 2016-12-19 16:56  所长  阅读(1185)  评论(0编辑  收藏  举报

导航