[Console]::OutputEncoding = [Text.Encoding]::UTF8 $f = "$env:TEMP\opencode\cold2.tsv" $lines = [IO.File]::ReadAllLines($f) function H2B($hex) { $n = $hex.Length / 2; $b = New-Object byte[] $n; for ($i = 0; $i -lt $n; $i++) { $b[$i] = [Convert]::ToByte($hex.Substring(2*$i, 2), 16) }; return $b } function G32le($b, $o) { return $b[$o] -bor ($b[$o+1] -shl 8) -bor ($b[$o+2] -shl 16) -bor ($b[$o+3] -shl 24) } Write-Host "=== cold2 前 120 帧 113→.1 (认领建立期) ===" $count = 0 foreach ($l in $lines) { $p = $l -split "`t"; if ($p.Count -lt 5) { continue } if ($p[1] -ne "192.168.123.113") { continue } $b = H2B $p[4] $t = [double]$p[0] $len = $b.Length $magic = [Text.Encoding]::ASCII.GetString($b[0..3]) $type = G32le $b 4 $desc = "" if ($magic -eq "ENet" -and $type -eq 4 -and $len -ge 0x50) { $sub = "{0:x2}{1:x2}" -f $b[0x19], $b[0x18] $flag = $b[0x30] if ($b[0x2A] -eq 0xCC -or $b[0x3C] -eq 0x01) { $msgLen = $b[0x3D]; $cc = $b[0x4F]; $pid = ($b[0x50] -shl 8) -bor $b[0x51] $desc = "RDM请求 sub=$sub flag=$('{0:x2}' -f $flag) msgLen=$msgLen CC=$('{0:x2}' -f $cc) PID=$('{0:x4}' -f $pid) TN=$('{0:x2}' -f $b[0x4A])" } else { $desc = "type4 sub=$sub flag=$('{0:x2}' -f $flag) 0x2A=$('{0:x2}' -f $b[0x2A])" } } elseif ($magic -eq "ENet" -and $type -eq 4) { $desc = "type4 短帧" } Write-Host ("{0,9:N3} len={1,-5} magic={2} type={3} {4}" -f $t, $len, $magic, $type, $desc) $count++ if ($count -ge 120) { break } }