From ac6f828ea67656d19dc26c69b555123740cccce2 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Tue, 29 Jun 2021 10:11:27 +0200 Subject: [PATCH] hfp: report status code --- example/hfp_ag_demo.c | 71 ++++++++++++++---------- example/hfp_hf_demo.c | 122 +++++++++++++++++++++++------------------- src/classic/hfp_ag.c | 4 +- 3 files changed, 112 insertions(+), 85 deletions(-) diff --git a/example/hfp_ag_demo.c b/example/hfp_ag_demo.c index 7141ca7bf..9537278e6 100644 --- a/example/hfp_ag_demo.c +++ b/example/hfp_ag_demo.c @@ -165,7 +165,7 @@ static void show_usage(void){ printf("l - Clear last number | L - Set last number\n"); printf("m - simulate incoming call from 7654321\n"); // printf("M - simulate call from 7654321 dropped\n"); - printf("n - Disable Voice Regocnition | N - Enable Voice Recognition\n"); + printf("n - Disable Voice Recognition | N - Enable Voice Recognition\n"); printf("o - Set speaker volume to 0 (minimum) | O - Set speaker volume to 9 (default)\n"); printf("p - Set speaker volume to 12 (higher) | P - Set speaker volume to 15 (maximum)\n"); printf("q - Set microphone gain to 0 (minimum) | Q - Set microphone gain to 9 (default)\n"); @@ -180,31 +180,33 @@ static void show_usage(void){ } static void stdin_process(char cmd){ + uint8_t status = ERROR_CODE_SUCCESS; + switch (cmd){ case 'a': log_info("USER:\'%c\'", cmd); printf("Establish HFP service level connection to %s...\n", bd_addr_to_str(device_addr)); - hfp_ag_establish_service_level_connection(device_addr); + status = hfp_ag_establish_service_level_connection(device_addr); break; case 'A': log_info("USER:\'%c\'", cmd); printf("Release HFP service level connection.\n"); - hfp_ag_release_service_level_connection(acl_handle); + status = hfp_ag_release_service_level_connection(acl_handle); break; case 'Z': log_info("USER:\'%c\'", cmd); printf("Release HFP service level connection to %s...\n", bd_addr_to_str(device_addr)); - hfp_ag_release_service_level_connection(acl_handle); + status = hfp_ag_release_service_level_connection(acl_handle); break; case 'b': log_info("USER:\'%c\'", cmd); printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr)); - hfp_ag_establish_audio_connection(acl_handle); + status = hfp_ag_establish_audio_connection(acl_handle); break; case 'B': log_info("USER:\'%c\'", cmd); printf("Release Audio connection.\n"); - hfp_ag_release_audio_connection(acl_handle); + status = hfp_ag_release_audio_connection(acl_handle); break; case 'c': log_info("USER:\'%c\'", cmd); @@ -230,7 +232,7 @@ static void stdin_process(char cmd){ case 'd': log_info("USER:\'%c\'", cmd); printf("Report AG failure\n"); - hfp_ag_report_extended_audio_gateway_error_result_code(acl_handle, HFP_CME_ERROR_AG_FAILURE); + status = hfp_ag_report_extended_audio_gateway_error_result_code(acl_handle, HFP_CME_ERROR_AG_FAILURE); break; case 'e': log_info("USER:\'%c\'", cmd); @@ -245,42 +247,42 @@ static void stdin_process(char cmd){ case 'f': log_info("USER:\'%c\'", cmd); printf("Disable cellular network\n"); - hfp_ag_set_registration_status(0); + status = hfp_ag_set_registration_status(0); break; case 'F': log_info("USER:\'%c\'", cmd); printf("Enable cellular network\n"); - hfp_ag_set_registration_status(1); + status = hfp_ag_set_registration_status(1); break; case 'g': log_info("USER:\'%c\'", cmd); printf("Set signal strength to 0\n"); - hfp_ag_set_signal_strength(0); + status = hfp_ag_set_signal_strength(0); break; case 'G': log_info("USER:\'%c\'", cmd); printf("Set signal strength to 5\n"); - hfp_ag_set_signal_strength(5); + status = hfp_ag_set_signal_strength(5); break; case 'h': log_info("USER:\'%c\'", cmd); printf("Disable roaming\n"); - hfp_ag_set_roaming_status(0); + status = hfp_ag_set_roaming_status(0); break; case 'H': log_info("USER:\'%c\'", cmd); printf("Enable roaming\n"); - hfp_ag_set_roaming_status(1); + status = hfp_ag_set_roaming_status(1); break; case 'i': log_info("USER:\'%c\'", cmd); printf("Set battery level to 3\n"); - hfp_ag_set_battery_level(3); + status = hfp_ag_set_battery_level(3); break; case 'I': log_info("USER:\'%c\'", cmd); printf("Set battery level to 5\n"); - hfp_ag_set_battery_level(5); + status = hfp_ag_set_battery_level(5); break; case 'j': log_info("USER:\'%c\'", cmd); @@ -315,52 +317,52 @@ static void stdin_process(char cmd){ case 'n': log_info("USER:\'%c\'", cmd); printf("Disable Voice Recognition\n"); - hfp_ag_activate_voice_recognition(acl_handle, 0); + status = hfp_ag_activate_voice_recognition(acl_handle, 0); break; case 'N': log_info("USER:\'%c\'", cmd); printf("Enable Voice Recognition\n"); - hfp_ag_activate_voice_recognition(acl_handle, 1); + status = hfp_ag_activate_voice_recognition(acl_handle, 1); break; case 'o': log_info("USER:\'%c\'", cmd); printf("Set speaker gain to 0 (minimum)\n"); - hfp_ag_set_speaker_gain(acl_handle, 0); + status = hfp_ag_set_speaker_gain(acl_handle, 0); break; case 'O': log_info("USER:\'%c\'", cmd); printf("Set speaker gain to 9 (default)\n"); - hfp_ag_set_speaker_gain(acl_handle, 9); + status = hfp_ag_set_speaker_gain(acl_handle, 9); break; case 'p': log_info("USER:\'%c\'", cmd); printf("Set speaker gain to 12 (higher)\n"); - hfp_ag_set_speaker_gain(acl_handle, 12); + status = hfp_ag_set_speaker_gain(acl_handle, 12); break; case 'P': log_info("USER:\'%c\'", cmd); printf("Set speaker gain to 15 (maximum)\n"); - hfp_ag_set_speaker_gain(acl_handle, 15); + status = hfp_ag_set_speaker_gain(acl_handle, 15); break; case 'q': log_info("USER:\'%c\'", cmd); printf("Set microphone gain to 0\n"); - hfp_ag_set_microphone_gain(acl_handle, 0); + status = hfp_ag_set_microphone_gain(acl_handle, 0); break; case 'Q': log_info("USER:\'%c\'", cmd); printf("Set microphone gain to 9\n"); - hfp_ag_set_microphone_gain(acl_handle, 9); + status = hfp_ag_set_microphone_gain(acl_handle, 9); break; case 's': log_info("USER:\'%c\'", cmd); printf("Set microphone gain to 12\n"); - hfp_ag_set_microphone_gain(acl_handle, 12); + status = hfp_ag_set_microphone_gain(acl_handle, 12); break; case 'S': log_info("USER:\'%c\'", cmd); printf("Set microphone gain to 15\n"); - hfp_ag_set_microphone_gain(acl_handle, 15); + status = hfp_ag_set_microphone_gain(acl_handle, 15); break; case 'R': log_info("USER:\'%c\'", cmd); @@ -400,6 +402,10 @@ static void stdin_process(char cmd){ show_usage(); break; } + + if (status != ERROR_CODE_SUCCESS){ + printf("Could not perform command, status 0x%02x\n", status); + } } #endif @@ -455,7 +461,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: status = hfp_subevent_service_level_connection_established_get_status(event); if (status != ERROR_CODE_SUCCESS){ - printf("Connection failed, staus 0x%02x\n", status); + printf("Connection failed, status 0x%02x\n", status); break; } acl_handle = hfp_subevent_service_level_connection_established_get_acl_handle(event); @@ -511,10 +517,10 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even if ( strcmp("1234567", hfp_subevent_place_call_with_number_get_number(event)) == 0 || strcmp("7654321", hfp_subevent_place_call_with_number_get_number(event)) == 0 || (memory_1_enabled && strcmp(">1", hfp_subevent_place_call_with_number_get_number(event)) == 0)){ - printf("Dialstring valid: accept call\n"); + printf("Dial string valid: accept call\n"); hfp_ag_outgoing_call_accepted(); } else { - printf("Dialstring invalid: reject call\n"); + printf("Dial string invalid: reject call\n"); hfp_ag_outgoing_call_rejected(); } break; @@ -530,6 +536,13 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even case HFP_SUBEVENT_CALL_ANSWERED: printf("Call answered by HF\n"); break; + case HFP_SUBEVENT_VOICE_RECOGNITION_STATUS: + if (hfp_subevent_voice_recognition_status_get_activated(event) > 0){ + printf("Voice recognition status activated\n"); + } else { + printf("Voice recognition status disabled\n"); + } + break; default: break; } @@ -609,7 +622,7 @@ int btstack_main(int argc, const char * argv[]){ // register for HFP events hfp_ag_register_packet_handler(&packet_handler); - // parse humand readable Bluetooth address + // parse human readable Bluetooth address sscanf_bd_addr(device_addr_string, device_addr); #ifdef HAVE_BTSTACK_STDIN diff --git a/example/hfp_hf_demo.c b/example/hfp_hf_demo.c index e4ed9f031..f3d83bc0e 100644 --- a/example/hfp_hf_demo.c +++ b/example/hfp_hf_demo.c @@ -151,7 +151,7 @@ static void show_usage(void){ printf("n/N - deactivate/activate voice recognition\n"); printf("0123456789#*-+ - send DTMF dial tones\n"); printf("x - request phone number for voice tag | X - current call status (ECS)\n"); - printf("y - release call with index 2 (ECC) | Y - private consulation with call 2(ECC)\n"); + printf("y - release call with index 2 (ECC) | Y - private consultation with call 2(ECC)\n"); printf("[ - Query Response and Hold status (RHH ?) | ] - Place call in a response and held state(RHH 0)\n"); printf("{ - Accept held call(RHH 1) | } - Reject held call(RHH 2)\n"); printf("? - Query Subscriber Number (NUM)\n"); @@ -160,11 +160,13 @@ static void show_usage(void){ } static void stdin_process(char c){ + uint8_t status = ERROR_CODE_SUCCESS; + cmd = c; // used in packet handler if (cmd >= '0' && cmd <= '9'){ printf("DTMF Code: %c\n", cmd); - hfp_hf_send_dtmf_code(acl_handle, cmd); + status = hfp_hf_send_dtmf_code(acl_handle, cmd); return; } @@ -175,77 +177,77 @@ static void stdin_process(char c){ case '*': log_info("USER:\'%c\'", cmd); printf("DTMF Code: %c\n", cmd); - hfp_hf_send_dtmf_code(acl_handle, cmd); + status = hfp_hf_send_dtmf_code(acl_handle, cmd); break; case 'a': log_info("USER:\'%c\'", cmd); 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); + status = hfp_hf_establish_service_level_connection(device_addr); break; case 'A': log_info("USER:\'%c\'", cmd); printf("Release Service level connection.\n"); - hfp_hf_release_service_level_connection(acl_handle); + status = hfp_hf_release_service_level_connection(acl_handle); break; case 'b': log_info("USER:\'%c\'", cmd); printf("Establish Audio connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); - hfp_hf_establish_audio_connection(acl_handle); + status = hfp_hf_establish_audio_connection(acl_handle); break; case 'B': log_info("USER:\'%c\'", cmd); printf("Release Audio service level connection.\n"); - hfp_hf_release_audio_connection(acl_handle); + status = hfp_hf_release_audio_connection(acl_handle); break; case 'C': log_info("USER:\'%c\'", cmd); printf("Enable registration status update for all AG indicators.\n"); - hfp_hf_enable_status_update_for_all_ag_indicators(acl_handle); + status = hfp_hf_enable_status_update_for_all_ag_indicators(acl_handle); break; case 'c': log_info("USER:\'%c\'", cmd); printf("Disable registration status update for all AG indicators.\n"); - hfp_hf_disable_status_update_for_all_ag_indicators(acl_handle); + status = hfp_hf_disable_status_update_for_all_ag_indicators(acl_handle); break; case 'D': log_info("USER:\'%c\'", cmd); printf("Set HFP AG registration status update for individual indicators (0111111).\n"); - hfp_hf_set_status_update_for_individual_ag_indicators(acl_handle, 63); + status = hfp_hf_set_status_update_for_individual_ag_indicators(acl_handle, 63); break; case 'd': log_info("USER:\'%c\'", cmd); printf("Query network operator.\n"); - hfp_hf_query_operator_selection(acl_handle); + status = hfp_hf_query_operator_selection(acl_handle); break; case 'E': log_info("USER:\'%c\'", cmd); printf("Enable reporting of the extended AG error result code.\n"); - hfp_hf_enable_report_extended_audio_gateway_error_result_code(acl_handle); + status = hfp_hf_enable_report_extended_audio_gateway_error_result_code(acl_handle); break; case 'e': log_info("USER:\'%c\'", cmd); printf("Disable reporting of the extended AG error result code.\n"); - hfp_hf_disable_report_extended_audio_gateway_error_result_code(acl_handle); + status = hfp_hf_disable_report_extended_audio_gateway_error_result_code(acl_handle); break; case 'f': log_info("USER:\'%c\'", cmd); printf("Answer incoming call.\n"); - hfp_hf_answer_incoming_call(acl_handle); + status = hfp_hf_answer_incoming_call(acl_handle); break; case 'F': log_info("USER:\'%c\'", cmd); printf("Hangup call.\n"); - hfp_hf_terminate_call(acl_handle); + status = hfp_hf_terminate_call(acl_handle); break; case 'G': log_info("USER:\'%c\'", cmd); printf("Reject incoming call.\n"); - hfp_hf_reject_incoming_call(acl_handle); + status = hfp_hf_reject_incoming_call(acl_handle); break; case 'g': log_info("USER:\'%c\'", cmd); printf("Query operator.\n"); - hfp_hf_query_operator_selection(acl_handle); + status = hfp_hf_query_operator_selection(acl_handle); break; case 't': log_info("USER:\'%c\'", cmd); @@ -255,187 +257,191 @@ static void stdin_process(char c){ case 'i': log_info("USER:\'%c\'", cmd); printf("Dial 1234567\n"); - hfp_hf_dial_number(acl_handle, "1234567"); + status = hfp_hf_dial_number(acl_handle, "1234567"); break; case 'I': log_info("USER:\'%c\'", cmd); printf("Dial 7654321\n"); - hfp_hf_dial_number(acl_handle, "7654321"); + status = hfp_hf_dial_number(acl_handle, "7654321"); break; case 'j': log_info("USER:\'%c\'", cmd); printf("Dial #1\n"); - hfp_hf_dial_memory(acl_handle,1); + status = hfp_hf_dial_memory(acl_handle,1); break; case 'J': log_info("USER:\'%c\'", cmd); printf("Dial #99\n"); - hfp_hf_dial_memory(acl_handle,99); + status = hfp_hf_dial_memory(acl_handle,99); break; case 'k': log_info("USER:\'%c\'", cmd); printf("Deactivate call waiting notification\n"); - hfp_hf_deactivate_call_waiting_notification(acl_handle); + status = hfp_hf_deactivate_call_waiting_notification(acl_handle); break; case 'K': log_info("USER:\'%c\'", cmd); printf("Activate call waiting notification\n"); - hfp_hf_activate_call_waiting_notification(acl_handle); + status = hfp_hf_activate_call_waiting_notification(acl_handle); break; case 'l': log_info("USER:\'%c\'", cmd); printf("Deactivate calling line notification\n"); - hfp_hf_deactivate_calling_line_notification(acl_handle); + status = hfp_hf_deactivate_calling_line_notification(acl_handle); break; case 'L': log_info("USER:\'%c\'", cmd); printf("Activate calling line notification\n"); - hfp_hf_activate_calling_line_notification(acl_handle); + status = hfp_hf_activate_calling_line_notification(acl_handle); break; case 'm': log_info("USER:\'%c\'", cmd); printf("Deactivate echo canceling and noise reduction\n"); - hfp_hf_deactivate_echo_canceling_and_noise_reduction(acl_handle); + status = hfp_hf_deactivate_echo_canceling_and_noise_reduction(acl_handle); break; case 'M': log_info("USER:\'%c\'", cmd); printf("Activate echo canceling and noise reduction\n"); - hfp_hf_activate_echo_canceling_and_noise_reduction(acl_handle); + status = hfp_hf_activate_echo_canceling_and_noise_reduction(acl_handle); break; case 'n': log_info("USER:\'%c\'", cmd); printf("Deactivate voice recognition\n"); - hfp_hf_deactivate_voice_recognition_notification(acl_handle); + status = hfp_hf_deactivate_voice_recognition_notification(acl_handle); break; case 'N': log_info("USER:\'%c\'", cmd); printf("Activate voice recognition %s\n", bd_addr_to_str(device_addr)); - hfp_hf_activate_voice_recognition_notification(acl_handle); + status = hfp_hf_activate_voice_recognition_notification(acl_handle); break; case 'o': log_info("USER:\'%c\'", cmd); printf("Set speaker gain to 0 (minimum)\n"); - hfp_hf_set_speaker_gain(acl_handle, 0); + status = hfp_hf_set_speaker_gain(acl_handle, 0); break; case 'O': log_info("USER:\'%c\'", cmd); printf("Set speaker gain to 9 (default)\n"); - hfp_hf_set_speaker_gain(acl_handle, 9); + status = hfp_hf_set_speaker_gain(acl_handle, 9); break; case 'p': log_info("USER:\'%c\'", cmd); printf("Set speaker gain to 12 (higher)\n"); - hfp_hf_set_speaker_gain(acl_handle, 12); + status = hfp_hf_set_speaker_gain(acl_handle, 12); break; case 'P': log_info("USER:\'%c\'", cmd); printf("Set speaker gain to 15 (maximum)\n"); - hfp_hf_set_speaker_gain(acl_handle, 15); + status = hfp_hf_set_speaker_gain(acl_handle, 15); break; case 'q': log_info("USER:\'%c\'", cmd); printf("Set microphone gain to 0\n"); - hfp_hf_set_microphone_gain(acl_handle, 0); + status = hfp_hf_set_microphone_gain(acl_handle, 0); break; case 'Q': log_info("USER:\'%c\'", cmd); printf("Set microphone gain to 9\n"); - hfp_hf_set_microphone_gain(acl_handle, 9); + status = hfp_hf_set_microphone_gain(acl_handle, 9); break; case 's': log_info("USER:\'%c\'", cmd); printf("Set microphone gain to 12\n"); - hfp_hf_set_microphone_gain(acl_handle, 12); + status = hfp_hf_set_microphone_gain(acl_handle, 12); break; case 'S': log_info("USER:\'%c\'", cmd); printf("Set microphone gain to 15\n"); - hfp_hf_set_microphone_gain(acl_handle, 15); + status = hfp_hf_set_microphone_gain(acl_handle, 15); break; case 'u': log_info("USER:\'%c\'", cmd); printf("Send 'user busy' (Three-Way Call 0)\n"); - hfp_hf_user_busy(acl_handle); + status = hfp_hf_user_busy(acl_handle); break; case 'U': log_info("USER:\'%c\'", cmd); printf("End active call and accept waiting/held call (Three-Way Call 1)\n"); - hfp_hf_end_active_and_accept_other(acl_handle); + status = hfp_hf_end_active_and_accept_other(acl_handle); break; case 'v': log_info("USER:\'%c\'", cmd); printf("Swap active call and hold/waiting call (Three-Way Call 2)\n"); - hfp_hf_swap_calls(acl_handle); + status = hfp_hf_swap_calls(acl_handle); break; case 'V': log_info("USER:\'%c\'", cmd); printf("Join hold call (Three-Way Call 3)\n"); - hfp_hf_join_held_call(acl_handle); + status = hfp_hf_join_held_call(acl_handle); break; case 'w': log_info("USER:\'%c\'", cmd); printf("Connect calls (Three-Way Call 4)\n"); - hfp_hf_connect_calls(acl_handle); + status = hfp_hf_connect_calls(acl_handle); break; case 'W': log_info("USER:\'%c\'", cmd); printf("Redial\n"); - hfp_hf_redial_last_number(acl_handle); + status = hfp_hf_redial_last_number(acl_handle); break; case 'x': log_info("USER:\'%c\'", cmd); printf("Request phone number for voice tag\n"); - hfp_hf_request_phone_number_for_voice_tag(acl_handle); + status = hfp_hf_request_phone_number_for_voice_tag(acl_handle); break; case 'X': log_info("USER:\'%c\'", cmd); printf("Query current call status\n"); - hfp_hf_query_current_call_status(acl_handle); + status = hfp_hf_query_current_call_status(acl_handle); break; case 'y': log_info("USER:\'%c\'", cmd); printf("Release call with index 2\n"); - hfp_hf_release_call_with_index(acl_handle, 2); + status = hfp_hf_release_call_with_index(acl_handle, 2); break; case 'Y': log_info("USER:\'%c\'", cmd); - printf("Private consulation with call 2\n"); - hfp_hf_private_consultation_with_call(acl_handle, 2); + printf("Private consultation with call 2\n"); + status = hfp_hf_private_consultation_with_call(acl_handle, 2); break; case '[': log_info("USER:\'%c\'", cmd); printf("Query Response and Hold status (RHH ?)\n"); - hfp_hf_rrh_query_status(acl_handle); + status = hfp_hf_rrh_query_status(acl_handle); break; case ']': log_info("USER:\'%c\'", cmd); printf("Place call in a response and held state (RHH 0)\n"); - hfp_hf_rrh_hold_call(acl_handle); + status = hfp_hf_rrh_hold_call(acl_handle); break; case '{': log_info("USER:\'%c\'", cmd); printf("Accept held call (RHH 1)\n"); - hfp_hf_rrh_accept_held_call(acl_handle); + status = hfp_hf_rrh_accept_held_call(acl_handle); break; case '}': log_info("USER:\'%c\'", cmd); printf("Reject held call (RHH 2)\n"); - hfp_hf_rrh_reject_held_call(acl_handle); + status = hfp_hf_rrh_reject_held_call(acl_handle); break; case '?': log_info("USER:\'%c\'", cmd); printf("Query Subscriber Number\n"); - hfp_hf_query_subscriber_number(acl_handle); + status = hfp_hf_query_subscriber_number(acl_handle); break; case '!': log_info("USER:\'%c\'", cmd); printf("Update HF indicator with assigned number 1 (HFI)\n"); - hfp_hf_set_hf_indicator(acl_handle, 1, 1); + status = hfp_hf_set_hf_indicator(acl_handle, 1, 1); break; default: show_usage(); break; } + + if (status != ERROR_CODE_SUCCESS){ + printf("Could not perform command, status 0x%02x\n", status); + } } #endif @@ -555,6 +561,13 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even printf(" - type : %d \n", hfp_subevent_enhanced_call_status_get_bnip_type(event)); printf(" - number : %s \n", hfp_subevent_enhanced_call_status_get_bnip_number(event)); break; + case HFP_SUBEVENT_VOICE_RECOGNITION_STATUS: + if (hfp_subevent_voice_recognition_status_get_activated(event) > 0){ + printf("Voice recognition status activated\n"); + } else { + printf("Voice recognition status disabled\n"); + } + break; default: break; } @@ -601,6 +614,7 @@ int btstack_main(int argc, const char * argv[]){ (1<