feat(M2): 实现核心/存储/网络/应用四层并端到端跑通
- 28 个源文件落地:core(device/sensor/scene/schedule/system)、hal(gpio/i2c/uart/sim)、 protocol(crc/frame)、storage(config/logger/storage)、net(json/http_request/http_server/router)、 web(内嵌单页界面)、app(menu/cli/commands/replay/web_app)、common(新增 bitops.c) - 全文件在 -std=c17 -Wall -Wextra -Wpedantic -Werror 下零告警 跨模块缺陷修复(集成阶段发现): 1. HAL I2C 字节序与业务层不一致(模拟后端小端 / sensor.c 按大端解析), 导致 16 路采样全部被判「传感器故障」、温度显示 125.0℃;统一为大端后 读数恢复 20.4℃ / 50.0%RH,报警等级「正常」 2. 采样路数固定 16 路导致同一探头重复 16 条;改为「传感器设备台数(至少 1 路)」, system_tick 与 CLI sensors 命令保持一致 3. 补齐 app.h 中缺失的 app_run_web()(新增 src/app/web_app.c),并给监听套接字 设 1 秒接收超时,使服务主循环得以周期性推进 system_tick 4. 收敛接口约束:schedule.h 只读矩阵接口去 const(C17 -Wpedantic 不允许 非 const → const 的二维数组隐式转换);system_save/system_render_dashboard 形参同步去 const;网页 JS 由整段字面量改为分段字面量 + 首次拼装(ISO C99 强制支持的 4095 字节单字面量下限);HTTP 响应体缓冲 4KB → 16KB 验证:debug/release/asan 三预设零告警构建通过;ctest 3/3;scripts/acceptance.sh A1~A7 全通过;HTTP 17 条路由实测(首页 2107B / CSS 2313B / JS 6740B / 设备列表 8 台 / 传感器 / 日志 / 报表 / 配置读写 / 协议帧 CRC 校验 / 自检 / 404 兜底);回放脚本 23/23 命令成功
This commit is contained in:
1 parent
e0cc5d578f
commit
b96d5690aa
16 files changed
+3325
-75
No files matched your search
+32
-12
@@ -758,7 +758,15 @@ static shs_err_t cmd_sensors(SmartHomeSystem *sys, int argc, char **argv, CmdBuf
|
||||
SHS_UNUSED(argc);
|
||||
SHS_UNUSED(argv);
|
||||
|
||||
err = sensor_read_all(sys->samples, SHS_MAX_SAMPLES, &got);
|
||||
/* 采样路数与 system_tick 保持一致:传感器设备台数(至少 1 路)—— 项目七 出参 */
|
||||
int channels = device_count_by_type(sys->devices, sys->device_count, SHS_DEV_SENSOR);
|
||||
if (channels < 1) {
|
||||
channels = 1;
|
||||
}
|
||||
if (channels > SHS_MAX_SAMPLES) {
|
||||
channels = SHS_MAX_SAMPLES;
|
||||
}
|
||||
err = sensor_read_all(sys->samples, channels, &got);
|
||||
if (err != SHS_OK) {
|
||||
cb_printf(cb, "传感器采集失败:%s\n", shs_strerror(err));
|
||||
return err;
|
||||
@@ -792,12 +800,14 @@ static shs_err_t cmd_sensors(SmartHomeSystem *sys, int argc, char **argv, CmdBuf
|
||||
/** ac <编号> <18-30>:设置目标温度并按当前温度自动选工作模式 */
|
||||
static shs_err_t cmd_ac(SmartHomeSystem *sys, int argc, char **argv, CmdBuf *cb)
|
||||
{
|
||||
uint16_t id = 0u;
|
||||
double target = 0.0;
|
||||
float current;
|
||||
Device *dev;
|
||||
shs_err_t err;
|
||||
shs_ac_mode_t mode;
|
||||
uint16_t id = 0u;
|
||||
double target = 0.0;
|
||||
float current;
|
||||
const char *source;
|
||||
Device *dev;
|
||||
shs_err_t err;
|
||||
shs_ac_mode_t mode;
|
||||
int i;
|
||||
|
||||
if (argc < 3) {
|
||||
cb_put(cb, "用法:ac <编号> <18-30>\n");
|
||||
@@ -827,10 +837,20 @@ static shs_err_t cmd_ac(SmartHomeSystem *sys, int argc, char **argv, CmdBuf *cb)
|
||||
return SHS_ERR_STATE;
|
||||
}
|
||||
|
||||
/* 当前温度优先取最近一次采样,没有采样则用设备上一次的关联温度作参考 */
|
||||
/* 当前温度:优先取最近一次“有效”采样(无效样本会被判为传感器故障,其换算值
|
||||
是越界值 125℃,不能当环境温度用),无有效采样时退回设备自身温度作参考 */
|
||||
current = dev->temperature_c;
|
||||
if (sys->sample_count > 0 && sys->sample_count <= SHS_MAX_SAMPLES) {
|
||||
current = sys->samples[sys->sample_count - 1].temperature_c;
|
||||
source = "设备温度";
|
||||
if (sys->sample_count > 0) {
|
||||
int start = (sys->sample_count > SHS_MAX_SAMPLES) ? SHS_MAX_SAMPLES : sys->sample_count;
|
||||
|
||||
for (i = start - 1; i >= 0; i--) {
|
||||
if (sys->samples[i].valid) {
|
||||
current = sys->samples[i].temperature_c;
|
||||
source = "环境采样";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = scene_ac_set_target(dev, (float)target);
|
||||
@@ -839,8 +859,8 @@ static shs_err_t cmd_ac(SmartHomeSystem *sys, int argc, char **argv, CmdBuf *cb)
|
||||
return err;
|
||||
}
|
||||
mode = scene_ac_mode_select(current, (float)target);
|
||||
cb_printf(cb, "空调 #%u %s:当前 %.1f℃ → 目标 %.1f℃(18~30℃),自动模式:%s\n",
|
||||
(unsigned)id, dev->name, (double)current, (double)target,
|
||||
cb_printf(cb, "空调 #%u %s:当前 %.1f℃(来源:%s)→ 目标 %.1f℃(18~30℃),自动模式:%s\n",
|
||||
(unsigned)id, dev->name, (double)current, source, (double)target,
|
||||
scene_ac_mode_name(mode));
|
||||
(void)logger_write(SHS_LOG_INFO, CMD_LOG_TAG, "ac #%u 目标 %.1f℃ 模式=%s",
|
||||
(unsigned)id, (double)target, scene_ac_mode_name(mode));
|
||||
|
||||
Reference in new issue
Block a user