Fix crash when WBS enabled.

This commit is contained in:
weitianhua 2019-12-02 18:17:44 +08:00
parent 45fb144224
commit ad4b11a4f1
6 changed files with 53 additions and 51 deletions

View file

@ -64,8 +64,8 @@ typedef enum
ESP_HF_ATA_RESPONSE_EVT, /*!< Answer an Incoming Call */ ESP_HF_ATA_RESPONSE_EVT, /*!< Answer an Incoming Call */
ESP_HF_CHUP_RESPONSE_EVT, /*!< Reject an Incoming Call */ ESP_HF_CHUP_RESPONSE_EVT, /*!< Reject an Incoming Call */
ESP_HF_DIAL_EVT, /*!< Origin an outgoing call with specific number or the dial the last number */ ESP_HF_DIAL_EVT, /*!< Origin an outgoing call with specific number or the dial the last number */
ESP_HF_BAC_RESPONSE_EVT, /*!< Codec Negotiation */ ESP_HF_WBS_RESPONSE_EVT, /*!< Codec Status */
ESP_HF_BCS_RESPONSE_EVT, /*!< Codec Negotiation */ ESP_HF_BCS_RESPONSE_EVT, /*!< Final Codec Choice */
} esp_hf_cb_event_t; } esp_hf_cb_event_t;
/// HFP AG callback parameters /// HFP AG callback parameters
@ -147,12 +147,19 @@ typedef union
esp_hf_nrec_t state; /*!< NREC enabled or disabled */ esp_hf_nrec_t state; /*!< NREC enabled or disabled */
} nrec; /*!< AG callback param of ESP_HF_NREC_RESPONSE_EVT */ } nrec; /*!< AG callback param of ESP_HF_NREC_RESPONSE_EVT */
/**
* @brief ESP_HF_WBS_RESPONSE_EVT
*/
struct hf_wbs_rep_param {
esp_hf_wbs_config_t codec; /*!< codec mode CVSD or mSBC */
} wbs_rep; /*!< AG callback param of ESP_HF_WBS_RESPONSE_EVT */
/** /**
* @brief ESP_HF_BCS_RESPONSE_EVT * @brief ESP_HF_BCS_RESPONSE_EVT
*/ */
struct hf_codec_param { struct hf_bcs_rep_param {
esp_hf_wbs_config_t mode; /*!< codec mode CVSD or mSBC */ esp_hf_wbs_config_t mode; /*!< codec mode CVSD or mSBC */
} codec; /*!< AG callback param of ESP_HF_BAC_RESPONSE_EVT */ } bcs_rep; /*!< AG callback param of ESP_HF_BCS_RESPONSE_EVT */
} esp_hf_cb_param_t; /*!< HFP AG callback param compound*/ } esp_hf_cb_param_t; /*!< HFP AG callback param compound*/

View file

@ -80,7 +80,7 @@ static hf_local_param_t hf_local_param[BTC_HF_NUM_CB];
/* wide band synchronous */ /* wide band synchronous */
#ifndef BTC_HF_WBS_PREFERRED #ifndef BTC_HF_WBS_PREFERRED
#define BTC_HF_WBS_PREFERRED FALSE #define BTC_HF_WBS_PREFERRED TRUE
#endif #endif
BOOLEAN btc_conf_hf_force_wbs = BTC_HF_WBS_PREFERRED; BOOLEAN btc_conf_hf_force_wbs = BTC_HF_WBS_PREFERRED;
@ -1426,51 +1426,41 @@ void btc_hf_cb_handler(btc_msg_t *msg)
case BTA_AG_AT_BAC_EVT: case BTA_AG_AT_BAC_EVT:
{ {
BTC_TRACE_DEBUG("AG Bitmap of peer-codecs %d", p_data->val.num); BTC_TRACE_DEBUG("AG Bitmap of peer-codecs %d", p_data->val.num);
memset(&param, 0, sizeof(esp_hf_cb_param_t));
param.codec.mode = p_data->val.num;
btc_hf_cb_to_app(ESP_HF_BAC_RESPONSE_EVT, &param);
break;
}
case BTA_AG_AT_BCS_EVT:
{
BTC_TRACE_DEBUG("AG Bitmap of peer-codecs %d", p_data->val.num);
memset(&param, 0, sizeof(esp_hf_cb_param_t));
param.codec.mode = p_data->val.num;
btc_hf_cb_to_app(ESP_HF_BCS_RESPONSE_EVT, &param);
break;
}
#if (BTM_WBS_INCLUDED == TRUE )
case BTA_AG_WBS_EVT:
{
BTC_TRACE_DEBUG("BTA_AG_WBS_EVT Set codec status %d codec %d 1=CVSD 2=MSBC", p_data->val.hdr.status, p_data->val.num);
memset(&param, 0, sizeof(esp_hf_cb_param_t));
param.codec.mode = p_data->val.num;
if(p_data->val.num == BTA_AG_CODEC_CVSD) {
btc_hf_cb_to_app(ESP_HF_BCS_RESPONSE_EVT, &param);
} else if(p_data->val.num == BTA_AG_CODEC_MSBC) {
btc_hf_cb_to_app(ESP_HF_BCS_RESPONSE_EVT, &param);
} else {
btc_hf_cb_to_app(ESP_HF_BCS_RESPONSE_EVT, &param);
}
break;
}
#endif
#if (BTM_WBS_INCLUDED == TRUE) #if (BTM_WBS_INCLUDED == TRUE)
/* If the peer supports mSBC and the BTC prefferred codec is also mSBC, then /* If the peer supports mSBC and the BTC prefferred codec is also mSBC, then
** we should set the BTA AG Codec to mSBC. This would trigger a +BCS to mSBC at the time ** we should set the BTA AG Codec to mSBC. This would trigger a +BCS to mSBC at the time
** of SCO connection establishment */ ** of SCO connection establishment */
if ((btc_conf_hf_force_wbs == TRUE) && (p_data->val.num & BTA_AG_CODEC_MSBC)) { if ((btc_conf_hf_force_wbs == TRUE) && (p_data->val.num & BTA_AG_CODEC_MSBC)) {
BTC_TRACE_EVENT("%s btc_hf override-Preferred Codec to MSBC", __FUNCTION__); BTC_TRACE_DEBUG("%s btc_hf override-Preferred Codec to MSBC", __FUNCTION__);
BTA_AgSetCodec(hf_local_param[idx].btc_hf_cb.handle,BTA_AG_CODEC_MSBC); BTA_AgSetCodec(hf_local_param[idx].btc_hf_cb.handle,BTA_AG_CODEC_MSBC);
} }
else { else {
BTC_TRACE_EVENT("%s btif_hf override-Preferred Codec to CVSD", __FUNCTION__); BTC_TRACE_DEBUG("%s btc_hf override-Preferred Codec to CVSD", __FUNCTION__);
BTA_AgSetCodec(hf_local_param[idx].btc_hf_cb.handle,BTA_AG_CODEC_CVSD); BTA_AgSetCodec(hf_local_param[idx].btc_hf_cb.handle,BTA_AG_CODEC_CVSD);
} }
#endif #endif
break; break;
}
#if (BTM_WBS_INCLUDED == TRUE)
case BTA_AG_WBS_EVT:
{
BTC_TRACE_DEBUG("Set codec status %d codec %d 1=CVSD 2=MSBC", p_data->val.hdr.status, p_data->val.value);
memset(&param, 0, sizeof(esp_hf_cb_param_t));
param.wbs_rep.codec = p_data->val.value;
btc_hf_cb_to_app(ESP_HF_WBS_RESPONSE_EVT, &param);
break;
}
#endif
case BTA_AG_AT_BCS_EVT:
{
BTC_TRACE_DEBUG("AG final seleded codec is %d 1=CVSD 2=MSBC", p_data->val.num);
memset(&param, 0, sizeof(esp_hf_cb_param_t));
param.bcs_rep.mode = p_data->val.num;
/* No ESP_HF_WBS_NONE case, becuase HFP 1.6 supported device can send BCS */
btc_hf_cb_to_app(ESP_HF_BCS_RESPONSE_EVT, &param);
break;
}
default: default:
BTC_TRACE_WARNING("%s: Unhandled event: %d", __FUNCTION__, event); BTC_TRACE_WARNING("%s: Unhandled event: %d", __FUNCTION__, event);
break; break;

View file

@ -6,7 +6,7 @@ This example is to show how to use the APIs of Hands-Free (HF) Audio Gateway (AG
### Hardware Required ### Hardware Required
This example is designed to run on commonly available ESP32 development board, e.g. ESP32-DevKitC. To operate it should be connected to an Hands-Free Unit running on a Headphone/Headset or on another ESP32 development board loaded with Hands Free Unit (hfp_hf) example from ESP-IDF. This example is designed to run on commonly available ESP32 development board, e.g. ESP32-DevKitC. To operate this example, it should be connected to an Hands-Free Unit running on a Headphone/Headset or on another ESP32 development board loaded with Hands Free Unit (hfp_hf) example from ESP-IDF.
### Configure the project ### Configure the project
@ -177,8 +177,8 @@ I (159311) BT_APP_HF: --ESP AG Audio Connection Disconnected.
You can type `hf d <num>;` to dial `<num>` from AG and log prints such as: You can type `hf d <num>;` to dial `<num>` from AG and log prints such as:
``` ```
E (207351) CNSL: Command [hf d 18629485549;] E (207351) CNSL: Command [hf d 123456;]
Dial number 18629485549 Dial number 123456
I (207361) BT_APP_HF: APP HFP event: AUDIO_STATE_EVT I (207361) BT_APP_HF: APP HFP event: AUDIO_STATE_EVT
I (207361) BT_APP_HF: --Audio State connecting I (207361) BT_APP_HF: --Audio State connecting
W (207361) BT_APPL: BTA_AG_SCO_OPENING_ST: Ignoring event 1 W (207361) BT_APPL: BTA_AG_SCO_OPENING_ST: Ignoring event 1

View file

@ -194,7 +194,7 @@ HF_CMD_HANDLER(ir_off)
HF_CMD_HANDLER(ac) HF_CMD_HANDLER(ac)
{ {
printf("Answer Call from AG.\n"); printf("Answer Call from AG.\n");
char *number = {"186xxxx5549"}; char *number = {"123456"};
esp_bt_hf_answer_call(hf_peer_addr,1,0,1,1,number,0); esp_bt_hf_answer_call(hf_peer_addr,1,0,1,1,number,0);
} }
@ -202,7 +202,7 @@ HF_CMD_HANDLER(ac)
HF_CMD_HANDLER(rc) HF_CMD_HANDLER(rc)
{ {
printf("Reject Call from AG.\n"); printf("Reject Call from AG.\n");
char *number = {"186xxxx5549"}; char *number = {"123456"};
esp_bt_hf_reject_call(hf_peer_addr,0,0,0,0,number,0); esp_bt_hf_reject_call(hf_peer_addr,0,0,0,0,number,0);
} }
@ -210,7 +210,7 @@ HF_CMD_HANDLER(rc)
HF_CMD_HANDLER(end) HF_CMD_HANDLER(end)
{ {
printf("End Call from AG.\n"); printf("End Call from AG.\n");
char *number = {"186xxxx5549"}; char *number = {"123456"};
esp_bt_hf_end_call(hf_peer_addr,0,0,0,0,number,0); esp_bt_hf_end_call(hf_peer_addr,0,0,0,0,number,0);
} }

View file

@ -40,7 +40,7 @@ const char *c_hf_evt_str[] = {
"ANSWER_INCOMING_EVT", /*!< ANSWER INCOMING EVT */ "ANSWER_INCOMING_EVT", /*!< ANSWER INCOMING EVT */
"REJECT_INCOMING_EVT", /*!< AREJECT INCOMING EVT */ "REJECT_INCOMING_EVT", /*!< AREJECT INCOMING EVT */
"DIAL_EVT", /*!< DIAL INCOMING EVT */ "DIAL_EVT", /*!< DIAL INCOMING EVT */
"BAC_EVT", /*!< CODEC NEGO EVT */ "WBS_EVT", /*!< CURRENT CODEC EVT */
"BCS_EVT", /*!< CODEC NEGO EVT */ "BCS_EVT", /*!< CODEC NEGO EVT */
}; };
@ -231,7 +231,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param)
esp_hf_current_call_mode_t mode = 0; esp_hf_current_call_mode_t mode = 0;
esp_hf_current_call_mpty_type_t mpty = 0; esp_hf_current_call_mpty_type_t mpty = 0;
//option //option
char *number = {"186xxxx5549"}; char *number = {"123456"};
esp_hf_call_addr_type_t type = ESP_HF_CALL_ADDR_TYPE_UNKNOWN; esp_hf_call_addr_type_t type = ESP_HF_CALL_ADDR_TYPE_UNKNOWN;
ESP_LOGI(BT_HF_TAG, "--Calling Line Identification."); ESP_LOGI(BT_HF_TAG, "--Calling Line Identification.");
@ -241,7 +241,7 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param)
case ESP_HF_CNUM_RESPONSE_EVT: case ESP_HF_CNUM_RESPONSE_EVT:
{ {
char *number = {"186xxxx5549"}; char *number = {"123456"};
esp_hf_subscriber_service_type_t type = 1; esp_hf_subscriber_service_type_t type = 1;
ESP_LOGI(BT_HF_TAG, "--Current Number is %s ,Type is %s.", number, c_subscriber_service_type_str[type]); ESP_LOGI(BT_HF_TAG, "--Current Number is %s ,Type is %s.", number, c_subscriber_service_type_str[type]);
esp_bt_hf_cnum_response(hf_peer_addr, number,type); esp_bt_hf_cnum_response(hf_peer_addr, number,type);
@ -288,11 +288,16 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param)
} }
break; break;
} }
#if (BTM_WBS_INCLUDED == TRUE)
case ESP_HF_BAC_RESPONSE_EVT: case ESP_HF_WBS_RESPONSE_EVT:
{
ESP_LOGI(BT_HF_TAG, "--Current codec: %s",c_codec_mode_str[param->wbs_rep.codec]);
break;
}
#endif
case ESP_HF_BCS_RESPONSE_EVT: case ESP_HF_BCS_RESPONSE_EVT:
{ {
ESP_LOGI(BT_HF_TAG, "--AG choose codec mode: %s",c_codec_mode_str[param->codec.mode]); ESP_LOGI(BT_HF_TAG, "--Consequence of codec negotiation: %s",c_codec_mode_str[param->bcs_rep.mode]);
break; break;
} }

View file

@ -21,7 +21,7 @@ static QueueHandle_t uart_queue;
static hf_msg_prs_cb_t hf_msg_parser; static hf_msg_prs_cb_t hf_msg_parser;
static const uart_config_t uart_cfg = { static const uart_config_t uart_cfg = {
.baud_rate = 115200, //1.5M .baud_rate = 115200,
.data_bits = UART_DATA_8_BITS, .data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE, .parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1, .stop_bits = UART_STOP_BITS_1,