📄 hfp_handler.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.4.2-release
FILE NAME
hfp_handler.c
DESCRIPTION
HFP handler.
*/
/****************************************************************************
Header files
*/
#include "headset_private.h"
#include "cvc_headset.h"
#include "headset_common.h"
#include "headset_tones.h"
#include "hfp_handler.h"
#include "hfp_audio.h"
#include "headset_volume.h"
#include <hfp.h>
#include <panic.h>
#ifdef DEBUG_HFP
#define HFP_DEBUG(x) DEBUG(x)
#else
#define HFP_DEBUG(x)
#endif
/*****************************************************************************/
void hfpHeadsetAnswerCall(const headsetTaskData *app)
{
/*
Call the HFP lib function, this will determine the AT cmd to send
depending on whether the profile instance is HSP or HFP compliant.
*/
HfpAnswerCall(app->hfp);
}
/*****************************************************************************/
void hfpHeadsetRejectCall(const headsetTaskData *app)
{
/* Reject incoming call - only valid for instances of HFP */
HfpRejectCall(app->hfp);
}
/*****************************************************************************/
void hfpHeadsetHangUpCall(const headsetTaskData *app)
{
/* Terminate the current ongoing call process */
HfpTerminateCall(app->hfp);
}
/*****************************************************************************/
void hfpHeadsetLastNumberRedial(const headsetTaskData *app)
{
/* Issue a redial request to the HFP lib */
HfpLastNumberRedial(app->hfp);
}
/*****************************************************************************/
void hfpHeadsetHandleVoiceRecognitionInd(headsetTaskData *app, const HFP_VOICE_RECOGNITION_IND_T *ind)
{
/* Update the local flag */
app->voice.voice_recognition_enabled = ind->enable;
app->voice.old_voice_recognition_enabled = app->voice.voice_recognition_enabled;
#ifdef INCLUDE_CVC
CvcSetMode(app);
#endif
}
/*****************************************************************************/
void hfpHeadsetVoiceRecognitionEnable(headsetTaskData *app, uint16 enable)
{
/*
Check the current status of the voice recognition and change it
Here, we're working under the assumption that the cmd succeeds so
we update the flag before we've received the cfm.
*/
/* Send the cmd to the AG */
HfpVoiceRecognitionEnable(app->hfp, enable);
HFP_DEBUG(("HFP: Sent voice enable %d to AG\n",enable));
#ifdef INCLUDE_CVC
CvcSetMode(app);
#endif
}
/*****************************************************************************/
void hfpHeadsetHandleVoiceRecognitionCfm(headsetTaskData *app, const HFP_VOICE_RECOGNITION_ENABLE_CFM_T *cfm)
{
/* If the cmd succeeds we've got the flag set to the right state anyway */
if (cfm->status == hfp_fail)
{
/* Voice recognition cmd not accepted - change the state to what it was */
app->voice.voice_recognition_enabled = app->voice.old_voice_recognition_enabled;
headsetPlayTone(app, tone_type_error);
#ifdef INCLUDE_CVC
CvcSetMode(app);
#endif
}
else
{
/* Voice recognition cmd was accepted - update the old state */
app->voice.old_voice_recognition_enabled = app->voice.voice_recognition_enabled;
}
}
/*****************************************************************************/
void hfpHeadsetHandleCallIndicator(headsetTaskData *app, const HFP_CALL_IND_T *ind)
{
HFP_DEBUG(("HFP: Call Ind = %d\n",ind->call));
if (ind->call)
{
/* Active call */
setHfpState(app, headsetActiveCall);
#ifdef INCLUDE_CVC
if (app->voice.voice_recognition_enabled)
CvcSetMode(app);
#endif
/* Deal with the case where a phone has a SCO link open during an incoming call
but doesn't support inband ring tones */
if (app->sco_sink && ((isRingTone(app->pcm_audio_state))||(isTonePlaying(app->pcm_audio_state))))
{
if (!isTonePlaying(app->pcm_audio_state))
setPcmState(app, pcm_sco);
(void) hfpSetupScoRouting(app);
}
}
else
{
/* If an active call has been released update state accordingly */
if (app->hfp_state == headsetActiveCall)
{
setHfpState(app, headsetConnected);
HFP_DEBUG(("HFP: state connected\n"));
headsetPlayTone(app, tone_type_call_end);
}
}
}
/*****************************************************************************/
void hfpHeadsetHandleCallSetupIndicator(headsetTaskData *app, const HFP_CALL_SETUP_IND_T *ind)
{
headsetHfpState old_hfp_state = app->hfp_state;
headsetHfpState new_hfp_state;
/* Update the local state according to the value in this indicator */
HFP_DEBUG(("HFP: Call Setup Ind = %d\n",ind->call_setup));
HFP_DEBUG(("HFP: old hfp_state = %d\n",app->hfp_state));
switch (ind->call_setup)
{
case hfp_no_call_setup:
if (app->hfp_state != headsetActiveCall && app->hfp_state != headsetConnecting)
setHfpState(app, headsetConnected);
break;
case hfp_incoming_call_setup:
if (app->hfp_state != headsetActiveCall)
{
setHfpState(app, headsetIncomingCallEstablish);
app->active_profile = hfp_active;
}
break;
case hfp_outgoing_call_setup:
case hfp_outgoing_call_alerting_setup:
setHfpState(app, headsetOutgoingCallEstablish);
break;
default:
/* Invalid call setup indicator value received. */
HFP_DEBUG(("HFP: PANIC!\n"));
Panic();
}
HFP_DEBUG(("HFP: new hfp_state = %d\n",app->hfp_state));
new_hfp_state = app->hfp_state;
if ((old_hfp_state == headsetIncomingCallEstablish) && (new_hfp_state == headsetConnected))
{
headsetPlayTone(app, tone_type_call_end);
/* Noone answered a locally generated ring tone so restart AV if necessary */
headsetRestartAV(app);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -