diff --git a/README.md b/README.md index 1604683..40f6148 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ pwsh -File tools/Publish-Avalonia.ps1 发布目录为 `artifacts/avalonia/win-x64` 和 `artifacts/avalonia/linux-x64`。默认构建及发布不再携带训练用 Python、SAM2 或 YOLO 权重;D3 服务使用自己的独立环境。相机仅支持 USB(UVC),不依赖工业相机 SDK。 +工位机通过 SSH 部署:Linux 用 `tools/Deploy-Linux.ps1`,记录见 [LINUX.md](LINUX.md);Windows 用 `tools/Deploy-Windows.ps1`,记录见 [WINDOWS.md](WINDOWS.md)。 + `--import-recipes 原数据根目录` 可以导入已有配方,`--check-standalone` / `--check-runtime` 检查本地手部模型和使用模拟 AI 的步骤门控,`--check-gpu` 额外要求手部推理使用 GPU;这些本地诊断不代表真实 D3 接口联调成功。 主界面步骤卡片以背景条显示已触发检查窗口的剩余时间,背景随剩余时间递减;确认完成后变绿,异常跳过后变红,不显示步骤名后的判定提示。 diff --git a/WINDOWS.md b/WINDOWS.md new file mode 100644 index 0000000..3db3e57 --- /dev/null +++ b/WINDOWS.md @@ -0,0 +1,40 @@ +# SopHelper Windows 工位机部署 + +跨平台入口是 `src/SopHelper.Avalonia`,Linux 侧记录见 [LINUX.md](LINUX.md),功能与运行约定见 [README.md](README.md)。 + +## 部署脚本 + +Windows 工位机用 SSH/SFTP 部署,目录约定与 `tools/Deploy-Linux.ps1` 一致: + +```powershell +# 发布 win-x64、本机自检、打包、传输、远端解包、自检并创建快捷方式 +.\tools\Deploy-Windows.ps1 -Target Administrator@192.168.0.184 +# 常用参数:-InstallRoot C:\sophelper、-ReleaseId 指定版本名、-SkipPublish 复用现有发布包、-SkipGpuCheck 跳过 GPU 自检 +``` + +- 发布复用 `artifacts/avalonia/win-x64`,打包为 `artifacts/.tar.gz`(不含历史遗留的 `python/`)。 +- 远端结构:`\releases\` 是版本目录,`\current` 是指向当前版本的目录联接; + `configs`、`models`、`workspace` 固定放在 `` 下,升级时版本目录内以目录联接指回,配方、模型和现场数据跨版本保留。 +- `ReleaseId` 默认 `avalonia-<时间>-`,工作树有未提交修改时追加 `-dirty`。 +- 安装脚本 `tools/windows/install-release.ps1` 在远端解包后运行 `--check-runtime` 与 `--check-gpu`,任一失败即部署失败; + 日志写入 `\workspace\logs\install-runtime.*.log`、`install-gpu.*.log`。 +- 脚本按 Windows PowerShell 5.1 编写并保存为带 BOM 的 UTF-8(无 BOM 时 5.1 会按系统代码页读取,中文注释和字符串会破坏解析)。 + `tools/Publish-Avalonia.ps1`、`tools/Deploy-Linux.ps1` 使用 .NET Core 专有 API,需要 PowerShell 7。 + +## W-184 首次部署(2026-11-20) + +`Administrator@192.168.0.184`(主机名 DESKTOP-MS5B7QN):Windows 11 专业版 10.0.26200、Gigabyte B550M DS3H AC R2、 +Ryzen 5 5600XT、32GB 内存、NVIDIA GeForce RTX 5060(驱动 32.0.16.1088)、C 盘 200GB(部署后剩余 135.3GB)。 +系统已有 VC++ 2015-2022 运行库、`bsdtar 3.8.4`,目录联接和快捷方式创建均已实测可用。免密 SSH 使用当前账户的密钥。 + +- 版本目录:`C:\sophelper\releases\avalonia-20261120-175451-b613630-dirty`,源码提交 `b613630` 加当时未提交的运行设置与判定改动, + 276 个文件、1.61GB(含 CUDA 13 / cuDNN 9 应用内运行库)。 +- 自检:本机 `--check-runtime` 通过;远端 `--check-runtime` 返回 `handBackend=CPU`、`sop=Completed`, + `--check-gpu` 返回 `handBackend=GPU (CUDA)`、`sop=Completed`,即 RTX 5060 上 CUDA 推理已启用(自检 AI 门控为模拟,不代表 djev 接口联调通过)。 +- 启动入口:`C:\Users\Administrator\Desktop\SopHelper.lnk` 与开始菜单 `Programs\SopHelper.lnk`, + 目标 `C:\sophelper\current\SopHelper.Avalonia.exe`,工作目录为版本目录。桌面程序需要在该机的登录桌面双击启动,SSH 会话内不显示界面。 +- 数据目录:`C:\sophelper\configs\sop` 带入 `d3-workflow.yaml`、`demo.yaml`、`hand-ai.yaml` 三个模板配方; + `C:\sophelper\models` 有 palm、landmark 两个手部模型(另有旧包遗留的 `yolo11n.onnx`,当前代码不加载)。 +- 未随包部署:djev 服务(该机没有 `E:\D3Lite`,程序启动时不会自动拉起,需在“运行设置 → djev”配置远端 `SOPHELPER_VISION_ENDPOINT`, + 或在工位机安装 djev 后由程序自动启动)、SAM2/训练用 Python 环境(`BundlePythonRuntime=false`,`current\python` 不存在)。 +- 相机:现场按 USB(UVC)接入,首次运行在“运行设置”里选择设备并确认实测 fps;本次未接相机,未做采集验证。 diff --git a/tools/Deploy-Windows.ps1 b/tools/Deploy-Windows.ps1 new file mode 100644 index 0000000..d151818 --- /dev/null +++ b/tools/Deploy-Windows.ps1 @@ -0,0 +1,56 @@ +param( + [string]$Target = 'Administrator@192.168.0.184', + [string]$InstallRoot = 'C:\sophelper', + [string]$ReleaseId = '', + [switch]$SkipPublish, + [switch]$SkipGpuCheck +) +# 通过 SSH/SCP 把当前 win-x64 发布包部署到远端 Windows 工位机。 +# 约定同 Deploy-Linux.ps1:发布复用 artifacts/avalonia//,每个版本放入 \releases\, +# configs/models/workspace 保留在 下,通过目录联接跨版本复用。 +$ErrorActionPreference = 'Stop' +if ($Target -notmatch '^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+$') { throw 'Target must be user@host' } +if ($InstallRoot -notmatch '^[A-Za-z]:\\[A-Za-z0-9_.\\-]+$') { throw 'InstallRoot must be an absolute Windows path without spaces' } +$repo = Split-Path $PSScriptRoot -Parent +$output = Join-Path $repo 'artifacts\avalonia\win-x64' +$remoteRootFwd = $InstallRoot.Replace('\', '/') +$sha = (& git -C $repo rev-parse --short HEAD | Out-String).Trim() +$dirty = @(& git -C $repo status --porcelain).Count -gt 0 +if (!$ReleaseId) { + $ReleaseId = 'avalonia-' + (Get-Date -Format 'yyyyMMdd-HHmmss') + '-' + $sha + if ($dirty) { $ReleaseId += '-dirty' } +} +Write-Host "Release: $ReleaseId (commit $sha$(if($dirty){' + 未提交修改'}))" + +if (!$SkipPublish) { + & dotnet publish (Join-Path $repo 'src\SopHelper.Avalonia') -c Release -r win-x64 --self-contained true -p:PublishSingleFile=false -p:BundlePythonRuntime=false -p:NativePlatform=Windows -o $output --nologo + if ($LASTEXITCODE) { throw 'Publish failed' } +} + +# 本机先自检,避免把跑不起来的包传到工位机。 +$exe = Join-Path $output 'SopHelper.Avalonia.exe' +if (!(Test-Path -LiteralPath $exe)) { throw "Missing published executable: $exe" } +$logDir = Join-Path (Split-Path $repo -Parent) 'scratch\test-results' +New-Item -ItemType Directory -Path $logDir -Force | Out-Null +$runtimeCheck = Start-Process -FilePath $exe -ArgumentList '--check-runtime' -NoNewWindow -PassThru -Wait ` + -RedirectStandardOutput (Join-Path $logDir 'deploy-windows-local-check-runtime.stdout.log') ` + -RedirectStandardError (Join-Path $logDir 'deploy-windows-local-check-runtime.stderr.log') +if ($runtimeCheck.ExitCode) { throw '本机 --check-runtime 自检失败,详见 scratch/test-results/deploy-windows-local-check-runtime.*.log' } +Write-Host '本机 --check-runtime 通过。' + +# 打包:不含 python(BundlePythonRuntime=false 时发布目录里的 python 为历史遗留)。 +$packageItems = Get-ChildItem -LiteralPath $output -Force | Where-Object { $_.Name -ne 'python' } | Select-Object -ExpandProperty Name +if (!$packageItems) { throw "Nothing to package in $output" } +$archive = Join-Path $repo ('artifacts\' + $ReleaseId + '.tar.gz') +if (Test-Path -LiteralPath $archive) { Remove-Item -LiteralPath $archive -Force } +& tar -czf $archive -C $output $packageItems +if ($LASTEXITCODE) { throw 'Packaging failed' } +Write-Host ('打包完成: ' + $archive + ' (' + [math]::Round((Get-Item $archive).Length/1MB,1) + ' MB)') + +& ssh -o BatchMode=yes $Target "New-Item -Force -ItemType Directory $InstallRoot, $InstallRoot\releases | Out-Null" +if ($LASTEXITCODE) { throw 'SSH failed' } +& scp -o BatchMode=yes $archive (Join-Path $PSScriptRoot 'windows\install-release.ps1') "${Target}:$remoteRootFwd/" +if ($LASTEXITCODE) { throw 'Transfer failed' } +& ssh -o BatchMode=yes $Target "powershell -NoProfile -ExecutionPolicy Bypass -File $InstallRoot\install-release.ps1 -ReleaseId $ReleaseId -InstallRoot $InstallRoot -SkipGpuCheck $([int][bool]$SkipGpuCheck)" +if ($LASTEXITCODE) { throw "安装或自检失败,详见 $InstallRoot\releases\$ReleaseId\workspace\logs" } +Write-Host "已部署 $ReleaseId 到 $Target;开始菜单和桌面均有 SopHelper 快捷方式。" diff --git a/tools/windows/install-release.ps1 b/tools/windows/install-release.ps1 new file mode 100644 index 0000000..5ea9f2a --- /dev/null +++ b/tools/windows/install-release.ps1 @@ -0,0 +1,78 @@ +param( + [string]$ReleaseId = $(throw 'Usage: install-release.ps1 -ReleaseId ID [-InstallRoot C:\sophelper] [-Archive path] [-SkipGpuCheck 1]'), + [string]$InstallRoot = 'C:\sophelper', + [string]$Archive = '', + [int]$SkipGpuCheck = 0 +) +# 远端安装脚本:解包 win-x64 版本、跨版本复用数据目录、自检并创建快捷方式。 +# 由 tools/Deploy-Windows.ps1 通过 SSH 调用,参数不含空格。 +$ErrorActionPreference = 'Stop' +$release = Join-Path $InstallRoot ('releases\' + $ReleaseId) +if (!$Archive) { $Archive = Join-Path $InstallRoot ($ReleaseId + '.tar.gz') } +if (!(Test-Path -LiteralPath $Archive)) { throw "Missing archive: $Archive" } +New-Item -ItemType Directory -Path $release -Force | Out-Null +tar -xzf $Archive -C $release +if ($LASTEXITCODE) { throw "解压失败: $Archive" } +$exe = Join-Path $release 'SopHelper.Avalonia.exe' +if (!(Test-Path -LiteralPath $exe)) { throw "Missing executable: $exe" } + +# 操作数据、配方、模型跨版本保留在 InstallRoot 下,版本目录内用目录联接指回去。 +foreach ($item in @('configs', 'models', 'workspace')) { + $shared = Join-Path $InstallRoot $item + $packed = Join-Path $release $item + if (!(Test-Path -LiteralPath $shared)) { + if ((Test-Path -LiteralPath $packed) -and ((Get-Item -LiteralPath $packed).Attributes -notmatch 'ReparsePoint')) { + Move-Item -LiteralPath $packed -Destination $shared + } else { + New-Item -ItemType Directory -Path $shared -Force | Out-Null + } + } + if ((Test-Path -LiteralPath $packed) -and ((Get-Item -LiteralPath $packed).Attributes -notmatch 'ReparsePoint')) { + Move-Item -LiteralPath $packed -Destination ($packed + '.packaged-' + (Get-Date -Format 'yyyyMMddHHmmss')) + } + if (!(Test-Path -LiteralPath $packed)) { + New-Item -ItemType Junction -Path $packed -Target $shared | Out-Null + } +} +New-Item -ItemType Directory -Path (Join-Path $InstallRoot 'workspace\logs') -Force | Out-Null + +$current = Join-Path $InstallRoot 'current' +if (Test-Path -LiteralPath $current) { (Get-Item -LiteralPath $current).Delete() } +New-Item -ItemType Junction -Path $current -Target $release | Out-Null + +function Invoke-SelfCheck([string]$Flag, [string]$Name) { + $out = Join-Path $InstallRoot ('workspace\logs\install-' + $Name + '.stdout.log') + $err = Join-Path $InstallRoot ('workspace\logs\install-' + $Name + '.stderr.log') + $process = Start-Process -FilePath $exe -ArgumentList $Flag -NoNewWindow -PassThru -Wait ` + -RedirectStandardOutput $out -RedirectStandardError $err + $text = '' + if (Test-Path -LiteralPath $out) { $text = (Get-Content -LiteralPath $out -Raw) } + return [pscustomobject]@{ name = $Flag; exitCode = $process.ExitCode; output = $text.Trim() } +} + +$checks = @() +$checks += Invoke-SelfCheck '--check-runtime' 'runtime' +if ($checks[-1].exitCode) { throw ('--check-runtime 失败,详见 ' + (Join-Path $InstallRoot 'workspace\logs\install-runtime.stderr.log')) } +if (!$SkipGpuCheck) { + $checks += Invoke-SelfCheck '--check-gpu' 'gpu' + if ($checks[-1].exitCode) { throw ('--check-gpu 失败,详见 ' + (Join-Path $InstallRoot 'workspace\logs\install-gpu.stderr.log')) } +} + +$shell = New-Object -ComObject WScript.Shell +foreach ($folder in @('Desktop', 'Programs')) { + $directory = [Environment]::GetFolderPath($folder) + if (!$directory) { continue } + New-Item -ItemType Directory -Path $directory -Force | Out-Null + $link = $shell.CreateShortcut((Join-Path $directory 'SopHelper.lnk')) + $link.TargetPath = $exe + $link.WorkingDirectory = $release + $link.IconLocation = $exe + ',0' + $link.Description = 'SopHelper SOP 工位检测(' + $ReleaseId + ')' + $link.Save() +} + +Write-Output (@{ + installed = $release + current = $current + checks = $checks +} | ConvertTo-Json -Depth 5 -Compress)