mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
feat(bt/bluedroid): Modify AT+CNUM response api and HFP AG example
This commit is contained in:
parent
0687fad3d6
commit
2a747a3058
@ -337,11 +337,14 @@ esp_err_t esp_hf_ag_clcc_response(esp_bd_addr_t remote_addr, int index, esp_hf_c
|
|||||||
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, esp_hf_subscriber_service_type_t type)
|
esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, int number_type, esp_hf_subscriber_service_type_t service_type)
|
||||||
{
|
{
|
||||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
if (number == NULL) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
btc_msg_t msg;
|
btc_msg_t msg;
|
||||||
msg.sig = BTC_SIG_API_CALL;
|
msg.sig = BTC_SIG_API_CALL;
|
||||||
msg.pid = BTC_PID_HF;
|
msg.pid = BTC_PID_HF;
|
||||||
@ -351,7 +354,8 @@ esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, esp_h
|
|||||||
memset(&arg, 0, sizeof(btc_hf_args_t));
|
memset(&arg, 0, sizeof(btc_hf_args_t));
|
||||||
memcpy(&(arg.cnum_rep), remote_addr, sizeof(esp_bd_addr_t));
|
memcpy(&(arg.cnum_rep), remote_addr, sizeof(esp_bd_addr_t));
|
||||||
arg.cnum_rep.number = number; //deep_copy
|
arg.cnum_rep.number = number; //deep_copy
|
||||||
arg.cnum_rep.type = type;
|
arg.cnum_rep.number_type = number_type;
|
||||||
|
arg.cnum_rep.service_type = service_type;
|
||||||
|
|
||||||
/* Switch to BTC context */
|
/* Switch to BTC context */
|
||||||
bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t),
|
bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t),
|
||||||
|
@ -525,14 +525,18 @@ esp_err_t esp_hf_ag_clcc_response(esp_bd_addr_t remote_addr, int index, esp_hf_c
|
|||||||
*
|
*
|
||||||
* @param[in] remote_addr: remote bluetooth device address
|
* @param[in] remote_addr: remote bluetooth device address
|
||||||
* @param[in] number: registration number
|
* @param[in] number: registration number
|
||||||
* @param[in] type: service type (unknown/voice/fax)
|
* @param[in] number_type: value of number type from
|
||||||
|
* 128-143: national or international, may contain prefix and/or escape digits
|
||||||
|
* 144-159: international, includes country code prefix, add "+" if needed
|
||||||
|
* 160-175: national, but no prefix nor escape digits
|
||||||
|
* @param[in] service_type: service type (unknown/voice/fax)
|
||||||
* @return
|
* @return
|
||||||
* - ESP_OK: disconnect request is sent to lower layer
|
* - ESP_OK: disconnect request is sent to lower layer
|
||||||
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
|
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
|
||||||
* - ESP_FAIL: others
|
* - ESP_FAIL: others
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, esp_hf_subscriber_service_type_t type);
|
esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, int number_type, esp_hf_subscriber_service_type_t service_type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -124,7 +124,7 @@ typedef enum {
|
|||||||
/// +CNUM service type of the phone number
|
/// +CNUM service type of the phone number
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ESP_HF_SUBSCRIBER_SERVICE_TYPE_UNKNOWN = 0, /*!< unknown */
|
ESP_HF_SUBSCRIBER_SERVICE_TYPE_UNKNOWN = 0, /*!< unknown */
|
||||||
ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE, /*!< voice service */
|
ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE = 4, /*!< voice service */
|
||||||
ESP_HF_SUBSCRIBER_SERVICE_TYPE_FAX, /*!< fax service */
|
ESP_HF_SUBSCRIBER_SERVICE_TYPE_FAX, /*!< fax service */
|
||||||
} esp_hf_subscriber_service_type_t;
|
} esp_hf_subscriber_service_type_t;
|
||||||
|
|
||||||
|
@ -607,7 +607,7 @@ static bt_status_t btc_hf_clcc_response(bt_bdaddr_t *bd_addr, int index, esp_hf_
|
|||||||
}
|
}
|
||||||
|
|
||||||
//AT+CNUM
|
//AT+CNUM
|
||||||
static bt_status_t btc_hf_cnum_response(bt_bdaddr_t *bd_addr, const char *number, esp_hf_subscriber_service_type_t type)
|
static bt_status_t btc_hf_cnum_response(bt_bdaddr_t *bd_addr, const char *number, int number_type, esp_hf_subscriber_service_type_t service_type)
|
||||||
{
|
{
|
||||||
int idx = btc_hf_idx_by_bdaddr(bd_addr);
|
int idx = btc_hf_idx_by_bdaddr(bd_addr);
|
||||||
CHECK_HF_SLC_CONNECTED(idx);
|
CHECK_HF_SLC_CONNECTED(idx);
|
||||||
@ -615,11 +615,11 @@ static bt_status_t btc_hf_cnum_response(bt_bdaddr_t *bd_addr, const char *number
|
|||||||
if (is_connected(idx, bd_addr)) {
|
if (is_connected(idx, bd_addr)) {
|
||||||
tBTA_AG_RES_DATA ag_res;
|
tBTA_AG_RES_DATA ag_res;
|
||||||
memset(&ag_res, 0, sizeof (ag_res));
|
memset(&ag_res, 0, sizeof (ag_res));
|
||||||
BTC_TRACE_EVENT("cnum_response: number = %s, type = %d", number, type);
|
BTC_TRACE_EVENT("cnum_response: number = %s, number type = %d, service type = %d", number, number_type, service_type);
|
||||||
if (number) {
|
if (service_type) {
|
||||||
sprintf(ag_res.str, ",\"%s\",%d",number, type);
|
sprintf(ag_res.str, ",\"%s\",%d,,%d",number, number_type, service_type);
|
||||||
} else {
|
} else {
|
||||||
sprintf(ag_res.str, ",\"\",%d",type);
|
sprintf(ag_res.str, ",\"%s\",%d,,",number, number_type);
|
||||||
}
|
}
|
||||||
ag_res.ok_flag = BTA_AG_OK_DONE;
|
ag_res.ok_flag = BTA_AG_OK_DONE;
|
||||||
BTA_AgResult(hf_local_param[idx].btc_hf_cb.handle, BTA_AG_CNUM_RES, &ag_res);
|
BTA_AgResult(hf_local_param[idx].btc_hf_cb.handle, BTA_AG_CNUM_RES, &ag_res);
|
||||||
@ -1142,7 +1142,7 @@ void btc_hf_call_handler(btc_msg_t *msg)
|
|||||||
|
|
||||||
case BTC_HF_CNUM_RESPONSE_EVT:
|
case BTC_HF_CNUM_RESPONSE_EVT:
|
||||||
{
|
{
|
||||||
btc_hf_cnum_response(&arg->cnum_rep.remote_addr, arg->cnum_rep.number, arg->cnum_rep.type);
|
btc_hf_cnum_response(&arg->cnum_rep.remote_addr, arg->cnum_rep.number, arg->cnum_rep.number_type, arg->cnum_rep.service_type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,8 @@ typedef union
|
|||||||
struct cnum_args {
|
struct cnum_args {
|
||||||
bt_bdaddr_t remote_addr;
|
bt_bdaddr_t remote_addr;
|
||||||
char *number;
|
char *number;
|
||||||
esp_hf_subscriber_service_type_t type;
|
int number_type;
|
||||||
|
esp_hf_subscriber_service_type_t service_type;
|
||||||
} cnum_rep;
|
} cnum_rep;
|
||||||
|
|
||||||
//BTC_HF_NREC_RESPONSE_EVT
|
//BTC_HF_NREC_RESPONSE_EVT
|
||||||
|
@ -148,7 +148,7 @@ HF_CMD_HANDLER(ind_change)
|
|||||||
if (sscanf(argv[3], "%d", &ntk_state) != 1 ||
|
if (sscanf(argv[3], "%d", &ntk_state) != 1 ||
|
||||||
(ntk_state != ESP_HF_NETWORK_STATE_NOT_AVAILABLE &&
|
(ntk_state != ESP_HF_NETWORK_STATE_NOT_AVAILABLE &&
|
||||||
ntk_state != ESP_HF_NETWORK_STATE_AVAILABLE)) {
|
ntk_state != ESP_HF_NETWORK_STATE_AVAILABLE)) {
|
||||||
printf("Invalid argument for netwrok state %s\n", argv[3]);
|
printf("Invalid argument for network state %s\n", argv[3]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (sscanf(argv[4], "%d", &signal) != 1 ||
|
if (sscanf(argv[4], "%d", &signal) != 1 ||
|
||||||
|
@ -360,7 +360,12 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param)
|
|||||||
esp_hf_call_setup_status_t call_setup_state = 2;
|
esp_hf_call_setup_status_t call_setup_state = 2;
|
||||||
esp_hf_network_state_t ntk_state = 1;
|
esp_hf_network_state_t ntk_state = 1;
|
||||||
int signal = 2;
|
int signal = 2;
|
||||||
esp_hf_ag_devices_status_indchange(param->ind_upd.remote_addr,call_state,call_setup_state,ntk_state,signal);
|
int battery = 3;
|
||||||
|
esp_hf_ag_ciev_report(param->ind_upd.remote_addr, ESP_HF_IND_TYPE_CALL, call_state);
|
||||||
|
esp_hf_ag_ciev_report(param->ind_upd.remote_addr, ESP_HF_IND_TYPE_CALLSETUP, call_setup_state);
|
||||||
|
esp_hf_ag_ciev_report(param->ind_upd.remote_addr, ESP_HF_IND_TYPE_SERVICE, ntk_state);
|
||||||
|
esp_hf_ag_ciev_report(param->ind_upd.remote_addr, ESP_HF_IND_TYPE_SIGNAL, signal);
|
||||||
|
esp_hf_ag_ciev_report(param->ind_upd.remote_addr, ESP_HF_IND_TYPE_BATTCHG, battery);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,15 +404,25 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param)
|
|||||||
|
|
||||||
ESP_LOGI(BT_HF_TAG, "--Calling Line Identification.");
|
ESP_LOGI(BT_HF_TAG, "--Calling Line Identification.");
|
||||||
esp_hf_ag_clcc_response(param->clcc_rep.remote_addr, index, dir, current_call_status, mode, mpty, number, type);
|
esp_hf_ag_clcc_response(param->clcc_rep.remote_addr, index, dir, current_call_status, mode, mpty, number, type);
|
||||||
|
|
||||||
|
//AG shall always send ok response to HF
|
||||||
|
//index = 0 means response ok
|
||||||
|
index = 0;
|
||||||
|
esp_hf_ag_clcc_response(param->clcc_rep.remote_addr, index, dir, current_call_status, mode, mpty, number, type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ESP_HF_CNUM_RESPONSE_EVT:
|
case ESP_HF_CNUM_RESPONSE_EVT:
|
||||||
{
|
{
|
||||||
char *number = {"123456"};
|
char *number = {"123456"};
|
||||||
esp_hf_subscriber_service_type_t type = 1;
|
int number_type = 129;
|
||||||
ESP_LOGI(BT_HF_TAG, "--Current Number is %s ,Type is %s.", number, c_subscriber_service_type_str[type]);
|
esp_hf_subscriber_service_type_t service_type = ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE;
|
||||||
esp_hf_ag_cnum_response(param->cnum_rep.remote_addr, number,type);
|
if (service_type == ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE || service_type == ESP_HF_SUBSCRIBER_SERVICE_TYPE_FAX) {
|
||||||
|
ESP_LOGI(BT_HF_TAG, "--Current Number is %s, Number Type is %d, Service Type is %s.", number, number_type, c_subscriber_service_type_str[service_type - 3]);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(BT_HF_TAG, "--Current Number is %s, Number Type is %d, Service Type is %s.", number, number_type, c_subscriber_service_type_str[0]);
|
||||||
|
}
|
||||||
|
esp_hf_ag_cnum_response(hf_peer_addr, number, number_type, service_type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user