peripheralStateNotificationCB

peripheralStateNotificationCB

 /*********************************************************************
* @fn peripheralStateNotificationCB 外围设备 状态 通知 回调函数
*
* @brief Notification from the profile of a state change. 通知来自于profile的状态改变!
*
* @param@param newState - new state 形参:新状态,类型是一个枚举变量
*
* @return@return none
*/
static void peripheralStateNotificationCB( gaprole_States_t newState )
{
#ifdef PLUS_BROADCASTER //暂时不知 不作任何处理,2016年12月16日15:14:51
static uint8 first_conn_flag = ;
#endif // PLUS_BROADCASTER switch ( newState )
{
case GAPROLE_STARTED: //GAP 任务 开始,但 并不广播 的状态
{
uint8 ownAddress[B_ADDR_LEN]; //定义一个 存放 设备 地址的 buffer
uint8 systemId[DEVINFO_SYSTEM_ID_LEN];//定义一个存放 设备ID buffer //GAP 任务获取 设备 地址放到 ownAddress 临时 buffer中 GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); // use 6 bytes of device address for 8 bytes of system ID value
systemId[] = ownAddress[];
systemId[] = ownAddress[];
systemId[] = ownAddress[]; // set middle bytes to zero
systemId[] = 0x00;
systemId[] = 0x00; // shift three bytes up
systemId[] = ownAddress[];
systemId[] = ownAddress[];
systemId[] = ownAddress[]; //设备信息设置参数 系统ID 为 设备 地址的 前三个字节+00+后三个字节 DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId); #if (defined HAL_LCD) && (HAL_LCD == TRUE)
// Display device address
HalLcdWriteString( bdAddr2Str( ownAddress ), HAL_LCD_LINE_2 );
HalLcdWriteString( "Initialized", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; case GAPROLE_ADVERTISING://GAP 任务 开始广播 的状态
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Advertising", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; #ifdef PLUS_BROADCASTER //暂时不知 不作任何处理,2016年12月16日15:14:51
/* After a connection is dropped a device in PLUS_BROADCASTER will continue
* sending non-connectable advertisements and shall sending this change of
* state to the application. These are then disabled here so that sending
* connectable advertisements can resume.
*/
case GAPROLE_ADVERTISING_NONCONN:
{
uint8 advertEnabled = FALSE; // Disable non-connectable advertising.
GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8),
&advertEnabled); // Reset flag for next connection.
first_conn_flag = ;
}
break;
#endif //PLUS_BROADCASTER case GAPROLE_CONNECTED://GAP 任务 已经连接的状态
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Connected", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE) #ifdef PLUS_BROADCASTER
// Only turn advertising on for this state when we first connect
// otherwise, when we go from connected_advertising back to this state
// we will be turning advertising back on.
if ( first_conn_flag == )
{
uint8 advertEnabled = FALSE; // Turn on Advertising // Disable connectable advertising.
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8),
&advertEnabled); // Set to true for non-connectabel advertising.
advertEnabled = TRUE; // Enable non-connectable advertising.
GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8),
&advertEnabled); first_conn_flag = ;
}
#endif // PLUS_BROADCASTER
}
break; case GAPROLE_CONNECTED_ADV://GAP 任务连接状态下 进行广播 的状态
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Connected Advertising", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break;
case GAPROLE_WAITING://GAP 任务 等待进行 周期性广播的 状态
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Disconnected", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE) #ifdef PLUS_BROADCASTER
uint8 advertEnabled = TRUE; // Enabled connectable advertising.
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8),
&advertEnabled);
#endif //PLUS_BROADCASTER
}
break; case GAPROLE_WAITING_AFTER_TIMEOUT://GAP 任务 处于连接超时状态, 等待 执行 进行 周期性广播的 状态
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Timed Out", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE) #ifdef PLUS_BROADCASTER
// Reset flag for next connection.
first_conn_flag = ;
#endif //#ifdef (PLUS_BROADCASTER)
}
break; case GAPROLE_ERROR://GAP 任务处于 无效的状态,暂时不太理解,2016年12月16日15:18:39
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "Error", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; default://传入的GAP 状态参数有错
{
#if (defined HAL_LCD) && (HAL_LCD == TRUE)
HalLcdWriteString( "", HAL_LCD_LINE_3 );
#endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
}
break; } gapProfileState = newState; #if !defined( CC2540_MINIDK )
VOID gapProfileState; // added to prevent compiler warning with 添加编译器 警告 事件
// "CC2540 Slave" configurations
#endif }

截图 比较好看一点:

peripheralStateNotificationCB-LMLPHP

05-08 08:35