📄 hf_demo_app.c
字号:
printf(" 7) Call specified phone number\n");
printf(" 8) Answer incoming call\n");
printf(" 9) Reject incoming call\n");
#ifdef ENABLE_UNPLUGGED
printf(" a) Mic volume increase\n");
printf(" A) Mic volume decrease\n");
printf(" b) Speaker volume increase\n");
printf(" B) Speaker volume decrease\n");
printf(" c) Calling line identification (Clip)\n");
printf(" C) Last number redial\n");
printf(" d) Enable/disable CIEV commands from HFG\n");
printf(" h) AT-command prompt\n");
printf(" i) Operator network name\n");
printf(" j) Query subscriber number information\n");
printf(" k) Enhanced call handling menu\n");
printf(" l) Query list of current calls\n");
printf(" m) Show response and hold options\n");
printf(" q) Extended audio gateway error codes\n");
printf(" v) Voice recognition on/off\n");
#endif
printf(" s) Send C2C initialisation command (CSR2CSR)\n");
printf(" S) Request SMS (CSR2CSR)\n");
printf(" t) Toggle Active connection\n");
#ifdef ENABLE_SHUTDOWN
printf(" r) Restart application and scheduler\n");
#endif
printf(" u) Increase battery level (CSR2CSR)\n");
printf(" U) Decrease battery level (CSR2CSR)\n");
printf(" w) Send power status: Battery powered (CSR2CSR)\n");
printf(" W) Send power status: Externally powered (CSR2CSR)\n");
printf(" x) Send AT+CSR=(1,1),(2,1),(3,1),(4,1),(5,1) command (CSR2CSR)\n");
printf(" X) Send AT+CSR=(1,0),(2,0),(3,0),(4,0),(5,0) command (CSR2CSR)\n");
}
void playResponseAndHoldOptions(DemoInstdata_t * instData)
{
printf("\nResponse and hold options:\n");
printf(" p) Query response and hold status\n");
printf(" o) Put incoming call on hold\n");
printf(" n) Accept incoming call on hold\n");
printf(" N) Reject incoming call on hold\n");
}
void playSubMenuAT(DemoInstdata_t * instData)
{
printf("\n\nENTER COMMAND (Q to quit):\n..>");
}
void playSubMenuCallHandling(DemoInstdata_t *instData)
{
printf("\n\nCall Handling: \n");
printf("Options: \n");
printf(" a) List active and held calls\n");
printf(" b) Specify call\n");
printf(" c) .... back to main\n");
printf("\n");
printf("Actions for calls: \n");
printf(" 0) Release all held calls(or set UDUB)\n");
printf(" 1) Release all active calls and accept held or waiting\n");
printf(" 2) Place all active calls on hold and accept held or waiting\n");
printf(" 3) Add held call to conversation\n");
printf(" 4) Connect two calls and disconnect from both (Explicit Call Transfer)\n");
if(instData->selectedCall.specified)
{
printf("\nThe call specified for the following is (%i) \n", instData->selectedCall.index);
printf(" 5) Release specified call\n");
printf(" 6) Request private consultation with specified call\n");
}
}
void playCalls(DemoInstdata_t *instData)
{
printf("Querying List of Current Calls\n");
printf("ID:\tStatus:\tNumber\n");
appSendATCLCC();
}
void playIntro(DemoInstdata_t * instData)
{
switch(instData->cliState)
{
case cliMainMenu:
{
playMenu(instData);
break;
}
case cliSubMenuAT:
{
playSubMenuAT(instData);
break;
}
case cliSubMenuCallHandling:
{
playSubMenuCallHandling(instData);
break;
}
default:
{
printf("No menu to display - grave error");
/* unexpected cli state received */
}
}
}
void passkeyHandler(DemoInstdata_t *instData)
{
BchsKeyPress_t *key;
key = (BchsKeyPress_t*)instData->recvMsgP;
if (key->key == RETURN_KEY)
{
if (instData->passkeyLength == 0)
{
ScPasskeyResSend(FALSE, &(instData->bondingDevAddr), instData->passkeyLength, instData->passkey, TRUE, TRUE);
}
else
{
ScPasskeyResSend(TRUE, &(instData->bondingDevAddr), instData->passkeyLength, instData->passkey, TRUE, TRUE);
}
instData->state = idle;
printf("\n");
}
else if (key->key == BACKSPACE_KEY)
{
if (instData->passkeyLength > 0)
{
instData->passkeyLength--;
printf("\b \b");
}
}
else if ((key->key >= 32) && (key->key < 127))
{
if (instData->passkeyLength < 16)
{
instData->passkey[instData->passkeyLength++] = key->key;
printf("%c", key->key);
}
}
else
{
;
}
}
void phoneNumberHandler(DemoInstdata_t * instData)
{
BchsKeyPress_t *key;
key = (BchsKeyPress_t*)instData->recvMsgP;
if (key->key == RETURN_KEY)
{
if (instData->myPhoneNumber.length == 0)
{
printf("No phone to dial");
}
else
{
uint8_t *body;
char temp[5];
instData->myPhoneNumber.phoneNumber[instData->myPhoneNumber.length++] = ';';
instData->myPhoneNumber.phoneNumber[instData->myPhoneNumber.length++] = '\r';
body = pmalloc(instData->myPhoneNumber.length + 3);
sprintf(temp, "ATD");
memcpy(body, temp, 3);
memcpy(&body[3], instData->myPhoneNumber.phoneNumber, instData->myPhoneNumber.length);
HfAtCmdReqSend((uint8_t) (instData->myPhoneNumber.length + 3), body, HF_CONNECTION);
instData->myPhoneNumber.length = 0;
}
printf("\n");
instData->state = idle;
}
else if (key->key == BACKSPACE_KEY)
{
if (instData->myPhoneNumber.length > 0)
{
instData->myPhoneNumber.length--;
printf("\b \b");
}
}
else if ((key->key >= 32) && (key->key < 127))
{
if (instData->myPhoneNumber.length < 20)
{
instData->myPhoneNumber.phoneNumber[instData->myPhoneNumber.length++] = key->key;
printf("%c", key->key);
}
}
else
{
;
}
}
void ATCommandHandler(DemoInstdata_t * instData)
{
BchsKeyPress_t *key;
key = (BchsKeyPress_t*)instData->recvMsgP;
if (key->key == RETURN_KEY)
{
if (instData->myATCommand.ATCommandLen == 0)
{
printf("\n\nZero length command!\n\n..>");
}
else if(instData->myATCommand.ATCommandLen == 1 && instData->myATCommand.ATCommand[0] == 'Q')
{
instData->state = idle;
instData->cliState = cliMainMenu;
playIntro(instData);
instData->myATCommand.ATCommandLen = 0;
instData->myATCommand.ATCommand[0] = '\0';
}
else
{
uint8_t *body;
instData->myATCommand.ATCommand[instData->myATCommand.ATCommandLen++] = '\r';
instData->myATCommand.ATCommand[instData->myATCommand.ATCommandLen++] = '\0';
instData->myATCommand.ATCommandLen;
body = pmalloc(instData->myATCommand.ATCommandLen);
memcpy(&body[0], instData->myATCommand.ATCommand, instData->myATCommand.ATCommandLen);
HfAtCmdReqSend((uint8_t) (instData->myATCommand.ATCommandLen),body, HF_CONNECTION);
/*Reset command parameter*/
instData->myATCommand.ATCommandLen = 0;
instData->myATCommand.ATCommand[0] = '\0';
printf("\n..>");
}
}
else if (key->key == BACKSPACE_KEY)
{
if (instData->myATCommand.ATCommandLen > 0)
{
instData->myATCommand.ATCommandLen--;
printf("\b \b");
}
}
else if ((key->key >= 32) && (key->key < 127))
{
if (instData->myATCommand.ATCommandLen < 126)
{
instData->myATCommand.ATCommand[instData->myATCommand.ATCommandLen++] = key->key;
printf("%c", key->key);
}
}
else
{
;
}
}
static void initInstanceData(DemoInstdata_t * instData)
{
instData->conInstData[HF_CONNECTION].startup = STARTUP_MIC;
instData->conInstData[HS_CONNECTION].startup = STARTUP_MIC;
instData->conInstData[HF_CONNECTION].audioOn = FALSE;
instData->conInstData[HS_CONNECTION].audioOn = FALSE;
instData->conInstData[HF_CONNECTION].atState = sequence0;
instData->conInstData[HS_CONNECTION].atState = sequence0; /* Not used by HS */
instData->conInstData[HF_CONNECTION].speakerGain = 7;
instData->conInstData[HS_CONNECTION].speakerGain = 7;
instData->conInstData[HF_CONNECTION].micGain = 7;
instData->conInstData[HS_CONNECTION].micGain = 7;
instData->conInstData[HF_CONNECTION].voiceRecognition = FALSE;
instData->conInstData[HS_CONNECTION].voiceRecognition = FALSE; /* Not used by HS*/
instData->conInstData[HF_CONNECTION].linkState = disconnected_s;
instData->conInstData[HS_CONNECTION].linkState = disconnected_s;
instData->conInstData[HF_CONNECTION].threeWayCallingSupported = FALSE;
instData->conInstData[HS_CONNECTION].threeWayCallingSupported = FALSE; /* Not Used by HS */
instData->conInstData[HF_CONNECTION].atResultCounter = 0;
instData->conInstData[HS_CONNECTION].atResultCounter = 0; /* Not used by HS */
instData->conInstData[HF_CONNECTION].scoHandle = SCO_HANDLE_UNUSED;
instData->conInstData[HS_CONNECTION].scoHandle = SCO_HANDLE_UNUSED;
instData->conInstData[HF_CONNECTION].cmerStatus= TRUE;
instData->conInstData[HS_CONNECTION].cmerStatus = FALSE;
instData->conInstData[HF_CONNECTION].supportedFeatures = (HF_SUPPORT_CALL_WAITING_THREE_WAY_CALLING |
HF_SUPPORT_CLI_PRESENTATION_CAPABILITY |
HF_SUPPORT_REMOTE_VOLUME_CONTROL);
instData->conInstData[HS_CONNECTION].supportedFeatures = 1;
MemSet(&instData->conInstData[HF_CONNECTION].bdAddr, 0, sizeof(deviceAddr_t));
MemSet(&instData->conInstData[HS_CONNECTION].bdAddr, 0, sizeof(deviceAddr_t));
instData->conInstData[HF_CONNECTION].cmeErrorCodes = '0';
instData->conInstData[HS_CONNECTION].cmeErrorCodes = '0';
instData->currentConnection = NO_CONNECTION;
instData->myPhoneNumber.length = 0;
instData->myPhoneNumber.phoneNumber[0] = '\0';
instData->passkeyLength = 0;
instData->myATCommand.ATCommandLen = 0;
instData->myATCommand.ATCommand[0] = '\0';
instData->state = idle;
instData->preState = idle;
instData->cliState = cliMainMenu;
instData->selectedCall.specified = FALSE;
instData->selectedCall.index = 0;
instData->batteryLevel = 5;
#ifdef _BCHS_EXTERNAL_
instData->app_hdl = peer_get_external_qid(TESTQUEUE);
#else
instData->app_hdl = TESTQUEUE;
#endif
ScActivateReqSend(instData->app_hdl);
}
/**************************************************************************************************
*
* init function called by the scheduler upon initialisation. This function is used to boot
* the demo application by sending a request to bond with the headset. Bonding is not mandated
* according to the profile but is needed if encryption of the speech is required.
*
**************************************************************************************************/
void init_test(void **gash)
{
extern BD_ADDR_T defGlobalBdAddr;
deviceAddr_t zeroAddr;
DemoInstdata_t * instData;
*gash = (void *) pmalloc (sizeof(DemoInstdata_t));
instData = (DemoInstdata_t *) * gash;
initInstanceData(instData);
MemSet(&zeroAddr, 0, sizeof(deviceAddr_t));
if (!BdAddrEq(&defGlobalBdAddr, &zeroAddr))
{
instData->bondingDevAddr.lap = defGlobalBdAddr.lap;
instData->bondingDevAddr.nap = defGlobalBdAddr.nap;
instData->bondingDevAddr.uap = defGlobalBdAddr.uap;
}
else
{
instData->bondingDevAddr.lap = 0;
instData->bondingDevAddr.nap = 0;
instData->bondingDevAddr.uap = 0;
}
HfActivateExtReqSend(instData->app_hdl, instData->conInstData[HF_CONNECTION].supportedFeatures, TRUE);
instData->serverActivated = TRUE;
timed_event_in(KEYB_CHECK_TIMEOUT, KeyMessageService, 0, NULL);
playIntro(instData);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -