perf(iec104): 参数区按 17 项真实消费者收窄并接上真实定值模型
104 协议侧参数通道此前镜像了厂商点表的全部 430 条参数(697 槽), 但其中 413 条在本设备上没有任何消费者——104 与设备侧真实定值模型 prot_set 之间零调用,主站改定值只落在无人读的 RAM 镜像里,保护功能 毫无感知。本次按"严格按消费者收窄"口径收口: 可见性以 iec104_dtu_protection_mapping() 语义桥表为唯一判据,只放行 三段过流投退/定值/延时(9 项)、低压与过压定值/延时(4 项)、PT 与 CT 一次/二次额定(4 项)。其余参数在位表枚举层即不可见,主站读取 得到 COT=47 + P/N=1 的显式否定确认,不静默丢弃。values[697]→values[53]、 staged[264]→staged[17],并删除生成式 iec104_source_ranks.h。 桥表接真实源:iec104_serv 的 parameter_read/apply 从 NULL 改为直读 prot_set 与整批原子提交,Q10 量化后一次事务落地,持久化仍由 defaultTask 的脏标志闭环负责。 prot_set 因此出现两个运行时写者(netTask 的 104 与 uiTask 的本地整 定),原"写者靠启动时序串行"的约定失效。加入写事务互斥与 seqlock 序号:四个写入口全部进锁,校验与提前返回一律在 enter 之前;序号卡 奇数连续 8 拍即判保护闭锁,避免自检被永久跳过而静默失去防篡改能力。 锁的安装在 defaultTask 的存储 bring-up 阶段,不在 app_main_init—— 后者早于 osKernelInitialize,内核启动前禁止任何 RTOS 创建类 API。 实测:RW_IRAM1 117,304→113,720 B(−3,584 B,89.50%→86.76%); ER_IROM1 413,392→411,668 B(−1,724 B);iec104_source.o 5,656→2,056 B; prot_set.o 344→352 B(+8 B,写事务序号与锁句柄)。Keil 构建 0 错误 0 警告;主机侧 prot_set 175/175、iec104_dtu 7/7;真实 TCP 验收 13/13;暂存口径门禁 18 项全通过。 已知边界:模拟器不链接 iec104_serv.c,TCP 验收不覆盖 prot_set 绑定, 板端需实机确认主站写入能反映到本地定值页;17 项中 15 项的出厂默认 值与点表字面量不同,主站读到的是真实模型的值;绑定真实源后定值区 切换一律拒绝(单套活跃值无原子整区事务)。
This commit is contained in:
@@ -22,7 +22,7 @@ static bool parameter_apply(void *ctx, const iec104_source_change_t *v, size_t n
|
||||
{
|
||||
(void)ctx; (void)v; (void)n; (void)validate; ++apply_count; return true;
|
||||
}
|
||||
static void exchange(const uint8_t *frame, size_t length, uint8_t expected_cot)
|
||||
static void exchange(const uint8_t *frame, size_t length, uint8_t expected_type, uint8_t expected_cot)
|
||||
{
|
||||
size_t start = fake.sent_bytes, at;
|
||||
unsigned i; bool found = false;
|
||||
@@ -30,7 +30,7 @@ static void exchange(const uint8_t *frame, size_t length, uint8_t expected_cot)
|
||||
for (i = 0U; i < 20U; ++i) { turn(); }
|
||||
for (at = start; at + 6U <= fake.sent_bytes; at += (size_t)fake.output[at + 1U] + 2U) {
|
||||
CHECK(fake.output[at] == 0x68U);
|
||||
if (at + 12U <= fake.sent_bytes && !(fake.output[at + 2U] & 1U) && fake.output[at + 6U] == 203U) {
|
||||
if (at + 12U <= fake.sent_bytes && !(fake.output[at + 2U] & 1U) && fake.output[at + 6U] == expected_type) {
|
||||
CHECK(fake.output[at + 8U] == expected_cot); found = true;
|
||||
}
|
||||
}
|
||||
@@ -39,16 +39,23 @@ static void exchange(const uint8_t *frame, size_t length, uint8_t expected_cot)
|
||||
static void borrowed_failure(void)
|
||||
{
|
||||
iec104_source_bindings_t bind = {0};
|
||||
iec104_source_value_t before, after;
|
||||
static const uint8_t preset[] = {0x68,19,0,0,0,0,203,1,6,17,1,0,0,0,128,0x20,0x88,0,1,1,0};
|
||||
size_t i; uint16_t area0 = 0U, area1 = 0U;
|
||||
/* While real bindings are installed, the area-0 low<=high cross-check reads
|
||||
* semantic id 17 (PS_OV_VOL) through parameter_read. The fake fails id 17,
|
||||
* so a staged 0x8027 preset must be refused at solidify with no apply. */
|
||||
static const uint8_t preset[] = {0x68,22,0,0,0,0,203,1,6,17,1,0,0,0,128,0x27,0x80,0,38,4,0,0,200,0x42};
|
||||
static const uint8_t solidify[] = {0x68,13,2,0,0,0,203,0,6,17,1,0,0,0,0};
|
||||
bind.parameter_read = parameter_read; bind.parameter_apply = parameter_apply;
|
||||
iec104_source_bind(&bind);
|
||||
CHECK(iec104_source_remote_read(0U, 0x8820U, &before));
|
||||
exchange(preset, sizeof(preset), 7U);
|
||||
exchange(solidify, sizeof(solidify), 0x47U);
|
||||
CHECK(iec104_source_remote_read(0U, 0x8820U, &after));
|
||||
CHECK(before.bytes[0] == after.bytes[0] && apply_count == 0U);
|
||||
exchange(preset, sizeof(preset), 203U, 7U);
|
||||
exchange(solidify, sizeof(solidify), 203U, 0x47U);
|
||||
CHECK(apply_count == 0U);
|
||||
for (i = 0U; i < IEC104_DTU_PARAMETER_COUNT; ++i) {
|
||||
if (iec104_dtu_parameter_visible(i, 0U)) { ++area0; }
|
||||
if (iec104_dtu_parameter_visible(i, 1U)) { ++area1; }
|
||||
}
|
||||
CHECK(area0 == IEC104_DTU_CONSUMER_COUNT);
|
||||
CHECK(area1 == IEC104_DTU_SCOPED_CONSUMER_COUNT);
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,15 @@ def reference():
|
||||
parameters[int(ioa, 16)] = (int(tag), value.strip('"'))
|
||||
assert [len(tables[x]) for x in tables] == [59, 30, 4, 19, 430]
|
||||
assert len(parameters) == 345
|
||||
# Accepted consumer subset. This list is the acceptance specification and
|
||||
# must match the semantic bridge map in iec104_dtu_table.c item for item.
|
||||
# Every other configured profile row must be refused by the protocol layer.
|
||||
consumer_ioas = frozenset((
|
||||
0x8841, 0x8842, 0x8843, 0x8845, 0x8846, 0x8847, 0x8849, 0x884A, 0x884B,
|
||||
0x8027, 0x8028, 0x8029, 0x802A, 0x8024, 0x8025, 0x8040, 0x8041,
|
||||
))
|
||||
parameters = {ioa: row for ioa, row in parameters.items() if ioa in consumer_ioas}
|
||||
assert len(parameters) == 17
|
||||
assert set(tables["signals"]) == set(range(1, 0x42)) - set(range(0x2C, 0x32))
|
||||
assert set(tables["measurements"]) == set(range(0x4001, 0x401F))
|
||||
gi = {ioa: 1 for ioa in tables["signals"]}
|
||||
|
||||
@@ -186,9 +186,9 @@ class Acceptance:
|
||||
assert self.client.response(201, 7)[9:11] == b"\x00\x00"
|
||||
|
||||
def test_typed_preset_commit_cancel_readback(self):
|
||||
addresses = (0x8820, 0x8823, 0x882D, 0x802E)
|
||||
addresses = (0x8841, 0x8842, 0x8843, 0x8027)
|
||||
before = self.remote_read(addresses)
|
||||
change = [(0x8820, 1, 0), (0x8823, 38, 8.25), (0x882D, 45, 2), (0x802E, 35, 16777217)]
|
||||
change = [(0x8841, 1, 1), (0x8842, 38, 2.5), (0x8843, 38, 0.75), (0x8027, 38, 90.0)]
|
||||
original = [(ioa, before[ioa]["tag"], before[ioa]["value"]) for ioa in addresses]
|
||||
try:
|
||||
self.preset(change)
|
||||
@@ -200,6 +200,7 @@ class Acceptance:
|
||||
assert self.remote_read(addresses) == after, "TCP reconnect lost committed RAM values"
|
||||
self.preset(original)
|
||||
self.connect()
|
||||
self.remote_read(addresses)
|
||||
self.finish(pn=True)
|
||||
assert self.remote_read(addresses) == after, "disconnected stage became active"
|
||||
self.preset(original)
|
||||
@@ -214,10 +215,10 @@ class Acceptance:
|
||||
def test_unknown_and_bad_typed_requests(self):
|
||||
self.client.request(asdu(102, u24(0xFFFFFF), cot=5))
|
||||
self.client.response(102, 47, True)
|
||||
for ioa in (0xFFFFFF, 0x9601):
|
||||
for ioa in (0xFFFFFF, 0x9601, 0x8820, 0x8823):
|
||||
self.client.request(asdu(202, b"\x00\x00" + u24(ioa)))
|
||||
self.client.response(202, 47, True)
|
||||
for value in ([(0x8820, 1, 2)], [(0x8823, 45, 8)], [(0x8823, 38, float("nan"))]):
|
||||
for value in ([(0x8841, 1, 2)], [(0x8842, 45, 8)], [(0x8842, 38, float("nan"))]):
|
||||
self.preset(value, pn=True)
|
||||
self.finish(cancel=True)
|
||||
|
||||
|
||||
@@ -21,10 +21,11 @@ class WireOracleTests(unittest.TestCase):
|
||||
self.assertEqual(len(ref["gi"]), 225)
|
||||
self.assertEqual(len(ref["read"]), 121)
|
||||
self.assertEqual(len(ref["counters"]), 8)
|
||||
self.assertEqual(len(ref["remote"]), 345)
|
||||
self.assertEqual(len(ref["remote"]), 17)
|
||||
self.assertEqual(len(ref["diagnostic_aliases_pending_scope"]), 150)
|
||||
self.assertNotIn(0x9601, ref["remote"])
|
||||
self.assertEqual(ref["remote"][0x8858], (38, "25"))
|
||||
self.assertNotIn(0x8858, ref["remote"])
|
||||
self.assertEqual(ref["remote"][0x8842], (38, "1.2"))
|
||||
|
||||
def test_pn_zero_positive_and_one_negative(self):
|
||||
self.assertFalse(header(bytes.fromhex("64010711010000000014"))["pn"])
|
||||
|
||||
Reference in New Issue
Block a user