Files
STM32F4-Base/test/host/cal/cal_write.py
T
wandering1 685a366890 refactor(test): 把 test/host 顶层 25 个台架脚本按域收进 bench/
原来 test/host 一层混了三类东西:51 个主机侧单测模块目录、25 个台架驱动
与探针、若干专用目录。台架脚本平铺在顶层,与单测目录并列,看不出哪个是
「连板跑一次的」,也看不出加新脚本该往哪放。

现在按被验对象分域归档,单测模块目录一律不动(22 根 pre-commit 钩子逐个
点名它们,50 个运行器按固定层数推仓库根):

- bench/bench_defaults.py 台架连接默认值单一真源
- bench/ftp/ (10) FTP 功能、速率、鉴权、中止、完整性、背靠背复现
- bench/net/ (9) CH395F socket、keepalive 判死、挂机、复连压力、PASV、
  UDP 队列、链路时延对端
- bench/iec104/ (2) 主站客户端与它的离线样帧自检
- bench/wave/ (1) 录波段文件 PC 侧解码
- bench/screenlink/ (2) 屏板链路顶替与拉帧压测

顶层条目 78 -> 53。逐脚本作用、运行前置与「加新脚本往哪放」写在新建的
test/host/bench/README.md;test/host/README.md 增目录地图表,把原平铺的
网络/FTP 两节压成指针。

配套修正(移动后不修就会坏):
- 17 个脚本加上 bench/ 到 sys.path 的 bootstrap(sys.path[0] 是脚本自身
  目录,不补就 import bench_defaults 失败)
- cal/cal_write.py 本来就坏的(只插 cal/ 到自己 sys.path,import
  bench_defaults 直接 ModuleNotFoundError),补两段路径后可用
- e6_soak 与 wave_read 用 dirname 固定层数推仓库根,多两层后分别指向
  test/test 与 test/ci-artifacts(后者静默写错目录、不报错),层数已改对
- scripts/board_ui_nav.py 与 MDK-ARM 两个探针的 bench_defaults 搜索路径

清理与标注:删掉 test/host/iec104/(旧自研协议层单测退役后只剩一个零引用
的 stub 桩头);文档里对 test/host/iec104 与 iec104_serv 的引用加上「已
删除/已不存在 2026-11-18」状态词。冻结历史证据(带日期戳的台架日志)与
编号别名登记表里的旧路径按原样保留。
2026-11-18 12:46:03 +08:00

100 lines
4.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""两点标定写入器:C_SE_NC_1 两段写下发 r/b,C_RD 读回复核。
复用台架已验收主站库 test/host/bench/iec104/iec104_master.py(不重写协议层)。
地址(App/algo/run_par.c run_par_104_write):r = 0x8050+slot,
b = 0x8048+slot;slot UA0/UN3/IA4。执行卡:
docs/测试说明/专项验证/ADC多点标定执行流程.md §4。
用法:
python test/host/cal/cal_write.py --r 0x8050=995.99 --b 0x8048=-1 \
--read 0x8050,0x8048 --expect 995.99,-1
python test/host/cal/cal_write.py --read 0x8050,0x8054 --expect 995.99,29.52
写入顺序刻意**先 r 后 b**:b 走 adc_cal_set() 置 VALID 位,而 VALID 要求
r 已在带——先让 r 就位,语义干净。--b 必须是整数码值。
PN(否定确认)= 执行段拒绝:看串口 `[ERR] set ch=... rejected` 行。
输出纯 ASCII,可直接重定向归档为台架证据;exit 0 全过 / 1 有失败 / 2 连接或协议错误。
"""
import argparse
import os
import sys
# 依赖已随域归档:bench_defaults 在 test/host/bench/,iec104_master 在
# test/host/bench/iec104/。两者都要补进 sys.path(Python 默认只加脚本目录)。
_BENCH_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
os.pardir, "bench")
for _p in (os.path.abspath(_BENCH_DIR),
os.path.abspath(os.path.join(_BENCH_DIR, "iec104"))):
if _p not in sys.path:
sys.path.insert(0, _p)
import bench_defaults # noqa: E402
import iec104_master as m104 # noqa: E402
def parse_pair(text):
addr_s, val_s = text.split("=", 1)
return int(addr_s, 0), float(val_s)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--ip", default=bench_defaults.DEVICE_IP)
ap.add_argument("--port", type=int, default=2404)
ap.add_argument("--r", action="append", default=[],
help="0xADDR=FLOAT ratio write (repeatable, issued first)")
ap.add_argument("--b", action="append", default=[],
help="0xADDR=INT zero-code write (repeatable, sets VALID)")
ap.add_argument("--read", default="",
help="comma-separated IOA list, C_RD readback")
ap.add_argument("--expect", default="",
help="comma-separated expected values, same order as --read")
a = ap.parse_args()
reads = [x.strip() for x in a.read.split(",") if x.strip()]
expects = [float(x) for x in a.expect.split(",")] if a.expect else []
if not a.r and not a.b and not reads:
ap.error("need at least one --r / --b / --read")
ck = m104.Checks()
try:
m = m104.Master(a.ip, a.port)
except Exception as exc:
print("CONNECT FAIL: %r" % (exc,))
return 2
try:
m._send(m104.u_frame(m104.U_STARTDT_ACT), "U STARTDT act")
ck.add("startdt_con", m.wait_event(
lambda e: e[0] == "startdt_con", 5.0) is not None)
for text in a.r: # 1) ratio first
addr, val = parse_pair(text)
m104.se_write(m, ck, addr, val, "r_%04X" % addr)
for text in a.b: # 2) zero + VALID
addr, val = parse_pair(text)
if abs(val - round(val)) > 1e-6:
print("WARN b=%s not an integer code, truncated to %.0f"
% (text, round(val)))
val = float(round(val))
m104.se_write(m, ck, addr, val, "b_%04X" % addr)
for i, addr_s in enumerate(reads):
want = expects[i] if i < len(expects) else 0.0
m104.rd_set(m, ck, int(addr_s, 0), want, "rd_%s" % addr_s)
finally:
m.close()
bad = [n for n, ok, _ in ck.items if not ok]
print("SUMMARY %s total=%d fail=%d" %
("PASS" if not bad else "FAIL", len(ck.items), len(bad)))
if bad:
print("FAILED: %s" % ", ".join(bad))
return 0 if not bad else 1
if __name__ == "__main__":
sys.exit(main())