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

📄 main.c

📁 蓝牙耳机的源代码,结合csr的开发套件使用
💻 C
📖 第 1 页 / 共 4 页
字号:
/****************************************************************************Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006Part of BlueLab 3.5.2-releaseFILE NAME    main.c        DESCRIPTION    This is main file for the headset application software for BC4-HeadsetNOTES*//****************************************************************************    Header files*/#include "headset_private.h"#include "headset_init.h"#include "headset_auth.h"#include "headset_scan.h"#include "headset_slc.h" #include "headset_dut.h"  #include "headset_LEDmanager.h"#include "headset_buttonmanager.h"#include "headset_configmanager.h"#include "headset_events.h"#include "headset_statemanager.h"#include "headset_soundmanager.h"#include "headset_powermanager.h"#include "headset_callmanager.h"#include "headset_threewaycall.h"#ifdef TEST_HARNESS#include "test_headset.h"#endif#include <bdaddr.h>#include <connection.h>#include <panic.h>#include <ps.h>#include <pio.h>#include <stdlib.h>#include <stdio.h>#include <stream.h>#ifdef DEBUG_MAIN#define MAIN_DEBUG(x) DEBUG(x)#define TRUE_OR_FALSE(x)  ((x) ? 'T':'F')#else#define MAIN_DEBUG(x) #endif/* Single instance of AV Headset state */static hsTaskData theHeadset;#define POWER_OFF_DISABLE_TIME_SECS (20)typedef enum MessageTypeTag{        MSGTYPE_UNKNOWN = 0,        MSGTYPE_HFP, /*message From the HFP*/    MSGTYPE_CL , /*message from the CL*/       MSGTYPE_UE , /*massge from a User event*/           MSGTYPE_HS   /*message from the Headset (Internal)*/    }messageType_t ;static messageType_t headsetGetMessageType (MessageId pMsg ) ;static void headsetInitUserFeatures ( void ) ; static void handleHFPStatusCFM ( hsTaskData * theHeadset , hfp_lib_status pStatus ) ;/*************************************************************************NAME        getAppTask    DESCRIPTION    Returns the application main task.RETURNS    Task*/Task getAppTask(void){    return &theHeadset.task;}/*************************************************************************NAME        unhandledHeadsetState    DESCRIPTION    This function is called when a message arrives and the Headset is    in an unexpected state.  The error condition is reported and then the    application will Panic    RETURNS    */static void unhandledHeadsetState(headsetState state, MessageId id){    MAIN_DEBUG(("HS: st%d id 0x%x\n", state, id));}/*************************************************************************NAME        handleCLMessage    DESCRIPTION    Function to handle the CL Lib messages - these are independent of stateRETURNS*/static void handleCLMessage ( Task task, MessageId id, Message message ){     /*paranoia check we have a CL message*/    if ( headsetGetMessageType ( id )  != MSGTYPE_CL)    {        MAIN_DEBUG(( "hCLm Error[%x] \n",id )) ;    }        /* Handle incoming message identified by its message ID */    switch(id)    {  /* -- Connection Library Messages -- */        case CL_INIT_CFM:            MAIN_DEBUG(("CL_INIT_CFM [%d]\n" , ((CL_INIT_CFM_T*)message)->status ));            if(((CL_INIT_CFM_T*)message)->status == success)            {    			/* The Connection Library has been successfully initialised,        			   initialise the HFP library to instantiate an instance of both       			   the HFP and the HSP */    				headsetHfpInit(&theHeadset);            }            else            {                Panic();            }            break;     		case CL_SM_PIN_CODE_IND:            MAIN_DEBUG(("CL_SM_PIN_IND\n"));            headsetHandlePinCodeInd((CL_SM_PIN_CODE_IND_T*) message);            break;                    case CL_SM_AUTHORISE_IND:            MAIN_DEBUG(("CL_SM_AUTHORISE_IND\n"));            headsetHandleAuthoriseInd((CL_SM_AUTHORISE_IND_T*) message);            break;                    case CL_SM_AUTHENTICATE_CFM:            MAIN_DEBUG(("CL_SM_AUTHENTICATE_CFM\n"));            headsetHandleAuthenticateCfm(&theHeadset, (CL_SM_AUTHENTICATE_CFM_T*) message);            break;                    case CL_DM_REMOTE_FEATURES_CFM:            MAIN_DEBUG(("HS : Supported Features\n")) ;            headsetHandleRemoteSuppFeatures(&theHeadset, (CL_DM_REMOTE_FEATURES_CFM_T *)(message));            break ;     case CL_SM_GET_ATTRIBUTE_CFM:   MAIN_DEBUG(("HS : CL_SM_GET_ATTRIBUTE_CFM\n"));   soundManagerHandleVolumeLevel(&theHeadset, (CL_SM_GET_ATTRIBUTE_CFM_T *)(message));   break;           case CL_DM_SYNC_CONNECT_CFM:                case CL_DM_SYNC_CONNECT_IND:        case CL_DM_SYNC_DISCONNECT_IND:       	case CL_DM_ACL_OPENED_IND:        case CL_DM_ACL_CLOSED_IND:        case CL_DM_ROLE_CFM:        case CL_DM_INQUIRE_RESULT:        case CL_DM_REMOTE_NAME_COMPLETE:        case CL_DM_CLASS_OF_DEVICE_CFM:        case CL_DM_LOCAL_BD_ADDR_CFM:        case CL_DM_LINK_QUALITY_CFM:        case CL_DM_RSSI_CFM:        case CL_DM_CLOCK_OFFSET_CFM:        case CL_SM_SECURITY_LEVEL_CFM:        case CL_SDP_UNREGISTER_CFM:        case CL_SDP_OPEN_SEARCH_CFM:        case CL_SDP_CLOSE_SEARCH_CFM:        case CL_SDP_SERVICE_SEARCH_CFM:        case CL_SDP_ATTRIBUTE_SEARCH_CFM:        case CL_SDP_SERVICE_SEARCH_ATTRIBUTE_CFM:        case CL_L2CAP_REGISTER_CFM:        case CL_L2CAP_UNREGISTER_CFM:        case CL_L2CAP_CONNECT_CFM:        case CL_L2CAP_CONNECT_IND:        case CL_L2CAP_DISCONNECT_IND:        case CL_RFCOMM_REGISTER_CFM:        case CL_RFCOMM_CONNECT_CFM:        case CL_RFCOMM_CONNECT_IND:        case CL_RFCOMM_DISCONNECT_IND:        case CL_RFCOMM_CONTROL_IND:        case CL_DM_LINK_POLICY_IND:                    MAIN_DEBUG(("Headset - Unhandled CL msg[%x]\n", id));            break;                    default :                MAIN_DEBUG(("HS : CL ? [%x]\n", id)) ;                break ;    }   }/*************************************************************************NAME        handleUEMessage    DESCRIPTION    handles messages from the User EventsRETURNS    */static void handleUEMessage  ( Task task, MessageId id, Message message ){    /* Event state control is done by the config - we will be in the right state for the message    therefore messages need only be passed to the relative handlers unless configurable */    headsetState lState = stateManagerGetState() ;                 /*if we do not want the event received to be indicated then set this to FALSE*/    bool lIndicateEvent = TRUE ;    /* Deal with user generated Event specific actions*/    switch ( id )    {               /*these are the events that are not user generated and can occur at any time*/        case EventOkBattery:        case EventChargerDisconnected:        case EventLEDEventComplete:        case EventTrickleCharge:        case EventLowBattery:        case EventPowerOff:        case EventLinkLoss:        case EventSLCConnected:        case EventError:        case EventChargeError:        case EventChargeErrorInIdleState:        case EventCancelLedIndication:        case EventAutoSwitchOff:            /*do nothing for these events*/        break ;        default:                    /* If we have had an event then reset the timer - if it was the event then we will switch off anyway*/            if (theHeadset.AutoSwitchOffTimeSecs !=0)            {                /*MAIN_DEBUG(("HS: AUTOSent Ev[%x] Time[%d]\n",id , theHeadset.AutoSwitchOffTimeSecs )) ;*/                MessageCancelAll( task , EventAutoSwitchOff ) ;                MessageSendLater( task , EventAutoSwitchOff , 0 , D_SEC(theHeadset.AutoSwitchOffTimeSecs) ) ;                            }                /*handles the LED event timeouts - restarts state indications if we have had a user generated event only*/            if (theHeadset.theLEDTask.gLEDSStateTimeout)            {                   MAIN_DEBUG(("HS: Restart St Inds[%d]\n", stateManagerGetState() )) ;                                    LEDManagerIndicateState (&theHeadset.theLEDTask , stateManagerGetState() ) ;                     theHeadset.theLEDTask.gLEDSStateTimeout = FALSE ;            }            else            {                    /*reset the current number of repeats complete - i.e restart the timer so that the leds will disable after                    the correct time*/                LEDManagerResetStateIndNumRepeatsComplete  ( &theHeadset.theLEDTask ) ;            }           break;    }         MAIN_DEBUG (( "HS : UE[%x]\n", id ));                 /* The configurable Events*/    switch ( id )    {           case (EventPowerOn):            MAIN_DEBUG(("HS: Power On\n" ))                            /*we have received the power on event- we have fully powered on*/            stateManagerPowerOn( &theHeadset ) ;                        LedManagerEnableLEDS ( &theHeadset.theLEDTask ) ;                if ( theHeadset.features.DisablePowerOffAfterPowerOn )            {                theHeadset.PowerOffIsEnabled = FALSE ;                MessageSendLater ( &theHeadset.task , EventEnablePowerOff , 0 , D_SEC ( theHeadset.DisablePowerOffAfterPowerOnTimeSecs ) ) ;            }            else            {                theHeadset.PowerOffIsEnabled = TRUE ;            }            break ;                    case (EventPowerOff):                MAIN_DEBUG(("HS: PowerOff - En[%c]\n" , ((theHeadset.PowerOffIsEnabled) ? 'T':'F') )) ;                        if ( theHeadset.PowerOffIsEnabled )            {                stateManagerEnterPoweringOffState ( &theHeadset ) ;                                    if (theHeadset.theSoundTask.gMuted == VOL_MUTED)                {                    soundManagerMuteOff ( &theHeadset ) ;                }                                headsetClearQueueudEvent ( &theHeadset ) ;            }            else            {                lIndicateEvent = FALSE ;            }            MessageCancelAll ( &theHeadset.task , EventPairingFail) ;                        break ;        case (EventInitateVoiceDial):            MAIN_DEBUG(("HS: InitVoiceDial [%c] [%d]\n", (theHeadset.supp_features_local & HFP_VOICE_RECOGNITION ) ? 'T':'F' , theHeadset.VoiceRecognitionIsActive )) ;                            /*Toggle the voice dial behaviour depending on whether we are currently active*/            if (theHeadset.VoiceRecognitionIsActive)            {                headsetCancelVoiceDial ( &theHeadset ) ;                lIndicateEvent = FALSE ;            }            else            {                                headsetInitiateVoiceDial ( &theHeadset) ;            }                        break ;           case (EventLastNumberRedial):            MAIN_DEBUG(("HS: LNR\n" )) ;                        headsetInitiateLNR ( &theHeadset ) ;                       break ;           case (EventAnswer):            MAIN_DEBUG(("HS: Answer\n" )) ;            /* Call the HFP lib function, this will determine the AT cmd to send               depending on whether the profile instance is HSP or HFP compliant. */             headsetAnswerCall(&theHeadset);            break ;           case (EventReject):            MAIN_DEBUG(("HS: Reject\n" )) ;            /* Reject incoming call - only valid for instances of HFP */             headsetRejectCall(&theHeadset);            break ;           case (EventCancelEnd):            MAIN_DEBUG(("HS: CancelEnd\n" )) ;            /* Terminate the current ongoing call process */            headsetHangUpCall(&theHeadset);            break ;           case (EventTransferToggle):            MAIN_DEBUG(("HS: Transfer\n" )) ;            headsetTransferToggle(&theHeadset);            break ;           case (EventToggleMute):            MAIN_DEBUG(("EventToggleMute\n")) ;            soundManagerToggleMute( &theHeadset ) ;            break ;        case (EventDoCompleteUnMuteMic):                    MAIN_DEBUG(("EventCompleteMute\n")) ;                soundManagerCompleteUnmute ( &theHeadset ) ;            break;        case EventMuteOn :            MAIN_DEBUG(("EventMuteOn\n")) ;                soundManagerMuteOn (&theHeadset) ;            break ;        case EventMuteOff:            MAIN_DEBUG(("EventMuteOff\n")) ;                soundManagerMuteOff ( &theHeadset ) ;            break ;           case (EventVolumeUp):                    MAIN_DEBUG(("EventVolumeUp\n")) ;            soundManagerVolumeUp( &theHeadset ) ;            break ;           case (EventVolumeDown):            soundManagerVolumeDown( &theHeadset ) ;                      break ;                                   case (EventEnterPairing):            MAIN_DEBUG(("HS: EnterPair [%d]\n" , stateManagerGetState() )) ;            /*go into pairing mode*/ 

⌨️ 快捷键说明

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