Files
STM32F4-Base/test/host/iec104_dtu/MATRIX.md
T
wandering1 7da5c7b74c fix(iec104): 拒绝 SN!=0 的假成功写入,并删除 prot_set 的错误第二真源
问题一(安全级):绑定真实参数源后,Type203 走 SN=1..4 的预置与固化会回
COT=7 肯定确认,但 parameter_apply 一次都没被调用 —— 区域 1..4 的分段项在
mapped() 里凑不出 changes[],commit_stage() 的 n==0 让 apply 被跳过,而
values[] 与 parameter_commits 照旧更新,回读也返回出厂镜像冒充当前值。
主站看到"改成功",保护定值一个字没动。

修法:remote_action() 在绑定真实源后对 SN!=0 一律否定确认;remote_lookup()
对 SN!=0 的读返回错误而不是镜像;READ_AREA 绑定后只报区域 0;提交计数移到
真调过 apply 之后。未绑定模拟面保留 0..4 与原有语义,模拟器不受影响。

新增 preset_to_prot_set_test:真实 TCP 夹具 + 手写线上字节,链接
iec104_core/iec104_source/iec104_dtu_table/prot_set,钉住五条契约。四个
变异体(删入口守卫、计数移回无条件、删读侧守卫、READ_AREA 恒报 4)分别
红在对应断言上,证明用例不是为变绿而放松。

问题二:prot_set 的 g_prot_set_meta[].comm_addr 是与语义桥表冲突的错误
第二真源,17 项里 13 项地址指向完全不同的点表语义(如 0x8842 过流一段
定值被标成检同期压差闭锁定值),另有 10 项地址在点表里根本不存在。产品
代码零引用,但 adc_cal.h 已把它当"变比的家"引用,等于给错表盖章。

修法:删除 comm_addr 字段与全部地址注释,元数据表改 4 字段;协议地址的
唯一真源是 iec104_dtu_table.c 的 17 项语义桥表。同步改 check_setview_limits
的 meta 解析、两处单测与四篇活文档。armcc 实测 .constdata 640 B 不变。

验证:Keil 0 错误 0 警告(Code=365,928 / RO=45,764 / RW=2,752 /
ZI=168,392,RW_IRAM1=113,720 B / 86.76%);transport 11/11、真实 TCP
验收 13/13、prot_set 173/173、prot_elm 60/60、prot_dim 44/44、
prot_set_store 16/16、adc_cal 150/150、iec104_serv 60/60、iec104_dtu
7/7;check_setview_limits 40/40/40 OK;模拟器构建 OK;pre-commit RC=0。
2026-11-19 17:16:56 +08:00

13 KiB

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; only17 are real consumers (9 area-scoped), and the other413 are metadata-only and refused at protocol layer. Unbound simulator: SN0 shows17 and SN1..4 show9. Bound real source: only SN0 exists; SN!=0 reads/writes are explicitly refused. 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; remote17 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 11/11 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:

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.