hfp: use HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED/DISABLED instead of HFP_SUBEVENT_VOICE_RECOGNITION_STATUS event

This commit is contained in:
Milanka Ringwald 2021-08-17 23:25:17 +02:00
parent cab761d05e
commit 553a4a561f
8 changed files with 127 additions and 61 deletions

View File

@ -595,18 +595,30 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
hfp_ag_send_dtmf_code_done(acl_handle);
break;
case HFP_SUBEVENT_VOICE_RECOGNITION_STATUS:
status = hfp_subevent_voice_recognition_status_get_status(event);
case HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED:
status = hfp_subevent_voice_recognition_enabled_get_status(event);
if (status != ERROR_CODE_SUCCESS){
printf("Voice Recognition command failed\n");
printf("Voice Recognition Enable command failed\n");
break;
}
if (hfp_subevent_voice_recognition_status_get_state(event) > 0){
printf("\nVoice recognition status ACTIVATED\n\n");
} else {
printf("\nVoice recognition status DEACTIVATED\n\n");
}
switch (hfp_subevent_voice_recognition_enabled_get_enhanced(event)){
case 1:
printf("\nVoice recognition status ENABLED\n\n");
break;
default:
printf("\nEnhanced voice recognition status ENABLED\n\n");
break;
}
break;
case HFP_SUBEVENT_VOICE_RECOGNITION_DISABLED:
status = hfp_subevent_voice_recognition_disabled_get_status(event);
if (status != ERROR_CODE_SUCCESS){
printf("Voice Recognition Disable command failed\n");
break;
}
printf("Voice Recognition DISABLED\n");
break;
case HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_HF_READY_FOR_AUDIO:

View File

@ -603,18 +603,30 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
printf(" - number : %s \n", hfp_subevent_enhanced_call_status_get_bnip_number(event));
break;
case HFP_SUBEVENT_VOICE_RECOGNITION_STATUS:
status = hfp_subevent_voice_recognition_status_get_status(event);
case HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED:
status = hfp_subevent_voice_recognition_enabled_get_status(event);
if (status != ERROR_CODE_SUCCESS){
printf("Voice Recognition command failed\n");
break;
}
if (hfp_subevent_voice_recognition_status_get_state(event) > 0){
printf("\nVoice recognition status ACTIVATED\n\n");
} else {
printf("\nVoice recognition status DEACTIVATED\n\n");
}
switch (hfp_subevent_voice_recognition_enabled_get_enhanced(event)){
case 1:
printf("\nVoice recognition status ENABLED\n\n");
break;
default:
printf("\nEnhanced voice recognition status ENABLED\n\n");
break;
}
break;
case HFP_SUBEVENT_VOICE_RECOGNITION_DISABLED:
status = hfp_subevent_voice_recognition_disabled_get_status(event);
if (status != ERROR_CODE_SUCCESS){
printf("Voice Recognition Disable command failed\n");
break;
}
printf("Voice Recognition DISABLED\n");
break;
case HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_HF_READY_FOR_AUDIO:

View File

@ -1784,9 +1784,17 @@ typedef uint8_t sm_key_t[16];
* @param subevent_code
* @param acl_handle
* @param status // 0-success
* @param state // 0-deactivated, 1-activated, 2-activated using enhanced
* @param enhanced // 0-legacy, 1-enhanced
*/
#define HFP_SUBEVENT_VOICE_RECOGNITION_STATUS 0x1E
#define HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED 0x1E
/**
* @format 1H1
* @param subevent_code
* @param acl_handle
* @param status // 0-success
*/
#define HFP_SUBEVENT_VOICE_RECOGNITION_DISABLED 0x1F
/**
* @format 1H1
@ -1794,7 +1802,7 @@ typedef uint8_t sm_key_t[16];
* @param acl_handle
* @param status
*/
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_HF_READY_FOR_AUDIO 0x1F
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_HF_READY_FOR_AUDIO 0x20
/**
@ -1803,7 +1811,7 @@ typedef uint8_t sm_key_t[16];
* @param acl_handle
* @param status
*/
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_READY_TO_ACCEPT_AUDIO_INPUT 0x20
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_READY_TO_ACCEPT_AUDIO_INPUT 0x21
/**
* @format 1H1
@ -1811,7 +1819,7 @@ typedef uint8_t sm_key_t[16];
* @param acl_handle
* @param status
*/
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_IS_STARTING_SOUND 0x21
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_IS_STARTING_SOUND 0x22
/**
* @format 1H1
@ -1819,7 +1827,7 @@ typedef uint8_t sm_key_t[16];
* @param acl_handle
* @param status
*/
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_IS_PROCESSING_AUDIO_INPUT 0x22
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_IS_PROCESSING_AUDIO_INPUT 0x23
/**
* @format 1H1
@ -1827,7 +1835,7 @@ typedef uint8_t sm_key_t[16];
* @param acl_handle
* @param status
*/
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_MESSAGE_SENT 0x23
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_MESSAGE_SENT 0x24
/**
@ -1840,7 +1848,7 @@ typedef uint8_t sm_key_t[16];
* @param text_length
* @param text
*/
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_MESSAGE 0x24
#define HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_AG_MESSAGE 0x25
/**
* @format 1H1
@ -1848,7 +1856,7 @@ typedef uint8_t sm_key_t[16];
* @param acl_handle
* @param status
*/
#define HFP_SUBEVENT_ECHO_CANCELING_AND_NOISE_REDUCTION_DEACTIVATE 0x25
#define HFP_SUBEVENT_ECHO_CANCELING_AND_NOISE_REDUCTION_DEACTIVATE 0x26
/**
* @format 1H21
@ -1857,7 +1865,7 @@ typedef uint8_t sm_key_t[16];
* @param uuid
* @param value
*/
#define HFP_SUBEVENT_HF_INDICATOR 0x26
#define HFP_SUBEVENT_HF_INDICATOR 0x27
// ANCS Client

View File

@ -4718,33 +4718,52 @@ static inline uint8_t hfp_subevent_in_band_ring_tone_get_status(const uint8_t *
}
/**
* @brief Get field acl_handle from event HFP_SUBEVENT_VOICE_RECOGNITION_STATUS
* @brief Get field acl_handle from event HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED
* @param event packet
* @return acl_handle
* @note: btstack_type H
*/
static inline hci_con_handle_t hfp_subevent_voice_recognition_status_get_acl_handle(const uint8_t * event){
static inline hci_con_handle_t hfp_subevent_voice_recognition_enabled_get_acl_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field status from event HFP_SUBEVENT_VOICE_RECOGNITION_STATUS
* @brief Get field status from event HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED
* @param event packet
* @return status
* @note: btstack_type 1
*/
static inline uint8_t hfp_subevent_voice_recognition_status_get_status(const uint8_t * event){
static inline uint8_t hfp_subevent_voice_recognition_enabled_get_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field state from event HFP_SUBEVENT_VOICE_RECOGNITION_STATUS
* @brief Get field enhanced from event HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED
* @param event packet
* @return state
* @return enhanced
* @note: btstack_type 1
*/
static inline uint8_t hfp_subevent_voice_recognition_status_get_state(const uint8_t * event){
static inline uint8_t hfp_subevent_voice_recognition_enabled_get_enhanced(const uint8_t * event){
return event[6];
}
/**
* @brief Get field acl_handle from event HFP_SUBEVENT_VOICE_RECOGNITION_DISABLED
* @param event packet
* @return acl_handle
* @note: btstack_type H
*/
static inline hci_con_handle_t hfp_subevent_voice_recognition_disabled_get_acl_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field status from event HFP_SUBEVENT_VOICE_RECOGNITION_DISABLED
* @param event packet
* @return status
* @note: btstack_type 1
*/
static inline uint8_t hfp_subevent_voice_recognition_disabled_get_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field acl_handle from event HFP_SUBEVENT_ENHANCED_VOICE_RECOGNITION_HF_READY_FOR_AUDIO
* @param event packet

View File

@ -353,27 +353,30 @@ void hfp_emit_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, ui
hfp_emit_event_for_context(hfp_connection, event, sizeof(event));
}
void hfp_emit_voice_recognition_state_event(hfp_connection_t * hfp_connection, uint8_t status){
hci_con_handle_t acl_handle = (hfp_connection != NULL) ? hfp_connection->acl_handle : HCI_CON_HANDLE_INVALID;
void hfp_emit_voice_recognition_enabled(hfp_connection_t * hfp_connection, uint8_t status){
btstack_assert(hfp_connection != NULL);
uint8_t event[7];
event[0] = HCI_EVENT_HFP_META;
event[1] = sizeof(event) - 2;
event[2] = HFP_SUBEVENT_VOICE_RECOGNITION_STATUS;
event[2] = HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED;
little_endian_store_16(event, 3, acl_handle);
little_endian_store_16(event, 3, hfp_connection->acl_handle);
event[5] = status; // 0:success
event[6] = hfp_connection->enhanced_voice_recognition_enabled ? 1 : 0;
hfp_emit_event_for_context(hfp_connection, event, sizeof(event));
}
void hfp_emit_voice_recognition_disabled(hfp_connection_t * hfp_connection, uint8_t status){
btstack_assert(hfp_connection != NULL);
uint8_t event[6];
event[0] = HCI_EVENT_HFP_META;
event[1] = sizeof(event) - 2;
event[2] = HFP_SUBEVENT_VOICE_RECOGNITION_DISABLED;
switch (hfp_connection->vra_state){
case HFP_VRA_VOICE_RECOGNITION_ACTIVATED:
event[6] = 1;
break;
case HFP_VRA_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO:
event[6] = 2;
break;
default:
event[6] = 0;
break;
}
little_endian_store_16(event, 3, hfp_connection->acl_handle);
event[5] = status; // 0:success
hfp_emit_event_for_context(hfp_connection, event, sizeof(event));
}
@ -538,9 +541,9 @@ static void hfp_reset_voice_recognition(hfp_connection_t * hfp_connection){
hfp_connection->vra_state = HFP_VRA_VOICE_RECOGNITION_OFF;
if (current_vra_state != HFP_VRA_VOICE_RECOGNITION_OFF){
hfp_emit_voice_recognition_state_event(hfp_connection, HFP_VRA_VOICE_RECOGNITION_OFF);
hfp_emit_voice_recognition_disabled(hfp_connection, ERROR_CODE_SUCCESS);
} else if (hfp_connection->vra_state_requested != HFP_VRA_VOICE_RECOGNITION_OFF){
hfp_emit_voice_recognition_state_event(hfp_connection, HFP_VRA_VOICE_RECOGNITION_OFF);
hfp_emit_voice_recognition_disabled(hfp_connection, ERROR_CODE_SUCCESS);
}
hfp_connection->vra_state_requested = HFP_VRA_VOICE_RECOGNITION_OFF;

View File

@ -749,12 +749,19 @@ void hfp_emit_string_event(hfp_connection_t * hfp_connection, uint8_t event_subt
void hfp_emit_slc_connection_event(hfp_connection_t * hfp_connection, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr);
/**
* @brief Emit HFP_SUBEVENT_VOICE_RECOGNITION_STATUS event
* @brief Emit HFP_SUBEVENT_VOICE_RECOGNITION_ENABLED event
* @param hfp_connection
* @param status ERROR_CODE_SUCCESS if successful, otherwise ERROR_CODE_COMMAND_DISALLOWED
* @param state 0 if deactivated, 1 if activated
*/
void hfp_emit_voice_recognition_state_event(hfp_connection_t * hfp_connection, uint8_t status);
void hfp_emit_voice_recognition_enabled(hfp_connection_t * hfp_connection, uint8_t status);
/**
* @brief Emit HFP_SUBEVENT_VOICE_RECOGNITION_DISABLED event
* @param hfp_connection
* @param status ERROR_CODE_SUCCESS if successful, otherwise ERROR_CODE_COMMAND_DISALLOWED
*/
void hfp_emit_voice_recognition_disabled(hfp_connection_t * hfp_connection, uint8_t status);
void hfp_emit_enhanced_voice_recognition_hf_ready_for_audio_event(hfp_connection_t * hfp_connection, uint8_t status);
void hfp_emit_enhanced_voice_recognition_state_event(hfp_connection_t * hfp_connection, uint8_t status);

View File

@ -894,7 +894,12 @@ static int hfp_ag_voice_recognition_state_machine(hfp_connection_t * hfp_connect
done = hfp_ag_send_voice_recognition_cmd(hfp_connection, hfp_connection->ag_activate_voice_recognition_value);
if (done == 0){
hfp_connection->vra_state_requested = hfp_connection->vra_state;
hfp_emit_voice_recognition_state_event(hfp_connection, ERROR_CODE_COMMAND_DISALLOWED);
if (hfp_connection->ag_activate_voice_recognition_value == 1){
hfp_emit_voice_recognition_enabled(hfp_connection, done);
} else {
hfp_emit_voice_recognition_disabled(hfp_connection, done);
}
return 0;
}
break;
@ -944,7 +949,7 @@ static int hfp_ag_voice_recognition_state_machine(hfp_connection_t * hfp_connect
status = hfp_ag_setup_audio_connection(hfp_connection);
if (status != ERROR_CODE_SUCCESS){
hfp_connection->vra_state_requested = hfp_connection->vra_state;
hfp_emit_voice_recognition_state_event(hfp_connection, status);
hfp_emit_voice_recognition_enabled(hfp_connection, status);
return 0;
}
}
@ -963,7 +968,7 @@ static int hfp_ag_voice_recognition_state_machine(hfp_connection_t * hfp_connect
hfp_trigger_release_audio_connection(hfp_connection);
}
hfp_emit_voice_recognition_state_event(hfp_connection, ERROR_CODE_SUCCESS);
hfp_emit_voice_recognition_disabled(hfp_connection, ERROR_CODE_SUCCESS);
break;
case HFP_VRA_W2_SEND_VOICE_RECOGNITION_ACTIVATED:
@ -972,14 +977,14 @@ static int hfp_ag_voice_recognition_state_machine(hfp_connection_t * hfp_connect
status = hfp_ag_setup_audio_connection(hfp_connection);
if (status != ERROR_CODE_SUCCESS){
hfp_connection->vra_state_requested = hfp_connection->vra_state;
hfp_emit_voice_recognition_state_event(hfp_connection, status);
hfp_emit_voice_recognition_enabled(hfp_connection, status);
return 0;
}
}
hfp_connection->vra_state = HFP_VRA_VOICE_RECOGNITION_ACTIVATED;
hfp_connection->vra_state_requested = hfp_connection->vra_state;
hfp_emit_voice_recognition_state_event(hfp_connection, ERROR_CODE_SUCCESS);
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
break;
default:
@ -2819,7 +2824,7 @@ uint8_t hfp_ag_activate_voice_recognition(hci_con_handle_t acl_handle){
hfp_connection->ag_activate_voice_recognition_value = 1;
hfp_connection->vra_state_requested = HFP_VRA_W2_SEND_VOICE_RECOGNITION_ACTIVATED;
hfp_connection->command = HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION;
hfp_connection->enhanced_voice_recognition_enabled = enhanced_vra_supported;
// hfp_connection->enhanced_voice_recognition_enabled = enhanced_vra_supported;
hfp_connection->ag_audio_connection_opened_before_vra = hfp_ag_is_audio_connection_active(hfp_connection);
hfp_connection->ag_vra_state = HFP_VOICE_RECOGNITION_STATE_AG_READY;
hfp_ag_run_for_context(hfp_connection);

View File

@ -588,7 +588,7 @@ static int hfp_hf_voice_recognition_state_machine(hfp_connection_t * hfp_connect
if (hfp_connection->activate_voice_recognition){
hfp_hf_activate_voice_recognition(hfp_connection->acl_handle);
} else {
hfp_emit_voice_recognition_state_event(hfp_connection, ERROR_CODE_SUCCESS);
hfp_emit_voice_recognition_disabled(hfp_connection, ERROR_CODE_SUCCESS);
}
break;
@ -599,7 +599,7 @@ static int hfp_hf_voice_recognition_state_machine(hfp_connection_t * hfp_connect
if (hfp_connection->deactivate_voice_recognition){
hfp_hf_deactivate_voice_recognition(hfp_connection->acl_handle);
} else {
hfp_emit_voice_recognition_state_event(hfp_connection, ERROR_CODE_SUCCESS);
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
}
break;
@ -1286,7 +1286,7 @@ static void hfp_hf_handle_rfcomm_command(hfp_connection_t * hfp_connection){
break;
}
hfp_connection->vra_state_requested = hfp_connection->vra_state;
hfp_emit_voice_recognition_state_event(hfp_connection, ERROR_CODE_UNSPECIFIED_ERROR);
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_UNSPECIFIED_ERROR);
hfp_reset_context_flags(hfp_connection);
return;
}