ota双备份升级成功
This commit is contained in:
@ -28,6 +28,7 @@
|
||||
#include "./sensor/AK8963.h"
|
||||
#include "asm/rtc.h"
|
||||
#include "system/timer.h"
|
||||
#include "adv_time_stamp_setting.h"
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//宏定义
|
||||
#define ENABLE_XLOG 1
|
||||
@ -50,13 +51,15 @@
|
||||
void send_data_to_ble_client(const u8* data, u16 length);
|
||||
extern void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec);
|
||||
extern void close_process(u16* pid,char* name);
|
||||
void start_collect_fuc(void);
|
||||
void BLE_send_fuc(void);
|
||||
//END -- 函数定义
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//START -- 变量定义
|
||||
|
||||
static u32 timer_offset_ms = 0;
|
||||
|
||||
typedef struct {
|
||||
// -- 六轴 --
|
||||
@ -69,7 +72,9 @@ typedef struct {
|
||||
int adc_P;
|
||||
int adc_T;
|
||||
// -- 左/右腿 --
|
||||
uint8_t foot; //1:左脚;2:右脚
|
||||
uint8_t foot_state; //1:左脚;2:右脚
|
||||
// -- 时间 --
|
||||
u32 timestamp_ms;
|
||||
|
||||
} BLE_send_data_t;
|
||||
|
||||
@ -79,9 +84,27 @@ static int count = 0;
|
||||
static circle_buffer_t BLE_send_buff; // 环形缓冲区管理结构体
|
||||
BLE_send_data_t BLE_send_data[SENSOR_DATA_BUFFER_SIZE];
|
||||
|
||||
// -- 任务id --
|
||||
u16 SC7U22_calibration_id;
|
||||
u16 start_collect_fuc_id;
|
||||
u16 BLE_send_fuc_id;
|
||||
//END -- 变量定义
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// 重置计时器
|
||||
void reset_ms_timer(void) {
|
||||
timer_offset_ms = sys_timer_get_ms();
|
||||
xlog("Timer has been reset.\n");
|
||||
}
|
||||
|
||||
// 获取从上次重置后经过的毫秒数
|
||||
u32 get_ms_timer(void) {
|
||||
return sys_timer_get_ms() - timer_offset_ms;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------------
|
||||
// --------------------------------------------定时器回调函数----------------------------------------------------------
|
||||
/**
|
||||
* @brief 六轴静态校准
|
||||
*
|
||||
@ -131,8 +154,7 @@ void SC7U22_static_calibration(void){
|
||||
*
|
||||
*/
|
||||
void start_collect_fuc(void){
|
||||
// xlog("=======sensor_read_data START\n");
|
||||
|
||||
// xlog("=======sensor_read_data START\n");
|
||||
static signed short combined_raw_data[6];
|
||||
static int initialized = 0;
|
||||
static int calibration_done = 0;
|
||||
@ -165,6 +187,9 @@ void start_collect_fuc(void){
|
||||
memcpy(&BLE_send_data_tmp.SC7U22_data[3], gyr_data_buf, 3 * sizeof(signed short));
|
||||
memcpy(BLE_send_data_tmp.mmc5603nj_buffer, mmc5603nj_buffer, 9);
|
||||
BLE_send_data_tmp.speed_cms = speed;
|
||||
extern u8 foot_init;
|
||||
BLE_send_data_tmp.foot_state = foot_init;
|
||||
BLE_send_data_tmp.timestamp_ms = get_ms_timer();
|
||||
|
||||
// -- 放进缓冲区 --
|
||||
if(circle_buffer_is_full(&BLE_send_buff) == 0){
|
||||
@ -296,9 +321,69 @@ void BLE_send_fuc(void){
|
||||
|
||||
send_data_to_ble_client(&speed_packet, SPEED_PACKET_LEN);
|
||||
}
|
||||
|
||||
// --- 封装并发送数据 ---
|
||||
{
|
||||
// 协议定义: 包头(2) + 长度(1) + 类型(1) + 数据(5) = 9字节
|
||||
const uint8_t OTHER_PACKET_LEN = 9;
|
||||
const uint8_t OTHER_PAYLOAD_LEN = 6; // 类型(1) + 数据(5)
|
||||
const uint8_t OTHER_TYPE = 0x05;
|
||||
|
||||
uint8_t oher_packet[OTHER_PACKET_LEN];
|
||||
|
||||
// 填充包头
|
||||
oher_packet[0] = 0xBB;
|
||||
oher_packet[1] = 0xBE;
|
||||
// 填充长度
|
||||
oher_packet[2] = OTHER_PACKET_LEN;
|
||||
// 填充类型
|
||||
oher_packet[3] = OTHER_TYPE;
|
||||
|
||||
// 小端模式
|
||||
oher_packet[4] = (uint8_t)data_to_send.foot_state; // 数据来源
|
||||
|
||||
oher_packet[5] = (uint8_t)((data_to_send.timestamp_ms >> 0) & 0xFF); // LSB
|
||||
oher_packet[6] = (uint8_t)((data_to_send.timestamp_ms >> 8) & 0xFF);
|
||||
oher_packet[7] = (uint8_t)((data_to_send.timestamp_ms >> 16) & 0xFF);
|
||||
oher_packet[8] = (uint8_t)((data_to_send.timestamp_ms >> 24) & 0xFF); // MSB
|
||||
send_data_to_ble_client(&oher_packet, OTHER_PACKET_LEN);
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* @brief 六轴静态校验
|
||||
*
|
||||
*/
|
||||
void start_calibration(void){
|
||||
create_process(&SC7U22_calibration_id,"SC7U22_calibration",NULL,SC7U22_static_calibration,10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 开始采集传感器数据并通过ble发送
|
||||
*
|
||||
*/
|
||||
void start_clloct(void){
|
||||
reset_ms_timer();
|
||||
create_process(&start_collect_fuc_id,"start_collect",NULL,start_collect_fuc,10);
|
||||
create_process(&BLE_send_fuc_id,"BLE_send_fuc",NULL,BLE_send_fuc,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 停止采集和ble发送
|
||||
*
|
||||
*/
|
||||
void stop_clloct(void){
|
||||
close_process(&start_collect_fuc_id,"start_collect");
|
||||
close_process(&BLE_send_fuc_id,"BLE_send_fuc");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化,在app_main.c的app_main函数被调用
|
||||
*
|
||||
*/
|
||||
void xtell_task_create(void){
|
||||
|
||||
#if TCFG_GSENOR_USER_IIC_TYPE
|
||||
@ -320,8 +405,7 @@ void xtell_task_create(void){
|
||||
circle_buffer_init(&BLE_send_buff, BLE_send_data, SENSOR_DATA_BUFFER_SIZE, sizeof(BLE_send_data_t));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -334,36 +418,21 @@ void bmp280_test(void){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void gsensor_test(void){
|
||||
// static signed short combined_raw_data[6];
|
||||
// static int initialized = 0;
|
||||
// static int calibration_done = 0;
|
||||
// char status = 0;
|
||||
// BLE_send_data_t BLE_send_data_tmp;
|
||||
// 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);
|
||||
|
||||
// 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(0, combined_raw_data, angle,NULL, 0, quaternion_output);
|
||||
|
||||
// // -- 速度计算 --
|
||||
// memcpy(acc_data_buf, &combined_raw_data[0], 3 * sizeof(signed short));
|
||||
// memcpy(gyr_data_buf, &combined_raw_data[3], 3 * sizeof(signed short));
|
||||
// uint16_t speed = sensor_processing_task(acc_data_buf,gyr_data_buf,angle, quaternion_output);
|
||||
|
||||
#if 1
|
||||
if(count >= 5){
|
||||
xlog("==============time============\n");
|
||||
u32 current_ms = sys_timer_get_ms();
|
||||
xlog("====== current system time: %u ms\n", current_ms);
|
||||
|
||||
u32 current_time = get_ms_timer();
|
||||
xlog("Time since last reset: %u ms\n", current_time);
|
||||
|
||||
// 为了演示,我们在这里调用重置
|
||||
if (current_time > 5000) { // 比如超过5秒就重置一次
|
||||
reset_ms_timer();
|
||||
}
|
||||
|
||||
count = 0;
|
||||
}
|
||||
count++;
|
||||
|
||||
Reference in New Issue
Block a user