TT12-MCU/applications/log2file.c
CSSC-WORK\murmur 8050a35073 更新 #define ROOT_PATH "/sd/debuglog" //设置保存路径
alarmer.c 添加定时启动时的sem   timerIsReady();
cfg.c 更新 set_cfg逻辑 及 updateAllSysCfg
main.c 清理

updateAllSysCfg 待完善,有bug
2023-08-29 19:29:58 +08:00

85 lines
2.3 KiB
C

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-16 murmur the first version
*/
#include <..\rt-thread\components\utilities\ulog\backend\ulog_be.h>
#include "usrcfg.h"
/*
* 后端注册表
*/
struct _log_file
{
char *name; //文件名
ulog_backend_t backend;
struct ulog_file_be *file_be;
const char *dir_path; //保存路径
rt_size_t max_num; //保存最大文件数量
rt_size_t max_size; //保存最大文件大小
rt_size_t buf_size; //文件保存缓存大小
};
/*
* 文件后端标识
*/
typedef enum
{
console_id,
sys_id,
motion_id,
}ulog_file_be_name;
#define ROOT_PATH ROOT_PATH_DEBUG //设置保存路径
#define FILE_SIZE 10*1024 //设置单个文件大小
#define BUFF_SIZE 1*1024 //设备缓存区大小
static struct ulog_backend sys_log_backend;
static struct ulog_file_be sys_log_file;
char logfilename[30];// = "23_08_27";
extern char *getTimestmp(char *str);
static struct _log_file table[] =
{
{"motion" ,&sys_log_backend,&sys_log_file,ROOT_PATH,5,FILE_SIZE,BUFF_SIZE},
{"sys" ,&sys_log_backend,&sys_log_file,ROOT_PATH,10,FILE_SIZE,BUFF_SIZE},
};
/* Private function prototypes -----------------------------------------------*/
/**
* @brief 系统日志文件后端初始化.
* @param None.
* @retval None.
* @note None.
*/
void sys_log_file_backend_init(void)
{
struct ulog_file_be *file_be = &sys_log_file;
uint8_t id = sys_id;
file_be->parent = sys_log_backend;
char tmstr[30];//定义时间前缀
getTimestmp(tmstr);
strncpy(logfilename,tmstr,14);
tmstr[14]='\0';
tmstr[10]='#';
ulog_file_backend_init( file_be,
strcat(tmstr,table[id].name),
table[id].dir_path,
table[id].max_num,
table[id].max_size,
table[id].buf_size);
ulog_file_backend_enable(file_be); //必须使能才能有效
}
ulog_file_backend_deinit();
MSH_CMD_EXPORT(sys_log_file_backend_init,log2file);
//INIT_APP_EXPORT(sys_log_file_backend_init);