docs(skills): 按技能审核报告拆分 8 个大主文件并归档 IEC104 探针
技能主文件只留默认路径、成功输出样例、失败索引表与禁令;长尾规程逐字 搬进各技能 reference/,索引键与 reference 小节标题一一对应。 拆分结果(改前 -> 改后,字节): - keil-build 21779 -> 5837,新建 3 篇 reference - task-worktree 24163 -> 11448,新建 4 篇 reference,A-G/C2 节号保号 - draw-diagram 18907 -> 6496,新建 5 篇 reference - mem-budget 13046 -> 8020,新建 4 篇 reference - id-family-semantic-migration 11509 -> 8077,新建 2 篇 reference - stale-doc-count-sweep 8156 -> 6371,新建 1 篇 reference - serial-boot-test 8464 -> 6663,新建 2 篇 reference - board-ui-nav 5350 -> 4364,新建 1 篇 reference 其余 9 个技能补真实成功输出样例(判据串取自本轮实跑或文档原文)。 check_skill_size.py rc=0,17 个主文件无悬空指针。 IEC104 探针入库:ci-artifacts/ 里可复用的三个验收脚本迁入 test/host/iec104_dtu/(纯标准库、argparse、ASCII 输出、exit 0/1/2), 协议逻辑逐字保留,含三处探针自身缺陷修复(GI 漏 3 字节 IOA、I 帧 过滤判反、MEAS 键用 source_addr 而非 IOA)。一次性设计度量按 PROBE_INDEX.md 登记不迁入,运行方法见 PROBE_RUNBOOK.md。
This commit is contained in:
@@ -33,6 +33,9 @@
|
||||
| `iec104_master.py` | **IEC 60870-5-104 主站客户端(台架复测/保护定值持久化)**:连设备 :2404(工厂默认,`--port` 可指别的)跑 STARTDT → 总召(actcon/四组背景扫描/actterm)→ 经 C_SE 两段写临时压低 OC1 定值确定性触发 YX16 变位(COT=3)→ 恢复 → YK11 两段式 → C_RD 读回;**保护定值持久化模式 `--b7-pre/--b7-post/--b7-mark/--b7-check`**(中间 ST-LINK 复位):YK12 两段投退→保护退出/联动、定值与压板态跨复位保持(含非默认 7.5 往返);纯标准库,输出纯 ASCII 可直接重定向归档为台架证据(判据 exit 0/1/2) |
|
||||
| `cal_fit.py` | **N 点最小二乘标定参数求解(全仓唯一实现,v2.2 起固件侧拟合已删除)**(**3~8 点**,推荐 5 点):`--selftest` 跑金标向量回归(原 C 侧 `r_q16=39322000 / b=12` + 4 条拒绝路径,exit 0 全过 / 1 有失败,改动算法后必跑);`--from-doc` 直接读执行卡 §3 `CALDATA` 长表(每行一个点:路 \| 序号 \| 屏上读数 \| 注入已知量)按路分组拟合,输出合并 `WRITE-ALL` 命令;单路 `--sem/--x/--y` 亦可(`--x` = `meas:` 行 mV/mA 原样、`--y` = V/A 内部 ×1000,`--r-old/--b-old` 指读数采集时的设备参数);执行卡 `docs/测试说明/专项验证/ADC多点标定执行流程.md` §3;exit 0 可写 / 2 拒绝(入参越界 `bad argument`、点数越界、点位没拉开、单调性反转、斜率非正、r/b 越带、残差 >2%、表还是旧 6 列)或未填 |
|
||||
| `cal_write.py` | **标定参数写入器**(库层复用 `iec104_master.py`):C_SE 两段写下发定值段 `0x8050~`(变比 r)/`0x8048~`(零点 b,落笔置 VALID),C_RD 读回复核;每路先 r 后 b,输出纯 ASCII 可归档;执行卡 `docs/测试说明/专项验证/ADC多点标定执行流程.md` §4;exit 0 全过 / 1 有失败 / 2 连接或协议错误 |
|
||||
| `iec104_dtu/verify_board_acceptance.py` | **真板 104 只读验收**(STARTDT→总召→逐点核对 10 个映射遥测 + 59 SP + 16 DP →命令拒绝→对时确认):固件/点表变更后连板跑;`--host/--port` 默认 `192.168.31.100:2404`,纯标准库、ASCII 输出;exit 0 全过 / 1 检查失败 / 2 连接或协议错误;用法见 `iec104_dtu/PROBE_RUNBOOK.md` |
|
||||
| `iec104_dtu/verify_simulator_lan_bind.py` | **模拟器 104 任意地址绑定与局域网可达性验证**(启动 `lvgl_sim` 后查 `0.0.0.0:port` 监听 + 本机 IPv4 STARTDT 握手):模拟器绑定/CLI 变更后跑;`--exe/--output/--duration/--lan-ip` 可覆盖,纯标准库、ASCII 输出;exit 0 通过 / 1 断言失败 / 2 环境错误;同机验证,不证明防火墙放行 |
|
||||
| `iec104_dtu/verify_simulator_duration_evidence.py` | **模拟器自然退出证据探针**(拒绝 select/execute→对时→无 COT10/11→`--iec104-duration` 自然退出打印 STOP 汇总):引用 `simulated_actions` 前跑;`--exe/--host/--port/--duration/--output` 可覆盖,纯标准库、ASCII 输出;exit 0 全过 / 1 行为失败 / 2 启动或读取错误 |
|
||||
|
||||
### 时间 / 时延
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
# IEC104 probe triage and migration index
|
||||
|
||||
This is the tracked index for the temporary IEC104 probes that previously lived
|
||||
under ignored `ci-artifacts/`. Only reusable protocol-correctness acceptance
|
||||
probes (A) were normalized into `test/host/iec104_dtu/`. One-off design
|
||||
measurements (B) stay out of the test tree. Scripts already covered by tracked
|
||||
assets (C) were not migrated. The source paths below are historical:
|
||||
`ci-artifacts/` is gitignored and may not exist in a fresh clone.
|
||||
|
||||
## A - reusable protocol acceptance (migrated)
|
||||
|
||||
| Source | Class | Disposition | One-line verdict |
|
||||
|---|---|---|---|
|
||||
| `ci-artifacts/iec104-bench/board_probe.py` | A | Migrated to `test/host/iec104_dtu/verify_board_acceptance.py` | Real-board read-only acceptance: STARTDT, GI, 10 mapped measurements, 59 SP + 16 DP, command refusal, clock confirmation. Exit 0 = all checks pass, 1 = a check fails, 2 = connection/protocol error. |
|
||||
| `ci-artifacts/iec104-lan/verify_lan.py` | A | Migrated to `test/host/iec104_dtu/verify_simulator_lan_bind.py` | Simulator wildcard bind and local-IPv4 STARTDT check. Exit 0 = wildcard listener and handshakes pass, 1 = assertion fails, 2 = missing exe/tooling error. Same-host only. |
|
||||
| `ci-artifacts/iec104-tests/duration-evidence/duration_refusal_probe.py` | A | Migrated to `test/host/iec104_dtu/verify_simulator_duration_evidence.py` | Simulator finite-duration evidence for refused commands, clock sync, no completion frames and clean STOP. Exit 0 = all checks pass, 1 = behaviour fails, 2 = startup/read error. |
|
||||
|
||||
## B - one-off design-time measurement (not migrated)
|
||||
|
||||
| Source | Class | Disposition | One-line verdict |
|
||||
|---|---|---|---|
|
||||
| `ci-artifacts/iec104-cutover/probe_nostore_effect.py` | B | Keep as one-off evidence; not in `test/host/` | Compares `iec104_source.o` ZI with/without `IEC104_SOURCE_NO_VALUE_STORE`; answers a macro-cost question, not future protocol correctness. |
|
||||
| `ci-artifacts/iec104-cutover/ac5_probe_32.py` | B | Keep as one-off evidence; not in `test/host/` | AC5 warning-surface probe driven by the historical registration manifest; design-time compiler evidence. |
|
||||
| `ci-artifacts/iec104-cutover/gen_source_ranks.py` | B | Keep as one-off evidence; not in `test/host/` | Generates a dense rank header from a frozen profile; a code generator, not a test. |
|
||||
| `ci-artifacts/iec104-cutover/recompute_reach_budget.py` | B | Keep as one-off evidence; not in `test/host/` | Recomputes RAM budget from one-off link logs; design accounting only. |
|
||||
| `ci-artifacts/iec104-cutover/register_mdk.py` | B | Keep as one-off evidence; not in `test/host/` | One-time MDK registration script driven by a manifest; host tests must never register product files. |
|
||||
| `ci-artifacts/iec104-cutover/verify-slot-equivalence.py` | B | Keep as one-off evidence; not in `test/host/` | Proves old/new storage mappings equivalent for a specific redesign; not a reusable 104 acceptance probe. |
|
||||
| `ci-artifacts/iec104-cutover/serv-attrib/serv_surface_probe.py` | B | Keep as one-off evidence; not in `test/host/` | Reports stack frames of one frozen task build; design measurement. |
|
||||
| `ci-artifacts/iec104-build/verify_vendor.py` | B | Keep as one-off evidence; not in `test/host/` | Pins 17 controlled vendor diffs and hashes a frozen release; design drift evidence. |
|
||||
| `ci-artifacts/iec104-build/capacity_boundaries.py` | B | Keep as one-off evidence; not in `test/host/` | Compiles vendor TcpServer.c at guessed capacity limits; capacity design, not protocol acceptance. |
|
||||
| `ci-artifacts/iec104-build/link_resource_probe.py` | B | Keep as one-off evidence; not in `test/host/` | Isolated armlink resource probe with hard-coded Keil paths and historical object inventory. |
|
||||
| `ci-artifacts/iec104-build/summarize_matrix.py` | B | Keep as one-off evidence; not in `test/host/` | Reformats `vendor-ac5-results.json` into a matrix; depends on a one-off artifact tree. |
|
||||
| `ci-artifacts/iec104-build/vendor_style_scan.py` | B | Keep as one-off evidence; not in `test/host/` | Wrapper around the coding-standard hook for a frozen vendor file list. |
|
||||
| `ci-artifacts/iec104-build/final_static_scan.py` | B | Keep as one-off evidence; not in `test/host/` | Freezes explicit vendor/simulator source lists and hashes for a past review. |
|
||||
| `ci-artifacts/iec104-build/tiny_resource_probe.py` | B | Keep as one-off evidence; not in `test/host/` | Compiles/links a hypothetical tiny-capacity variant; not a product configuration test. |
|
||||
| `ci-artifacts/iec104-review/verify_vendor.py` | B | Keep as one-off evidence; not in `test/host/` | Asserts 84 upstream hashes, 43 static assertions and controlled diffs of a historical review tree. |
|
||||
| `ci-artifacts/iec104-review/any_bind_review.py` | B | Keep as one-off evidence; reusable part migrated | Reviews one frozen simulator SHA256 and writes review-only JSON; wildcard bind check migrated to A. |
|
||||
| `ci-artifacts/iec104-review/boundaries.py` | B | Keep as one-off evidence; not in `test/host/` | Re-checks capacity compile boundaries at a hard-coded Keil path; duplicate of `iec104-build/capacity_boundaries.py`. |
|
||||
| `ci-artifacts/iec104-review/mcu_closure_review.py` | B | Keep as one-off evidence; not in `test/host/` | Rebuilds a historic MCU closure map and checks a 3336-byte symbol; not a protocol test. |
|
||||
| `ci-artifacts/iec104-review/run_masks.py` | B | Keep as one-off evidence; not in `test/host/` | Compiles a one-off `masks.c` with MSVC; depends on a review-tree fixture. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/cap_sweep.py` | B | Keep as one-off evidence; not in `test/host/` | Sweeps TCP capacities through ARMCC and fromelf for RAM sizing. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/dump.py` | B | Keep as one-off evidence; not in `test/host/` | Dumps section data of one historical object through fromelf. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/objs.py` | B | Keep as one-off evidence; not in `test/host/` | Parses a historical Keil map's object summary by RW+ZI. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/objsyms.py` | B | Keep as one-off evidence; not in `test/host/` | Lists data symbols of one named object from a historical Keil map. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/region.py` | B | Keep as one-off evidence; not in `test/host/` | Aggregates execution-region rows from a historical Keil map. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/region2.py` | B | Keep as one-off evidence; not in `test/host/` | Refined Keil map region/section aggregation for the same one-off review. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/secsum.py` | B | Keep as one-off evidence; not in `test/host/` | Converts fromelf section sizes into a RO/RAM table for historical objects. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/sweep2.py` | B | Keep as one-off evidence; not in `test/host/` | Compiles a single vendor TU under alternate capacity defines and reports RO/RAM. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/sweep3.py` | B | Keep as one-off evidence; not in `test/host/` | Measures .bss of one vendor TU under a fixed set of capacity overrides. |
|
||||
| `ci-artifacts/iec104-review/ramprobe/syms.py` | B | Keep as one-off evidence; not in `test/host/` | Greps named symbols from a historical Keil map. |
|
||||
| `ci-artifacts/hash_iec104_sim_release.py` | B | Keep as one-off evidence; not in `test/host/` | Rewrites a release source hash list from a historical vcxproj; snapshot tool, not a test. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/capacity-candidates.py` | B | Keep as one-off evidence; not in `test/host/` | Enumerates hypothetical capacity pools for the skeleton design. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/compile_real_serv_exact.py` | B | Keep as one-off evidence; not in `test/host/` | Recreates the historical product compile surface for one serv TU. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/link_skeleton.py` | B | Keep as one-off evidence; not in `test/host/` | Measures skeleton closure RO/RW+ZI with isolated armlink objects. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/link_whole_image.py` | B | Keep as one-off evidence; not in `test/host/` | Measures whole-image reachability with a draft Net backend. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/link_whole_with_business.py` | B | Keep as one-off evidence; not in `test/host/` | Adds business TUs to the isolated link for a three-tier RAM comparison. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/measure_skeleton.py` | B | Keep as one-off evidence; not in `test/host/` | Compiles/links the skeleton TU set and records ARMCC/fromelf sizes. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/pool_parts_report.py` | B | Keep as one-off evidence; not in `test/host/` | Parses pool-size constants from historical fromelf output. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/summarize_matrix.py` | B | Keep as one-off evidence; not in `test/host/` | Summarizes skeleton link maps against a fixed RAM floor. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/summarize_skeleton.py` | B | Keep as one-off evidence; not in `test/host/` | Aggregates per-TU ROM/RAM from a historical measurement JSON. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/summarize_whole_image.py` | B | Keep as one-off evidence; not in `test/host/` | Summarizes whole-image link maps against a fixed RAM floor. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/tu_closure.py` | B | Keep as one-off evidence; not in `test/host/` | Explains skeleton/business TU split from one historical .xref map. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/core-trim/candidate_a_delta.py` | B | Keep as one-off evidence; not in `test/host/` | Measures code-trim delta against a git-HEAD baseline copy. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/core-trim/link_core_trim.py` | B | Keep as one-off evidence; not in `test/host/` | Links two core-trim variants and subtracts library RAM from map totals. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/core-trim/link_reach_fixed.py` | B | Keep as one-off evidence; not in `test/host/` | Re-links with a corrected core/source reach root across four tiers. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/core-trim/measure_business_tu.py` | B | Keep as one-off evidence; not in `test/host/` | Compiles business TUs in two tiers and extracts RAM with fromelf. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/core-trim/ram_by_object.py` | B | Keep as one-off evidence; not in `test/host/` | Lists per-object RAM from historical core-trim objects. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/core-trim/summarize_core_trim.py` | B | Keep as one-off evidence; not in `test/host/` | Parses size symbols produced by the one-off core-trim probe. |
|
||||
| `ci-artifacts/iec104-mcu-skeleton/core-trim/simcheck/gen_probes.py` | B | Keep as one-off evidence; not in `test/host/` | Generates probe C files for the one-off skeleton simulation check. |
|
||||
| `ci-artifacts/iec104-mcu-plan/files/capture_evidence.py` | B | Keep as one-off evidence; not in `test/host/` | Captures selected source ranges into a historical evidence text file. |
|
||||
| `ci-artifacts/iec104-mcu-plan/persistence/audit_parameters.py` | B | Keep as one-off evidence; not in `test/host/` | Audits a frozen writable-parameter predicate and writes CSV to stdout. |
|
||||
| `ci-artifacts/iec104-mcu-plan/resources/link_closure.py` | B | Keep as one-off evidence; not in `test/host/` | Links a conservative file-domain closure from historical objects. |
|
||||
| `ci-artifacts/iec104-mcu-plan/resources/measure_closure.py` | B | Keep as one-off evidence; not in `test/host/` | Copies upstream sources and compiles them in isolation for sizing. |
|
||||
| `ci-artifacts/iec104-mcu-plan/resources/seal_evidence.py` | B | Keep as one-off evidence; not in `test/host/` | Hashes all evidence files in one design directory into a manifest. |
|
||||
| `ci-artifacts/iec104-mcu-feasibility/files/run.py` | B | Keep as one-off evidence; not in `test/host/` | Isolated MSVC host run of file-domain feasibility fixtures. |
|
||||
| `ci-artifacts/iec104-mcu-feasibility/independent-tests/run_checks.py` | B | Keep as one-off evidence; not in `test/host/` | Runs artifact-only persistence feasibility probes and mutants. |
|
||||
| `ci-artifacts/iec104-mcu-feasibility/independent-tests/run_layout.py` | B | Keep as one-off evidence; not in `test/host/` | Checks a frozen candidate layout oracle with MSVC fixtures. |
|
||||
| `ci-artifacts/iec104-mcu-feasibility/persistence/run_model.py` | B | Keep as one-off evidence; not in `test/host/` | Runs an isolated persistence-state-machine model with injected faults. |
|
||||
| `ci-artifacts/iec104-mcu-feasibility/resources/measure_layout.py` | B | Keep as one-off evidence; not in `test/host/` | Compiles/links a frozen layout candidate for RAM comparison. |
|
||||
|
||||
## C - already covered by tracked assets (not migrated)
|
||||
|
||||
| Source | Class | Disposition | One-line verdict |
|
||||
|---|---|---|---|
|
||||
| `ci-artifacts/iec104-review/cli_final.py` | C | Not migrated | Covered by `test/host/iec104_dtu/run_tcp_test.py` and the simulator CLI contract in `test/host/iec104_dtu/MATRIX.md`; this file additionally pinned one historical SHA256. |
|
||||
| `ci-artifacts/iec104-build/baseline-f84855a5/**/*.py` | C | Not migrated | Frozen baseline copy of already tracked repository scripts; no new probe logic. |
|
||||
|
||||
## Files added under `test/host/iec104_dtu/`
|
||||
|
||||
- `verify_board_acceptance.py`, `verify_simulator_lan_bind.py`, `verify_simulator_duration_evidence.py`: normalized A-class probes.
|
||||
- `PROBE_INDEX.md`: this classification index.
|
||||
- `PROBE_RUNBOOK.md`: how and when to run the three normalized probes.
|
||||
@@ -0,0 +1,55 @@
|
||||
# IEC104 probe runbook (tracked acceptance assets)
|
||||
|
||||
## 什么时候跑
|
||||
|
||||
| Script | When | Exit codes |
|
||||
|---|---|---|
|
||||
| `verify_board_acceptance.py` | After DTU firmware/point-table changes, against a real board | 0 all checks pass, 1 a check fails, 2 connection/protocol error |
|
||||
| `verify_simulator_lan_bind.py` | After simulator bind-address/CLI change or before a LAN bench session | 0 wildcard listener and local handshake pass, 1 assertion fails, 2 missing exe/tooling error |
|
||||
| `verify_simulator_duration_evidence.py` | Before quoting STOP-summary counters, when a clean finite-duration run is needed | 0 refusals/clock/completion and exit status pass, 1 behaviour fails, 2 startup/read error |
|
||||
|
||||
## 前置条件
|
||||
|
||||
- Real board: powered, reachable at `192.168.31.100`, firmware IEC104 listener on `2404`,
|
||||
profile table matching `App/protocol/iec60870/examples/iec104_dtu_profile.h`.
|
||||
- Simulator: `simulator/build/Debug/lvgl_sim.exe` built with IEC104 headless CLI,
|
||||
chosen port free, Windows `Get-NetTCPConnection` available for the LAN bind probe.
|
||||
- All three scripts are Python 3 standard library only. They print ASCII only and
|
||||
use exit codes as their verdict; redirect stdout/stderr to a log file for evidence.
|
||||
- `verify_board_acceptance.py` imports `wire.py` beside itself; run from anywhere with
|
||||
`python <repo>/test/host/iec104_dtu/verify_board_acceptance.py ...`.
|
||||
|
||||
## 怎么跑
|
||||
|
||||
From repository root:
|
||||
|
||||
```bash
|
||||
python -B test/host/iec104_dtu/verify_board_acceptance.py --help
|
||||
python -B test/host/iec104_dtu/verify_board_acceptance.py --host 192.168.31.100 --port 2404
|
||||
|
||||
python -B test/host/iec104_dtu/verify_simulator_lan_bind.py --help
|
||||
python -B test/host/iec104_dtu/verify_simulator_lan_bind.py --duration 12
|
||||
|
||||
python -B test/host/iec104_dtu/verify_simulator_duration_evidence.py --help
|
||||
python -B test/host/iec104_dtu/verify_simulator_duration_evidence.py \
|
||||
--exe simulator/build/Debug/lvgl_sim.exe --port 24040 --duration 10 \
|
||||
--output ci-artifacts/iec104-tests/duration-evidence
|
||||
```
|
||||
|
||||
## 判据
|
||||
|
||||
- Board: GI terminates; all mapped measurements present; `SP 59/59` and `DP 16/16`;
|
||||
command `C_SC_NA_1` is refused with COT 7 and P/N=1; `C_CS_NA_1` is confirmed.
|
||||
- LAN bind: OS listener is `0.0.0.0` owned by the simulator PID; STARTDT handshake replies
|
||||
`68040b000000`; process exits 0 and the listener disappears. This is same-host evidence
|
||||
only, not proof that another LAN device can pass through a firewall.
|
||||
- Duration evidence: two refused `C_SC_NA_1` commands produce only COT 7/P/N=1; no COT 10
|
||||
or COT 11 follows; clock read replies; simulator exits 0 and `simulator.log` contains
|
||||
its STOP summary line with `simulated_actions=`.
|
||||
|
||||
## 分类与历史来源
|
||||
|
||||
`PROBE_INDEX.md` lists every rescued script and its A/B/C disposition. One-off design
|
||||
measurements were intentionally not placed in `test/host/`; their original paths under
|
||||
`ci-artifacts/` are ignored by git and may disappear, but they are not needed to repeat
|
||||
protocol acceptance.
|
||||
@@ -0,0 +1,164 @@
|
||||
"""Board-side IEC 60870-5-104 acceptance probe (read-only, no state changes).
|
||||
|
||||
Run this when a real DTU board at 192.168.31.100:2404 must be re-accepted after
|
||||
a firmware or point-table change. It performs STARTDT, a station general
|
||||
interrogation, checks every mapped measurement and DTU signal is reported, then
|
||||
proves command refusal and clock confirmation.
|
||||
Prerequisites: the board is powered, its 104 listener is reachable, and the
|
||||
point table matches iec104_dtu_profile.h. An unreachable board, a non-104
|
||||
listener or bad frame sequence exits 2; a missing point or an unexpected
|
||||
command reply exits 1.
|
||||
"""
|
||||
import argparse
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
sys.path.insert(0, str(HERE))
|
||||
import wire # noqa: E402
|
||||
|
||||
HOST = "192.168.31.100"
|
||||
PORT = 2404
|
||||
|
||||
# IOA -> label, from the DTU profile table (iec104_dtu_profile.h).
|
||||
# NOTE: s_meas_map[] in iec104_serv.c is keyed by source address (0x9605 etc.),
|
||||
# NOT by IOA. The wire carries IOA, so the probe must look up 0x400C.. here.
|
||||
MEAS = {
|
||||
0x400C: "UA", 0x400D: "UB", 0x400E: "UC", 0x400F: "UN",
|
||||
0x4015: "IA", 0x4016: "IB", 0x4017: "IC", 0x4018: "IN",
|
||||
0x4007: "freq", 0x4003: "temp",
|
||||
}
|
||||
YX_SP = 0x0001 # singles start here, 59 points
|
||||
YX_DP = 0x1001 # doubles start here, 16 points
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--host", default=HOST, help="board IPv4 address")
|
||||
parser.add_argument("--port", type=int, default=PORT, help="board IEC104 TCP port")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main(host, port):
|
||||
problems = []
|
||||
gi_done = False
|
||||
trace = []
|
||||
t0 = time.monotonic()
|
||||
c = wire.Client(host, port, trace, timeout=8)
|
||||
print("connected to %s:%d in %.0f ms" % (host, port, (time.monotonic() - t0) * 1000))
|
||||
c.start()
|
||||
print("STARTDT confirmed (%.0f ms)" % ((time.monotonic() - t0) * 1000))
|
||||
|
||||
# General interrogation, QOI=20 (station), COT=6 ACT.
|
||||
# Type 100 的载荷是 IOA(3) + QOI(1):漏掉 IOA 会让 ASDU 只有 1 字节,
|
||||
# vendor IEC60870_Parse_ASDU_Header 判载荷不足 -> FRAME_ERROR -> 断链。
|
||||
c.request(wire.asdu(100, wire.u24(0) + bytes((20,)), cot=6))
|
||||
end = time.monotonic() + 25
|
||||
seen = {}
|
||||
while time.monotonic() < end:
|
||||
try:
|
||||
frame = c.frame(time.monotonic() + 2.0)
|
||||
except (TimeoutError, socket.timeout):
|
||||
break
|
||||
if frame[2] & 1:
|
||||
continue # S/U 帧:control 域最低位为 1;只有最低位为 0 才是 I 帧
|
||||
data = frame[6:]
|
||||
h = wire.header(data)
|
||||
if h["type"] == 100 and h["cot"] == 10:
|
||||
print("GI activation terminated")
|
||||
gi_done = True
|
||||
break
|
||||
if h["type"] not in (1, 3, 9, 13, 30, 31, 34, 35, 36, 37):
|
||||
continue
|
||||
try:
|
||||
for row in wire.objects(data):
|
||||
seen.setdefault(row["ioa"], row)
|
||||
except AssertionError as exc:
|
||||
print(" decode issue:", exc)
|
||||
problems.append("decode issue")
|
||||
if not gi_done:
|
||||
problems.append("GI not terminated")
|
||||
|
||||
print("\n=== measurements (mapped by iec104_serv.c s_meas_map) ===")
|
||||
for ioa, name in sorted(MEAS.items()):
|
||||
row = seen.get(ioa)
|
||||
if row is None:
|
||||
print(" %-5s IOA 0x%04X : ABSENT" % (name, ioa))
|
||||
problems.append("measurement absent %s" % name)
|
||||
else:
|
||||
iv = "IV" if row.get("quality", 0) & 0x80 else "valid"
|
||||
if row["type"] in (13, 36, 112, 206, 207):
|
||||
shown = "%.4f" % row["value"]
|
||||
else:
|
||||
shown = str(row["value"])
|
||||
print(" %-5s IOA 0x%04X : type=%d value=%-10s quality=0x%02X %s"
|
||||
% (name, ioa, row["type"], shown, row.get("quality", 0), iv))
|
||||
|
||||
print("\n=== DTU signals 59 SP + 16 DP ===")
|
||||
sp_present = sum(1 for i in range(YX_SP, YX_SP + 59) if i in seen)
|
||||
dp_present = sum(1 for i in range(YX_DP, YX_DP + 16) if i in seen)
|
||||
print(" SP 0x%04X..0x%04X present %d/59" % (YX_SP, YX_SP + 58, sp_present))
|
||||
print(" DP 0x%04X..0x%04X present %d/16" % (YX_DP, YX_DP + 15, dp_present))
|
||||
if sp_present != 59:
|
||||
problems.append("SP present %d/59" % sp_present)
|
||||
if dp_present != 16:
|
||||
problems.append("DP present %d/16" % dp_present)
|
||||
iv_sp = sum(1 for i in range(YX_SP, YX_SP + 59)
|
||||
if i in seen and seen[i].get("quality", 0) & 0x80)
|
||||
iv_dp = sum(1 for i in range(YX_DP, YX_DP + 16)
|
||||
if i in seen and seen[i].get("quality", 0) & 0x80)
|
||||
print(" SP carrying IV: %d, DP carrying IV: %d" % (iv_sp, iv_dp))
|
||||
|
||||
print("\n=== totals ===")
|
||||
by_type = {}
|
||||
for row in seen.values():
|
||||
by_type[row["type"]] = by_type.get(row["type"], 0) + 1
|
||||
print(" distinct IOA reported:", len(seen), " by type:", dict(sorted(by_type.items())))
|
||||
print(" frames: tx=%d rx=%d" % (sum(1 for x in trace if x["direction"] == "tx"),
|
||||
sum(1 for x in trace if x["direction"] == "rx")))
|
||||
|
||||
# Negative-path probes: commands must be refused, never confirmed.
|
||||
print("\n=== command refusal (must not be confirmed) ===")
|
||||
payload = wire.u24(0x6001) + bytes((0x01, 0x00))
|
||||
c.request(wire.asdu(45, payload, cot=6))
|
||||
try:
|
||||
data = c.response(45, cot=7, pn=True)
|
||||
print(" C_SC_NA_1 0x6001 -> COT 7 P/N=1 refusal (correct)")
|
||||
except (TimeoutError, AssertionError) as exc:
|
||||
print(" C_SC_NA_1 0x6001 -> UNEXPECTED:", exc)
|
||||
problems.append("C_SC refusal unexpected")
|
||||
|
||||
print("\n=== clock synchronisation (C_CS_NA_1) ===")
|
||||
now = time.localtime()
|
||||
cp56 = struct.pack("<HBBBBB", now.tm_sec * 1000 + now.tm_min * 0, now.tm_min,
|
||||
now.tm_hour, now.tm_mday, now.tm_mon, now.tm_year - 2000)
|
||||
# Type 103 的载荷顺序 = IOA(3) + CP56Time2a(7):IOA 在**前**。
|
||||
# 写成 CP56 在前会让 vendor 把时标头 3 字节当 IOA 解析,回 COT 47(未知 IOA)。
|
||||
c.request(wire.asdu(103, wire.u24(0) + cp56, cot=6))
|
||||
try:
|
||||
data = c.response(103, cot=7)
|
||||
print(" C_CS_NA_1 -> COT 7 confirmed:", data.hex())
|
||||
except (TimeoutError, AssertionError) as exc:
|
||||
print(" C_CS_NA_1 -> UNEXPECTED:", exc)
|
||||
problems.append("C_CS confirmation unexpected")
|
||||
|
||||
c.close()
|
||||
|
||||
print("\n=== verdict ===")
|
||||
print("FAILURES: %d" % len(problems))
|
||||
for item in problems:
|
||||
print(" " + item)
|
||||
return 1 if problems else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parsed = parse_args()
|
||||
try:
|
||||
rc = main(parsed.host, parsed.port)
|
||||
except (OSError, socket.timeout, TimeoutError, AssertionError) as exc:
|
||||
print("PROTOCOL_ERROR %s" % type(exc).__name__)
|
||||
rc = 2
|
||||
raise SystemExit(rc)
|
||||
@@ -0,0 +1,120 @@
|
||||
"""Simulator duration-mode evidence: refused command, clock sync, clean STOP.
|
||||
|
||||
Run when IEC104 simulator STOP-summary evidence is needed, especially because
|
||||
run_tcp_test.py terminates the process before it prints simulated_actions.
|
||||
This probe uses --iec104-duration so the headless loop exits on its own.
|
||||
Prerequisites: a simulator binary supporting --iec104-headless and
|
||||
--iec104-duration is available and the chosen port is free.
|
||||
Exit 0 = refusals/completion/clock checks passed and simulator exited 0;
|
||||
1 = a behavioural check failed; 2 = simulator could not be started or read.
|
||||
"""
|
||||
import argparse
|
||||
import pathlib
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT / "test" / "host" / "iec104_dtu"))
|
||||
|
||||
from wire import Client, asdu, cp56, header, u24 # noqa: E402
|
||||
|
||||
|
||||
def wait_listen(host, port, deadline_s=15.0):
|
||||
deadline = time.monotonic() + deadline_s
|
||||
while time.monotonic() < deadline:
|
||||
try:
|
||||
with socket.create_connection((host, port), 0.2):
|
||||
return
|
||||
except OSError:
|
||||
time.sleep(0.05)
|
||||
raise TimeoutError("simulator did not listen")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--exe", type=pathlib.Path, required=True)
|
||||
parser.add_argument("--host", default="127.0.0.1")
|
||||
parser.add_argument("--port", type=int, default=24040)
|
||||
parser.add_argument("--duration", type=int, default=10)
|
||||
parser.add_argument("--output", type=pathlib.Path,
|
||||
default=ROOT / "ci-artifacts/iec104-tests/duration-evidence")
|
||||
args = parser.parse_args()
|
||||
|
||||
args.output.mkdir(parents=True, exist_ok=True)
|
||||
log_path = args.output / "simulator.log"
|
||||
trace = []
|
||||
problems = []
|
||||
|
||||
try:
|
||||
with log_path.open("w", encoding="utf-8") as log:
|
||||
process = subprocess.Popen(
|
||||
[str(args.exe), "--iec104", "--iec104-headless",
|
||||
"--iec104-port", str(args.port), "--iec104-duration", str(args.duration)],
|
||||
cwd=str(args.output), stdout=log, stderr=subprocess.STDOUT)
|
||||
try:
|
||||
wait_listen(args.host, args.port)
|
||||
client = Client(args.host, args.port, trace)
|
||||
client.start()
|
||||
|
||||
# 1) SELECT then EXECUTE on a command point: both must be refused.
|
||||
client.request(asdu(46, u24(0x6002) + bytes((2 | 128,))))
|
||||
data = client.response(46, 7, pn=True)
|
||||
assert header(data)["cot"] == 7, data.hex()
|
||||
print("REFUSED select ioa=0x6002 cot=%d pn=%s" %
|
||||
(header(data)["cot"], header(data)["pn"]))
|
||||
|
||||
client.request(asdu(46, u24(0x6002) + bytes((2,))))
|
||||
data = client.response(46, 7, pn=True)
|
||||
assert header(data)["cot"] == 7, data.hex()
|
||||
print("REFUSED execute ioa=0x6002 cot=%d pn=%s" %
|
||||
(header(data)["cot"], header(data)["pn"]))
|
||||
|
||||
# 2) One clock sync so clock_sets is exercised (device-only, no OS clock).
|
||||
stamp = struct.pack("<HBBBBB", 30000, 22, 11, 17, 6, 35)
|
||||
client.request(asdu(103, u24(0) + stamp))
|
||||
client.response(103, 7)
|
||||
client.request(asdu(103, u24(0) + bytes(7), cot=5))
|
||||
reply = client.response(103, 5)
|
||||
print("CLOCK sync iso=%s" % cp56(reply[-7:])["iso"])
|
||||
|
||||
# 3) Confirm no ACT_TERM / no return-info followed the refusals.
|
||||
start = len(client.asdus)
|
||||
deadline = time.monotonic() + 0.5
|
||||
try:
|
||||
while time.monotonic() < deadline:
|
||||
client.frame(deadline)
|
||||
except (socket.timeout, TimeoutError):
|
||||
pass
|
||||
for item in client.asdus[start:]:
|
||||
item_header = header(item)
|
||||
assert not (item_header["type"] == 46 and item_header["cot"] == 10), item.hex()
|
||||
assert item_header["cot"] != 11, item.hex()
|
||||
print("NO_COMPLETION verified (no COT 10, no COT 11)")
|
||||
|
||||
client.close()
|
||||
print("CLIENT closed, waiting for graceful stop...", flush=True)
|
||||
rc = process.wait(timeout=args.duration + 30)
|
||||
print("SIMULATOR exit=%d" % rc)
|
||||
if rc != 0:
|
||||
problems.append("simulator exit %d" % rc)
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.terminate()
|
||||
try:
|
||||
process.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:
|
||||
process.kill()
|
||||
print("\n===== simulator.log =====")
|
||||
print(log_path.read_text(encoding="utf-8").strip())
|
||||
except (OSError, subprocess.SubprocessError, socket.timeout, TimeoutError,
|
||||
AssertionError, ValueError) as exc:
|
||||
print("FAIL %s: %s" % (type(exc).__name__, str(exc)[:500]))
|
||||
return 2
|
||||
return 1 if problems else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,113 @@
|
||||
"""LAN reachability verification for the IEC 60870-5-104 simulator listener.
|
||||
|
||||
Run after a simulator bind-address change (or before a LAN bench session) to
|
||||
confirm the listener is bound to 0.0.0.0 and answers STARTDT on local IPv4
|
||||
addresses. It starts the local lvgl_sim binary in headless IEC104 duration mode.
|
||||
Prerequisites: simulator/build/Debug/lvgl_sim.exe exists with the IEC104 CLI
|
||||
contract, Get-NetTCPConnection is available, and local IPv4 is configured.
|
||||
A missing binary, wrong bind address, bad STARTDT reply or simulator exits
|
||||
nonzero returns 1; a PowerShell/tooling error returns 2.
|
||||
This checks the same host only: it does not prove another LAN device can pass
|
||||
through a firewall.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import pathlib
|
||||
import re
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def parser():
|
||||
p = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
p.add_argument("--exe", type=pathlib.Path,
|
||||
default=pathlib.Path(__file__).resolve().parents[2] / "simulator/build/Debug/lvgl_sim.exe",
|
||||
help="lvgl_sim executable to start")
|
||||
p.add_argument("--output", type=pathlib.Path,
|
||||
default=pathlib.Path(__file__).resolve().parents[2] / "ci-artifacts/iec104-lan",
|
||||
help="directory for report.json")
|
||||
p.add_argument("--duration", type=int, default=12,
|
||||
help="simulator lifetime in seconds")
|
||||
p.add_argument("--lan-ip", default=None,
|
||||
help="extra local IPv4 address to probe; auto-detected when present")
|
||||
return p
|
||||
|
||||
|
||||
def powershell(code):
|
||||
r = subprocess.run(["powershell.exe", "-NoProfile", "-Command", code],
|
||||
capture_output=True, text=True, timeout=15)
|
||||
assert r.returncode == 0, (r.returncode, r.stdout, r.stderr)
|
||||
return r.stdout.strip()
|
||||
|
||||
|
||||
def main():
|
||||
args = parser().parse_args()
|
||||
exe = args.exe.resolve()
|
||||
out = args.output.resolve()
|
||||
if not exe.is_file():
|
||||
print("MISSING exe: %s" % exe)
|
||||
return 2
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
ips = json.loads(powershell(
|
||||
"ConvertTo-Json -Compress -InputObject @(Get-NetIPAddress "
|
||||
"-AddressFamily IPv4 | Select-Object -ExpandProperty IPAddress)"))
|
||||
if args.lan_ip:
|
||||
ips.append(args.lan_ip)
|
||||
process = subprocess.Popen(
|
||||
[str(exe), "--iec104", "--iec104-headless", "--iec104-port", "0",
|
||||
"--iec104-duration", str(args.duration)],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
try:
|
||||
ready = process.stdout.readline().strip()
|
||||
match = re.search(r"port=(\d+)", ready)
|
||||
assert match, ready
|
||||
port = int(match.group(1))
|
||||
listeners = json.loads(powershell(
|
||||
"ConvertTo-Json -Compress -InputObject @(Get-NetTCPConnection "
|
||||
"-State Listen -LocalPort %d | Select-Object LocalAddress,LocalPort,OwningProcess)" % port))
|
||||
assert any(x["LocalAddress"] == "0.0.0.0" and x["OwningProcess"] == process.pid
|
||||
for x in listeners), listeners
|
||||
results = []
|
||||
targets = ["127.0.0.1"] + ([args.lan_ip] if args.lan_ip else [])
|
||||
for host in targets:
|
||||
time.sleep(0.25)
|
||||
with socket.create_connection((host, port), timeout=3) as sock:
|
||||
sock.settimeout(3)
|
||||
sock.sendall(bytes.fromhex("680407000000"))
|
||||
data = b""
|
||||
while len(data) < 6:
|
||||
data += sock.recv(6 - len(data))
|
||||
assert data == bytes.fromhex("68040b000000"), data.hex()
|
||||
results.append({"target": host, "sent": "680407000000",
|
||||
"received": data.hex(), "scope": "same-host only"})
|
||||
stdout, stderr = process.communicate(timeout=args.duration + 10)
|
||||
assert process.returncode == 0, (process.returncode, stderr)
|
||||
leftovers = json.loads(powershell(
|
||||
"ConvertTo-Json -Compress -InputObject @(Get-NetTCPConnection -State Listen "
|
||||
"-LocalPort %d -ErrorAction SilentlyContinue | Where-Object OwningProcess -eq %d)" %
|
||||
(port, process.pid)))
|
||||
assert not leftovers, leftovers
|
||||
report = {"exe": str(exe), "sha256": hashlib.sha256(exe.read_bytes()).hexdigest(),
|
||||
"pid": process.pid, "ready": ready, "local_ipv4": ips,
|
||||
"listeners": listeners, "handshakes": results,
|
||||
"exit_code": process.returncode, "stdout": stdout, "stderr": stderr,
|
||||
"remote_firewall_verified": False, "listener_after_exit": False}
|
||||
(out / "report.json").write_text(json.dumps(report, indent=2), encoding="utf-8")
|
||||
print(json.dumps(report, indent=2))
|
||||
return 0
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.terminate()
|
||||
process.communicate(timeout=5)
|
||||
except (OSError, subprocess.SubprocessError, ValueError, AssertionError) as exc:
|
||||
print("FAIL: %s" % type(exc).__name__)
|
||||
print(str(exc)[:1000])
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user