现场"扫描枪收不到按键"需要区分"按键没到内核"与"到了内核但上层丢了", 以及区分"供电不足/外设取电"与"枪线材问题",补三个可直接复用的工具: - scripts/scan-forensics.ps1:故障当场一键取证(设备/root/uptime、/proc/bus/input/devices、 dmesg usb/hid、App 侧 logcat(WMSScan/WMSPage/UniConsole)、dumpsys input、内核 getevent 抓窗), 并自动输出判据:内核有按键而 App keys=0 -> 上层(Android 分发/WebView);内核无按键 -> 枪/线/供电。 - scripts/power-probe.sh:采样 SARADC / 温度 / 扫码枪是否仍在总线上(RK818 不上报电流, 这是唯一可用的侧面遥测)。 - scripts/power-load-test.sh:固定负载(屏幕最亮 + N 核忙循环)压测并在结束后自动杀掉负载。 实测结论(X9R 12V/2A 24W 临界、音响插平板 USB 口会冲掉 Hub + 枪)见 README 机型注意一节。
121 lines
5.1 KiB
PowerShell
121 lines
5.1 KiB
PowerShell
# scan-forensics.ps1
|
|
# One-shot evidence capture for the "scanner stops working" fault (WMS X9R tablet).
|
|
#
|
|
# Why: on 2026-09-25 the field log proved the break is BELOW the JS layer
|
|
# (60s heartbeat keys=0 while every JS gate was green). The only thing JS cannot see is
|
|
# whether the kernel/Activity still gets the key events. This script captures that layer.
|
|
#
|
|
# Usage (tablet plugged in, USB debugging on):
|
|
# powershell -NoProfile -ExecutionPolicy Bypass -File scripts\scan-forensics.ps1
|
|
# powershell -NoProfile -ExecutionPolicy Bypass -File scripts\scan-forensics.ps1 -Seconds 30
|
|
#
|
|
# Run it WHILE the fault is present, and scan the gun 3-5 times during the capture window.
|
|
# Everything is kept (no cleanup) under -OutDir.
|
|
#
|
|
# Verdict rules:
|
|
# kernel key DOWN > 0 but app heartbeat keys=0 -> Android dispatch / WebView / IME layer
|
|
# kernel key DOWN = 0 -> gun / cable / USB port (hardware) or scan service
|
|
#
|
|
# ASCII only on purpose: `powershell -File` reads non-ASCII scripts as ANSI on this machine.
|
|
|
|
param(
|
|
[int]$Seconds = 20,
|
|
[string]$OutDir = ''
|
|
)
|
|
|
|
$ErrorActionPreference = 'Continue'
|
|
|
|
function Find-Adb {
|
|
$candidates = @(
|
|
(Join-Path $env:LOCALAPPDATA 'Android\Sdk\platform-tools\adb.exe'),
|
|
'C:\Android\Sdk\platform-tools\adb.exe',
|
|
'D:\Android\Sdk\platform-tools\adb.exe'
|
|
)
|
|
foreach ($c in $candidates) {
|
|
if (Test-Path $c) { return $c }
|
|
}
|
|
$cmd = Get-Command adb -ErrorAction SilentlyContinue
|
|
if ($cmd) { return $cmd.Source }
|
|
throw 'adb.exe not found. Set PATH or edit Find-Adb in this script.'
|
|
}
|
|
|
|
if (-not $OutDir) {
|
|
$OutDir = Join-Path $env:TEMP ('scan-forensics\' + (Get-Date -Format 'yyyyMMdd-HHmmss'))
|
|
}
|
|
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
|
|
|
|
$adb = Find-Adb
|
|
Write-Host "adb = $adb"
|
|
Write-Host "out dir = $OutDir"
|
|
Write-Host ''
|
|
|
|
function Sh($cmd) { & $adb shell $cmd 2>&1 }
|
|
function Save($name, $lines) {
|
|
$path = Join-Path $OutDir $name
|
|
$lines | Out-File -FilePath $path -Encoding utf8
|
|
Write-Host (" saved {0}" -f $name)
|
|
}
|
|
|
|
# 1) device present?
|
|
$devices = & $adb devices 2>&1
|
|
$serial = ($devices | Select-String -Pattern '^\S+\s+device$' | ForEach-Object { $_.Line.Split()[0] }) | Select-Object -First 1
|
|
if (-not $serial) {
|
|
Write-Host '!! no adb device. Check: USB debugging on, try another USB port (this box only works on some ports), replug.' -ForegroundColor Red
|
|
Write-Host ($devices -join "`n")
|
|
exit 2
|
|
}
|
|
Write-Host "device = $serial"
|
|
& $adb root 2>&1 | Out-Null
|
|
& $adb wait-for-device 2>&1 | Out-Null
|
|
|
|
# 2) static environment
|
|
Save '00-device.txt' @(
|
|
"serial = $serial",
|
|
"captured = $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')",
|
|
"id = $(Sh 'id')",
|
|
"model = $(Sh 'getprop ro.product.model')",
|
|
"android = $(Sh 'getprop ro.build.version.release') build=$(Sh 'getprop ro.build.type') selinux=$(Sh 'getenforce')",
|
|
"uptime = $(Sh 'cat /proc/uptime') (seconds since boot - tells whether a reboot just happened)",
|
|
"pkg = $(Sh 'dumpsys window | grep -E ''mCurrentFocus|mFocusedApp''')"
|
|
)
|
|
|
|
Save '01-input-devices.txt' (Sh 'cat /proc/bus/input/devices')
|
|
Save '02-dmesg-usb-input.txt' (Sh "dmesg | grep -iE 'usb|newtologic|hid|input:' | tail -n 120")
|
|
Save '03-app-logcat.txt' (Sh "logcat -d -s WMSScan:V WMSPage:V UniConsole:V UniViewConsole:V | tail -n 400")
|
|
Save '04-dumpsys-input.txt' (Sh 'dumpsys input | head -n 250')
|
|
|
|
# 3) kernel key stream (scan now!)
|
|
$gevPath = Join-Path $OutDir '05-getevent.txt'
|
|
Write-Host ''
|
|
Write-Host ("==> SCAN THE GUN 3-5 TIMES NOW (you have {0} seconds) <==" -f $Seconds) -ForegroundColor Yellow
|
|
& $adb shell "timeout $Seconds getevent -lt" 2>&1 | Out-File -FilePath $gevPath -Encoding utf8
|
|
Write-Host (" saved 05-getevent.txt")
|
|
|
|
# 4) verdict
|
|
$gev = Get-Content $gevPath -ErrorAction SilentlyContinue
|
|
$keyDown = @($gev | Select-String -Pattern 'EV_KEY\s+(KEY_[0-9A-Z_]+)\s+DOWN' -AllMatches)
|
|
$enterDown = @($gev | Select-String -Pattern 'EV_KEY\s+KEY_ENTER\s+DOWN')
|
|
$gunLines = @($gev | Select-String -Pattern 'event\d+.*EV_KEY')
|
|
$logcat = Get-Content (Join-Path $OutDir '03-app-logcat.txt') -ErrorAction SilentlyContinue
|
|
$health = @($logcat | Select-String -Pattern 'health.*keys=' | Select-Object -Last 1)
|
|
|
|
Write-Host ''
|
|
Write-Host '================ VERDICT ================'
|
|
Write-Host ("kernel : key DOWN events = {0} (ENTER = {1})" -f $keyDown.Count, $enterDown.Count)
|
|
Write-Host (" gun/kernel EV_KEY lines = {0}" -f $gunLines.Count)
|
|
if ($health.Count -gt 0) {
|
|
Write-Host ("app : last heartbeat -> {0}" -f $health[0].Line.Trim())
|
|
} else {
|
|
Write-Host 'app : no WMSScan heartbeat in logcat buffer (buffer may have wrapped)'
|
|
}
|
|
Write-Host ''
|
|
if ($keyDown.Count -ge 3) {
|
|
Write-Host 'kernel HAS key events -> the break is ABOVE the kernel (Android dispatch / WebView / IME / app).' -ForegroundColor Green
|
|
Write-Host ' Next: compare with the app heartbeat keys= above. keys=0 here means the app never got them.'
|
|
} else {
|
|
Write-Host 'kernel has NO (or almost no) key events -> gun / cable / USB port / scan service (hardware).' -ForegroundColor Red
|
|
Write-Host ' Next: swap cable+port, watch dmesg in 02-dmesg-usb-input.txt for disconnect/reconnect.'
|
|
}
|
|
Write-Host ''
|
|
Write-Host 'Keep this folder for the vendor/customer report. Nothing was deleted.'
|