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

📄 a2dp_sd_open.c

📁 CSR蓝牙MP3播放USB DONGLE源码
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.5.2-release

FILE NAME
    a2dp_sd_open.c

DESCRIPTION
    Open the AV transport and signalling channels

NOTES
    
*/


/****************************************************************************
    Header files
*/
#include "a2dp_sd_private.h"
#include "a2dp_sd_open.h"
#include "a2dp_sd_initiate.h"

#include <bdaddr.h>
#include <panic.h>
#include <ps.h>


/****************************************************************************
NAME    
    a2dpSdHandleA2dpOpenCfm
    
DESCRIPTION
    Handle the open cfm received from the A2DP lib.

RETURNS
    void
*/
void a2dpSdHandleA2dpOpenCfm(a2dpSourceDongleTaskData *theApp, const A2DP_OPEN_CFM_T *cfm)
{
    /* Check the outcome of the open request */
    if (cfm->result == a2dp_success)
    {
        bdaddr bd_addr;
        
        /* Update the local state */
        avSourceDongleUpdateA2dpState(a2dp_state_connected);
        
        /* Store the sink and MTU size */
        theApp->media_sink = cfm->media_sink;

        /* Cancel the connect attempt timer. */
        (void) MessageCancelAll(getTheAppTask(), APP_CONNECT_TIMEOUT_IND);

        /* 
            We are connected - start streaming 
        */
        A2dpStart(theApp->a2dp, cfm->media_sink);

        /*
            The remote device appears to be good so update our stored 
            Bluetooth address if required.
        */
        if (SinkGetBdAddr(cfm->media_sink, &bd_addr))
        {
            if(!BdaddrIsSame(&theApp->av_sink_addr, &bd_addr))
            {
                /* Update the sink address */
                theApp->av_sink_addr = bd_addr;
        
                /* Update PS if changed */
                (void)PsStore(PS_AV_SINK_ADDR, &theApp->av_sink_addr, sizeof(bdaddr));
            }
        }
    }
    else
    {
        /* Return to accepting state */
        avSourceDongleUpdateA2dpState(a2dp_state_accepting);

        if (!theApp->connect_timer_expired)
        {
            /* We still have reconnection attempts so try again to connect to headset */
            if (!BdaddrIsZero(&theApp->av_sink_addr))
            {
                a2dpSdInitiateRequest(&theApp->av_sink_addr);
            }
			else
				/* Cancel the connect attempt timer this is a failed discovery. */
				(void) MessageCancelAll(getTheAppTask(), APP_CONNECT_TIMEOUT_IND);
        }
    }

    /* If we have a discovery pending start it now */
    if (theApp->discover_pending)
        MessageSend(&theApp->task, APP_DISCOVER_REQ, 0);
}


/****************************************************************************
NAME    
    a2dpSdHandleOpenInd
    
DESCRIPTION
    Handle an indication that a remote device is opening an AV channel
    to our device.

RETURNS
    void
*/
void a2dpSdHandleOpenInd(a2dpSourceDongleTaskData *theApp, const A2DP_OPEN_IND_T *ind)
{
    bdaddr addr;

    /* Update the local state */
    avSourceDongleUpdateA2dpState(a2dp_state_connected);
    
    /* Store the sink and mtu for the media channel */
    theApp->media_sink = ind->media_sink;

    /* Get the address of the device that connected to us */
    if (!SinkGetBdAddr(ind->media_sink, &addr))
        Panic();
    else
    {
        /* If the sink is not the one we expect, disconnect */
        if (!BdaddrIsSame(&theApp->av_sink_addr, &addr))
            MessageSend(&theApp->task, APP_CLOSE_REQ, 0);
    }
}

⌨️ 快捷键说明

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