This commit is contained in:
lmx
2025-10-30 16:14:14 +08:00
parent c21ac0ab82
commit a6919c7e43
28 changed files with 209514 additions and 209842 deletions

View File

@ -5,6 +5,8 @@
"colorful_lights.h": "c",
"board_jl701n_anc_cfg.h": "c",
"update_loader_download.h": "c",
"iic_soft.h": "c"
"iic_soft.h": "c",
"circle_buffer.h": "c",
"default_event_handler.h": "c"
}
}

View File

@ -1647,3 +1647,28 @@ void send_version_to_sibling(void)
}
#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);
}
}

View File

@ -70,8 +70,8 @@
#include "bt_background.h"
#include "default_event_handler.h"
// 为xtell传感器模块声明外部SPP处理函数
extern void xtell_spp_data_handler(u8 packet_type, u16 ch, u8 *packet, u16 size);
#define xlog(format, ...) printf("[%s] " format, __func__, ##__VA_ARGS__)
#ifdef CONFIG_BOARD_AISPEECH_VAD_ASR
extern int ais_platform_asr_open(void);
@ -493,10 +493,7 @@ void spp_data_handler(u8 packet_type, u16 ch, u8 *packet, u16 size)
break;
}
// 将SPP事件转发给xtell传感器模块处理
if (xtell_spp_data_handler) {
xtell_spp_data_handler(packet_type, ch, packet, size);
}
}
extern const char *sdk_version_info_get(void);
@ -2692,6 +2689,15 @@ static int state_machine(struct application *app, enum app_state state, struct i
bredr_handle_register();
EARPHONE_STATE_INIT();
btstack_init();
u8 mac_data[6];
extern void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf);
rcsp_adv_fill_mac_addr(mac_data); //读取MAC地址
xlog("ble xtell BT mac data:%x:%x:%x:%x:%x:%x",mac_data[0],mac_data[1],mac_data[2],mac_data[3],mac_data[4],mac_data[5]);
xlog("=============bt_function_select_init================\n");
#if TCFG_USER_TWS_ENABLE
tws_profile_init();
sys_key_event_filter_disable();

View File

@ -1,101 +0,0 @@
#include "system/includes.h"
#include "media/includes.h"
#include "tone_player.h"
#include "earphone.h"
#include "app_config.h"
#include "app_action.h"
#include "app_task.h"
#include "btstack/avctp_user.h"
#include "btstack/btstack_task.h"
#include "btctrler/btctrler_task.h"
#include "btstack/frame_queque.h"
#include "user_cfg.h"
#include "aec_user.h"
#include "classic/hci_lmp.h"
#include "bt_common.h"
#include "bt_ble.h"
#include "bt_tws.h"
#include "pbg_user.h"
#include "btstack/bluetooth.h"
#include "colorful_lights/colorful_lights.h"
#if TCFG_AUDIO_ANC_ENABLE
#include "audio_anc.h"
#endif/*TCFG_AUDIO_ANC_ENABLE*/
#if TCFG_ANC_BOX_ENABLE
#include "app_ancbox.h"
#endif
#if TCFG_USER_TWS_ENABLE
#include "bt_tws.h"
#endif
#if TCFG_AUDIO_SPATIAL_EFFECT_ENABLE
#include "spatial_imu_trim.h"
#endif /*TCFG_AUDIO_SPATIAL_EFFECT_ENABLE*/
#if (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_ADV)
#include "include/bt_ble.h"
#endif
#if TCFG_AUDIO_CVP_DUT_ENABLE
#include "audio_cvp_dut.h"
#endif /*TCFG_AUDIO_CVP_DUT_ENABLE*/
#if TCFG_CHARGESTORE_ENABLE || TCFG_TEST_BOX_ENABLE
#include "app_chargestore.h"
#endif
#include "jl_kws/jl_kws_api.h"
#include "asm/charge.h"
#include "app_charge.h"
#include "ui_manage.h"
#include "app_chargestore.h"
#include "app_umidigi_chargestore.h"
#include "app_testbox.h"
#include "app_online_cfg.h"
#include "app_main.h"
#include "app_power_manage.h"
#include "gSensor/gSensor_manage.h"
#include "key_event_deal.h"
#include "classic/tws_api.h"
#include "asm/pwm_led.h"
#include "ir_sensor/ir_manage.h"
#include "in_ear_detect/in_ear_manage.h"
#include "vol_sync.h"
#include "bt_background.h"
#include "default_event_handler.h"
#ifdef CONFIG_BOARD_AISPEECH_VAD_ASR
extern int ais_platform_asr_open(void);
extern void ais_platform_asr_close(void);
#endif /*CONFIG_BOARD_AISPEECH_VAD_ASR*/
#define LOG_TAG_CONST EARPHONE
#define LOG_TAG "[EARPHONE]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
/* #define LOG_DUMP_ENABLE */
#define LOG_CLI_ENABLE
#include "debug.h"
static const struct application_operation app_earphone_ops = {
.state_machine = state_machine,
.event_handler = event_handler,
};
/*
* 注册earphone模式
*/
REGISTER_APPLICATION(app_BLE) = {
.name = "BLE",
.action = ACTION_EARPHONE_MAIN,
.ops = &app_earphone_ops,
.state = APP_STA_DESTROY,
};

View File

@ -23,6 +23,9 @@
#define xlog(format, ...) printf("[%s] " format, __func__, ##__VA_ARGS__)
void send_data_to_ble_client(const u8* data, u16 length);
// --- 任务ID ---
static u16 xtell_i2c_test_id;
static u16 collect_data_id;
@ -33,50 +36,9 @@ static u16 send_data_id;
static u8 sensor_data_buffer[SENSOR_DATA_BUFFER_SIZE];
static circle_buffer_t sensor_cb;
// --- 蓝牙SPP ---
static u8 spp_connected = 0;
//处理从手机接收到的SPP命令
static void handle_spp_command(u8 *packet, u16 size) {
if (size == 10 && strncmp((const char *)packet, "disconnect", 10) == 0) {
xlog("Received the 'disconnect' command, preparing to terminate the connection...\n");
// 发送一个通用的断开连接命令
user_send_cmd_prepare(USER_CTRL_DISCONNECTION_HCI, 0, NULL);
}
else {
xlog("Received an unknown SPP command. The content is as follows:\n");
put_buf(packet, size);
}
}
// SPP事件处理 (移除static使其全局可见)
void xtell_spp_data_handler(u8 packet_type, u16 ch, u8 *packet, u16 size) {
xlog("xtell_spp_data_handler\n");
switch (packet_type) {
case 1: // SPP_CONNECT
xlog("SPP connected\n");
spp_connected = 1;
break;
case 2: // SPP_DISCONNECT
xlog("SPP disconnected\n");
spp_connected = 0;
break;
case 7: // SPP_DATA
// 调用命令处理函数
handle_spp_command(packet, size);
break;
default:
xlog("spp event error\n");
break;
}
}
// 采集传感器数据并存入环形缓冲区的任务
void collect_and_buffer_sensor_data_task(void) {
if (!spp_connected) {
xlog("SPP not connected. Skipping data collection.\n");
return; // 如果未连接,则不采集数据
}
motion_data_t current_motion;
axis_info_xtell total_accel;
@ -103,27 +65,13 @@ void collect_and_buffer_sensor_data_task(void) {
}
}
// 从环形缓冲区读取数据并通过SPP发送的任务
// 从环形缓冲区读取数据并发送
void send_sensor_data_task(void) {
// xlog("发送任务执行,连接状态: %d, 缓冲区大小: %d\n", spp_connected, circle_buffer_get_size(&sensor_cb));
if (!spp_connected || circle_buffer_get_size(&sensor_cb) == 0) {
return;
}
#define MAX_SPP_PACKET_SIZE 128 // 根据实际情况调整
u8 send_buf[MAX_SPP_PACKET_SIZE];
u16 len_to_read = circle_buffer_get_size(&sensor_cb);
if (len_to_read > MAX_SPP_PACKET_SIZE) {
len_to_read = MAX_SPP_PACKET_SIZE;
}
u16 read_len = circle_buffer_read(&sensor_cb, send_buf, len_to_read);
if (read_len > 0) {
user_send_cmd_prepare(USER_CTRL_SPP_SEND_DATA, read_len, send_buf);
}
xlog("send data by spp\n");
//查询开关机状态
u8 temp[5]={0xBB,0xBE,0x02,0x00,0x00};
printf("xtell_ble_send\n");
send_data_to_ble_client(&temp,5);
}
void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec){
@ -152,18 +100,16 @@ void xtell_main(void){
//开经典蓝牙
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL); //打开蓝牙可发现,已连接时不能操作
delay_2ms(50);
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL); //打开蓝牙可连接
delay_2ms(50);
// user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL); //打开蓝牙可发现,已连接时不能操作
// delay_2ms(50);
// user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL); //打开蓝牙可连接
// delay_2ms(50);
// connect_last_device_from_vm(); //自动回连上一个设备
// 初始化环形缓冲区
circle_buffer_init(&sensor_cb, sensor_data_buffer, SENSOR_DATA_BUFFER_SIZE);
// 注册SPP数据处理回调 (此操作已由earphone.c统一处理此处不再需要)
/* spp_data_deal_handle_register(xtell_spp_data_handler); */
// 创建一个定时器每200ms调用一次核心计算任务
create_process(&xtell_i2c_test_id, "xtell_i2c_test", NULL, xtell_i2c_test, (u32)(SAMPLING_PERIOD_S * 1000));

View File

@ -15,6 +15,7 @@
lp_signature_set = ABSOLUTE(0x1fd6c);
memmem = ABSOLUTE(0x1fd70);
memcpy = ABSOLUTE(0x1fd74);

View File

@ -14,6 +14,7 @@
sdfile_vfs_ops
sbc_decoder

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -15,6 +15,7 @@
@echo off
Setlocal enabledelayedexpansion
@echo ********************************************************************************

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1919,6 +1919,7 @@ objs/apps/common/third_party_profile/jieli/JL_rcsp/bt_trans_data/le_rcsp_adv_mod
-r=objs/apps/common/third_party_profile/jieli/JL_rcsp/bt_trans_data/le_rcsp_adv_module.c.o,send_version_to_sibling,pl
-r=objs/apps/common/third_party_profile/jieli/JL_rcsp/bt_trans_data/le_rcsp_adv_module.c.o,get_vid_pid_ver_from_cfg_file,l
-r=objs/apps/common/third_party_profile/jieli/JL_rcsp/bt_trans_data/le_rcsp_adv_module.c.o,tws_api_send_data_to_sibling,l
-r=objs/apps/common/third_party_profile/jieli/JL_rcsp/bt_trans_data/le_rcsp_adv_module.c.o,send_data_to_ble_client,pl
-r=objs/apps/common/third_party_profile/jieli/JL_rcsp/bt_trans_data/le_rcsp_adv_module.c.o,sm_just_works_confirm,l
-r=objs/apps/common/third_party_profile/jieli/JL_rcsp/bt_trans_data/le_rcsp_adv_module.c.o,printf_buf,l
-r=objs/apps/common/third_party_profile/jieli/JL_rcsp/bt_trans_data/le_rcsp_adv_module.c.o,little_endian_read_16,l
@ -3134,7 +3135,6 @@ objs/apps/earphone/earphone.c.o
-r=objs/apps/earphone/earphone.c.o,link_fix_rx_update_result,
-r=objs/apps/earphone/earphone.c.o,printf,l
-r=objs/apps/earphone/earphone.c.o,spp_data_handler,pl
-r=objs/apps/earphone/earphone.c.o,xtell_spp_data_handler,l
-r=objs/apps/earphone/earphone.c.o,bredr_handle_register,pl
-r=objs/apps/earphone/earphone.c.o,spp_data_deal_handle_register,l
-r=objs/apps/earphone/earphone.c.o,bt_fast_test_handle_register,l
@ -3267,6 +3267,7 @@ objs/apps/earphone/earphone.c.o
-r=objs/apps/earphone/earphone.c.o,bt_pll_para,l
-r=objs/apps/earphone/earphone.c.o,rcsp_earphone_state_init,l
-r=objs/apps/earphone/earphone.c.o,btstack_init,l
-r=objs/apps/earphone/earphone.c.o,rcsp_adv_fill_mac_addr,l
-r=objs/apps/earphone/earphone.c.o,sys_key_event_enable,l
-r=objs/apps/earphone/earphone.c.o,colorful_lights_function,l
-r=objs/apps/earphone/earphone.c.o,init_ok,pl
@ -6304,18 +6305,15 @@ objs/apps/earphone/xtell_Sensor/LIS2DH12.c.o
-r=objs/apps/earphone/xtell_Sensor/LIS2DH12.c.o,gsensor_static_flag,pl
-r=objs/apps/earphone/xtell_Sensor/LIS2DH12.c.o,gsensor_alarm,pl
objs/apps/earphone/xtell_Sensor/main.c.o
-r=objs/apps/earphone/xtell_Sensor/main.c.o,xtell_spp_data_handler,pl
-r=objs/apps/earphone/xtell_Sensor/main.c.o,printf,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,collect_and_buffer_sensor_data_task,pl
-r=objs/apps/earphone/xtell_Sensor/main.c.o,get_motion_data,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,get_current_accel_mss,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,get_linear_accel_mss,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,snprintf,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,circle_buffer_write,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,printf,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,send_sensor_data_task,pl
-r=objs/apps/earphone/xtell_Sensor/main.c.o,circle_buffer_get_size,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,circle_buffer_read,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,user_send_cmd_prepare,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,send_data_to_ble_client,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,create_process,pl
-r=objs/apps/earphone/xtell_Sensor/main.c.o,sys_timer_add,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,rcsp_adv_fill_mac_addr,pl
@ -6324,11 +6322,9 @@ objs/apps/earphone/xtell_Sensor/main.c.o
-r=objs/apps/earphone/xtell_Sensor/main.c.o,xtell_main,pl
-r=objs/apps/earphone/xtell_Sensor/main.c.o,soft_iic_init,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,LIS2DH12_Config,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,delay_2ms,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,circle_buffer_init,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,xtell_i2c_test,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,strncmp,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,put_buf,l
-r=objs/apps/earphone/xtell_Sensor/main.c.o,puts,l
objs/apps/earphone/xtell_Sensor/circle_buffer.c.o
-r=objs/apps/earphone/xtell_Sensor/circle_buffer.c.o,circle_buffer_init,pl
-r=objs/apps/earphone/xtell_Sensor/circle_buffer.c.o,circle_buffer_write,pl

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.