refactor: 按角色分 web/ diag/ launch/ 三层, 根目录只留主程序

18 个文件平铺根目录太乱, 按角色归拢:
  web/     ecat.html/css + motor.html/js —— 前端资源
  diag/    ecat_scan / ecat_sniff / ecat_esc_regs —— 独立诊断脚本, 互不依赖
  launch/  5 个 .bat/.vbs 双击入口
根目录只留 ecat_server / ecat_tool / ecat_flash_eeprom / test_motor_backend:
这几个互相 import(tool→flash_eeprom, test→server), 挪进子目录就得改 import
或加包, 收益不抵成本。

配套改动:
  _STATIC_MAP 的值加 web/ 前缀 —— URL 路径刻意保持不变(/、/ecat.css、
  /motor.html), 页面内相对引用、书签、外部链接一律不用改。
  launch/ 里 %~dp0 现在指向 launch\, 五个启动器统一改为先取上一层作 ROOT
  (bat 用 %~dp0.., vbs 用两次 GetParentFolderName), run_scan 顺带指向
  diag\ecat_scan.py。

验证: 7 个 py 全编译通过; test_motor_backend 8 项全通过; 服务实起后 6 条
静态路由全 200 且 MIME 正确(js 是 application/javascript)、404 兜底正常;
Edge headless 渲染主页与 motor 页, CSS 294 规则加载、9 个节点样式生效、
零加载失败零 JS 异常; bat/vbs 的 ROOT 解析实测指到项目根, 五个目标文件
全部命中; ecat_tool adapters 与 diag/ecat_scan.py 实跑正常。
This commit is contained in:
cbb
2026-09-03 22:08:38 +08:00
parent 47ea85fb23
commit beb33ffe50
15 changed files with 62 additions and 31 deletions
+10
View File
@@ -0,0 +1,10 @@
@echo off
rem EtherCAT master tool for DCU LAN9252 (scan/flash/send/monitor)
rem Examples: ecat.bat status | ecat.bat flash | ecat.bat send --u64 0x1,0x2,0x3,0x4 --duration 5
rem 本文件在 launch\ 下, %~dp0 指向 launch\, 故 ROOT 取其上一层。
chcp 65001 >nul
set PYTHONUTF8=1
set "ROOT=%~dp0.."
cd /d "%ROOT%"
"%ROOT%\venv\Scripts\python.exe" ecat_tool.py %*
pause
+14
View File
@@ -0,0 +1,14 @@
' DCU EtherCAT desktop window (pywebview/WebView2). No console, no browser tab.
' Browser-tab launcher: ecat_web.vbs Console-mode debug launcher: ecat_web.bat
' 本文件在 launch\ 下: 先取自身所在目录, 再上一层拿到项目根。
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
here = fso.GetParentFolderName(WScript.ScriptFullName)
base = fso.GetParentFolderName(here)
sh.CurrentDirectory = base
sh.Environment("PROCESS")("PYTHONUTF8") = "1"
' WebView2: keep GPU rasterization but disable GPU compositing.
' Full hardware acceleration white-screens this window on some GPU drivers;
' --disable-gpu-compositing fixes it while still using the GPU for raster.
sh.Environment("PROCESS")("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS") = "--disable-gpu-compositing"
sh.Run """" & base & "\venv\Scripts\pythonw.exe"" """ & base & "\ecat_server.py"" --window", 0, False
+9
View File
@@ -0,0 +1,9 @@
@echo off
rem DCU EtherCAT master web console (serves web\ecat.html + pysoem API)
rem 本文件在 launch\ 下, %~dp0 指向 launch\, 故 ROOT 取其上一层。
chcp 65001 >nul
set PYTHONUTF8=1
set "ROOT=%~dp0.."
cd /d "%ROOT%"
"%ROOT%\venv\Scripts\python.exe" ecat_server.py
pause
+10
View File
@@ -0,0 +1,10 @@
' DCU EtherCAT web console - hidden launcher (no console window).
' Double-click me. Console-mode debug launcher (visible logs): ecat_web.bat
' 本文件在 launch\ 下: 先取自身所在目录, 再上一层拿到项目根。
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
here = fso.GetParentFolderName(WScript.ScriptFullName)
base = fso.GetParentFolderName(here)
sh.CurrentDirectory = base
sh.Environment("PROCESS")("PYTHONUTF8") = "1"
sh.Run """" & base & "\venv\Scripts\python.exe"" """ & base & "\ecat_server.py""", 0, False
+12
View File
@@ -0,0 +1,12 @@
@echo off
rem EtherCAT master bring-up scan (LAN9252)
rem Usage: run_scan.bat -> list Npcap adapters
rem run_scan.bat I226 -> scan EtherCAT slaves (add --op for PDO test)
rem 本文件在 launch\ 下, %~dp0 指向 launch\, 故 ROOT 取其上一层;
rem 扫描脚本已挪进 diag\。
chcp 65001 >nul
set PYTHONUTF8=1
set "ROOT=%~dp0.."
cd /d "%ROOT%"
"%ROOT%\venv\Scripts\python.exe" diag\ecat_scan.py %*
pause