⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headset_slc.c

📁 蓝牙耳机的源代码,结合csr的开发套件使用
💻 C
📖 第 1 页 / 共 2 页
字号:
            slcConnectLastAG( pApp , pProfile) ;        break;        case LastNone:        default:                    break;    }}    /*Attempt a connection as a profile  type to a device given a bluetooth address*/static void slcAttemptConnect ( hsTaskData *pApp, hfp_profile pProfile  , bdaddr * pAddr){        /*attempt the connection*/    switch ( pProfile )    {        case (hfp_handsfree_profile) :        {            pApp->profile_connected = hfp_handsfree_profile;            SLC_DEBUG(("SLC: Attempt HFP\n")) ;                                    /* Issue a connect request for HFP */            HfpSlcConnect(pApp->hfp, pAddr, 0);        }            break;        case (hfp_headset_profile) :        {            pApp->profile_connected = hfp_headset_profile;            SLC_DEBUG(("SLC: Attempt HSP\n")) ;                                    /* Issue a connect request for HFP */            HfpSlcConnect(pApp->hsp, pAddr, 0);        }           break;        default:            Panic();        break;    }}static void slcProfileConnected (hsTaskData * pApp , HFP * pProfile, Sink sink){	bdaddr ag_addr;	SLC_DEBUG(("SLC: Connected[%x]\n", (int)sink)) ;		/* Enter connected state if applicable*/    if ( !stateManagerIsConnected() )    {        stateManagerEnterConnectedState( pApp );	}	/* Store the address as the last used AG which can be obtained from the sink */	if (SinkGetBdAddr(sink, &ag_addr))    {        slcStoreBdaddr ( pApp , &ag_addr ) ;                slcCallTransferNotInProgress( pApp ) ;		/* Send volume level to AG we have just connected too */		soundManagerVolumeDefault(&ag_addr);    }   	else	{    		/* Something is very wrong, couldn't get the addr from the sink */		Panic();    }        /* Send a user event to the app for indication purposes*/    MessageSend (&pApp->task , EventSLCConnected , 0 );	    /* Now we are connected, then we can reset the paging states*/              gSlcData.gNextPage = PageUnknown;        /*re-set this*/    pApp->NetworkIsPresent = TRUE ;            	/* Read the remote supported features of the AG */	ConnectionReadRemoteSuppFeatures(getAppTask(), sink);	}void slcStoreBdaddr ( hsTaskData * pApp , const bdaddr * pAddr ) {    bdaddr lDefaultAddr;    uint16 lDefaultLen = 0 ;            lDefaultLen = PsRetrieve(PSKEY_DEFAULT_AG, &lDefaultAddr, sizeof(bdaddr)) ;        if (pApp->features.DefaultIsDifferentToLastAG)    {            /*then we have no default address so store this one*/        if (lDefaultLen != sizeof(bdaddr) )        {        	(void) PsStore(PSKEY_DEFAULT_AG, pAddr, sizeof(bdaddr));            }        else        {                /*providing this address is different to the default & we are configured to use seperate Default & last storage*/            if ( BdaddrIsSame( &lDefaultAddr , pAddr) )            {               gSlcData.gLastConnected = LastDefault;                 }            else            {	              /* store the last used AG if we have connected */                (void) PsStore(PSKEY_LAST_USED_AG, pAddr, sizeof(bdaddr));                            gSlcData.gLastConnected = LastLast ;            }        }    }    else    {        /**default can be the same as the last*/        if (lDefaultLen != sizeof(bdaddr) )        {        	(void) PsStore(PSKEY_DEFAULT_AG, pAddr, sizeof(bdaddr));            }                /*always store the last*/               (void) PsStore(PSKEY_LAST_USED_AG, pAddr, sizeof(bdaddr));                    gSlcData.gLastConnected = LastLast ;               }}/****************************************************************************NAME        headsetDisconnectSlc    DESCRIPTION    Disconnect the SLC associated with this profile instance.RETURNS    void*/void headsetDisconnectSlc(hsTaskData *app){    /* Issue the disconnect request and let the HFP lib do the rest */	if(app->profile_connected == hfp_no_profile)		return;	else if(app->profile_connected == hfp_handsfree_profile)    	HfpSlcDisconnect(app->hfp);	else		HfpSlcDisconnect(app->hsp);    MessageSend(&app->task , EventSLCDisconnected , 0) ;}/****************************************************************************NAME        headsetHandleSlcDisconnectInd    DESCRIPTION    Indication that the SLC has been released.RETURNS    void*/void headsetHandleSlcDisconnectInd(hsTaskData *app, const HFP_SLC_DISCONNECT_IND_T *ind){	bdaddr	ag_addr;		/* Get the bdaddr of the last AG we were connected too */	if(PsRetrieve(PSKEY_LAST_USED_AG, &ag_addr, sizeof(bdaddr)))	{		soundManagerStoreVolumeLevel(app, &ag_addr);	}	else	{		if(PsRetrieve(PSKEY_DEFAULT_AG, &ag_addr, sizeof(bdaddr)))		{			soundManagerStoreVolumeLevel(app, &ag_addr);		}		}		/* Check if this was the result of an abnormal link loss */    if (ind->status == hfp_disconnect_link_loss )     {        SLC_DEBUG(("SLC: Link Loss Detect\n")) ;                if (app->features.AutoReconnectLinkLoss)        {            gSlcData.gLinkLossOccured = app->LinkLossNumRetries ;            MessageSend( &app->task , EventLinkLoss , 0 ) ;                    }                        /*a link loss is not a call transfer*/        slcCallTransferNotInProgress( app) ;    }    else    {        gSlcData.gNextPage = PageUnknown;                    /*a disconnect in active call state is a call transfer*/        if (stateManagerGetState() == headsetActiveCall)        {            slcCallTransferInProgress( app) ;                     }        else        {            slcCallTransferNotInProgress( app) ;        }    }            /* Update the app state if we are on*/    if ( stateManagerIsConnected() )    {        stateManagerEnterConnectableState( app, FALSE ) ;    }        MessageSend(&app->task , EventSLCDisconnected , 0) ;            /* Connection disconnected */    app->profile_connected = hfp_no_profile;	/* Reset in-band ring tone support flag */	app->RingInfo.InBandRingEnabled = FALSE;}/****************************************************************************NAME        headsetHandleRemoteSuppFeatures    DESCRIPTION    Supported features of the remote device contained in the message if the     read succeeded. RETURNS    void*/void headsetHandleRemoteSuppFeatures(hsTaskData *app, const CL_DM_REMOTE_FEATURES_CFM_T *cfm){    /*         If the read request succeeded then store the first work of the supported features         We should in theory store all four words but currently we only need the info in         the first word so for the sake of efficiency for the moment only store that.    */    if (cfm->status == hci_success)	{        app->supp_features_remote = cfm->features[0];                SLC_DEBUG(("SLC: SuppFeat[%x]\n", app->supp_features_remote)) ;	} }    /*received after a link loss fail  or retry after time t*/void slcConnectAfterLinkLoss ( hsTaskData *pApp ){    gSlcData.gNextPage = PageUnknown ;        slcConnectLastConnectedAG(pApp, hfp_handsfree_profile ) ;}void slcEstablishSLCRequest ( hsTaskData *pApp, hfp_profile pProfile ){    ARAction_t lARAction = AR_LastConnected ;                /*handle call transfer action*/    if ( gSlcData.gCallTransferInProgress )    {        lARAction = pApp->features.ActionOnCallTransfer ;                    SLC_DEBUG(("SLC: Est Last - Call Tx in Progress [%d]\n" , lARAction));    }    else    {        switch (gSlcData.gLastConnected)        {            case LastLast:                        /*then we have just been disconnected from an AG*/                 switch( pApp->features.ActionOnDisconnect)                 {                     case AR_Swap:                        lARAction = AR_Default ;                                    SLC_DEBUG(("SLC: Discon Swap - [%s]\n" , gDebugReconStrings[lARAction]));                     break ;                     case AR_SwapSwap:                        lARAction = AR_DefaultThenLast ;                                    SLC_DEBUG(("SLC: Discon SwapSwap - [%s]\n" , gDebugReconStrings[lARAction]));                     break ;                     default:                                             lARAction = pApp->features.ActionOnDisconnect ;                     break;                 }                             break ;                    case LastDefault:                       /*then we have just been disconnected from an AG*/                 switch( pApp->features.ActionOnDisconnect)                 {                     case AR_Swap:                        lARAction = AR_Last ;                                    SLC_DEBUG(("SLC: Discon Swap - [%s]\n" , gDebugReconStrings[lARAction]));                     break ;                     case AR_SwapSwap:                        lARAction = AR_LastThenDefault ;                                    SLC_DEBUG(("SLC: Discon SwapSwap - [%s]\n" , gDebugReconStrings[lARAction]));                     break ;                     default:                                             lARAction = pApp->features.ActionOnDisconnect ;                     break;                 }              break ;            case LastNone:                    /*we are freshly powered on / Not connected - use poweron action*/                lARAction = pApp->features.ActionOnPowerOn ;                                SLC_DEBUG(("SLC: Est Power On - [%s]\n" , gDebugReconStrings[lARAction]));            break ;            default:            break ;                }    }    slcHandleSlcConnectRequest(pApp, hfp_handsfree_profile , lARAction) ;    }/****************************************************************************NAME        headsetHandleServiceIndicator    DESCRIPTION    Interprets the service Indicator messages and sends the appropriate Headset message RETURNS    void*/void headsetHandleServiceIndicator ( hsTaskData * pApp , const HFP_SERVICE_IND_T *pInd ) {    if ( pInd->service )    {        MessageSend(&pApp->task , EventNetworkOrServicePresent , 0 ) ;        pApp->NetworkIsPresent = TRUE ;    }    else /*the network service is OK*/    {        /*should only send tis if not currently sending it*/        if (pApp->NetworkIsPresent)        {            MessageSend(&pApp->task , EventNetworkOrServiceNotPresent  , 0 ) ;                        pApp->NetworkIsPresent = FALSE ;        }    }}void slcCallTransferInProgress( hsTaskData * pApp) {    gSlcData.gCallTransferInProgress = TRUE ;}void slcCallTransferNotInProgress( hsTaskData * pApp ) {    gSlcData.gCallTransferInProgress = FALSE ;}   void slcReset(void){	gSlcData.gNextPage = PageUnknown; 	gSlcData.gLastConnected = LastNone;	gSlcData.gCurrPaging = PagingLast;	gSlcData.gCallTransferInProgress = FALSE;	gSlcData.gLinkLossOccured = FALSE;}         

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -