- config.yaml: 恢复现场 IP(10.50.253.165/.181/.182)、s331_2 端口 502 - config.yaml: S331 全部 32 位量 word_order 改 CDAB,瞬时流量 scale=60 (m3/min -> m3/h) - config.yaml: 11# 电表功率/电能类型改 int32;第二路 RTU 从站 slave_id 改 10 - poller.py: 过滤 S331 无数据哨兵 -9999 与非有限值,避免污染周期基准 - rtu.py: 新增 SafeRTUFramer 支持多点半总线,忽略其它从站请求 - 新增 config.debug.yaml、README.md、wheelhouse 离线依赖 - tests: 适配新配置(ttyS7/address_offset);新增 pytest.ini 限定 testpaths
72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
"""V3.3 精确点表对齐校验脚本"""
|
|
import sys
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
|
|
from gateway.config import load_config
|
|
|
|
cfg = load_config(Path("config/config.yaml"))
|
|
|
|
# V3.3 第 5 节期望值
|
|
EXPECT = {
|
|
"s331_1": {"slave_id": 10, "host": "10.50.253.181", "compressors": {
|
|
3: (112, 114), 4: (122, 124), 5: (132, 134), 11: (142, 144)}},
|
|
"s331_2": {"slave_id": 20, "host": "10.50.253.182", "compressors": {
|
|
6: (118, 120), 7: (128, 130), 8: (138, 140), 9: (148, 150), 10: (158, 160)}},
|
|
}
|
|
|
|
# V3.3 第 4 节蘑菇云电表功率地址
|
|
METER_EXP = {3: 149, 4: 157, 5: 165, 6: 173, 7: 181, 8: 189, 9: 213, 10: 205, 11: 197}
|
|
|
|
errors = []
|
|
|
|
# 1) S331 TCP Server 参数
|
|
for dev_name, exp in EXPECT.items():
|
|
dev = cfg.devices[dev_name]
|
|
if dev.slave_id != exp["slave_id"]:
|
|
errors.append(f"{dev_name} slave_id {dev.slave_id} != {exp['slave_id']}")
|
|
if dev.host != exp["host"]:
|
|
errors.append(f"{dev_name} host {dev.host} != {exp['host']}")
|
|
|
|
# 2) S331 气量地址 + 类型
|
|
for c in cfg.compressors:
|
|
exp = EXPECT[c.s331]["compressors"].get(c.id)
|
|
if exp:
|
|
got = (c.flow_instant.address, c.flow_total.address)
|
|
if got != exp:
|
|
errors.append(f"{c.id}# flow_addr {got} != {exp}")
|
|
if c.flow_total.type != "uint32":
|
|
errors.append(f"{c.id}# flow_total type {c.flow_total.type} != uint32")
|
|
if c.flow_instant.type != "float32":
|
|
errors.append(f"{c.id}# flow_instant type {c.flow_instant.type} != float32")
|
|
|
|
# 3) 蘑菇云电表功率地址
|
|
for c in cfg.compressors:
|
|
if c.power_instant.address != METER_EXP[c.id]:
|
|
errors.append(f"{c.id}# power_addr {c.power_instant.address} != {METER_EXP[c.id]}")
|
|
|
|
if errors:
|
|
print("V3.3 ALIGNMENT FAILED:")
|
|
for e in errors:
|
|
print(f" - {e}")
|
|
sys.exit(1)
|
|
|
|
print("ALL V3.3 CHECKS PASS")
|
|
print()
|
|
print("=== Final config summary ===")
|
|
print(f"mogo_meter : {cfg.devices['mogo_meter'].host}:{cfg.devices['mogo_meter'].port} slave={cfg.devices['mogo_meter'].slave_id}")
|
|
for name in ("s331_1", "s331_2"):
|
|
dev = cfg.devices[name]
|
|
print(f"{name}: {dev.host}:{dev.port} slave={dev.slave_id}")
|
|
print()
|
|
for c in cfg.compressors:
|
|
print(f" {c.id:>2}# s331={c.s331} idx={c.register_index} "
|
|
f"flow_inst={c.flow_instant.address}({c.flow_instant.type}) "
|
|
f"flow_tot={c.flow_total.address}({c.flow_total.type}) "
|
|
f"pow={c.power_instant.address}({c.power_instant.type}) "
|
|
f"energy={c.energy_total.address}({c.energy_total.type})")
|
|
print()
|
|
print("RTU slaves:")
|
|
for s in cfg.slaves:
|
|
print(f" {s.name}: {s.port} slave_id={s.slave_id}")
|