From 674ebed504c4f20ba888c073ba42beef8ed31266 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 16 Jul 2021 16:15:44 +0200 Subject: [PATCH] hfp: emit call answered and terminated events --- example/hfp_ag_demo.c | 16 ++++++++++------ example/hfp_hf_demo.c | 5 +++++ src/classic/hfp_ag.c | 2 +- src/classic/hfp_ag.h | 2 +- src/classic/hfp_hf.c | 10 +++++++++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/example/hfp_ag_demo.c b/example/hfp_ag_demo.c index c62cbfd6c..fbcf0a7b5 100644 --- a/example/hfp_ag_demo.c +++ b/example/hfp_ag_demo.c @@ -160,7 +160,7 @@ static void show_usage(void){ printf("c - simulate incoming call from 1234567 | C - simulate call from 1234567 dropped\n"); printf("d - report AG failure\n"); printf("D - delete all link keys\n"); - printf("e - answer call on AG | E - reject call on AG\n"); + printf("e - answer call on AG | E - terminate call on AG\n"); printf("r - disable in-band ring tone | R - enable in-band ring tone\n"); printf("f - Disable cellular network | F - Enable cellular network\n"); printf("g - Set signal strength to 0 | G - Set signal strength to 5\n"); @@ -247,7 +247,7 @@ static void stdin_process(char cmd){ break; case 'E': log_info("USER:\'%c\'", cmd); - printf("Reject call on AG\n"); + printf("Terminate call on AG\n"); hfp_ag_terminate_call(); break; case 'f': @@ -559,9 +559,15 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even hci_request_sco_can_send_now_event(); } break; + + case HFP_SUBEVENT_CALL_ANSWERED: + printf("Call answered\n"); + break; + case HFP_SUBEVENT_CALL_TERMINATED: printf("Call terminated\n"); break; + case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED: printf("Audio connection released\n"); sco_handle = HCI_CON_HANDLE_INVALID; @@ -595,14 +601,12 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even printf("Attach number to voice tag. Sending '1234567\n"); hfp_ag_send_phone_number_for_voice_tag(acl_handle, "1234567"); break; + case HFP_SUBEVENT_TRANSMIT_DTMF_CODES: printf("Send DTMF Codes: '%s'\n", hfp_subevent_transmit_dtmf_codes_get_dtmf(event)); hfp_ag_send_dtmf_code_done(acl_handle); break; - case HFP_SUBEVENT_CALL_ANSWERED: - printf("Call answered by HF\n"); - break; - + case HFP_SUBEVENT_VOICE_RECOGNITION_STATUS: status = hfp_subevent_voice_recognition_status_get_status(event); if (status != ERROR_CODE_SUCCESS){ diff --git a/example/hfp_hf_demo.c b/example/hfp_hf_demo.c index a47d80bf2..79a75d3d0 100644 --- a/example/hfp_hf_demo.c +++ b/example/hfp_hf_demo.c @@ -528,6 +528,11 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even hci_request_sco_can_send_now_event(); } break; + + case HFP_SUBEVENT_CALL_ANSWERED: + printf("Call answered\n"); + break; + case HFP_SUBEVENT_CALL_TERMINATED: printf("Call terminated\n"); break; diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c index df73c5b02..fa832b963 100644 --- a/src/classic/hfp_ag.c +++ b/src/classic/hfp_ag.c @@ -1634,7 +1634,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * hfp_con default: break; } - hfp_emit_simple_event(hfp_connection, HFP_SUBEVENT_CALL_TERMINATED); break; case HFP_AG_TERMINATE_CALL_BY_AG: @@ -1823,6 +1822,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * hfp_con hfp_ag_transfer_callheld_state(); } hfp_ag_hf_stop_ringing(hfp_connection); + hfp_emit_simple_event(hfp_connection, HFP_SUBEVENT_CALL_ANSWERED); break; } diff --git a/src/classic/hfp_ag.h b/src/classic/hfp_ag.h index 23a20a51d..be562fe3c 100644 --- a/src/classic/hfp_ag.h +++ b/src/classic/hfp_ag.h @@ -416,7 +416,7 @@ void hfp_ag_outgoing_call_ringing(void); void hfp_ag_outgoing_call_established(void); /** - * @brief Pass the call droped event to the AG. + * @brief Pass the call dropped event to the AG. */ void hfp_ag_call_dropped(void); diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c index 57535f17e..4410496cb 100644 --- a/src/classic/hfp_hf.c +++ b/src/classic/hfp_hf.c @@ -1189,7 +1189,15 @@ static void hfp_hf_handle_transfer_ag_indicator_status(hfp_connection_t * hfp_co // avoid set but not used warning (void) hfp_hf_callheld_status; } else if (strcmp(hfp_connection->ag_indicators[i].name, "call") == 0){ - hfp_hf_call_status = (hfp_call_status_t) hfp_connection->ag_indicators[i].status; + hfp_call_status_t new_hf_call_status = (hfp_call_status_t) hfp_connection->ag_indicators[i].status; + if (hfp_hf_call_status != new_hf_call_status){ + if (new_hf_call_status == HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS){ + hfp_emit_simple_event(hfp_connection, HFP_SUBEVENT_CALL_TERMINATED); + } else { + hfp_emit_simple_event(hfp_connection, HFP_SUBEVENT_CALL_ANSWERED); + } + } + hfp_hf_call_status = new_hf_call_status; } hfp_connection->ag_indicators[i].status_changed = 0; hfp_emit_ag_indicator_event(hfp_connection, &hfp_connection->ag_indicators[i]);