feat(iec104): 在模拟器跑通共享协议核心与标准DTU点表

引入成熟 IEC 60870-5-104 子站的只读子集(App/protocol/iec60870,28 个源文件
按原字节复制,UPSTREAM.sha256 记录来源,兼容补丁保留全部断言与容量),在其上
装配单属主共享核心(Start/Poll/Stop/Get_Status),并把标准 DTU 演示点表全量
接入为唯一真源。

- iec104_core:threadless 推进,poll 零等待,通知/交互/COV 扫描全部有界;
  生命周期区分失败启动待重试、重复启动拒绝、断线保固化 RAM。
- iec104_dtu_table / iec104_source:标准 DTU 全点表注册,无数据源的点读 0,
  遥控只做模拟状态可读回,不触碰实际出口。
- iec104_sim:仅窗口与独立服务模式起真实 TCP,无头黄金模式保持确定性假统计。
- test/host/iec104_dtu:独立真实 TCP 11 项、传输层 10 项、生命周期与借用负例。

验证:lvgl_sim 真实 TCP 11/11、传输 10/10,UI 像素回归未回退;AC5 单 TU
编译 0 错误 0 诊断。板端尚未切换:完整库闭包 RAM 超 92% 门禁净增预算 25730B,
结论为停止转实施,记录在 IEC104_MCU最小可行性验证.md。旧实现与 board 服务
保持原样,未提交 MDK 工程改动,未烧板。
This commit is contained in:
2026-11-17 20:48:00 +08:00
parent f84855a559
commit 2e9272cc8a
117 changed files with 54273 additions and 10 deletions
+57
View File
@@ -0,0 +1,57 @@
"""Test the independent acceptance oracle/decoder; not product acceptance."""
import struct
import unittest
from oracle import reference
from wire import asdu, header, objects, remote_objects, tlv
class WireOracleTests(unittest.TestCase):
def test_reference_has_independently_derived_sets(self):
ref = reference()
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["diagnostic_aliases_pending_scope"]), 150)
self.assertNotIn(0x9601, ref["remote"])
self.assertEqual(ref["remote"][0x8858], (38, "25"))
def test_pn_zero_positive_and_one_negative(self):
self.assertFalse(header(bytes.fromhex("64010711010000000014"))["pn"])
self.assertTrue(header(bytes.fromhex("64014711010000000014"))["pn"])
self.assertEqual(header(bytes.fromhex("64014711010000000014"))["cot"], 7)
def test_float_objects_nonsequential_and_sequential(self):
rows = objects(bytes.fromhex("0d02141101000140000000c03f00024000000020c000"))
self.assertEqual([(r["ioa"], r["value"]) for r in rows], [(0x4001, 1.5), (0x4002, -2.5)])
rows = objects(bytes.fromhex("0d82141101000140000000c03f00000020c000"))
self.assertEqual([(r["ioa"], r["value"]) for r in rows], [(0x4001, 1.5), (0x4002, -2.5)])
def test_truncation_and_trailing_bytes_rejected(self):
valid = bytes.fromhex("01011411010001000000")
for bad in (valid[:-1], valid + b"\x00"):
with self.assertRaises(AssertionError):
objects(bad)
def test_remote_type_tags_decode_independent_vector(self):
vector = bytes.fromhex("ca030711010000000020880001010123880026040000e0402d88002d020100")
rows = remote_objects(vector)
self.assertEqual([(r["ioa"], r["tag"], r["value"]) for r in rows], [(0x8820, 1, 1), (0x8823, 38, 7.0), (0x882D, 45, 1)])
self.assertEqual(tlv(0x8823, 38, 7.0), bytes.fromhex("23880026040000e040"))
def test_remote_malformed_tlv_length_rejected(self):
with self.assertRaises(AssertionError):
remote_objects(bytes.fromhex("ca01071101000000002388002603000000"))
def test_maximum_apdu_is_255_not_257(self):
payload = bytes.fromhex("000080ffffff0000") + bytes(235)
data = asdu(203, payload)
self.assertEqual(len(data), 249)
frame = bytes((0x68, len(data) + 4)) + struct.pack("<HH", 0, 0) + data
self.assertEqual(len(frame), 255)
self.assertEqual(frame[1], 253)
if __name__ == "__main__":
unittest.main(verbosity=2)