hf_demo_app.c
来自「BlueTooth Host Software HandFree相关的lib/a」· C语言 代码 · 共 1,754 行 · 第 1/5 页
C
1,754 行
}
#ifdef ENABLE_SHUTDOWN
void deinit_test(void **gash)
{
DemoInstdata_t * instData;
uint16 msg_type;
void *msg_data;
instData = (DemoInstdata_t *) *gash;
/* get a message from the demoapplication message queue. The message is returned in prim
and the event type in eventType */
while ( get_message(TESTQUEUE, &msg_type, &msg_data) )
{
switch (msg_type)
{
case HF_PRIM:
{
HfPrim_t *primType;
primType = (HfPrim_t *) msg_data;
switch (*primType)
{
case HF_AT_CMD_IND:
{
HF_AT_CMD_IND_T *prim;
prim = (HF_AT_CMD_IND_T *) msg_data;
pfree(prim->payload);
break;
}
}
break;
}
}
pfree(msg_data);
}
pfree (instData);
}
#endif
/**************************************************************************************************
*
* this is the demo application handler function. All primitives sent to the demo application will
* be received in here. The scheduler ensures that the function is activated when a signal is put
* on the demo application signal queue.
*
**************************************************************************************************/
void test_handler(void **gash)
{
DemoInstdata_t * instData;
uint16_t eventType;
void * prim;
instData = (DemoInstdata_t *) *gash;
/* get a message from the demoapplication message queue. The message is returned in prim
and the event type in eventType */
get_message(TESTQUEUE, &eventType, &prim);
instData->recvMsgP = prim;
/* two event types must be handled. SC for bonding and AG for the connection and audio
related signalling */
switch (eventType)
{
case SC_PRIM:
{
handleScPrim(instData);
break;
}
case HF_PRIM:
{
handleHfPrim(instData);
break;
}
case CM_PRIM:
{
handleCmPrim(instData);
break;
}
case KEY_MESSAGE:
{
handleKeybPrim(instData);
break;
}
case ENV_PRIM:
{
EnvPrim_t *primType;
primType = (EnvPrim_t *) prim;
if(*primType == ENV_CLEANUP_IND)
{
printf("(Environment cleanup indication received)\n");
initInstanceData(instData);
/* Should exit, but cannot complete cleanup when the profile is also running in userspace */
}
break;
}
default:
{
/* unexpected primitive received */
printf("####### default in testhandler %x,\n",eventType);
}
} /* end switch(eventType) */
/* free the received signal again. If the signal for some reason
* must be stored in the application the pointer (prim) must be
* set to NULL in order not to free it here */
pfree(prim);
}
/**************************************************************************************************
*
* an Hfg event is received.
*
**************************************************************************************************/
void handleHfPrim(DemoInstdata_t * instData)
{
HfPrim_t *prim;
uint16_t *primType;
void * thePrim = instData->recvMsgP;
prim = (HfPrim_t *) thePrim;
primType = (uint16_t *) prim;
switch (*primType)
{
case HF_MAP_SCO_PCM_IND:
{
HF_MAP_SCO_PCM_IND_T *hfPrim;
hfPrim = (HF_MAP_SCO_PCM_IND_T *)primType;
HfMapScoPcmResSend(hfPrim->connectionType, PCM_SLOT, PCM_SLOT_REALLOCATE);
break;
}
case HF_DEACTIVATE_CFM:
{
playIntro(instData);
initInstanceData(instData);
instData->serverActivated = FALSE;
break;
}
case HF_DISCONNECT_IND:
{
HF_DISCONNECT_IND_T *prim;
prim = (HF_DISCONNECT_IND_T *) thePrim;
instData->conInstData[prim->connectionType].startup = STARTUP_MIC;
instData->conInstData[prim->connectionType].audioOn = FALSE;
instData->conInstData[prim->connectionType].atState = sequence0;
instData->conInstData[prim->connectionType].linkState = disconnected_s;
if (instData->conInstData[prim->connectionType].scoHandle != SCO_HANDLE_UNUSED)
{
/* if we receive disconnect without receiving HFG_AUDIO_IND (Audio Off) */
deRegisterScoHandle(instData->conInstData[prim->connectionType].scoHandle);
}
if (instData->currentConnection == prim->connectionType)
{
if (prim->connectionType == HF_CONNECTION)
{
if (instData->conInstData[HS_CONNECTION].linkState == connected_s)
{
instData->currentConnection = HS_CONNECTION;
}
else
{
instData->currentConnection = NO_CONNECTION;
}
}
else if (prim->connectionType == HS_CONNECTION)
{
if (instData->conInstData[HF_CONNECTION].linkState == connected_s)
{
instData->currentConnection = HF_CONNECTION;
}
else
{
instData->currentConnection = NO_CONNECTION;
}
}
}
/* this was not the active connection */
playIntro(instData);
if (prim->result == ABNORMAL_LINK_DISCONNECT)
{
printf("Link lost to %s\n", (prim->connectionType == HF_CONNECTION ? "HF" : "HS"));
}
else
{
printf("Disconnect ind received from: %s\n", prim->connectionType == HF_CONNECTION ? "Handsfree Gateway\0" : "Audio Gateway\0");
}
break;
}
case HF_AUDIO_EXT_IND:
{
HF_AUDIO_EXT_IND_T *prim;
prim = (HF_AUDIO_EXT_IND_T *) thePrim;
instData->conInstData[prim->connectionType].audioOn = prim->audioOn;
printf("%s Audio is %s (%i)\n", getHfHsString(prim->connectionType), (prim->audioOn ? "ON" : "OFF"), prim->linkType);
instData->conInstData[prim->connectionType].scoHandle = prim->scoHandle;
if (prim->audioOn)
{
RegisterScoHandle(prim->scoHandle,inComingBcspSound);
}
else
{
deRegisterScoHandle(instData->conInstData[prim->connectionType].scoHandle);
}
break;
}
case HF_SERVICE_CONNECT_IND:
{
HF_SERVICE_CONNECT_IND_T *myPrim;
myPrim = (HF_SERVICE_CONNECT_IND_T *) thePrim;
if (myPrim->result == SUCCESS)
{
if (myPrim->connectionType == HF_CONNECTION)
{
printf("Service level connection esatblished to: %s\n", myPrim->serviceName);
/* Send microphone level */
if(instData->conInstData[myPrim->connectionType].startup == STARTUP_MIC)
{
timed_event_in(SECOND*2,
startup_mic_gain,
myPrim->connectionType,
instData);
}
}
else
{
printf("Headset connected to %s\n", myPrim->serviceName);
}
instData->currentConnection = myPrim->connectionType;
instData->conInstData[myPrim->connectionType].bdAddr.lap = myPrim->deviceAddr.lap;
instData->conInstData[myPrim->connectionType].bdAddr.uap = myPrim->deviceAddr.uap;
instData->conInstData[myPrim->connectionType].bdAddr.nap = myPrim->deviceAddr.nap;
instData->conInstData[myPrim->connectionType].linkState = connected_s;
#ifdef ADVANCED_HF
if (myPrim->connectionType == HF_CONNECTION)
{
instData->conInstData[myPrim->connectionType].threeWayCallingSupported =
(myPrim->supportedFeatures & HFG_SUPPORT_THREE_WAY_CALLING) ? TRUE : FALSE;
if (instData->conInstData[myPrim->connectionType].atState == sequence0)
appSendBrsf(HF_SUPPORT_CLI_PRESENTATION_CAPABILITY);
instData->conInstData[myPrim->connectionType].atState = sequence1;
instData->conInstData[myPrim->connectionType].atResultCounter = 0;
}
}
#endif
}
else
{
printf("Service level connect req. failed, code: %i\n", myPrim->result);
instData->state = idle;
}
break;
}
case HF_STATUS_IND:
{
HF_STATUS_IND_T *myPrim;
myPrim = (HF_STATUS_IND_T *) thePrim;
if (instData->state == idle)
{
/* only print if app is in idle state */
printf("%s Link status: %d\n", getHfHsString(myPrim->connectionType), myPrim->statusEvent);
}
if (myPrim->statusEvent == LINK_STATUS_DISCONNECTED)
{
instData->conInstData[myPrim->connectionType].atState = sequence0;
instData->conInstData[myPrim->connectionType].linkState = disconnected_s;
}
break;
}
#ifndef ADVANCED_HF
/* ADVANCED_HF is _not_ set. This means that the HF
* profile will parse the AT-commands and deliver
* high-level pre-parsed and validated signals to use */
case HF_SPEAKER_GAIN_IND:
{
HF_SPEAKER_GAIN_IND_T *myPrim;
myPrim = (HF_SPEAKER_GAIN_IND_T *) thePrim;
printf("%s Speaker vol change to: %i\n", getHfHsString(myPrim->connectionType), myPrim->gain);
instData->conInstData[myPrim->connectionType].speakerGain = myPrim->gain;
break;
}
case HF_MIC_GAIN_IND:
{
HF_MIC_GAIN_IND_T *myPrim;
myPrim = (HF_MIC_GAIN_IND_T *) thePrim;
printf("%s Mic vol change to: %i\n", getHfHsString(myPrim->connectionType), myPrim->gain);
instData->conInstData[myPrim->connectionType].micGain = myPrim->gain;
break;
}
case HF_RING_IND:
{
printf("Ring received\n");
break;
}
case HF_CIEV_IND:
{
HF_CIEV_IND_T * prim;
prim = (HF_CIEV_IND_T *) thePrim;
printf("CIEV_IND: %s = %d\n", prim->name, prim->value);
break;
}
case HF_BTRH_IND:
{
HF_BTRH_IND_T *prim;
prim = (HF_BTRH_IND_T *) thePrim;
printf("\nResponse and hold status: %c\n", prim->value);
switch(prim->value)
{
case '0':
{
printf(" - Incoming call on hold\n");
break;
}
case '1':
{
printf(" - Held incoming call accepted\n");
break;
}
case '2':
{
printf(" - Held incoming call rejected\n");
break;
}
default:
{
printf("... error in btrh indication - unspecified value received\n");
}
}
break;
}
case HF_CLCC_IND:
{
HF_CLCC_IND_T *prim;
uint8_t *type;
prim = (HF_CLCC_IND_T *) thePrim;
printf("Call in AG\n\n");
printf("Param idx %i\n",prim->idx);
printf("Param status %i\n",prim->status);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?