feat(iec104): 把 104 骨架完整迁到 MCU 板端并在台架跑通总召

把 IEC104 从模拟器端整体搬到板端:协议栈原先由独立 iec104Task 驱动,
现在改为 netTask 单 owner 的 threadless 驱动,退役独立任务。

驱动与后端:
- 新增 iec104_net_mcu.c/.h,实现 IEC104_Net.h 的 11 个 ABI 函数,
  用槽表加单调句柄映射 net_socket 的单 fd 模型;CLIENT 拆除只走
  net_drop_conn_locked,绝不 net_close 监听 fd。
- net_socket 增 5 个 owner-only 接口(net_accept_locked、
  net_drop_conn_locked、net_pending_bytes、net_send_try、
  net_mono_now_ms)。
- iec104_serv.c 重写为 iec104_serv_net_tick(),在 netTask 1ms 主循环
  里驱动 core;无 osDelay/阻塞调用,喂狗是第一句。
- Src/freertos.c 删除 iec104Task 三件套,对应栈水位探针表项同步删除。

内存:目标板 192KB SRAM 装不下 vendor 默认容量档,按实测裁剪到
skeleton 档(TCP 缓冲、业务池、SOE 256->128、值槽密集化),
RW_IRAM1 118,408 B / 90.3%,留 2,178 B 余量。

台架修复(只在真硬件暴露):
- SNTP s_ctx.fd 零初始化后为 0,而 net fd 0 是合法槽位下标,
  首次代次变化时误 net_close(0) 关掉 ftpTask 的监听槽,导致 104
  连接被 FTP 的 220 banner 抢走;改为显式 .fd = -1。
- Accept 幂等:单 fd 模型下 vendor 每轮重试 Accept 会拿到同一 fd,
  后端改为会话在役时返 WOULD_BLOCK,Close 不再清槽。

验证:
- Keil 全量重建 0 error 0 warning,uvprojx 零抖动。
- 模拟器真实 TCP 13/13、transport 10/10。
- netmcu 后端单测 13/13(新增 N12)。
- 台架 serial-boot-test required 全中;板端 2404 总召 129 帧收到
  59 遥信(53 有源、全 IV)+ 16 双点 + 30 遥测(PT1 三相非零、
  UN/频率/温度按未标定置 IV)、遥控选择执行全否定、校时 COT 7。
- 期间顺带修正 UI 漂移自检文案、.serialtest required 陈旧项、
  coding-standard 对 vendor 与外部 ABI 名字的排除口径。
This commit is contained in:
2026-11-18 10:29:18 +08:00
parent 2e9272cc8a
commit 90cc9a7d99
125 changed files with 7463 additions and 5335 deletions
@@ -4,6 +4,9 @@
#include "iec104_test_config.h"
#include "iec104_tcp_fixture.h"
#define SOE_CAP IEC104_ASDU_SOE_MAX_CAPACITY
#define SOE_OVER (IEC104_ASDU_SOE_MAX_CAPACITY + 1U)
static unsigned strict_groups;
/**
@@ -463,24 +466,24 @@ static void soe_flush_all(void)
*/
static void soe_capacity_isolation(void)
{
unsigned strict, id, ids[256];
unsigned strict, id, ids[SOE_CAP];
for (strict = 0U; strict < 2U; ++strict) {
IEC104_TcpServerStatus_t status;
soe_begin(strict);
for (id = 1U; id <= 256U; ++id) { soe_enqueue(id, 1U, false, NULL); }
for (id = 1U; id <= SOE_CAP; ++id) { soe_enqueue(id, 1U, false, NULL); }
CHECK(IEC104_TcpServer_Get_Status(sut, &status, NULL) == IEC104_TCP_OK);
CHECK(status.soe_queue.capacity == 256U && status.soe_queue.stored_count == 256U);
CHECK(status.soe_queue.capacity == SOE_CAP && status.soe_queue.stored_count == SOE_CAP);
CHECK(status.soe_queue.dropped_pending_count == 0U);
for (id = 1U; id <= 64U; ++id) { event(8U, (uint8_t)id, 120U); }
CHECK(IEC104_TcpServer_Get_Status(sut, &status, NULL) == IEC104_TCP_OK);
CHECK(status.soe_queue.stored_count == 256U && status.soe_queue.dropped_pending_count == 0U);
soe_enqueue(257U, 1U, false, NULL);
CHECK(status.soe_queue.stored_count == SOE_CAP && status.soe_queue.dropped_pending_count == 0U);
soe_enqueue(SOE_OVER, 1U, false, NULL);
CHECK(IEC104_TcpServer_Get_Status(sut, &status, NULL) == IEC104_TCP_OK);
CHECK(status.soe_queue.stored_count == 256U && status.soe_queue.dropped_pending_count == 1U);
CHECK(status.soe_queue.stored_count == SOE_CAP && status.soe_queue.dropped_pending_count == 1U);
CHECK(IEC104_TcpServer_Release_Startup(sut, sut->generation, sut->activation_id) == IEC104_TCP_SUBMIT_OK);
soe_flush_all();
CHECK(output_soe_ids(ids, 256U) == 256U);
for (id = 0U; id < 256U; ++id) { CHECK(ids[id] == id + 2U); }
CHECK(output_soe_ids(ids, SOE_CAP) == SOE_CAP);
for (id = 0U; id < SOE_CAP; ++id) { CHECK(ids[id] == id + 2U); }
CHECK(IEC104_TcpServer_Get_Status(sut, &status, NULL) == IEC104_TCP_OK);
CHECK(status.soe_queue.stored_count == 0U && status.soe_queue.retired_count == 0U);
end();
@@ -497,29 +500,29 @@ static void soe_capacity_isolation(void)
*/
static void soe_overwritten_ack_identity(void)
{
unsigned strict, id, ids[257];
unsigned strict, id, ids[SOE_OVER];
for (strict = 0U; strict < 2U; ++strict) {
IEC104_TcpServerStatus_t status;
soe_begin(strict); soe_enqueue(1U, 1U, false, NULL);
CHECK(IEC104_TcpServer_Release_Startup(sut, sut->generation, sut->activation_id) == IEC104_TCP_SUBMIT_OK);
emit(1U); CHECK(output_soe_ids(ids, 257U) == 1U && ids[0] == 1U);
emit(1U); CHECK(output_soe_ids(ids, SOE_OVER) == 1U && ids[0] == 1U);
CHECK(IEC104_AsduQueue_Set_Startup_Pending(&sut->queue, sut->generation, 1U) == IEC104_ASDU_QUEUE_OK);
for (id = 2U; id <= 257U; ++id) { soe_enqueue(id, 1U, false, NULL); }
for (id = 2U; id <= SOE_OVER; ++id) { soe_enqueue(id, 1U, false, NULL); }
CHECK(IEC104_TcpServer_Get_Status(sut, &status, NULL) == IEC104_TCP_OK);
CHECK(status.soe_queue.stored_count == 256U && status.soe_queue.retired_count == 1U);
CHECK(status.soe_queue.stored_count == SOE_CAP && status.soe_queue.retired_count == 1U);
CHECK(status.soe_queue.overwritten_unacked_count == 1U);
push_ack(1U); emit(2U);
CHECK(IEC104_TcpServer_Get_Status(sut, &status, NULL) == IEC104_TCP_OK);
CHECK(status.soe_queue.stored_count == 256U && status.soe_queue.retired_count == 0U);
CHECK(status.soe_queue.stored_count == SOE_CAP && status.soe_queue.retired_count == 0U);
CHECK(IEC104_TcpServer_Release_Startup(sut, sut->generation, sut->activation_id) == IEC104_TCP_SUBMIT_OK);
emit(1U); CHECK(output_soe_ids(ids, 257U) >= 2U && ids[1] == 2U);
emit(1U); CHECK(output_soe_ids(ids, SOE_OVER) >= 2U && ids[1] == 2U);
CHECK(IEC104_AsduQueue_Set_Startup_Pending(&sut->queue, sut->generation, 1U) == IEC104_ASDU_QUEUE_OK);
push_ack(2U); emit(2U);
CHECK(IEC104_TcpServer_Get_Status(sut, &status, NULL) == IEC104_TCP_OK);
CHECK(status.soe_queue.stored_count == 255U && status.soe_queue.retired_count == 0U);
CHECK(status.soe_queue.stored_count == (SOE_CAP - 1U) && status.soe_queue.retired_count == 0U);
CHECK(IEC104_TcpServer_Release_Startup(sut, sut->generation, sut->activation_id) == IEC104_TCP_SUBMIT_OK);
soe_flush_all(); CHECK(output_soe_ids(ids, 257U) == 257U);
for (id = 0U; id < 257U; ++id) { CHECK(ids[id] == id + 1U); }
soe_flush_all(); CHECK(output_soe_ids(ids, SOE_OVER) == SOE_OVER);
for (id = 0U; id < SOE_OVER; ++id) { CHECK(ids[id] == id + 1U); }
end();
}
++strict_groups;