蓝牙发送速率提升
This commit is contained in:
@ -49,7 +49,7 @@
|
||||
#include "classic/tws_api.h"
|
||||
#include "rcsp_adv_user_update.h"
|
||||
#include "bt_tws.h"
|
||||
|
||||
// #include "le_trans_data.h"
|
||||
#if (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_ADV_RCSP)
|
||||
|
||||
#if TCFG_CHARGE_BOX_ENABLE
|
||||
@ -86,8 +86,10 @@ static const char user_tag_string[] = {EIR_TAG_STRING};
|
||||
/* #include "debug.h" */
|
||||
|
||||
//------
|
||||
#define ATT_LOCAL_PAYLOAD_SIZE (200) //note: need >= 20
|
||||
#define ATT_SEND_CBUF_SIZE (512) //note: need >= 20,缓存大小,可修改
|
||||
// #define ATT_LOCAL_PAYLOAD_SIZE (200*10) //note: need >= 20
|
||||
// #define ATT_SEND_CBUF_SIZE (1024 * 50) //note: need >= 20,缓存大小,可修改
|
||||
#define ATT_LOCAL_PAYLOAD_SIZE (517) //note: need >= 20
|
||||
#define ATT_SEND_CBUF_SIZE (1024 * 2) //note: need >= 20,缓存大小,可修改
|
||||
#define ATT_RAM_BUFSIZE (ATT_CTRL_BLOCK_SIZE + ATT_LOCAL_PAYLOAD_SIZE + ATT_SEND_CBUF_SIZE) //note:
|
||||
static u8 att_ram_buffer[ATT_RAM_BUFSIZE] __attribute__((aligned(4)));
|
||||
//---------------
|
||||
@ -109,9 +111,10 @@ static const uint8_t sm_min_key_size = 7;
|
||||
static const uint8_t connection_update_enable = 1; ///0--disable, 1--enable
|
||||
static uint8_t connection_update_cnt = 0; //
|
||||
static const struct conn_update_param_t connection_param_table[] = {
|
||||
{16, 24, 16, 600},
|
||||
{12, 28, 14, 600},//11
|
||||
{8, 20, 20, 600},//3.7
|
||||
{6, 12, 0, 400},//3.7
|
||||
// {16, 24, 16, 600},
|
||||
// {12, 28, 14, 600},//11
|
||||
// {8, 20, 20, 600},//3.7
|
||||
/* {12, 28, 4, 600},//3.7 */
|
||||
/* {12, 24, 30, 600},//3.05 */
|
||||
};
|
||||
@ -299,6 +302,17 @@ void test_data_send_packet(void)
|
||||
|
||||
static void can_send_now_wakeup(void)
|
||||
{
|
||||
// static signed char acc_data_buf[60] = {
|
||||
// 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22
|
||||
// };
|
||||
// extern void send_data_to_ble_client(const u8* data, u16 length);
|
||||
// send_data_to_ble_client(&acc_data_buf, 60);
|
||||
|
||||
putchar('E');
|
||||
if (ble_resume_send_wakeup) {
|
||||
ble_resume_send_wakeup();
|
||||
@ -315,6 +329,24 @@ u8 ble_update_get_ready_jump_flag(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 添加到 le_rcsp_adv_module.c
|
||||
static void set_connection_data_length(u16 tx_octets, u16 tx_time) //xtell
|
||||
{
|
||||
if (con_handle) {
|
||||
ble_user_cmd_prepare(BLE_CMD_SET_DATA_LENGTH, 3, con_handle, tx_octets, tx_time);
|
||||
}
|
||||
}
|
||||
|
||||
static void set_connection_data_phy(u8 tx_phy, u8 rx_phy)//xtell
|
||||
{
|
||||
if (0 == con_handle) {
|
||||
return;
|
||||
}
|
||||
u8 all_phys = 0;
|
||||
u16 phy_options = 0; // 根据你的 SDK 定义调整
|
||||
ble_user_cmd_prepare(BLE_CMD_SET_PHY, 5, con_handle, all_phys, tx_phy, rx_phy, phy_options);
|
||||
}
|
||||
|
||||
/*
|
||||
* @section Packet Handler
|
||||
*
|
||||
@ -370,6 +402,16 @@ static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
connection_update_complete_success(packet);
|
||||
break;
|
||||
}
|
||||
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE: //xtell
|
||||
log_info("APP HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE\n");
|
||||
set_connection_data_phy(2, 2); // 2 表示 2M PHY
|
||||
break;
|
||||
|
||||
case HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE://xtell
|
||||
log_info("APP HCI_SUBEVENT_LE_PHY_UPDATE %s\n", packet[4] ? "Fail" : "Succ"); // packet[4] 是 status
|
||||
log_info("Tx PHY: %d\n", packet[5]); // packet[5] 是 TX_PHY
|
||||
log_info("Rx PHY: %d\n", packet[6]); // packet[6] 是 RX_PHY
|
||||
break;
|
||||
break;
|
||||
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
@ -410,6 +452,7 @@ static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3;
|
||||
log_info("ATT MTU = %u\n", mtu);
|
||||
ble_user_cmd_prepare(BLE_CMD_ATT_MTU_SIZE, 1, mtu);
|
||||
set_connection_data_length(251, 2120);//xtell
|
||||
break;
|
||||
|
||||
case HCI_EVENT_VENDOR_REMOTE_TEST:
|
||||
@ -571,6 +614,7 @@ static int app_send_user_data(u16 handle, u8 *data, u16 len, u8 handle_type)
|
||||
|
||||
ret = ble_user_cmd_prepare(BLE_CMD_ATT_SEND_DATA, 4, handle, data, len, handle_type);
|
||||
if (ret == BLE_BUFFER_FULL) {
|
||||
printf("app_send_user_data: buffer full\n");
|
||||
ret = APP_BLE_BUFF_FULL;
|
||||
}
|
||||
|
||||
@ -1663,12 +1707,8 @@ void send_version_to_sibling(void)
|
||||
data[2] = ver >> 8;
|
||||
tws_api_send_data_to_sibling(data, sizeof(data), TWS_FUNC_ID_SEQ_RAND_SYNC);
|
||||
}
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
void send_data_to_ble_client(const u8* data, u16 length)
|
||||
{
|
||||
// 检查数据长度是否有效
|
||||
@ -1677,8 +1717,8 @@ void send_data_to_ble_client(const u8* data, u16 length)
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查缓冲区空间
|
||||
if (app_send_user_data_check(length)) {
|
||||
// // 检查缓冲区空间
|
||||
// if (app_send_user_data_check(length)) {
|
||||
// 发送数据
|
||||
int ret = app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, data, length, ATT_OP_NOTIFY);
|
||||
if (ret == 0) { // 假设 0 表示成功
|
||||
@ -1686,7 +1726,12 @@ void send_data_to_ble_client(const u8* data, u16 length)
|
||||
} else {
|
||||
// printf("Failed to send data: Length %d, Error code: %d\n", length, ret);
|
||||
}
|
||||
} else {
|
||||
// printf("Insufficient buffer space to send data: Length %d\n", length);
|
||||
}
|
||||
}
|
||||
// } else {
|
||||
// printf("Insufficient buffer space to send data: Length %d\n", length);
|
||||
// }
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -81,9 +81,9 @@ extern void printf_buf(u8 *buf, u32 len);
|
||||
|
||||
//------
|
||||
//ATT发送的包长, note: 20 <=need >= MTU
|
||||
#define ATT_LOCAL_MTU_SIZE (200) //
|
||||
#define ATT_LOCAL_MTU_SIZE (517) //200
|
||||
//ATT缓存的buffer大小, note: need >= 20,可修改
|
||||
#define ATT_SEND_CBUF_SIZE (512) //
|
||||
#define ATT_SEND_CBUF_SIZE (512 * 20) //
|
||||
|
||||
//共配置的RAM
|
||||
#define ATT_RAM_BUFSIZE (ATT_CTRL_BLOCK_SIZE + ATT_LOCAL_MTU_SIZE + ATT_SEND_CBUF_SIZE) //note:
|
||||
@ -125,9 +125,10 @@ static uint8_t connection_update_cnt = 0; //
|
||||
|
||||
//参数表
|
||||
static const struct conn_update_param_t connection_param_table[] = {
|
||||
{16, 24, 10, 600},//11
|
||||
{12, 28, 10, 600},//3.7
|
||||
{8, 20, 10, 600},
|
||||
{6, 12, 0, 400},//11
|
||||
// {16, 24, 10, 600},//11
|
||||
// {12, 28, 10, 600},//3.7
|
||||
// {8, 20, 10, 600},
|
||||
/* {12, 28, 4, 600},//3.7 */
|
||||
/* {12, 24, 30, 600},//3.05 */
|
||||
};
|
||||
@ -706,6 +707,11 @@ static int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_h
|
||||
u16 handle = att_handle;
|
||||
|
||||
log_info("write_callback, handle= 0x%04x,size = %d\n", handle, buffer_size);
|
||||
if(buffer[0] == 0xbe && buffer[1] == 0xbb){
|
||||
extern void test_func(void);
|
||||
test_func();
|
||||
}
|
||||
|
||||
|
||||
switch (handle) {
|
||||
|
||||
@ -1389,6 +1395,44 @@ void hangup_ans_call_handle(u8 en)
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void send_data_to_ble_client(const u8* data, u16 length)
|
||||
{
|
||||
// 检查数据长度是否有效
|
||||
if (length == 0 || length > 512) {
|
||||
printf("Error: Data length %d is out of range (1-512)\n", length);
|
||||
return;
|
||||
}
|
||||
|
||||
// // 检查缓冲区空间
|
||||
// if (app_send_user_data_check(length)) {
|
||||
// 发送数据
|
||||
int ret = app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, data, length, ATT_OP_NOTIFY);
|
||||
if (ret == 0) { // 假设 0 表示成功
|
||||
// printf("Data sent successfully: Length %d\n", length);
|
||||
} else {
|
||||
printf("Failed to send data: Length %d, Error code: %d\n", length, ret);
|
||||
}
|
||||
// } else {
|
||||
// printf("Insufficient buffer space to send data: Length %d\n", length);
|
||||
// }
|
||||
}
|
||||
|
||||
void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf)
|
||||
{
|
||||
#if (MUTIl_CHARGING_BOX_EN)
|
||||
u8 *mac_addr = get_chargebox_adv_addr();
|
||||
if (mac_addr) {
|
||||
swapX(mac_addr, mac_addr_buf, 6);
|
||||
}
|
||||
|
||||
/* printf("mac_addr:"); */
|
||||
/* printf_buf(mac_addr_buf, 6); */
|
||||
|
||||
#else
|
||||
swapX(bt_get_mac_addr(), mac_addr_buf, 6);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ extern void printf_buf(u8 *buf, u32 len);
|
||||
//------
|
||||
//ATT发送的包长, note: 20 <=need >= MTU
|
||||
#define ATT_LOCAL_MTU_SIZE (517) //
|
||||
//ATT缓存的buffer大小, note: need >= 20,可修改
|
||||
//ATT缓存的buffer大小, +: need >= 20,可修改
|
||||
#if(APP_MAIN == APP_WIRELESS_MIC_2T1)
|
||||
#define ATT_SEND_CBUF_SIZE (90)
|
||||
#else
|
||||
@ -92,7 +92,8 @@ static uint8_t connection_update_cnt = 0; //
|
||||
|
||||
//参数表
|
||||
static const struct conn_update_param_t connection_param_table[] = {
|
||||
{WIRELESS_BLE_CONNECT_INTERVAL, WIRELESS_BLE_CONNECT_INTERVAL, 0, 100},//11
|
||||
// {1, 5, 4, 600},//11
|
||||
{12, 24, 0, 400}, // 建议修改为此值 (15ms - 30ms interval)
|
||||
};
|
||||
|
||||
//共可用的参数组数
|
||||
@ -421,7 +422,7 @@ static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
|
||||
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE:
|
||||
log_info("APP HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE\n");
|
||||
set_connection_data_phy(CONN_SET_2M_PHY, CONN_SET_2M_PHY);
|
||||
// set_connection_data_phy(CONN_SET_2M_PHY, CONN_SET_2M_PHY);
|
||||
break;
|
||||
|
||||
case HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE:
|
||||
@ -453,7 +454,7 @@ static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3;
|
||||
log_info("ATT MTU = %u\n", mtu);
|
||||
ble_op_att_set_send_mtu(mtu);
|
||||
set_connection_data_length(251, 2120);
|
||||
// set_connection_data_length(251, 2120);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_VENDOR_REMOTE_TEST:
|
||||
@ -1067,6 +1068,44 @@ void ble_server_send_test_key_num(u8 key_num)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
void send_data_to_ble_client(const u8* data, u16 length)
|
||||
{
|
||||
// 检查数据长度是否有效
|
||||
if (length == 0 || length > 512) {
|
||||
printf("Error: Data length %d is out of range (1-512)\n", length);
|
||||
return;
|
||||
}
|
||||
|
||||
// // 检查缓冲区空间
|
||||
// if (app_send_user_data_check(length)) {
|
||||
// 发送数据
|
||||
int ret = app_send_user_data(ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, data, length, ATT_OP_NOTIFY);
|
||||
if (ret == 0) { // 假设 0 表示成功
|
||||
printf("Data sent successfully: Length %d\n", length);
|
||||
} else {
|
||||
printf("Failed to send data: Length %d, Error code: %d\n", length, ret);
|
||||
}
|
||||
// } else {
|
||||
// printf("Insufficient buffer space to send data: Length %d\n", length);
|
||||
// }
|
||||
}
|
||||
|
||||
void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf)
|
||||
{
|
||||
#if (MUTIl_CHARGING_BOX_EN)
|
||||
u8 *mac_addr = get_chargebox_adv_addr();
|
||||
if (mac_addr) {
|
||||
swapX(mac_addr, mac_addr_buf, 6);
|
||||
}
|
||||
|
||||
/* printf("mac_addr:"); */
|
||||
/* printf_buf(mac_addr_buf, 6); */
|
||||
|
||||
#else
|
||||
swapX(bt_get_mac_addr(), mac_addr_buf, 6);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user