📄 main.c
字号:
break;
case HFP_RELEASE_ACTIVE_ACCEPT_OTHER_CALL_CFM :
MAIN_DEBUG(("HS3 : HFP_RELEASE_ACTIVE_ACCEPT_OTHER_CALL_CFM_T [%c]\n" , (((HFP_RELEASE_ACTIVE_ACCEPT_OTHER_CALL_CFM_T *) message)->status == hfp_success)? 'T':'F' )) ;
headsetHandleThreeReleaseActiveAcceptOtherCfm (&theHeadset ,(HFP_RELEASE_ACTIVE_ACCEPT_OTHER_CALL_CFM_T *) message) ;
break;
case HFP_HOLD_ACTIVE_ACCEPT_OTHER_CALL_CFM :
MAIN_DEBUG(("HS3 : HFP_HOLD_ACTIVE_ACCEPT_OTHER_CALL_CFM_T [%c]\n", (((HFP_HOLD_ACTIVE_ACCEPT_OTHER_CALL_CFM_T * ) message)->status == hfp_success) ? 'T':'F' )) ;
headsetHandleThreeHoldActiveAcceptOtherCfm(&theHeadset ,(HFP_HOLD_ACTIVE_ACCEPT_OTHER_CALL_CFM_T * ) message);
break;
case HFP_ADD_HELD_CALL_CFM :
MAIN_DEBUG(("HS3 : HFP_ADD_HELD_CALL_CFM_T [%c]\n", (((HFP_ADD_HELD_CALL_CFM_T *)message)->status == hfp_success) ? 'T':'F' )) ;
headsetHandleThreeAddCall(&theHeadset ,(HFP_ADD_HELD_CALL_CFM_T *)message) ;
break ;
case HFP_EXPLICIT_CALL_TRANSFER_CFM :
MAIN_DEBUG(("HS3 : HFP_EXPLICIT_CALL_TRANSFER_CFM_T [%c]\n", (((HFP_EXPLICIT_CALL_TRANSFER_CFM_T * )message)->status == hfp_success)? 'T':'F' )) ;
headsetHandleThreeExplicitTransfer (&theHeadset ,(HFP_EXPLICIT_CALL_TRANSFER_CFM_T * )message) ;
break ;
/*******************************************************************/
/***Response Hold Messages*/
case HFP_RESPONSE_HOLD_STATUS_CFM:
MAIN_DEBUG(("HS: HFP_RESPONSE_HOLD_STATUS_CFM [%d]\n" , ((HFP_RESPONSE_HOLD_STATUS_CFM_T *)message)->status )) ;
break;
case HFP_RESPONSE_HOLD_HELD_CFM :
MAIN_DEBUG(("HS: HFP_RESPONSE_HOLD_HELD_CFM [%d]\n" , ((HFP_RESPONSE_HOLD_HELD_CFM_T *)message)->status )) ;
break;
case HFP_RESPONSE_HOLD_ACCEPT_CFM:
MAIN_DEBUG(("HS: HFP_RESPONSE_HOLD_ACCEPT_CFM [%d]\n" , ((HFP_RESPONSE_HOLD_ACCEPT_CFM_T*)message)->status )) ;
break;
case HFP_RESPONSE_HOLD_REJECT_CFM:
MAIN_DEBUG(("HS: HFP_RESPONSE_HOLD_REJECT_CFM [%d]\n" , ((HFP_RESPONSE_HOLD_REJECT_CFM_T*)message)->status )) ;
break;
case HFP_RESPONSE_HOLD_STATUS_IND:
headsethandleResponseHoldInd ( &theHeadset , (HFP_RESPONSE_HOLD_STATUS_IND_T *)message ) ;
break;
/*******************************************************************/
case HFP_SUBSCRIBER_NUMBER_CFM:
MAIN_DEBUG(("HS3: HFP_SUBSCRIBER_NUMBER_CFM [%c]\n" , (((HFP_SUBSCRIBER_NUMBER_CFM_T*)message)->status == hfp_success) ? 'T' :'F' )) ;
break ;
case HFP_SUBSCRIBER_NUMBER_IND:
{
uint16 i=0;
MAIN_DEBUG(("HS3: HFP_SUBSCRIBER_NUMBER_IND [%d]\n" , ((HFP_SUBSCRIBER_NUMBER_IND_T*)message)->service )) ;
for (i=0;i< ((HFP_SUBSCRIBER_NUMBER_IND_T*)message)->size_number ; i++)
{
MAIN_DEBUG(("%c", ((HFP_SUBSCRIBER_NUMBER_IND_T*)message)->number[i])) ;
}
MAIN_DEBUG(("\n")) ;
}
break ;
case HFP_CURRENT_CALLS_CFM:
MAIN_DEBUG(("HS3: HFP_CURRENT_CALLS_CFM [%c]\n", (((HFP_CURRENT_CALLS_CFM_T*)message)->status == hfp_success) ? 'T' :'F' )) ;
break ;
case HFP_CURRENT_CALLS_IND:
MAIN_DEBUG(("HS3: HFP_CURRENT_CALLS_IND id[%d] mult[%d] status[%d]\n" ,
((HFP_CURRENT_CALLS_IND_T*)message)->call_idx ,
((HFP_CURRENT_CALLS_IND_T*)message)->multiparty ,
((HFP_CURRENT_CALLS_IND_T*)message)->status)) ;
headsetHandleCurrentCallsInd ( &theHeadset , (HFP_CURRENT_CALLS_IND_T *) message ) ;
break;
/******************************************************************/
/**New Esco handling messages**/
case HFP_AUDIO_CONNECT_IND:
MAIN_DEBUG(("****HFP_AUDIO_CONNECT_IND\n")) ;
audioHandleSyncConnectInd( &theHeadset , (HFP_AUDIO_CONNECT_IND_T *)message ) ;
break ;
case HFP_AUDIO_CONNECT_CFM:
MAIN_DEBUG(("****HFP_AUDIO_CONNECT_CFM[%x][%x][%s%s%s] r[%d]t[%d]\n", ((HFP_AUDIO_CONNECT_CFM_T *)message)->status ,
(int)((HFP_AUDIO_CONNECT_CFM_T *)message)->audio_sink ,
((((HFP_AUDIO_CONNECT_CFM_T *)message)->link_type == sync_link_sco) ? "SCO" : "" ) ,
((((HFP_AUDIO_CONNECT_CFM_T *)message)->link_type == sync_link_esco) ? "eSCO" : "" ) ,
((((HFP_AUDIO_CONNECT_CFM_T *)message)->link_type == sync_link_unknown) ? "unk?" : "" ) ,
(int)((HFP_AUDIO_CONNECT_CFM_T *)message)->rx_bandwidth ,
(int)((HFP_AUDIO_CONNECT_CFM_T *)message)->tx_bandwidth
)) ;
audioHandleSyncConnectCfm ( &theHeadset , (HFP_AUDIO_CONNECT_CFM_T *)message ) ;
break ;
case HFP_AUDIO_DISCONNECT_IND:
MAIN_DEBUG(("****HFP_AUDIO_DISCONNECT_IND [%x]\n", ((HFP_AUDIO_DISCONNECT_IND_T *)message)->status)) ;
audioHandleSyncDisconnectInd (&theHeadset , (HFP_AUDIO_DISCONNECT_IND_T *)message) ;
break ;
/*********************************************************************/
/*Other 1.5 messages*/
case HFP_SIGNAL_IND:
MAIN_DEBUG(("HS: HFP_SIGNAL_IND [%d]\n", ((HFP_SIGNAL_IND_T* )message)->signal )) ;
break ;
case HFP_ROAM_IND:
MAIN_DEBUG(("HS: HFP_ROAM_IND [%d]\n", ((HFP_ROAM_IND_T* )message)->roam )) ;
break;
case HFP_BATTCHG_IND:
MAIN_DEBUG(("HS: HFP_BATTCHG_IND [%d]\n", ((HFP_BATTCHG_IND_T* )message)->battchg )) ;
break;
case HFP_CALLHELD_IND:
MAIN_DEBUG(("HS: HFP_CALLHELD_IND_T [%d]\n", ((HFP_CALLHELD_IND_T* )message)->callheld )) ;
break ;
/*******************************************************************/
default :
MAIN_DEBUG(("HS : HFP ? [%x]\n",id)) ;
break ;
}
}
/*************************************************************************
NAME
handleHSMessage
DESCRIPTION
handles the Headset Messages
RETURNS
*/
static void handleHSMessage ( Task task, MessageId id, Message message )
{
headsetState current_headset_state = stateManagerGetState();
/* Handle incoming message identified by its message ID */
switch (id )
{
/* -- Headset Application Messages */
case HEADSET_INIT_CFM:
MAIN_DEBUG(("HEADSET_INIT_CFM\n"));
switch(current_headset_state)
{
case headsetPoweringOn:
/* The headset is now initialised */
/*init the configurable parameters*/
headsetInitUserFeatures ( ) ;
break;
case headsetConnectable:
case headsetConnDiscoverable:
case headsetConnected:
case headsetOutgoingCallEstablish:
case headsetIncomingCallEstablish:
case headsetActiveCall:
default:
unhandledHeadsetState(current_headset_state, id);
}
break;
default:
MAIN_DEBUG(("HS : HS ? [%x]\n",id));
break;
}
}
/*************************************************************************
NAME
headsetInitUserFeatures
DESCRIPTION
This function initialises all of the user features - this will result in a
poweron message if a user event is configured correctly and the headset will
complete the power on
RETURNS
*/
static void headsetInitUserFeatures ( void )
{
/* Initialise the Sound Manager */
soundManagerInit(&theHeadset) ;
/* Initialise the LED Manager */
LEDManagerInit( &theHeadset.theLEDTask ) ;
/* Initialise the Power Manager */
theHeadset.power = powerManagerInit();
/* Initialise the Button Manager */
buttonManagerInit(&theHeadset.theButtonTask , &theHeadset.task) ;
/* Once system Managers are initialised, load up the configuration */
configManagerInit(&theHeadset);
/* Set to a known value*/
theHeadset.VoiceRecognitionIsActive = FALSE ;
/* Enter the limbo state as we may be ON due to a charger being plugged in */
stateManagerEnterLimboState ( &theHeadset ) ;
if (theHeadset.VolumeOrientationIsInverted)
{
MessageSend ( &theHeadset.task , EventVolumeOrientationInvert , 0 ) ;
}
/*what is the effect of this on motorola?*/
LedManagerEnableLEDS ( &theHeadset.theLEDTask ) ;
/*check the charger input pin to see if the charger is connected*/
if (theHeadset.input_PIO.charger_input != 0xF )
{
uint16 lPin = ( 1<< theHeadset.input_PIO.charger_input) ;
if (PioGet() & lPin)
{
MessageSend(&theHeadset.task, EventChargerConnected , 0 );
}
}
}
/*************************************************************************
NAME
app_handler
DESCRIPTION
This is the main message handler for the Headset Application. All
messages pass through this handler to the subsequent handlers.
RETURNS
*/
static void app_handler(Task task, MessageId id, Message message)
{
messageType_t lMsgType = MSGTYPE_UNKNOWN;
/* Get the origin of the message*/
lMsgType = headsetGetMessageType(id);
/* Handle the message with the appropriate handler */
switch ( lMsgType )
{
case (MSGTYPE_CL):
handleCLMessage(task, id, message);
break;
case (MSGTYPE_HFP):
handleHFPMessage(task, id, message);
break;
case (MSGTYPE_HS):
handleHSMessage(task, id, message);
break;
case (MSGTYPE_UE):
handleUEMessage(task, id, message);
break;
default:
break;
}
#ifdef TEST_HARNESS
if ((lMsgType == MSGTYPE_CL)||(lMsgType == MSGTYPE_HFP))
test_handle_lib_message(task, id, message);
#endif
}
/* The Headset Application starts here...*/
int main(void)
{
DEBUG (("Main [%s]\n",__TIME__));
/*the internal regs must be latched on (smps and LDO)*/
/*set the feature bits - these will be overwitten on configuration*/
theHeadset.features.PowerOnSMPS = TRUE ;
theHeadset.features.PowerOnLDO = TRUE ;
LEDManagerSetPowerPin ( &theHeadset , POWER_ON ) ;
/* Set up the Application task handler */
theHeadset.task.handler = app_handler;
/* Initialise headset state */
theHeadset.profile_connected = hfp_no_profile;
theHeadset.hfp = NULL;
theHeadset.hsp = NULL;
/* Initialise the Connection Library */
ConnectionInit(&theHeadset.task);
#ifdef TEST_HARNESS
test_register(&theHeadset.task);
#endif
/* Start the message scheduler loop */
MessageLoop();
/* Never get here...*/
return 0;
}
#ifdef DEBUG_MESSAGES
#define DEBUG_MSG(x) DEBUG(x)
#else
#define DEBUG_MSG(x)
#endif
/*Determine the origin of the message*/
static messageType_t headsetGetMessageType (MessageId pMsg )
{
messageType_t lMsgType = MSGTYPE_UNKNOWN ;
/* determine the message type based on base and offset */
if ( ( pMsg >= EVENTS_EVENT_BASE ) && ( pMsg <= EVENTS_LAST_EVENT ) )
{
/* Message is a User Generated Event */
lMsgType = MSGTYPE_UE ;
DEBUG_MSG (( "HS: MT UE [%x]\n", pMsg ));
}
if ( (pMsg >= CL_MESSAGE_BASE) && (pMsg <= CL_MESSAGE_TOP) )
{
lMsgType = MSGTYPE_CL ;
DEBUG_MSG (( "HS: MT CL [%x]\n", pMsg ));
}
if ( (pMsg >= HFP_MESSAGE_BASE ) && (pMsg <= HFP_EXTRA_INDICATOR_UPDATE_IND) )
{
lMsgType = MSGTYPE_HFP ;
DEBUG_MSG (( "HS: MT HFP [%x]\n", pMsg ));
}
if ( (pMsg >= HEADSET_MSG_BASE ) && (pMsg <= HEADSET_MESSAGE_TOP) )
{
lMsgType = MSGTYPE_HS ;
DEBUG_MSG (( "HS: MT HS [%x]\n", pMsg ));
}
/* This message is not one of the above */
if (lMsgType == MSGTYPE_UNKNOWN)
{
/* Pass this message to default handler */
DEBUG_MSG(("MSGTYPE ? [%x]\n", pMsg)) ;
}
return lMsgType ;
}
#ifdef DEBUG_MALLOC
#define MA_DEBUG(x) DEBUG(x)
#else
#define MA_DEBUG(x)
#endif
void * mallocPanic ( size_t pSize )
{
static uint16 lSize = 0 ;
static uint16 lCalls = 0 ;
void * lResult;
lCalls++ ;
lSize += pSize ;
MA_DEBUG(("HS :n[%d] s[%d] t[%d]\n",lCalls, pSize, lSize));
lResult = malloc ( pSize ) ;
/*and panic if the malloc fails*/
if ( lResult == NULL )
{
MA_DEBUG(("MA : !\n")) ;
Panic() ;
}
return lResult ;
}
/*************************************************************************
NAME
handleHFPStatusCFM
DESCRIPTION
Handles a status response from the HFP and sends an error message if one was received
RETURNS
*/
static void handleHFPStatusCFM ( hsTaskData * theHeadset , hfp_lib_status pStatus )
{
if (pStatus != hfp_success )
{
MAIN_DEBUG(("HS: HFP CFM Err [%d]\n" , pStatus)) ;
MessageSend ( &theHeadset->task , EventError , 0 ) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -