refactor(motor+hygiene): P1 拆分 main.js 并收敛总线/toast + P3 卫生清理
R4: main.js 4647→1894 行,外提 scope/ota/seq/conn-poll R5: waitVersion/queryNodeIdParam 下沉 transport R6: ecat-bus.js 单点 bootstrap;repairEcatDc 缺 DC 字段不 motor/start R7: toast-stack + utils 统一 DOM/quiet 助手 R12–R16: scripts 精简至正式清单、报告进 docs/reports、lab dump 清理、 README/CSS 所有权说明、网卡默认 I210 单点
This commit is contained in:
@@ -160,11 +160,14 @@ export async function runEcatBootstrap(opts) {
|
||||
|
||||
/**
|
||||
* DC/周期自愈:被配错(free-run 或 ≥1ms)时拉回 250µs。
|
||||
* health 未回报 dc/period 字段时**不动总线**(healthCheck 契约:只读)。
|
||||
* @returns {Promise<object|null>} null=无需修复
|
||||
*/
|
||||
export async function repairEcatDc(ecatPost) {
|
||||
var h = await ecatPost("native/health", {}, 2000).catch(function () { return null; });
|
||||
if (!h || !h.ok) return null;
|
||||
/* 缺关键字段 = 无法证明配错,禁止 motor/start(healthCheck 要求不碰 start) */
|
||||
if (h.dc == null && h.period_ms == null && h.dc_cycle_us == null) return null;
|
||||
var dcs = Number(h.dc_cycle_us);
|
||||
var per = Number(h.period_ms);
|
||||
if (h.dc === 1 && dcs === ECAT_DC_CYCLE_US &&
|
||||
|
||||
+2
-1
@@ -106,7 +106,8 @@ async function ensureBusOpen(force) {
|
||||
if (st && st.ok === true) return true;
|
||||
} catch (_) { /* 后端还没起来:下面 open 请求会触发代理自动拉起 */ }
|
||||
}
|
||||
var substr = 'I210';
|
||||
var substr = ECAT_DEFAULT_ADAPTER;
|
||||
|
||||
try {
|
||||
var s = localStorage.getItem('dcu_ecat_adapter');
|
||||
if (s && s.trim()) substr = s.trim();
|
||||
|
||||
+4
-1
@@ -31,6 +31,8 @@
|
||||
* 请求统一走 ConnectionHub(device-link.ecatPost),与 Owner 健康轮询同源。
|
||||
*/
|
||||
import { deviceLink } from '../common/device-link.js';
|
||||
import { ECAT_DEFAULT_ADAPTER } from '../common/ecat-bus.js';
|
||||
|
||||
|
||||
var POLL_MS = 1000; /* 正常轮询节拍(负载窗口 1s 一滚,再快没意义) */
|
||||
var STALE_MS = 3000; /* 超过 3 个窗口没刷新即视为过期 */
|
||||
@@ -101,7 +103,8 @@ function adapterSubstr() {
|
||||
var s = localStorage.getItem('dcu_ecat_adapter');
|
||||
if (s && s.trim()) return s.trim();
|
||||
} catch (_) {}
|
||||
return 'I210';
|
||||
return ECAT_DEFAULT_ADAPTER;
|
||||
|
||||
}
|
||||
|
||||
/** 刷写/上传进行中:绝不动总线(open=loop_stop,start=抢 OP)。 */
|
||||
|
||||
@@ -125,7 +125,8 @@ section("[1] probe() 自动开网卡 + 自动起循环(四级链条的 2/3/4
|
||||
check("open 用默认网卡子串 I210", st.openSubstr === "I210", String(st.openSubstr));
|
||||
check("随后自动调用 /api/motor/start(进 OP + 起后台循环)", st.started === true);
|
||||
check("open 在 start 之前", st.calls.indexOf("/ecat/api/open") < st.calls.indexOf("/ecat/api/motor/start"));
|
||||
check("periodMs 由后端回报写入", tp.debug().periodMs === 4, String(tp.debug().periodMs));
|
||||
check("periodMs 钉在 DC 250µs 档(产品硬约束,非 stub 旧默认 4ms)",
|
||||
Math.abs(tp.debug().periodMs - 0.25) < 1e-6, String(tp.debug().periodMs));
|
||||
}
|
||||
|
||||
/* ── 2. 已连接且循环在跑时不要重复 open / motor/start(幂等)── */
|
||||
|
||||
Reference in New Issue
Block a user