bigbaicai

芯方式是以半导体人、电子工程师等电子行业相关领域从业人员为核心的知识经验学习、分享、交流社群。 凭借开放、合作、共赢的运营理念,聚集了来自国内外知名院校和顶尖科技公司的半导体人、电子工程师。 我们致力于营造专业、认真、有温度的分享交流环境,将高质量的内容和方案成规模地生产和分享,帮助个人和团队在芯方式找到有价值的Key。 http://www.icfans.com/

mt2523[BT] 如何获取通话列表

0
阅读(239) 评论(0)

mt2523[BT] 如何获取通话列表


当前FAQ是基于SDK 4.0.0的版本,依赖于Sink module来实现,请确保您的版本高于SDK 4.0.0并且已经包含了sink的module
1. 添加一个sink service event来回报通话列表
File: middleware\mtk\bt_sink\inc\bt_sink_srv.h
#define BT_SINK_SRV_EVENT_HF_CALL_LIST_INFORMATION
(BT_SINK_SRV_EVENT_HF_START + 4)
2. 添加sink service event对应的结构体
File: middleware\MTK\bt_sink\inc\bt_sink_srv.h
typedef struct {
bt_bd_addr_t bt_addr;
uint8_t index; /**< Index of the call on the audio gateway. */
uint8_t director; /**< The director of the call, 0 - Mobile Originated, 1
- Mobile Terminated. */
bt_hfp_call_status_t state; /**< The call state of the call. */
bt_hfp_call_mode_t mode; /**< The call mode of the call. */
uint8_t multiple_party; /**< If the call is multiple party, 0 - Not
Multiparty, 1 - Multiparty. */
uint16_t num_size; /**< The phone number size of the call. */
uint8_t number[BT_SINK_SRV_MAX_PHONE_NUMBER]; /**< The phone number of the
call. */
bt_hfp_phone_num_format_t type; /**< The address type of the call. */
bool final;
} bt_sink_srv_call_list_information_t;
typedef union {
bt_sink_srv_state_change_t state_change;
bt_sink_srv_caller_information_t caller_info;
bt_sink_srv_connection_information_t connection_info;
bt_sink_srv_volume_change_t volume_change;
bt_sink_srv_call_list_information_t call_list; // add the structure to the
union.
} bt_sink_srv_event_param_t;


3. 添加一个flag用于区分用户请求或是内部调用
File: middleware\MTK\bt_sink\inc\bt_sink_srv_hf.h
typedef enum {
BT_SINK_SRV_HF_FLAG_NONE = 0x0000,
BT_SINK_SRV_HF_FLAG_SCO_ACTIVE = 0x0001,
BT_SINK_SRV_HF_FLAG_QUERY_NAME = 0x0002,
BT_SINK_SRV_HF_FLAG_USER_REJECT = 0x0004,
BT_SINK_SRV_HF_FLAG_QUERY_LIST = 0x0008 // add the flag
} bt_sink_srv_hf_flag_t;


4. 添加函数声明
File: middleware\MTK\bt_sink\inc\bt_sink_srv_hf.h
void bt_sink_srv_hf_query_call_list(bt_bd_addr_t *address);


5. 添加获取通话列表的函数定义
File: middleware\MTK\bt_sink\src\bt_sink_srv_hf_call_manager.c
void bt_sink_srv_hf_query_call_list(bt_bd_addr_t *address)
{
bt_sink_srv_profile_t *bt_sink_srv_hf_p = NULL;
bt_sink_srv_hf_context_t *bt_sink_srv_hf_context_p = NULL;
bt_bd_addr_t *address_p = address;
if (NULL == address_p) {
address_p = bt_sink_srv_cm_last_connected_device();
}
bt_sink_srv_hf_p = bt_sink_srv_cm_find_profile_by_address(address_p,
BT_SINK_SRV_UUID_HF);
if (NULL != bt_sink_srv_hf_p) {
bt_sink_srv_hf_context_p = (bt_sink_srv_hf_context_t *)bt_sink_srv_hf_p-
>data;
if (NULL != bt_sink_srv_hf_context_p &&
!(bt_sink_srv_hf_context_p->flag & BT_SINK_SRV_HF_FLAG_QUERY_LIST)) {
bt_sink_srv_hf_context_p->flag |= BT_SINK_SRV_HF_FLAG_QUERY_LIST;
BT_SINK_SRV_HF_QUERY_CALL_LIST(bt_sink_srv_hf_context_p->handle);
}
}
}


6. 回报通话列表
File: middleware\MTK\bt_sink\src\bt_sink_srv_hf.c
bt_status_t bt_sink_srv_hf_common_callback(bt_msg_type_t msg, bt_status_t
status, void *buffer)
{
//...
switch (msg) {
//...
case BT_HFP_CURRENT_CALLS_IND: {
bt_hfp_call_list_ind_t *message = (bt_hfp_call_list_ind_t *)buffer;
address_p = bt_hfp_get_bd_addr_by_handle(message->handle);
bt_sink_srv_hf_p = bt_sink_srv_cm_find_profile_by_address(address_p,
BT_SINK_SRV_UUID_HF);
if (NULL != bt_sink_srv_hf_p) {
bt_sink_srv_hf_handle_call_info_ind((bt_sink_srv_hf_context_t
*)bt_sink_srv_hf_p->data, message);
}
// Add start
if (((bt_sink_srv_hf_context_t *)bt_sink_srv_hf_p->data)->flag &
BT_SINK_SRV_HF_FLAG_QUERY_LIST) {
bt_sink_srv_event_param_t *event =
bt_sink_srv_memory_alloc(sizeof(*event));
if (NULL != event) {
bt_sink_srv_meMCPy(&event->call_list.bt_addr, address_p,
sizeof(*address_p));
event->call_list.index = message->index;
event->call_list.director = message->director;
event->call_list.state = message->state;
event->call_list.mode = message->mode;
event->call_list.multiple_party = message->multiple_party;
event->call_list.num_size = message->num_size;
event->call_list.final = false;
bt_sink_srv_memcpy(event->call_list.number, message->number,
BT_SINK_SRV_MAX_PHONE_NUMBER);
bt_sink_srv_event_callback(BT_SINK_SRV_EVENT_HF_CALL_LIST_INFORMATION,
event);
bt_sink_srv_memory_free(event);
}
}
// Add End
}
break;
//...
// Add start
case BT_HFP_ACTION_CMD_CNF: {
bt_hfp_action_cnf_t *message = (bt_hfp_action_cnf_t *)buffer;
address_p = bt_hfp_get_bd_addr_by_handle(message->handle);
bt_sink_srv_hf_p = bt_sink_srv_cm_find_profile_by_address(address_p,
BT_SINK_SRV_UUID_HF);
if (NULL != bt_sink_srv_hf_p) {
bt_sink_srv_hf_context_p = (bt_sink_srv_hf_context_t *)bt_sink_srv_hf_p-
>data;
if (NULL != bt_sink_srv_hf_context_p && (bt_sink_srv_hf_context_p->flag &
BT_SINK_SRV_HF_FLAG_QUERY_LIST)) {
bt_sink_srv_event_param_t *event =
bt_sink_srv_memory_alloc(sizeof(*event));
bt_sink_srv_hf_context_p->flag &= (~(BT_SINK_SRV_HF_FLAG_QUERY_LIST));
if (NULL != event) {
bt_sink_srv_memcpy(&event->call_list.bt_addr, address_p,
sizeof(*address_p));
event->call_list.final = true;
bt_sink_srv_event_callback(BT_SINK_SRV_EVENT_HF_CALL_LIST_INFORMATION,
event);
bt_sink_srv_memory_free(event);
}
}
}
}
break;
// Add End
//...
}
//...
}


7. 添加一个新的action入口
File: middleware\MTK\bt_sink\src\bt_sink_srv_hf.c
bt_sink_srv_status_t bt_sink_srv_hf_action_handler(bt_sink_srv_action_t
action, void *parameters)
{
//...
switch (msg) {
//...
// Add start
case BT_SINK_SRV_ACTION_QUERY_CALL_LIST: {
bt_sink_srv_hf_query_call_list((bt_bd_addr_t *)parameters);
}
break;
// Add end
default:
bt_sink_srv_report("[Sink][HF] Unexcepted action:%x", action);
break;
}
return result;
}


8. 接收sink service event,根据需要进行处理
File: project\MT2523_HDK\apps\IOT_sdk_demo\src\bt_audio\sink\bt_sink_app_event.c
bt_sink_srv_status_t bt_sink_app_event_handler(bt_sink_srv_event_t
event_id, void *parameters)
{
//...
switch (event_id) {
//...
// Add start
case BT_SINK_SRV_EVENT_HF_CALL_LIST_INFORMATION:
bt_sink_app_report("[Sink] call list information,
address:0x%2x,0x%2x,0x%2x,0x%2x,0x%2x,0x%2x, final:%d",
event->call_list.bt_addr[5],
event->call_list.bt_addr[4],
event->call_list.bt_addr[3],
event->call_list.bt_addr[2],
event->call_list.bt_addr[1],
event->call_list.bt_addr[0],
event->call_list.final);
bt_sink_app_report("[Sink] call list information, idx:%d, dir:%d,
state:%d, mode:%d, mul:%d, size:%d, type:%d",
event->call_list.index,
event->call_list.director,
event->call_list.state,
event->call_list.mode,
event->call_list.multiple_party,
event->call_list.num_size,
event->call_list.type);
break;
// Add end
default:
break;
}
return BT_SINK_SRV_STATUS_SUCCESS;
}


9. 根据需要,使用action的API来获取通话列表
File: project\mt2523_hdk\apps\iot_sdk_demo\src\bt_audio\sink\bt_sink_app_event.c
// Add start
#include "bt_sink_srv_action.h"
// Add end
bt_sink_srv_status_t bt_sink_app_event_handler(bt_sink_srv_event_t
event_id, void *parameters)
{
bt_sink_srv_event_param_t *event = (bt_sink_srv_event_param_t
*)parameters;
bt_sink_app_report("[Sink] event:0x%x", event_id);
switch (event_id) {
//...
case BT_SINK_SRV_EVENT_STATE_CHANGE:
bt_sink_app_report("[Sink] state change, previous:0x%x, now:0x%x", event-
>state_change.previous, event->state_change.now);
bt_sink_app_context.state = event->state_change.now;
bt_sink_app_ATCI_indicate(event->state_change.now);
// Add start
if (event->state_change.now & BT_SINK_SRV_STATE_ALL_CALLS) {
bt_sink_srv_action_send(BT_SINK_SRV_ACTION_QUERY_CALL_LIST, NULL);
}
break;
// Add end
//...
}
//...
return BT_SINK_SRV_STATUS_SUCCESS;
}


10. 添加UT/IT入口,通过输入AT+BTSINKIT=CLCC可以测试功能
File: middleware\MTK\bt_sink\src\bt_sink_srv_atci_cmd.c
static int16_t bt_sink_srv_cmd_entry(const char *string)
{
//...
// Add start
} else if (0 == bt_sink_srv_memcmp(string, CMD_PARAM("CLCC"))) {
bt_bd_addr_t *address_p = bt_sink_srv_cm_last_connected_device();
bt_sink_srv_action_send(BT_SINK_SRV_ACTION_QUERY_CALL_LIST, address_p);
}
// Add end
return 0;
}