蓝牙协议栈学习——GAP_LINK_ESTABLISHED_EVENT产生之后会发生什么
1.主机回调函数中
static void BLECentralEventCB( gapCentralRoleEvent_t *pEvent ) //主机事件回调函数
{
。。。
case GAP_LINK_ESTABLISHED_EVENT:
{
if ( pEvent->gap.hdr.status == SUCCESS )//GAP_MSG_EVENT and status
{
BLE_Status_t.bleConnectState = BLE_STATE_CONNECTED; //蓝牙状态为连接成功
BLE_BasePara_t.bleConnHdl = pEvent->linkCmpl.connectionHandle;//记录连接句柄
if ( BLE_BasePara_t.bleCharHdl == 0 )//如果特征值句柄没有读到,则开始发现时间函数
{osal_start_timerEx( simpleBLETaskId, START_DISCOVERY_EVT, DEFAULT_SVC_DISCOVERY_DELAY ); }
}
else{/*状态置位空闲*/}
}
break;
}
2.
case GAP_LINK_ESTABLISHED_EVENT:
{
gapEstLinkReqEvent_t *pPkt = (gapEstLinkReqEvent_t *) pMsg;
if (pPkt->hdr.status == SUCCESS)
{
// Notify the Bond Manager of the connection
VOID GAPBondMgr_LinkEst( pPkt->devAddrType, pPkt->devAddr,
pPkt->connectionHandle, GAP_PROFILE_CENTRAL );//进入绑定
}
}
break;
3.
case GAP_LINK_ESTABLISHED_EVENT:
{
gapEstLinkReqEvent_t *pPkt = (gapEstLinkReqEvent_t *)pMsg;
if ( pPkt->hdr.status == SUCCESS )
{
VOID osal_memcpy( gapRole_ConnectedDevAddr, pPkt->devAddr, B_ADDR_LEN );
gapRole_ConnectionHandle = pPkt->connectionHandle;
gapRole_state = GAPROLE_CONNECTED;
if ( gapRole_RSSIReadRate )
{
// Start the RSSI Reads
VOID osal_start_timerEx( gapRole_TaskID, RSSI_READ_EVT, gapRole_RSSIReadRate );
}
// Store connection information
gapRole_ConnInterval = pPkt->connInterval;
gapRole_ConnSlaveLatency = pPkt->connLatency;
gapRole_ConnTimeout = pPkt->connTimeout;
// Check whether update parameter request is enabled
if ( gapRole_ParamUpdateEnable == TRUE )
{
// Get the minimum time upon connection establishment before the
// peripheral can start a connection update procedure.
uint16 timeout = GAP_GetParamValue( TGAP_CONN_PAUSE_PERIPHERAL );
osal_start_timerEx( gapRole_TaskID, START_CONN_UPDATE_EVT, timeout*1000 );
}
// Notify the Bond Manager to the connection
VOID GAPBondMgr_LinkEst( pPkt->devAddrType, pPkt->devAddr, pPkt->connectionHandle, GAP_PROFILE_PERIPHERAL );
}
else if ( pPkt->hdr.status == bleGAPConnNotAcceptable )
{
// Set enabler to FALSE; device will become discoverable again when
// this value gets set to TRUE
gapRole_AdvEnabled = FALSE;
// Go to WAITING state, and then start advertising
gapRole_state = GAPROLE_WAITING;
}
else
{
gapRole_state = GAPROLE_ERROR;
}
notify = TRUE;
}
break;
4.
case GAP_LINK_ESTABLISHED_EVENT:
{
gapEstLinkReqEvent_t *pPkt = (gapEstLinkReqEvent_t *)pMsg;
if ( pPkt->hdr.status == SUCCESS )
{
VOID osal_memcpy( gapRole_ConnectedDevAddr, pPkt->devAddr, B_ADDR_LEN );
gapRole_ConnectionHandle = pPkt->connectionHandle;
gapRole_state = GAPROLE_CONNECTED;
if ( gapRole_RSSIReadRate )
{
// Start the RSSI Reads
VOID osal_start_timerEx( gapRole_TaskID, RSSI_READ_EVT, gapRole_RSSIReadRate );
}
// Check whether update parameter request is enabled, and check the connection parameters
if ( ( gapRole_ParamUpdateEnable == TRUE ) &&
( (pPkt->connInterval < gapRole_MinConnInterval) ||
(pPkt->connInterval > gapRole_MaxConnInterval) ||
(pPkt->connLatency != gapRole_SlaveLatency) ||
(pPkt->connTimeout != gapRole_TimeoutMultiplier) ))
{
gapRole_SendUpdateParam( pPkt->connInterval, pPkt->connLatency );
}
// Notify the Bond Manager to the connection
VOID GAPBondMgr_LinkEst( pPkt->devAddrType, pPkt->devAddr, pPkt->connectionHandle, GAP_PROFILE_PERIPHERAL );
}
else
{
gapRole_state = GAPROLE_ERROR;
}
notify = TRUE;
}
break;
原文地址:https://blog.csdn.net/qq_35451217/article/details/107521082
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!