hfp: send DTMF codes

This commit is contained in:
Matthias Ringwald 2015-11-28 11:25:10 +01:00
parent 26fa4657e8
commit 6d6770b5f9
4 changed files with 44 additions and 0 deletions

View File

@ -563,6 +563,7 @@ typedef struct hfp_connection {
uint8_t hf_send_chld_2;
uint8_t hf_send_chld_3;
uint8_t hf_send_chld_4;
char hf_send_dtmf_code;
uint8_t hf_activate_call_waiting_notification;
uint8_t hf_deactivate_call_waiting_notification;

View File

@ -304,6 +304,12 @@ static int hfp_hf_send_chld(uint16_t cid, int number){
return send_str_over_rfcomm(cid, buffer);
}
static int hfp_hf_send_dtmf(uint16_t cid, char code){
char buffer[20];
sprintf(buffer, "AT%s=%c\r\n", HFP_TRANSMIT_DTMF_CODES, code);
return send_str_over_rfcomm(cid, buffer);
}
static void hfp_emit_ag_indicator_event(hfp_callback_t callback, int status, hfp_ag_indicator_t indicator){
if (!callback) return;
uint8_t event[6+HFP_MAX_INDICATOR_DESC_SIZE+1];
@ -664,6 +670,14 @@ static void hfp_run_for_context(hfp_connection_t * context){
return;
}
if (context->hf_send_dtmf_code){
char code = context->hf_send_dtmf_code;
context->hf_send_dtmf_code = 0;
context->ok_pending = 1;
hfp_hf_send_dtmf(context->rfcomm_cid, code);
return;
}
if (done) return;
// deal with disconnect
switch (context->state){
@ -1261,3 +1275,12 @@ void hfp_hf_set_speaker_gain(bd_addr_t bd_addr, int gain){
hfp_run_for_context(connection);
}
/*
* @brief
*/
void hfp_hf_send_dtmf_code(bd_addr_t bd_addr, char code){
hfp_hf_establish_service_level_connection(bd_addr);
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
connection->hf_send_dtmf_code = code;
hfp_run_for_context(connection);
}

View File

@ -255,6 +255,11 @@ void hfp_hf_set_microphone_gain(bd_addr_t bd_addr, int gain);
*/
void hfp_hf_set_speaker_gain(bd_addr_t bd_addr, int gain);
/*
* @brief
*/
void hfp_hf_send_dtmf_code(bd_addr_t bd_addr, char code);
/* API_END */
#if defined __cplusplus

View File

@ -150,6 +150,7 @@ static void show_usage(void){
printf("V - Join held call (Three-Way Call 3)\n");
printf("w - Connect calls (Three-Way Call 4)\n");
printf("W - redial\n");
printf("0123456789#*-+ - send DTMF dial tones\n");
printf("---\n");
printf("Ctrl-c - exit\n");
@ -158,7 +159,21 @@ static void show_usage(void){
static int stdin_process(struct data_source *ds){
read(ds->fd, &cmd, 1);
if (cmd >= '0' && cmd <= '9'){
printf("DTMF Code: %c\n", cmd);
hfp_hf_send_dtmf_code(device_addr, cmd);
return 0;
}
switch (cmd){
case '#':
case '-':
case '+':
case '*':
printf("DTMF Code: %c\n", cmd);
hfp_hf_send_dtmf_code(device_addr, cmd);
break;
case 'a':
printf("Establish Service level connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr));
hfp_hf_establish_service_level_connection(device_addr);