JL703N_JL701N-EDR 与 BLE client + server 并行优化 BLE client 的效率
📎 原始文档:https://www.kdocs.cn/l/coRp8KNnvzZ0 JL703N/JL701N-EDR 与 BLE client + server 并行优化 BLE client 的效率
前言
主要针对连接 edr 后 开启 BLE scan (legacy ble scan)和 advertising 时,client 难连接上的情况。
也试用于 EDR + BLE Client + TWS page 时的情况,该策略目前支持 SDK:
- 703 le audio v2.0.0 patch01.07 之后
- 701 le audio v2.0.0 patch01.12 之后
软件配置
三方协议示例使用 sdk_config.h:
#define TCFG_THIRD_PARTY_PROTOCOLS_ENABLE 1 // 第三方协议配置
#if TCFG_THIRD_PARTY_PROTOCOLS_ENABLE
#define TCFG_THIRD_PARTY_PROTOCOLS_SEL (0 | CUSTOM_DEMO_EN | MULTI_CLIENT_EN) // 第三方协议选择
#endif // TCFG_THIRD_PARTY_PROTOCOLS_ENABLE
lib_btctrler_config.c:
const int config_btctler_le_slave_multilink = 1;
lib_btstack_config.c
const int config_le_hci_connection_num = 2;
使用方法
- ble_op_set_leagcy_scan_priority(9); 优先级比 EDR 高
- ble_op_set_leagcy_scan_priority(11); 优先级比 EDR 低
- ble 优先级高会影响 edr 的连接,需要根据情况调整优先级占用的时间,ble_op_set_leagcy_scan_priority 只在 ble scan 开启的时候才生效
- example: 开启 scan 时调整 BLE scan 的优先级
连接后停止
- scan 优先级翻转 demo:
#if BLE_DYN_PRIO_PERIOD_ENABLE
typedef struct {
u16 period_ms;
u16 high_ms; // 高优先级占用时间,单位ms
void (*set_high)(void);
void (*set_low)(void);
u16 timer_id;
u8 state;
} duty_cycle_hdl_t;
static void ble_dyn_prio_handler(void *priv)
{
duty_cycle_hdl_t *hdl = (duty_cycle_hdl_t *)priv;
hdl->timer_id = 0;
if (hdl->state) {
hdl->set_low();
hdl->state = 0;
u16 low_time = hdl->period_ms - hdl->high_ms;
if (low_time > 0) {
hdl->timer_id = sys_timeout_add(hdl, ble_dyn_prio_handler, low_time);
}
} else {
hdl->set_high();
hdl->state = 1;
u16 high_time = hdl->high_ms;
if (high_time > 0) {
hdl->timer_id = sys_timeout_add(hdl, ble_dyn_prio_handler, high_time);
}
}
}
// 启动动态优先级
static void ble_dyn_prio_start(duty_cycle_hdl_t *hdl)
{
if (hdl->timer_id) {
sys_timeout_del(hdl->timer_id);
hdl->timer_id = 0;
}
hdl->state = 1;
hdl->set_high();
u16 high_time = hdl->high_ms;
if (high_time > 0) {
hdl->timer_id = sys_timeout_add(hdl, ble_dyn_prio_handler, high_time);
log_info("%s, high_time = %d", __func__, high_time);
}
}
// 停止动态优先级
static void ble_dyn_prio_stop(duty_cycle_hdl_t *hdl)
{
if (hdl->timer_id) {
sys_timeout_del(hdl->timer_id);
hdl->timer_id = 0;
}
hdl->set_low();
hdl->state = 0;
log_info("%s", __func__);
}
// 动态调整高优先级时间
static void ble_update_duty_cycle(duty_cycle_hdl_t *hdl, u16 new_high_ms)
{
hdl->high_ms = new_high_ms;
ble_dyn_prio_start(hdl);
log_info("%s, new_high_ms = %d", __func__, new_high_ms);
}
static void ble_set_high_priority(void) { ble_op_set_leagcy_scan_priority(9); }
static void ble_set_low_priority(void) { ble_op_set_leagcy_scan_priority(11); }
static duty_cycle_hdl_t g_dyn_prio_hdl = {
.period_ms = 500, // 调整该参数控制优先级翻转的频率
.high_ms = 100, // 高优先级占有时间,单位ms
.set_high = ble_set_high_priority,
.set_low = ble_set_low_priority,
.timer_id = 0,
.state = 0,
};
#endif // BLE_DYN_PRIO_PERIOD_ENABLE
其他
- BLE scan 周期参数调整:
//搜索 周期大小, 建议 SET_SCAN_INTERVAL > SET_SCAN_WINDOW
#define SET_SCAN_INTERVAL ADV_SCAN_MS(19) // unit: ms
#define SET_SCAN_WINDOW ADV_SCAN_MS(17) // unit: ms
- BLE Client 连接 server 回连速度:
static u8 pair_reconnect_search_profile = 0;//回连是否搜索profile
static const client_conn_cfg_t client_conn_config = {
...
...
.search_uuid_cnt = 0, // 配置不搜索profile,加快回连速度
...
...
};
- client 连接参数参考 注:欲要 server 使用主机连接参数,请配置 l2cap_connection_update_request_just 返回 1 拒接 server 的连接参数
默认:
static const struct conn_update_param_t connection_param_table[] = {
{16, 24, 0, 600},
{12, 28, 0, 600},
{8, 20, 0, 600},
{50, 60, 0, 600},
};
传数据时:
static const struct conn_update_param_t connection_param_table[] = {
{19, 22, 0, 400},
{25, 29, 0, 400},
{31, 35, 0, 400},
};
空闲,低数据传输时:
static const struct conn_update_param_t connection_param_table[] = {
{190, 220, 0, 600},
{250, 290, 0, 600},
{310, 350, 0, 600},
};
- 如果 Client 回连时常出现 0x08 (超时)断开 尝试修改
#define SET_CONN_TIMEOUT 200 //(unit:10ms)