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:
sambu committed 2026-09-14 19:34:18 +08:00
commit 578a770737
36 files changed
+2914

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
/**
* @file system.h
* @brief 系统级对象:聚合设备、房间、区域树、定时矩阵、采样与配置
*
* 教材对应:项目八 结构体嵌套 · 项目五 数组 · 项目十 项目集成与部署。
*/
#ifndef SHS_SYSTEM_H
#define SHS_SYSTEM_H
#include "shs/common.h"
#include "shs/errors.h"
#include "shs/device.h"
#include "shs/sensor.h"
#include "shs/schedule.h"
#include "shs/config.h"
/** 系统运行模式 */
typedef enum {
SHS_MODE_CLI = 0, /**< 控制台交互模式 */
SHS_MODE_WEB, /**< 网页服务模式 */
SHS_MODE_REPLAY /**< 脚本回放模式(自动演示) */
} shs_run_mode_t;
/** 智能家居系统总对象(全局唯一) */
typedef struct {
Device devices[SHS_MAX_DEVICES]; /**< 设备表(一维数组) */
int device_count; /**< 当前设备数 */
Room rooms[SHS_MAX_ROOMS]; /**< 房间表 */
int room_count;
Zone zones[SHS_MAX_ZONES]; /**< 区域树(父指针数组) */
int zone_count;
shs_matrix_t schedule; /**< 周×时定时矩阵(二维数组) */
SensorSample samples[SHS_MAX_SAMPLES]; /**< 最近采样缓存 */
int sample_count;
SystemConfig config; /**< 系统配置 */
char data_dir[64]; /**< 数据目录(配置文件/日志/设备表) */
char config_path[128]; /**< 配置文件路径 */
char devices_path[128]; /**< 设备表文件路径 */
char log_path[128]; /**< 日志文件路径 */
shs_run_mode_t mode; /**< 运行模式 */
uint32_t start_ts; /**< 启动时间戳 */
uint32_t tick_count; /**< 主循环计数(循环次数统计) */
bool initialized; /**< 是否已初始化 */
} SmartHomeSystem;
/** 取全局系统对象(全局变量 + 单例访问,项目六 生命周期) */
SmartHomeSystem *system_instance(void);
/** 初始化:填默认配置、生成数据文件路径、初始化 HAL 与日志 */
shs_err_t system_init(SmartHomeSystem *sys, const char *data_dir, shs_run_mode_t mode);
/** 从磁盘加载配置与设备表(文件不存在时使用默认值与演示数据) */
shs_err_t system_load(SmartHomeSystem *sys);
/** 保存配置与设备表 */
shs_err_t system_save(const SmartHomeSystem *sys);
/** 载入演示数据:8 个设备、3 个房间、区域树、一周定时计划 */
shs_err_t system_seed_demo(SmartHomeSystem *sys);
/** 主循环单步:采集传感器、检查报警、执行定时任务(返回执行的动作数) */
int system_tick(SmartHomeSystem *sys, uint32_t now_ts);
/** 系统自检:逐项检查并输出报告文本(项目十 整体测试) */
shs_err_t system_self_test(SmartHomeSystem *sys, char *report, size_t report_size);
/** 把全屋状态渲染为文本(CLI 仪表盘) */
shs_err_t system_render_dashboard(const SmartHomeSystem *sys, char *buf, size_t buf_size);
/** 运行模式名称 */
const char *system_mode_name(shs_run_mode_t mode);
#endif /* SHS_SYSTEM_H */