68 lines
3.5 KiB
PowerShell
68 lines
3.5 KiB
PowerShell
# MAG160C 逆向会话恢复脚本
|
||
# 用法: powershell -ExecutionPolicy Bypass -File tools\resume_rev.ps1
|
||
# 作用: 检查设备/进程/工具状态, 重新编译 demo3, 采集 demo3 帧数据,
|
||
# 并在必要时跑官方采集, 输出对比所需文件。中断恢复时直接运行。
|
||
|
||
$ErrorActionPreference = "Continue"
|
||
$proj = "C:\Project\MAG160C"
|
||
$art = "$proj\build-artifacts"
|
||
$pairsDir = "$proj\analysis\pairs_final_20260813"
|
||
|
||
Write-Host "=== 1. 环境检查 ==="
|
||
$dev = Get-CimInstance Win32_PnPEntity -ErrorAction SilentlyContinue | Where-Object { $_.DeviceID -match "VID_833C" }
|
||
if ($dev) { Write-Host "设备: $($dev.Name) OK" } else { Write-Host "!!! 设备未连接" }
|
||
|
||
Write-Host "=== 2. 清理冲突进程 ==="
|
||
Stop-Process -Name mag160c_demo3, tsdk_pair3, tsdk_pair2 -Force -ErrorAction SilentlyContinue
|
||
Start-Sleep 1
|
||
|
||
Write-Host "=== 3. 编译 demo3 v5 ==="
|
||
gcc -O2 -w -DMAG160C_STATIC -I"$proj\csdk\third_party\libusb\win64" -I"$proj\csdk\include" -I"$proj\csdk\src" -o "$art\mag160c_demo3.exe" "$proj\csdk\tools\mag160c_demo3.c" "$proj\csdk\src\mag160c_display.c" "$proj\csdk\src\mag160c_error.c" "$proj\csdk\third_party\libusb\win64\libusb-1.0.x64.a" -lgdi32 -luser32
|
||
if ($LASTEXITCODE -ne 0) { Write-Host "编译失败"; exit 1 }
|
||
Write-Host "编译 OK"
|
||
|
||
Write-Host "=== 4. 编译官方采集工具 ==="
|
||
gcc -O2 -w -o "$art\tsdk_pair3.exe" "$proj\csdk\tools\tsdk_pair3.c"
|
||
if ($LASTEXITCODE -ne 0) { Write-Host "tsdk_pair3 编译失败"; exit 1 }
|
||
Write-Host "编译 OK"
|
||
|
||
Write-Host "=== 5. 检查 DDT ==="
|
||
if (-not (Test-Path "$art\mag160c_official.ddt")) {
|
||
# 官方标定缓存:%TEMP%\Core<设备序列号>(运行官方 App 时生成)
|
||
$coreDir = Get-ChildItem "$env:TEMP" -Directory -Filter "Core*" -ErrorAction SilentlyContinue | Select-Object -First 1
|
||
if ($coreDir) {
|
||
Copy-Item $coreDir.FullName "$art\mag160c_official.ddt" -Force
|
||
Write-Host "DDT 从 %TEMP%\Core<序列号> 复制"
|
||
} else { Write-Host "!!! DDT 缺失" }
|
||
} else { Write-Host "DDT OK" }
|
||
|
||
Write-Host "=== 6. 运行 demo3 采集(35s,捕获帧在 fcount=300/600/900)==="
|
||
Remove-Item "$art\demo3_frame_capture.bin" -Force -ErrorAction SilentlyContinue
|
||
Remove-Item "$art\demo3_diag.txt" -Force -ErrorAction SilentlyContinue
|
||
Start-Process "$art\mag160c_demo3.exe" -WorkingDirectory $art
|
||
Start-Sleep 35
|
||
Stop-Process -Name mag160c_demo3 -Force -ErrorAction SilentlyContinue
|
||
if (Test-Path "$art\demo3_frame_capture.bin") {
|
||
Write-Host "捕获 OK: $((Get-Item "$art\demo3_frame_capture.bin").Length) 字节"
|
||
} else { Write-Host "!!! 无捕获文件, 检查 demo3_diag.txt" }
|
||
|
||
Write-Host "=== 7. 官方采集(同场景, 需保持镜头不动)==="
|
||
if (-not (Test-Path "$pairsDir\pair_000.raw")) {
|
||
New-Item -ItemType Directory -Path $pairsDir -Force | Out-Null
|
||
& "$art\tsdk_pair3.exe" $pairsDir 8 6000 > "$pairsDir\run.log" 2>&1
|
||
Move-Item "$proj\config.txt" "$pairsDir\config.txt" -Force -ErrorAction SilentlyContinue
|
||
Move-Item "$proj\pair_0*.meta", "$proj\pair_0*.win" $pairsDir -Force -ErrorAction SilentlyContinue
|
||
Write-Host "官方采集完成"
|
||
} else { Write-Host "官方数据已存在, 跳过" }
|
||
|
||
Write-Host "=== 8. 对比 ==="
|
||
# compare_live.py was an ad-hoc analysis helper of the original session and is
|
||
# not shipped with the repo (临时分析脚本不入库); the step is skipped gracefully.
|
||
if (Test-Path "$env:TEMP\compare_live.py") {
|
||
python "$env:TEMP\compare_live.py"
|
||
} else {
|
||
Write-Host "跳过: %TEMP%\compare_live.py 不存在(一次性分析脚本,重新生成后再跑)"
|
||
}
|
||
|
||
Write-Host "=== 完成。下一步见 analysis\session_state.md ==="
|