Files
STM32F4-Base/test/host/iec104_dtu/MATRIX.md
T
wandering1 90cc9a7d99 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 名字的排除口径。
2026-11-18 10:29:18 +08:00

68 lines
13 KiB
Markdown

# Independent IEC104 DTU acceptance matrix
## Oracle and scope
Read-only reference: `IEC60870-Slave/examples/iec104_dtu_profile.h`, `iec104_example_points.h`, and `iec104_slave_example.c`. Tests do not import the implementation model or compare two model views. Profile numeric counts are checked against independently parsed rows; runtime ranges below are traced to the original runtime, not guessed from the replacement.
- SP: profile 59 IOAs, 0x0001..0x0041 excluding 0x002c..0x0031.
- DP: runtime 16 IOAs 0x1001..0x1010 (`EXAMPLE_DOUBLE_COUNT`, GI/Read).
- Measurements: profile 30 IOAs 0x4001..0x401e, GI Type13.
- Energy: profile four metadata rows; runtime `EXAMPLE_COUNTER_COUNT=8` exposes 0x6401..0x6408 (not four). Counter interrogation is independent of GI.
- Step and bitstring: runtime eight each at 0x1201 and 0x1301; Read only, not GI.
- Commands: profile 19 plus runtime step eight, setpoint30 and bitstring eight. Some extension command forms are disabled by original default policy; visibility is not permission.
- Standard parameters: runtime 120, four groups of30 at 0x8601+group*0x20. Group0 first4 Type111, remainder Type110; groups1/2 Type111; group3 Type112. GI includes these.
- Remote parameters: profile430 metadata entries,345 configured readable in SN0;85 unconfigured remain metadata-only per Lead clarification. SN1..4 action parameters only (original model reports88). Never infer a fixed296 total.
- Example diagnostic aliases (scope pending, not silently equated to standard product points):41 measurement source aliases 0x9601..0x962c excluding0x961c..0x961e;93 digital aliases0x9141..0x919d;16 pulse aliases0xb100..0xb10f. Source: original `Example_Read_Point` lines3063..3081. Retained in oracle inventory but excluded from first standard acceptance run pending Lead scope decision.
- Original demo nonzero initial observations are NOT acceptance values: source-less visible observations must start at zero. Configured parameters retain typed configured values. Do not erase quality flags or real protection lockout.
## Tests and independent observations
Measured status: `ci-artifacts/iec104-tests/tcp-final/report.json` records 11/11 PASS on the frozen `lvgl_sim.exe` SHA256 `d2285bbc68ce4353c814dbcc455a2083b56e81fc54bf88081402e821c6a92833`. Exact GI225 includes parameter value/QPM checks; CI8 uses original default Type206; Read121 checks zero/IV or SB plus CP56 legality; remote345 compares independent original typed defaults. The run includes area changes, preset/read unchanged/commit/read changed/cancel, disconnected stage invalidation, committed RAM retained across TCP reconnect, UInt16777217 precision, unknown/unconfigured addresses, malformed typed values, APDU255, split/coalesced streams, causal SBO state/feedback and rejected-command invariance, full device time and progression, unchanged host clock, and 30-second monotonic SBO expiry. Normal pre-START TESTFR and illegal pre-START I-frame close are distinct assertions. Source/transport/core probes record 10/10 PASS in `transport-final/report.json`; these are separately linked migrated production sources, not old-library binaries.
Remaining unverified: malformed GI CA/IOA/QOI combinations; inbound APDU overlimit close; wrong TLV declared length on product TCP; every one of the 65 command entries and default-disabled extension permissions; nonzero measurement deadband reference stability; Spontaneous negative time_kind; injected Close/Destroy/GetStatus cleanup failures (no supported fixture injection); atomic platform apply rejection after validation; mapped-UShort callback overflow/fraction (no reachable mapped UShort entry). Type 110/111/112 LOAD is now covered (`test_standard_parameter_load_110_111_112`: accept per type, KPA mismatch, type mismatch, unknown IOA/CA/COT, per-group range, NaN, TEST bit, single-GI readback, restore) and Type 113 activation is covered (`test_standard_parameter_activation_113`: QPA=3 activate/deactivate, QPA=1/2 refusal while their config extensions stay off, IOA!=0 refusal, TEST bit, COT 45/46). What remains unverified there: QPA=1/QPA=2 positive paths (require `IEC104_PARAMETER_EXT_QPA_LOADED`/`_OBJECT` to be enabled, which this build does not do), the two-phase PREPARE/COMMIT apply-on-ACK flow, and periodic-scan output after QPA=3 activation. TCP tests terminate the process, so normal finite-deadline shutdown and UI are separately owned simulator evidence. The TCP suite (11 cases in the frozen snapshot above, 13 as of 2026-11-18) is not an assertion that all commands/features were exhaustively tested. Diagnostic aliases150 are deliberately excluded by Lead scope decision and must return unknown rather than fabricated zero success.
Initialization contract frozen by Lead after data/core review: observations are zero with IV; step/bit simulation is zero with SB. Parameters are configuration, not sampled observations: preserve original legal typed defaults and read-only mappings. This is the chosen integration contract, not a quotation of the original user wording. Committed values survive ordinary TCP reconnect in RAM; reconnect discards selections/stages; explicit service initialization restores defaults; no persistence is claimed.
The table below is the overall design matrix; only the measured status above is a coverage claim. Items listed as remaining unverified are not passes.
| Behavior | Positive evidence | Negative/boundary evidence |
|---|---|---|
| STARTDT, STOPDT, TESTFR | Exact U confirmations | Business before START rejected/no publication |
| GI | ACTCON, complete exact SP/DP/YC/standard-parameter set, no duplicates, ACTTERM | Bad CA/IOA/QOI; PN asserted separately |
| Read | Each runtime readable IOA independently requested and decoded | Unknown address COT47 PN1 |
| Parameters200/201 | Switch area then read current/min/max | Invalid area rejected, current unchanged |
| Parameters202 | Exact configured IOA/tag/value set vs source profile; count/length/SN/PI | Unknown and unconfigured address, incorrect tag/length, NaN |
| Parameters203 | Read baseline -> preset -> read unchanged -> solidify -> read changed -> restore | Execute without preset; preset/cancel/read unchanged; disconnected stage cannot execute |
| SBO | Select -> execute -> ACTCON/ACTTERM -> state feedback/readback | Execute first, wrong state, different IOA, repeated execute, timeout, reconnect |
| Simulation safety | Feedback and action log; source audit confirms no physical output call | No claim of physical safety from socket-send success alone |
| Clock | Deliberate device-clock offset, response + subsequent event CP56/clock diagnostic | Host wall-minus-monotonic unchanged; SBO timeout still monotonic |
| TCP stream | Split start/header/body, concatenated frames, reconnect sequence reset | Complete255-byte APDU/length253/ASDU249; reject overlimit; service-side short write via separately linked Net stub |
| UI | Same executable hash used for TCP and independent golden tests | No golden updates to hide regression |
## Evidence rules
Every request/response frame is retained as hex with monotonic timestamps. Each decoded object is written with IOA/type/value. Report failures, timeouts and missing observability as failures or explicit unverified items, never passes. Record executable hash and reference hashes. Existing `test/host/iec104`, `iec104_serv`, and master RX tests remain untouched. After code settles, run corresponding unit-test hooks or `scripts/ci_local.py`; Keil and simulator builds are coordinated with the build owner, not launched concurrently.
## Reproduction and toolchain
Run from the repository root:
```text
python -B test/host/iec104_dtu/run_unit_test.py
python -B test/host/iec104_dtu/run_tcp_test.py --exe simulator/build/Debug/lvgl_sim.exe --output ci-artifacts/iec104-tests/tcp-rerun
python -B test/host/iec104_dtu/run_transport_test.py --output ci-artifacts/iec104-tests/transport-rerun
python -B test/host/iec104_dtu/run_transport_test.py --only core_lifecycle --output ci-artifacts/iec104-tests/lifecycle-rerun
python -B test/host/iec104_dtu/run_transport_test.py --only source_binding --output ci-artifacts/iec104-tests/source-rerun
python -B test/host/iec104_dtu/run_transport_test.py --only vendor_boundary --output ci-artifacts/iec104-tests/boundary-rerun
```
TCP requires Python standard library and the final same-UI simulator binary; use a distinct `--port` when tests run concurrently. Transport/probes require MSVC x64 and Windows SDK, discovered by existing `test/host/common/unit_test_harness.py::locate_toolchain` (standard VS installation directories, no `vcvars` or `vswhere` invocation). Explicit `DTU_MSVC_CL` and `DTU_WINDOWS_KITS_ROOT` overrides obey that shared harness contract. Compiler path, command, source SHA256 and per-fixture build/run logs are retained. `/W3 /WX /std:c11 /utf-8` are used without warning suppression. Idle upstream fixture has a checked size_t-to-uint32 conversion in its generated artifact copy; report preserves upstream and adapted hashes. Original library and old host tests are not edited. Preserved legacy runners were actually executed: IEC104179/179 and IEC104 SERV37/37 PASS, combined command exit0; summary `ci-artifacts/iec104-tests/legacy-regression.txt` records existing compiler warnings, so this is not a zero-warning legacy-build claim.
The self-test runner only tests the independent decoder/oracle (7 tests), not product acceptance. Existing total host discovery sees `run_unit_test.py`. As of 2026-11-18 the real TCP runner IS registered as an automatic coverage gate: `.pre-commit-config.yaml` declares hook `iec104-tcp` (`stages: [manual]`, entry = the repo's gate launcher `gate_python.py` followed by `check_iec104_tcp.py`, `pass_filenames: false`), which builds `lvgl_sim.exe` incrementally, runs `run_tcp_test.py`, and writes `ci-artifacts/iec104-tests/tcp-gate/{report.json,wire.json,objects.json,simulator.log}`. Verified by a genuine run: `pre-commit run --all-files --hook-stage manual iec104-tcp` -> `Passed`, wall clock 16.8 s, report recorded 11/11 PASS at that time; as of 2026-11-18 the suite is 13 cases (`test_standard_parameter_load_110_111_112`, `test_standard_parameter_activation_113` added) and a full run gives 13/13, canonical evidence `ci-artifacts/iec104-tests/s5/report.json`. Three limits are stated rather than hidden: (1) it is a manual-stage hook, so `git commit` does not run it - the local sweep is `scripts/ci_local.py` and the remote CI's manual stage; (2) the remote CI (`.gitea/workflows/ci.yml`) does NOT build the simulator, so it deliberately omits this hook from its `$hooks` list - the gate only ever runs on a developer machine that has `simulator/build/Debug/lvgl_sim.exe`; (3) the hook builds through `build_sim.bat`, i.e. VENDOR DEFAULT capacities (RX 2048 / HIGH 1024 / NORMAL 4096 / RECORD 32 / EVENT 68), so it does NOT exercise the P6a tier the firmware actually ships (RX 256 / HIGH 288 / NORMAL 272 / RECORD 4 / EVENT 11); the P6a evidence is a separate build via `ci-artifacts/iec104-cutover/build_sim_p6a.ps1` plus the same runner, and the two must not be quoted for each other. The MSVC transport runner remains an explicit acceptance entrypoint only (recorded in `transport-final/report.json`), not a hook. New firmware registration/Keil build and existing host coverage gates are separately owned; this file does not claim CI/coverage/dual-target registration passed. No old tests were deleted to hide regressions.
Oracle corrections retained with failures: QPM is `{1,3,4,2}` from original enum, not group+1; original CI defaults to Type206, not15; pre-START I-frame is FATAL close per original Link; wrong-IOA EXEC does not clear a prior selection, so reselecting without cancellation invokes duplicate-select rejection. The genuine product Read Type1/3 compatibility defect was separately repaired to Type30/31 CP56 before the final binary. Earlier failing snapshots remain in artifacts.
## Requested simulator CLI
Current user-authorized basic contract: `lvgl_sim.exe --iec104 --iec104-headless --iec104-port N --iec104-duration S`; bind `0.0.0.0` to listen on all local IPv4 interfaces, READY after bind, finite lifetime. The test client still defaults to `127.0.0.1` for local acceptance. The historical `d2285bbc...c6a92833` 11-case results above were measured over loopback before this bind-address change; they do not establish external-IP or LAN reachability of the new binary. New wildcard-listen and address/handshake evidence will be recorded separately after simulator/reviewer verification; a connection from the same host to its LAN IPv4 is not proof of access from another LAN device. Lead rejected a production send-chunk switch: server-side short-write/WOULD_BLOCK must use a separately linked Net stub, while real TCP split covers inbound reconstruction. Device time is independently readable with Type103/COT5. Action counters/source audit are required for the no-physical-DO claim. No hardware, macro changes, commit or push.