From 2304ed6999b12391962a1e09bebd82995caada22 Mon Sep 17 00:00:00 2001 From: cbb <2625274797@qq.com> Date: Mon, 21 Sep 2026 02:28:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(motor+hygiene):=20P1=20=E6=8B=86?= =?UTF-8?q?=E5=88=86=20main.js=20=E5=B9=B6=E6=94=B6=E6=95=9B=E6=80=BB?= =?UTF-8?q?=E7=BA=BF/toast=20+=20P3=20=E5=8D=AB=E7=94=9F=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 单点 --- js/common/ecat-bus.js | 3 +++ js/ota/boot_ecat.js | 3 ++- js/ota/ecat_load.js | 5 ++++- scripts/test_ecat_autostart.mjs | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/js/common/ecat-bus.js b/js/common/ecat-bus.js index 45ac9d6..3f2dbd2 100644 --- a/js/common/ecat-bus.js +++ b/js/common/ecat-bus.js @@ -160,11 +160,14 @@ export async function runEcatBootstrap(opts) { /** * DC/周期自愈:被配错(free-run 或 ≥1ms)时拉回 250µs。 + * health 未回报 dc/period 字段时**不动总线**(healthCheck 契约:只读)。 * @returns {Promise} 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 && diff --git a/js/ota/boot_ecat.js b/js/ota/boot_ecat.js index 71ec0c4..363213d 100644 --- a/js/ota/boot_ecat.js +++ b/js/ota/boot_ecat.js @@ -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(); diff --git a/js/ota/ecat_load.js b/js/ota/ecat_load.js index c0340e5..4b2cd68 100644 --- a/js/ota/ecat_load.js +++ b/js/ota/ecat_load.js @@ -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)。 */ diff --git a/scripts/test_ecat_autostart.mjs b/scripts/test_ecat_autostart.mjs index ef66921..d3a9cb2 100644 --- a/scripts/test_ecat_autostart.mjs +++ b/scripts/test_ecat_autostart.mjs @@ -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(幂等)── */