chore(M0): 建立 CLion/CMake 工程骨架与测试框架
- CMake 多目标工程:shs_core 静态库 + smart_home 可执行 + shs_tests 测试 - CMakePresets.json:debug/release/asan/coverage 四个预设(debug 告警即错误) - 自研零依赖测试框架 tests/framework/test_framework.h + 运行器(套件过滤、CTest 集成) - 工具:tools/header_check.sh 头文件独立编译检查(接口冻结门) - 已实现公共层:errors / string_utils / num_utils,main 启动自检 - 实测:debug 预设 0 告警、ctest 3/3 通过(45 项断言)
This commit is contained in:
commit
578a770737
36 files changed
+2914
No files matched your search
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @file storage.h
|
||||
* @brief 设备表与报表的持久化(二进制 + 文本)
|
||||
*
|
||||
* 教材对应:项目九 任务二「文件操作——设备配置保存与日志记录」;
|
||||
* 项目八 结构体的整体读写;项目五 字符串输出。
|
||||
*
|
||||
* 说明:本工程按教材范围使用"文件持久化",不引入数据库——
|
||||
* 设备表用二进制(fwrite/fread,结构体块的整存整取,含魔数与版本),
|
||||
* 可读导出用文本(CSV / 报表),配置用 ini 文本(见 config.h)。
|
||||
*/
|
||||
#ifndef SHS_STORAGE_H
|
||||
#define SHS_STORAGE_H
|
||||
|
||||
#include "shs/common.h"
|
||||
#include "shs/errors.h"
|
||||
#include "shs/device.h"
|
||||
|
||||
#define SHS_DEVICE_FILE_MAGIC 0x53485344u /**< 'SHSD' 文件魔数 */
|
||||
#define SHS_DEVICE_FILE_VERSION 1u /**< 文件格式版本 */
|
||||
|
||||
/** 二进制文件头(项目八 结构体 + 项目九 文件) */
|
||||
typedef struct {
|
||||
uint32_t magic; /**< 魔数,防止读入无关文件 */
|
||||
uint16_t version; /**< 格式版本 */
|
||||
uint16_t device_count; /**< 设备条目数 */
|
||||
uint32_t checksum; /**< 设备区简单校验和 */
|
||||
} DeviceFileHeader;
|
||||
|
||||
/** 保存设备表(二进制) */
|
||||
shs_err_t storage_save_devices(const char *path, const Device devices[], int count);
|
||||
/** 读取设备表(二进制,校验魔数/版本/条数) */
|
||||
shs_err_t storage_load_devices(const char *path, Device devices[], int max_devices, int *out_count);
|
||||
/** 导出为 CSV 文本(便于 Excel 打开) */
|
||||
shs_err_t storage_export_csv(const char *path, const Device devices[], int count);
|
||||
/** 导出定时矩阵为文本(二维数组 + 嵌套循环) */
|
||||
shs_err_t storage_export_matrix(const char *path, const char *title,
|
||||
const char *matrix_text);
|
||||
/** 确保目录存在(不存在则创建) */
|
||||
shs_err_t storage_ensure_dir(const char *dir);
|
||||
/** 文件是否存在 */
|
||||
bool storage_file_exists(const char *path);
|
||||
/** 取文件大小(字节),失败返回 -1 */
|
||||
long storage_file_size(const char *path);
|
||||
|
||||
#endif /* SHS_STORAGE_H */
|
||||
Reference in new issue
Block a user