Files
99_7018_lmx/apps/earphone/xtell_Sensor/send_data.c

177 lines
5.6 KiB
C
Raw Normal View History

2025-10-29 16:24:16 +08:00
#include "system/includes.h"
#include "btstack/btstack_task.h"
#include "app_config.h"
#include "app_action.h"
#include "asm/pwm_led.h"
#include "tone_player.h"
#include "ui_manage.h"
#include "gpio.h"
#include "app_main.h"
#include "asm/charge.h"
#include "update.h"
#include "app_power_manage.h"
#include "audio_config.h"
#include "app_charge.h"
#include "bt_profile_cfg.h"
#include "dev_manager/dev_manager.h"
#include "update_loader_download.h"
2025-11-11 19:31:34 +08:00
#include "./sensor/SC7U22.h"
#include "./buffer/circle_buffer.h"
2025-10-30 11:33:38 +08:00
#include "btstack/avctp_user.h"
2025-11-03 18:48:15 +08:00
#include "calculate/skiing_tracker.h"
2025-11-06 19:24:51 +08:00
#include "xtell.h"
2025-11-18 10:15:00 +08:00
#include "./ano/ano_protocol.h"
2025-11-20 09:24:11 +08:00
#include "./sensor/MMC56.h"
#include "./sensor/BMP280.h"
2025-11-20 19:30:34 +08:00
#include "./sensor/AK8963.h"
2025-10-31 09:40:15 +08:00
///////////////////////////////////////////////////////////////////////////////////////////////////
//宏定义
#define ENABLE_XLOG 1
#ifdef xlog
#undef xlog
#endif
#if ENABLE_XLOG
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
#else
#define xlog(format, ...) ((void)0)
#endif
2025-11-21 14:54:21 +08:00
#define SENSOR_DATA_BUFFER_SIZE 500 // 定义缓冲区可以存储XXX个sensor_data_t元素
2025-10-31 09:40:15 +08:00
//
///////////////////////////////////////////////////////////////////////////////////////////////////
2025-10-29 16:24:16 +08:00
2025-10-31 10:38:17 +08:00
//////////////////////////////////////////////////////////////////////////////////////////////////
//START -- 函数定义
2025-10-30 16:14:14 +08:00
void send_data_to_ble_client(const u8* data, u16 length);
2025-11-03 18:48:15 +08:00
extern void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec);
2025-11-21 14:54:21 +08:00
extern void close_process(u16* pid,char* name);
2025-10-31 10:38:17 +08:00
//END -- 函数定义
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//START -- 变量定义
2025-10-30 16:14:14 +08:00
2025-10-30 11:33:38 +08:00
2025-11-21 14:54:21 +08:00
typedef struct {
// -- 六轴 --
signed short acc_data[3];
signed short gyr_data[3];
// -- 磁力计 --
uint8_t mmc5603nj_buffer[9];
// -- 速度 --
int speed_cms;
// -- 气压计 --
//...
} BLE_send_data_t;
2025-11-03 18:48:15 +08:00
2025-11-20 19:30:34 +08:00
static int count = 0;
2025-11-11 19:31:34 +08:00
2025-11-21 14:54:21 +08:00
// --- 环形缓冲区 ---
static circle_buffer_t BLE_send_buff; // 环形缓冲区管理结构体
2025-11-18 10:15:00 +08:00
2025-11-21 14:54:21 +08:00
//END -- 变量定义
//////////////////////////////////////////////////////////////////////////////////////////////////
2025-10-29 16:24:16 +08:00
2025-11-21 14:54:21 +08:00
/**
* @brief
*
*/
void SC7U22_static_calibration(void){
signed short acc_data_buf[3];
signed short gyr_data_buf[3];
float angle[3];
float quaternion_output[3];
2025-11-06 19:24:51 +08:00
2025-11-21 14:54:21 +08:00
static signed short combined_raw_data[6];
static int calibration_done = 0;
char status = 0;
set_SC7U22_Error_Flag(0);
2025-11-04 14:40:55 +08:00
SL_SC7U22_RawData_Read(acc_data_buf,gyr_data_buf);
2025-11-21 14:54:21 +08:00
memcpy(&combined_raw_data[0], acc_data_buf, 3 * sizeof(signed short));
memcpy(&combined_raw_data[3], gyr_data_buf, 3 * sizeof(signed short));
status = Q_SL_SC7U22_Angle_Output(1, combined_raw_data, angle,NULL, 0, quaternion_output);
if(status == 1){ //校准完成
extern u16 SC7U22_calibration_id;
extern u8 SC7U22_init;
SC7U22_init = 1;
close_process(&SC7U22_calibration_id, "SC7U22_calibration");
u8 send2_1[5] = {0xBB,0xBE,0x02,0x00,0x01};
send_data_to_ble_client(&send2_1,strlen(send2_1));
2025-11-03 18:48:15 +08:00
}
2025-11-21 14:54:21 +08:00
// if(count > 100){
// count = 0;
// char log_buffer[100];
// // snprintf( log_buffer, sizeof(log_buffer),"status:%d\n",status);
// // send_data_to_ble_client(&log_buffer,strlen(log_buffer));
// xlog("status:%d\n", status);
// xlog("RawData:AX=%d,AY=%d,AZ=%d,GX=%d,GY=%d,GZ=%d\r\n",combined_raw_data[0],combined_raw_data[1],combined_raw_data[2],combined_raw_data[3],combined_raw_data[4],combined_raw_data[5]);
// }
// count++;
2025-11-04 14:40:55 +08:00
}
2025-11-11 19:31:34 +08:00
/**
2025-11-21 14:54:21 +08:00
* @brief
2025-11-11 19:31:34 +08:00
*
*/
2025-11-21 14:54:21 +08:00
void start_collect_fuc(void){
2025-11-13 09:50:42 +08:00
// xlog("=======sensor_read_data START\n");
2025-11-21 14:54:21 +08:00
2025-11-11 19:31:34 +08:00
static signed short combined_raw_data[6];
static int initialized = 0;
static int calibration_done = 0;
char status = 0;
2025-11-21 14:54:21 +08:00
BLE_send_data_t BLE_send_data;
uint8_t mmc5603nj_buffer[9];
signed short acc_data_buf[3];
signed short gyr_data_buf[3];
float angle[3];
float quaternion_output[3];
SL_SC7U22_RawData_Read(acc_data_buf,gyr_data_buf);
mmc5603nj_read_origin_data(mmc5603nj_buffer);
2025-11-13 09:50:42 +08:00
2025-11-21 14:54:21 +08:00
memcpy(&combined_raw_data[0], acc_data_buf, 3 * sizeof(signed short));
memcpy(&combined_raw_data[3], gyr_data_buf, 3 * sizeof(signed short));
2025-11-13 09:50:42 +08:00
2025-11-21 14:54:21 +08:00
status = Q_SL_SC7U22_Angle_Output(0, combined_raw_data, angle,NULL, 0, quaternion_output);
2025-11-03 18:48:15 +08:00
2025-11-21 14:54:21 +08:00
memcpy(acc_data_buf, &combined_raw_data[0], 3 * sizeof(signed short));
memcpy(gyr_data_buf, &combined_raw_data[3], 3 * sizeof(signed short));
int speed = sensor_processing_task(acc_data_buf,gyr_data_buf,angle, quaternion_output);
2025-11-18 17:27:06 +08:00
2025-11-21 14:54:21 +08:00
// -- 数据包装进结构体 --
2025-11-18 10:15:00 +08:00
2025-11-21 14:54:21 +08:00
memcpy(BLE_send_data.acc_data, acc_data_buf, 3 * sizeof(signed short));
memcpy(BLE_send_data.gyr_data, gyr_data_buf, 3 * sizeof(signed short));
memcpy(BLE_send_data.mmc5603nj_buffer, mmc5603nj_buffer, 9);
BLE_send_data.speed_cms = speed;
2025-11-20 19:30:34 +08:00
2025-11-18 10:15:00 +08:00
}
2025-11-03 18:48:15 +08:00
void xtell_task_create(void){
2025-10-29 16:24:16 +08:00
2025-11-11 19:31:34 +08:00
#if TCFG_GSENOR_USER_IIC_TYPE
int ret = hw_iic_init(0);
xlog("init iic result:%d\n", ret); //返回0成功
#else
2025-11-12 13:57:59 +08:00
int ret = soft_iic_init(0);
int num_chars_written = snprintf(log_buffer_1, sizeof(log_buffer_1),"init iic: %d\n", ret);
2025-11-11 19:31:34 +08:00
#endif
2025-11-20 19:30:34 +08:00
// MPU9250_Mag_Init();
//iic总线设备扫描
2025-11-21 14:54:21 +08:00
extern void i2c_scanner_probe(void);
i2c_scanner_probe();
2025-10-30 11:33:38 +08:00
2025-10-30 18:30:40 +08:00
xlog("xtell_task_create\n");
2025-10-30 11:33:38 +08:00
2025-11-21 14:54:21 +08:00
circle_buffer_init(&BLE_send_buff, sensor_read_buffer, SENSOR_DATA_BUFFER_SIZE, sizeof(BLE_send_data_t));
2025-11-11 09:38:51 +08:00
2025-10-30 11:33:38 +08:00
}