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。
This commit is contained in:
2026-11-19 17:16:56 +08:00
parent ea5ef6b751
commit 7da5c7b74c
20 changed files with 6982 additions and 6345 deletions
+2 -2
View File
@@ -11,13 +11,13 @@ Read-only reference: `IEC60870-Slave/examples/iec104_dtu_profile.h`, `iec104_exa
- 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.
- 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; 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.
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.
+1 -1
View File
@@ -21,7 +21,7 @@ assets (C) were not migrated. The source paths below are historical:
|---|---|---|---|
| `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/gen_source_ranks.py` | B | 随参数区收窄失效;历史一次性证据,不在 `test/host/` | 曾从冻结 profile 生成 dense rank header;其产物 `iec104_source_ranks.h` 已删除,17 项消费者排名现由 `App/iec60870/104/iec104_dtu_table.c` 运行时计算。 |
| `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. |
@@ -0,0 +1,268 @@
/* Real preset/solidify chain: 104 remote parameter -> prot_set atomic batch.
*
* 这份夹具守的是一个安全级契约:主站收到"肯定确认"的那一刻,prot_set 里必须
* 真的变了。修复前走 SN=1..4 的写入会回 COT=7(+)、回读也"看起来对",而
* prot_set 一个字都没动 —— 区域 1..4 的分段项在 mapped() 里凑不出 changes[],
* parameter_apply 根本没被调用,代价却记了一次提交。这里把它钉死:
* 1. 绑定真实源后 SN!=0 一律否定确认,且不产生任何提交、不改 prot_set;
* 2. SN=0 的预置 + 固化必须真的落到 prot_set;
* 3. 读回走真实源,不再返回 profile 里的出厂字面量;
* 4. 绑定后 READ_AREA 只报区域 0,未绑定的模拟面仍报 0..4;
* 5. parameter_commits 只在真的调过 apply 时加一。
*/
#include "iec104_tcp_fixture.h"
#include "iec104_core.h"
#include "iec104_source.h"
#include "prot_set.h"
static iec104_core_config_t config = {"127.0.0.1", 24041U, 1U};
static iec104_core_status_t status;
static unsigned apply_calls, validate_calls;
static void turn(void) { CHECK(iec104_core_poll() == 0); }
/* 生产版回调的等价物:读直取 prot_set,写走一次原子批量(含预检阶段)。 */
static bool parameter_read(void *ctx, uint16_t id, float *out)
{
(void)ctx;
if (out == NULL || id >= (uint16_t)PS_ID_COUNT) { return false; }
*out = prot_set_get_f((prot_set_id_t)id);
return true;
}
static bool parameter_apply(void *ctx, const iec104_source_change_t *v, size_t n, bool validate)
{
prot_set_change_t batch[IEC104_DTU_CONSUMER_COUNT];
size_t i;
(void)ctx;
if (v == NULL || n == 0U || n > IEC104_DTU_CONSUMER_COUNT) { return false; }
if (validate) { ++validate_calls; } else { ++apply_calls; }
for (i = 0U; i < n; ++i) {
if (v[i].id >= (uint16_t)PS_ID_COUNT) { return false; }
batch[i].id = (prot_set_id_t)v[i].id;
batch[i].q10 = PROT_SET_Q10(v[i].value);
}
return prot_set_apply_batch(batch, n, validate ? 1 : 0) == 0;
}
/* ---- 报文组装(全部按线上字节,不借用产品编码器) ------------------------- */
static void apdu(uint8_t *f, uint8_t asdu_len)
{
f[0] = 0x68U; f[1] = (uint8_t)(asdu_len + 4U);
f[2] = 0U; f[3] = 0U; f[4] = 0U; f[5] = 0U;
}
static void head_203(uint8_t *f, uint8_t count, uint8_t cot)
{
f[6] = 203U; f[7] = count; f[8] = cot; f[9] = 17U;
f[10] = 1U; f[11] = 0U;
}
/* PRESET:CA=1 / OA=17 / 单元素 Float(tag38) / 小端。SN 由调用方给。 */
static void preset_frame(uint8_t *f, uint16_t sn, uint32_t ioa, float value)
{
uint32_t bits;
size_t i;
memcpy(&bits, &value, 4U);
apdu(f, 18U); head_203(f, 1U, 6U);
f[12] = (uint8_t)(sn & 0xFFU); f[13] = (uint8_t)(sn >> 8);
f[14] = 0x80U; /* data[8] 的 PRESET 标志 */
f[15] = (uint8_t)(ioa & 0xFFU);
f[16] = (uint8_t)((ioa >> 8) & 0xFFU);
f[17] = (uint8_t)((ioa >> 16) & 0xFFU);
f[18] = 38U; f[19] = 4U;
for (i = 0U; i < 4U; ++i) { f[20U + i] = (uint8_t)(bits >> (8U * i)); }
}
static void solidify_frame(uint8_t *f, uint16_t sn)
{
apdu(f, 9U); head_203(f, 0U, 6U);
f[12] = (uint8_t)(sn & 0xFFU); f[13] = (uint8_t)(sn >> 8);
f[14] = 0U;
}
static void cancel_frame(uint8_t *f, uint16_t sn)
{
apdu(f, 9U); head_203(f, 0U, 8U);
f[12] = (uint8_t)(sn & 0xFFU); f[13] = (uint8_t)(sn >> 8);
f[14] = 0U;
}
static void area_frame(uint8_t *f)
{
apdu(f, 9U); f[6] = 201U; f[7] = 1U; f[8] = 6U; f[9] = 17U;
f[10] = 1U; f[11] = 0U; f[12] = 0U; f[13] = 0U; f[14] = 0U;
}
/* 202 读:ASDU 布局 = type/count/cot/OA/CA(2)/SN(2)/IOA(3),长度 8+3*count。
* SN 是定值区号 —— 绑定真实源后只有 0 区,其余区必须回否定而不是拿镜像冒充活值。 */
static void read_frame(uint8_t *f, uint16_t sn, uint32_t ioa)
{
apdu(f, 11U);
f[6] = 202U; f[7] = 1U; f[8] = 6U; f[9] = 17U;
f[10] = 1U; f[11] = 0U;
f[12] = (uint8_t)(sn & 0xFFU); f[13] = (uint8_t)(sn >> 8);
f[14] = (uint8_t)(ioa & 0xFFU);
f[15] = (uint8_t)((ioa >> 8) & 0xFFU);
f[16] = (uint8_t)((ioa >> 16) & 0xFFU);
}
/* 发一帧、跑若干轮,返回发送前的输出游标;调用方据此只看自己的回复。
* 不返回"找到几条"是刻意的:历史帧还留在 fake.output 里,按区间切片才不串行。 */
static size_t feed(const uint8_t *frame, size_t length)
{
size_t start = fake.sent_bytes;
unsigned i;
push(frame, length);
for (i = 0U; i < 20U; ++i) { turn(); }
return start;
}
/* 从 start 起把指定类型的 I 帧回复全读回来。返回匹配条数(调用方按条数断言,
* 避免"找到一条就当全对")。 */
static unsigned replies(uint8_t type, size_t start, uint8_t *cot, uint8_t *pn, unsigned cap)
{
size_t at;
unsigned n = 0U;
for (at = start; at + 6U <= fake.sent_bytes; at += (size_t)fake.output[at + 1U] + 2U) {
CHECK(fake.output[at] == 0x68U);
if ((fake.output[at + 2U] & 1U) != 0U || at + 12U > fake.sent_bytes) { continue; }
if (fake.output[at + 6U] != type) { continue; }
CHECK(n < cap);
cot[n] = (uint8_t)(fake.output[at + 8U] & 0x3FU);
pn[n] = (uint8_t)((fake.output[at + 8U] & 0x40U) != 0U ? 1U : 0U);
++n;
}
return n;
}
/* 发一帧并读回该类型的全部回复。 */
static unsigned exchange(const uint8_t *frame, size_t length, uint8_t type,
uint8_t *cot, uint8_t *pn, unsigned cap)
{
return replies(type, feed(frame, length), cot, pn, cap);
}
/* READ_AREA 的回复是镜像 ASDU 改写:current/min/max 落在 ASDU 偏移 9/11/13,
* 即线上帧偏移 15/17/19(ASDU 从 +6 起),ASDU 长度固定 15。 */
static void check_area(uint8_t expect_max)
{
uint8_t f[16];
uint8_t cot[4], pn[4];
size_t start;
unsigned n;
area_frame(f);
start = feed(f, 15U);
n = replies(201U, start, cot, pn, 4U);
CHECK(n == 1U && cot[0] == 7U && pn[0] == 0U);
{
size_t at, hit = 0U;
for (at = start; at + 6U <= fake.sent_bytes; at += (size_t)fake.output[at + 1U] + 2U) {
if ((fake.output[at + 2U] & 1U) != 0U || fake.output[at + 6U] != 201U) { continue; }
CHECK(at + 21U <= fake.sent_bytes);
CHECK(fake.output[at + 1U] == 19U); /* 15 ASDU + 4 */
CHECK(fake.output[at + 15U] == 0U && fake.output[at + 16U] == 0U); /* current = 0 */
CHECK(fake.output[at + 17U] == 0U && fake.output[at + 18U] == 0U); /* minimum = 0 */
CHECK(fake.output[at + 19U] == expect_max && fake.output[at + 20U] == 0U);
hit = 1U;
}
CHECK(hit);
}
}
static float read_back_8842(void)
{
iec104_source_value_t out;
float value;
CHECK(iec104_source_remote_read(0U, 0x8842U, &out));
CHECK(out.tag == 38U && out.length == 4U);
memcpy(&value, out.bytes, 4U);
return value;
}
int main(void)
{
iec104_source_bindings_t bind = {0};
iec104_source_stats_t stats;
uint8_t frame[24], cot[8], pn[8];
unsigned i, n;
float before;
prot_set_init();
CHECK(iec104_core_start(&config) == 0);
fake.accept_pending = 1U; turn();
push(start_act, sizeof(start_act));
for (i = 0U; i < 8U; ++i) { turn(); }
iec104_core_get_status(&status);
CHECK(status.connected && status.active && status.connections == 1U);
/* 未绑定模拟面:仍报 0..4,模拟器与主机夹具靠它演练分区语义。 */
check_area(4U);
/* 未绑定面走 SN=1 的分段项:协议照旧回肯定(模拟器要这套语义),但
* parameter_apply 一次没被调用 —— 此时"提交计数"必须老老实实是 0。
* 这是计数语义唯一可观测的路径:绑定后 n==0 已被入口守卫挡死。 */
preset_frame(frame, 1U, 0x8842U, 50.0f);
n = exchange(frame, 24U, 203U, cot, pn, 8U);
CHECK(n == 1U && cot[0] == 7U && pn[0] == 0U);
solidify_frame(frame, 1U);
n = exchange(frame, 15U, 203U, cot, pn, 8U);
CHECK(n == 1U && cot[0] == 7U && pn[0] == 0U);
CHECK(apply_calls == 0U && validate_calls == 0U);
iec104_source_stats(&stats);
CHECK(stats.parameter_commits == 0U); /* 没调过 apply 就不许记账 */
bind.parameter_read = parameter_read;
bind.parameter_apply = parameter_apply;
iec104_source_bind(&bind);
before = prot_set_get_f(PS_OC1_CUR);
CHECK(before > 9.9f && before < 10.1f);
/* 绑定后只报区域 0:报一个写不进去的区号等于邀请主站去撞墙。 */
check_area(0U);
/* 先走通 SN=0 的真链路,再做 SN!=0 的拒绝。
* 顺序不能反:一次被否定的 203 会在模块里建立恢复屏障(同归属直到
* CANCEL/DISCARD 前不再受理新批次),把它放前面会把后面的合法批次一起拦住
* ——那是协议行为,不是本夹具要测的东西。 */
preset_frame(frame, 0U, 0x8842U, 50.0f);
n = exchange(frame, 24U, 203U, cot, pn, 8U);
CHECK(n == 1U && cot[0] == 7U && pn[0] == 0U);
CHECK(apply_calls == 0U);
CHECK(prot_set_get_f(PS_OC1_CUR) == before);
/* 固化:预检 + 提交各一次,prot_set 必须真的变成 50.0 A。 */
solidify_frame(frame, 0U);
n = exchange(frame, 15U, 203U, cot, pn, 8U);
CHECK(n == 1U && cot[0] == 7U && pn[0] == 0U);
CHECK(validate_calls == 1U && apply_calls == 1U);
CHECK(prot_set_get_f(PS_OC1_CUR) > 49.9f && prot_set_get_f(PS_OC1_CUR) < 50.1f);
/* 读回走真实源:50.0 而不是 profile 里的出厂字面量 1.2。 */
CHECK(read_back_8842() > 49.9f && read_back_8842() < 50.1f);
/* 202 读 SN=1:绑定后没有第二套值区,必须回否定帧而不是拿镜像冒充活值。 */
read_frame(frame, 1U, 0x8842U);
n = exchange(frame, 17U, 202U, cot, pn, 8U);
CHECK(n >= 1U && pn[0] == 1U);
/* 202 读 SN=0:真链路,回肯定且元素是 50.0。 */
read_frame(frame, 0U, 0x8842U);
n = exchange(frame, 17U, 202U, cot, pn, 8U);
CHECK(n >= 1U && pn[0] == 0U);
/* 提交计数只在真的调过 apply 时加一。 */
iec104_source_stats(&stats);
CHECK(stats.parameter_commits == 1U);
/* SN=1 的预置必须被否定确认,prot_set 一字未动,apply 一次都没进。 */
preset_frame(frame, 1U, 0x8842U, 30.0f);
n = exchange(frame, 24U, 203U, cot, pn, 8U);
CHECK(n == 1U && cot[0] == 7U && pn[0] == 1U);
CHECK(validate_calls == 1U && apply_calls == 1U);
CHECK(prot_set_get_f(PS_OC1_CUR) > 49.9f && prot_set_get_f(PS_OC1_CUR) < 50.1f);
iec104_source_stats(&stats);
CHECK(stats.parameter_commits == 1U);
/* 收尾:把恢复屏障撤掉(合法 CANCEL),证明拒绝之后服务仍是活的。 */
cancel_frame(frame, 1U);
(void)exchange(frame, 15U, 203U, cot, pn, 8U);
CHECK(iec104_core_stop() == 0);
puts("preset/solidify -> prot_set chain, SN!=0 refusal, honest read-back: PASS");
return 0;
}
+5 -3
View File
@@ -61,12 +61,12 @@ def main():
include = [vendor / "104", vendor / "104/business", vendor / "common", vendor / "platform", vendor / "examples", original]
names = ("iec104_response_transport_test", "iec104_ack_tracking_test", "iec104_idle_transport_test", "iec104_strict_priority_transport_test", "iec104_tcp_event_ring_test", "iec104_tcp_scheduler_test", "iec104_remote_parameter_test")
results = []
for name in names + ("source_binding_test", "vendor_boundary_test", "core_lifecycle_test"):
for name in names + ("source_binding_test", "vendor_boundary_test", "core_lifecycle_test", "preset_to_prot_set_test"):
if args.only and args.only not in name:
continue
target = output / name
target.mkdir(exist_ok=True)
fixture = Path(__file__).parent / (name + ".c") if name in ("source_binding_test", "vendor_boundary_test", "core_lifecycle_test") else original / (name + ".c")
fixture = Path(__file__).parent / (name + ".c") if name in ("source_binding_test", "vendor_boundary_test", "core_lifecycle_test", "preset_to_prot_set_test") else original / (name + ".c")
adaptation = None
if name == "iec104_idle_transport_test":
text = fixture.read_text(encoding="utf-8-sig")
@@ -81,10 +81,12 @@ def main():
extra = [ROOT / "App/iec60870/104/iec104_source.c", ROOT / "App/iec60870/104/iec104_dtu_table.c", vendor / "104/IEC104_Net_Windows.c", vendor / "104/IEC104_TcpServer.c"]
if name == "core_lifecycle_test":
extra = [ROOT / "App/iec60870/104/iec104_core.c", ROOT / "App/iec60870/104/iec104_source.c", ROOT / "App/iec60870/104/iec104_dtu_table.c"]
if name == "preset_to_prot_set_test":
extra = [ROOT / "App/iec60870/104/iec104_core.c", ROOT / "App/iec60870/104/iec104_source.c", ROOT / "App/iec60870/104/iec104_dtu_table.c", ROOT / "App/algo/prot_set.c"]
flags = ["/nologo", "/std:c11", "/O2", "/W3", "/WX", "/utf-8", "/D_CRT_SECURE_NO_WARNINGS"]
if name == "iec104_remote_parameter_test":
flags += ["/DIEC104_REMOTE_PARAMETER_TEST_HOOKS", "/DIEC104_TCP_HIGH_CAPACITY=251"]
command = [cl] + flags + ["/I" + str(p) for p in include] + ["/I" + str(ROOT / "App/iec60870/104")] + [str(fixture)] + [str(p) for p in sources + extra] + ["/Fe:" + str(target / (name + ".exe"))] + (["/link", "ws2_32.lib"] if extra else [])
command = [cl] + flags + ["/I" + str(p) for p in include] + ["/I" + str(ROOT / "App/iec60870/104")] + ["/I" + str(ROOT / "App/algo")] + [str(fixture)] + [str(p) for p in sources + extra] + ["/Fe:" + str(target / (name + ".exe"))] + (["/link", "ws2_32.lib"] if extra else [])
build = subprocess.run(command, cwd=target, env=env, capture_output=True)
(target / "build.log").write_text(decode(build.stdout) + decode(build.stderr), encoding="utf-8")
row = {"name": name, "build_rc": build.returncode, "command": command, "fixture_sha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "adaptation": adaptation, "extra_sources_sha256": {str(p.relative_to(ROOT)): hashlib.sha256(p.read_bytes()).hexdigest() for p in extra}}
+6 -18
View File
@@ -12,7 +12,7 @@
* TC-PROTSET-004 load_raw:合法整表装载并封存;含越界项 → 整表不装载 +
* bad_mask 指认越界项(定值一致性:宁可全旧不可半新)
* TC-PROTSET-005 Q10 往返精度(±1 LSB)
* TC-PROTSET-006 元数据表自检:min<=max、投退项 0..1、非零通讯地址不重复
* TC-PROTSET-006 元数据表自检:min<=max、投退项 0..1
* TC-PROTSET-007 越界编号守卫(get/set)
* TC-PROTSET-008 全局软压板 PS_GLOBAL_EN(B7):默认投入、set_sealed 原子写
* 不破坏 selfcheck、脏标志三件套(peek/take/mark)
@@ -137,8 +137,8 @@ static void tc_q10_roundtrip(void) {
/* TC-PROTSET-006 */
static void tc_meta_sanity(void) {
uint32_t i, j;
int ok_range = 1, ok_ctl = 1, ok_addr = 1;
uint32_t i;
int ok_range = 1, ok_ctl = 1;
for (i = 0u; i < (uint32_t)PS_ID_COUNT; i++) {
const prot_set_meta_t *m = &g_prot_set_meta[i];
@@ -146,14 +146,9 @@ static void tc_meta_sanity(void) {
if ((m->def < m->min) || (m->def > m->max)) { ok_range = 0; }
if ((m->is_ctl != 0u) &&
((m->min != 0) || (m->max != PROT_SET_Q10(1)))) { ok_ctl = 0; }
if (m->comm_addr == 0u) { continue; }
for (j = i + 1u; j < (uint32_t)PS_ID_COUNT; j++) {
if (g_prot_set_meta[j].comm_addr == m->comm_addr) { ok_addr = 0; }
}
}
CHECK(ok_range, "TC-PROTSET-006 meta: min<=def<=max for all items");
CHECK(ok_ctl, "TC-PROTSET-006 meta: ctl items are 0..1");
CHECK(ok_addr, "TC-PROTSET-006 meta: comm addresses unique");
CHECK((uint32_t)PS_ID_COUNT <= 64u, "TC-PROTSET-006 item count fits 64-bit bad_mask (B8: 40)");
}
@@ -271,16 +266,9 @@ static void tc_of_uf_meta(void) {
CHECK((uint32_t)PROT_SET_BLOB_SZ == (PROT_SET_BLOB_HDR_SZ + 4u * 40u + 8u),
"TC-PROTSET-011 blob size = hdr + 4*40 + tail");
/* 地址:参考逐项地址不在本仓库 -> 8 项全部本地项(comm_addr=0,104 不可寻址) */
CHECK((g_prot_set_meta[PS_OF_EN].comm_addr == 0u)
&& (g_prot_set_meta[PS_OF_HZ].comm_addr == 0u)
&& (g_prot_set_meta[PS_OF_DLY].comm_addr == 0u)
&& (g_prot_set_meta[PS_UF_EN].comm_addr == 0u)
&& (g_prot_set_meta[PS_UF_HZ].comm_addr == 0u)
&& (g_prot_set_meta[PS_UF_DLY].comm_addr == 0u)
&& (g_prot_set_meta[PS_RET_OF].comm_addr == 0u)
&& (g_prot_set_meta[PS_RET_UF].comm_addr == 0u),
"TC-PROTSET-011 OF/UF items all local (comm_addr=0, pending reference table)");
/* 本地项判定已由 104 侧桥表 iec104_dtu_protection_mapping() 承担:
* OF/UF 八项的地址不在桥表内 → 104 C_RD/C_SE 不可寻址。本模块不再有
* 地址概念,故此处不再断言(且本编译单元不链 iec104_dtu_table.c)。 */
/* 投退 = ctl 项(0/1),其余 = 模拟量 Q10 */
CHECK((g_prot_set_meta[PS_OF_EN].is_ctl == 1u) && (g_prot_set_meta[PS_UF_EN].is_ctl == 1u)