[Console]::OutputEncoding = [Text.Encoding]::UTF8 # E2E: replay SET frame patched to virtual fixture 130 (addr 200), then GET verify $lines = [IO.File]::ReadAllLines("$env:TEMP\opencode\set123b.tsv") $hex = $null foreach ($l in $lines) { $p = $l -split "`t" if ($p.Count -lt 5 -or -not $p[4]) { continue } if ($p[1] -ne "192.168.123.113") { continue } $h = $p[4] -replace " ", "" if ($h.Length -ne 2168) { continue } if ($h.Substring(0x20 * 2, 4) -ne "0200") { continue } if ($h.Substring(0x3C * 2, 2) -ne "01") { continue } if ($h.Substring(0x3D * 2, 2) -ne "1a") { continue } if ($h.Substring(0x4F * 2, 2) -ne "30") { continue } if ($h.Substring(0x30 * 2, 2) -ne "00") { continue } $hex = $h; break } if (-not $hex) { throw "no SET frame" } $n = $hex.Length / 2 $req = New-Object byte[] $n for ($i = 0; $i -lt $n; $i++) { $req[$i] = [Convert]::ToByte($hex.Substring(2 * $i, 2), 16) } # patch: dest UID @0x3E = 010734670130, PD @0x53 = 00 C8 (addr 200) $vuid = [byte[]](0x01, 0x07, 0x34, 0x67, 0x01, 0x30) [Array]::Copy($vuid, 0, $req, 0x3E, 6) $req[0x53] = 0x00; $req[0x54] = 0xC8 $udp = New-Object System.Net.Sockets.UdpClient $udp.Client.ReceiveTimeout = 3000 $ep = New-Object System.Net.IPEndPoint([System.Net.IPAddress]::Parse("192.168.58.7"), 31772) function Send-Recv($frame, $label) { $sw = [Diagnostics.Stopwatch]::StartNew() [void]$udp.Send($frame, $frame.Length, $ep) while ($true) { try { $rep = $udp.Receive([ref]$ep) if ($rep.Length -lt 0x44) { continue } # skip 42B telemetry $srcS = ($rep[0x33..0x38] | ForEach-Object { $_.ToString("x2") }) -join "" $pdl = [int]$rep[0x41] $pdS = "" if ($pdl -gt 0 -and $rep.Length -ge 0x42 + $pdl) { $pdS = ($rep[0x42..(0x41 + $pdl)] | ForEach-Object { $_.ToString("x2") }) -join "" } $mlen = [int]$rep[0x2C]; $sum = 0 for ($i = 0x2A; $i -lt 0x2A + $mlen; $i++) { $sum += $rep[$i] } $ckv = ([int]$rep[0x2A + $mlen] -shl 8) -bor $rep[0x2A + $mlen + 1] $v = if (($sum -band 0xFFFF) -eq $ckv) { "OK" } else { "FAIL" } Write-Host ("{0}: {1}B {2}ms srcUID={3} CC={4:x2} PID={5:x2}{6:x2} PDL={7} PD={8} ck={9}" -f ` $label, $rep.Length, $sw.ElapsedMilliseconds, $srcS, $rep[0x3E], $rep[0x3F], $rep[0x40], $pdl, $pdS, $v) return } catch { Write-Host "${label}: no reply"; return } } } Send-Recv $req "SET 130 addr=200" Start-Sleep -Milliseconds 100 # GET: same frame, msgLen=0x18, CC=0x20, PDL=0 $get = [byte[]]$req.Clone() $get[0x3D] = 0x18; $get[0x4F] = 0x20; $get[0x52] = 0x00 $get[0x22] = $get[0x22] + 1 # bump query seq for clarity Send-Recv $get "GET 130 addr " $udp.Close()