feat(iec104): 在模拟器跑通共享协议核心与标准DTU点表

引入成熟 IEC 60870-5-104 子站的只读子集(App/protocol/iec60870,28 个源文件
按原字节复制,UPSTREAM.sha256 记录来源,兼容补丁保留全部断言与容量),在其上
装配单属主共享核心(Start/Poll/Stop/Get_Status),并把标准 DTU 演示点表全量
接入为唯一真源。

- iec104_core:threadless 推进,poll 零等待,通知/交互/COV 扫描全部有界;
  生命周期区分失败启动待重试、重复启动拒绝、断线保固化 RAM。
- iec104_dtu_table / iec104_source:标准 DTU 全点表注册,无数据源的点读 0,
  遥控只做模拟状态可读回,不触碰实际出口。
- iec104_sim:仅窗口与独立服务模式起真实 TCP,无头黄金模式保持确定性假统计。
- test/host/iec104_dtu:独立真实 TCP 11 项、传输层 10 项、生命周期与借用负例。

验证:lvgl_sim 真实 TCP 11/11、传输 10/10,UI 像素回归未回退;AC5 单 TU
编译 0 错误 0 诊断。板端尚未切换:完整库闭包 RAM 超 92% 门禁净增预算 25730B,
结论为停止转实施,记录在 IEC104_MCU最小可行性验证.md。旧实现与 board 服务
保持原样,未提交 MDK 工程改动,未烧板。
This commit is contained in:
2026-11-17 20:48:00 +08:00
parent f84855a559
commit 2e9272cc8a
117 changed files with 54273 additions and 10 deletions
+76 -1
View File
@@ -71,6 +71,8 @@
#include "lvgl.h"
#include "sim_port.h"
#include "iec104_sim.h"
#include "iec104_core.h"
#include "ui_menu.h"
#include "ui_standby.h"
#include "ui_content_page.h" /* task-2:--rtlive 直调框架自动刷新判定体 */
@@ -142,6 +144,17 @@ static uint32_t sim_map_key_char(char c) {
* 返回值:无
*/
static void sim_time_cb(char *buf, size_t len) {
if (iec104_sim_enabled()) {
ui_data_clock_t clock;
uint64_t seconds = iec104_sim_clock_local_s();
if (seconds <= UI_DATA_CLOCK_EPOCH_MAX &&
ui_data_clock_from_epoch((uint32_t)seconds, &clock) == 0) {
(void)ui_data_clock_format(&clock, buf, (uint32_t)len);
} else if (len != 0u) {
buf[0] = '\0';
}
return;
}
time_t t = time(NULL);
struct tm tmv = {0}; /* 显式清零:localtime_s/r 是"输出型"参数,静态分析按未初始化报 */
@@ -224,7 +237,11 @@ static int sim_maint_clock_set(uint32_t a_epoch) {
if ((a_epoch == 0u) || (a_epoch > (uint32_t)UI_DATA_CLOCK_EPOCH_MAX)) {
return -1;
}
s_sim_epoch = a_epoch;
if (iec104_sim_enabled()) {
if (iec104_sim_clock_set(a_epoch) != 0) { return -1; }
} else {
s_sim_epoch = a_epoch;
}
sim_publish_data_frames();
return 0;
}
@@ -1001,6 +1018,18 @@ static void sim_fill_rt_frame(ui_data_rt_t *p_rt, uint32_t n) {
p_rt->valid = 1u;
p_rt->eng = UI_DATA_ENG_PIN;
p_rt->tick_ms = 0u;
if (iec104_sim_enabled()) {
/* No acquisition is attached: do not publish the golden demonstration ramp. */
for (i = 0u; i < UI_DATA_YC_N; ++i) {
p_rt->yc[i].qds = UI_DATA_Q_IV;
}
for (i = 0u; i < UI_DATA_PH_MAX; ++i) {
p_rt->ph[i].qds = UI_DATA_Q_IV;
}
sim_time_cb(p_rt->clock, sizeof(p_rt->clock));
p_rt->clock_ok = (p_rt->clock[0] != '\0') ? 1u : 0u;
return;
}
/* 遥测下标 = adc_semantic_t 语义序(UA/UB/UC/UN/IA/IB/IC/IN/TEMP)。
* 模拟器不 include adc_input.h,故这里用语义序注释对照,不写符号名 */
p_rt->yc[0].val = 0.8123f; /* UA 基波(引脚电压域) */
@@ -1097,6 +1126,16 @@ static void sim_publish_rt_live(uint32_t n) {
sim_fill_rt_frame(&rt, n);
(void)ui_data_publish_rt(&rt);
if (iec104_sim_enabled()) {
ui_data_info_t info;
iec104_core_status_t status;
if (ui_data_info(&info) == 0) {
iec104_core_get_status(&status);
info.port_104 = status.bound_port;
info.iec104_conn_up = status.connections;
(void)ui_data_publish_info(&info);
}
}
}
static void sim_publish_data_frames(void) {
@@ -1137,6 +1176,20 @@ static void sim_publish_data_frames(void) {
info.iec104_apdu_tx = 128u;
info.iec104_tx_fail = 0u;
info.iec104_rx_bytes = 4096u;
if (iec104_sim_enabled()) {
iec104_core_status_t status;
iec104_core_get_status(&status);
info.port_104 = status.bound_port;
info.boot_ready = 0u;
info.boot_count = 0u;
info.boot_seq_state = 0u;
info.rst_cause = 0u;
info.iec104_conn_up = status.connections;
/* No all-APDU/byte counters are exposed; I-frame ACKs are not TX APDUs. */
info.iec104_apdu_tx = 0u;
info.iec104_tx_fail = 0u;
info.iec104_rx_bytes = 0u;
}
(void)ui_data_publish_info(&info);
}
@@ -1727,6 +1780,13 @@ static int run_logtest(void) {
* 返回值:0 - 正常退出或自检 PASS;非 0 - 失败 int
*/
int main(int argc, char **argv) {
iec104_sim_options_t protocol_options;
if (iec104_sim_parse(argc, argv, &protocol_options) != 0) {
return 2;
}
if (protocol_options.headless) {
return iec104_sim_run_headless(&protocol_options);
}
/* 形态旗标必须先扫(道F task-3):--keys / --standby 分支命中即 return,
* 放在它们后面的循环根本走不到 —— 这是旗标看似加了、实际只在无参窗口模式
* 生效的那类"看起来做了"的坑,写在这里省一个人重新踩 */
@@ -1809,6 +1869,12 @@ int main(int argc, char **argv) {
lv_sdl_window_set_title(disp, "STM32F4-Base UI Simulator (160x160 1bpp)");
}
/* Protocol startup is opt-in, after platform setup and before UI snapshots. */
if (protocol_options.enabled && iec104_sim_start(&protocol_options) != 0) {
SDL_Quit();
return 1;
}
/* 配置 RAM 副本:镜像 netTask 上电流程(net_cfg_load → 工厂默认) */
(void)net_cfg_load();
@@ -1880,6 +1946,12 @@ int main(int argc, char **argv) {
/* 轮询 RemoDispBus 协议(非阻塞收发) */
ui_net_sink_poll();
if (protocol_options.enabled && iec104_sim_poll() != 0) {
fprintf(stderr, "[iec104] POLL_FAILED\n");
(void)iec104_sim_stop();
SDL_Quit();
return 1;
}
/* 执行待处理"保存网口配置"请求(单线程主循环 = 配置引擎属主;
* 无请求 = 空操作);"立即应用"回调未注册 → 空操作 */
@@ -1921,6 +1993,9 @@ int main(int argc, char **argv) {
sleep_ms = (sleep_ms > spent_ms) ? (sleep_ms - spent_ms) : 1u;
}
if (protocol_options.enabled && sleep_ms > 5u) {
sleep_ms = 5u;
}
#ifdef _MSC_VER
Sleep(sleep_ms);
#else