[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 Hex($b) { return ($b | ForEach-Object { $_.ToString("x2") }) -join "" } # (a) 38.087 的 102B type=2 帧 Write-Host "=== (a) 首个 type=2 102B 帧 (claim 前) ===" foreach ($l in $lines) { $p = $l -split "`t"; if ($p.Count -lt 5) { continue } if ($p[1] -ne "192.168.123.113" -or $p[2] -ne "192.168.123.1") { continue } $b = H2B $p[4] if ($b.Length -eq 102 -and $b[4] -eq 2) { Write-Host (" t={0} len={1}" -f $p[0], $b.Length) Write-Host (" hex=" + (Hex $b)) break } } # (b) 首个 644B announce: 找主机IP(717ba8c0)偏移 + 其它可变字段 Write-Host "`n=== (b) 首个 644B type=1 announce ===" 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] if ($b.Length -eq 644) { Write-Host (" t={0} dst={1}" -f $p[0], $p[2]) $ip = [byte[]]@(0x71,0x7b,0xa8,0xc0) # 113.123.168.192 = LE of 192.168.123.113 for ($i = 0; $i -lt $b.Length - 4; $i++) { if ($b[$i] -eq 0x71 -and $b[$i+1] -eq 0x7b -and $b[$i+2] -eq 0xa8 -and $b[$i+3] -eq 0xc0) { Write-Host (" 主机IP@0x{0:x}" -f $i) } } Write-Host (" 0x00-0x40: " + (Hex $b[0..0x3F])) break } } # (c) rdm_disc_req 模板 0x18-0x19 / 0x2A-0x3B Write-Host "`n=== (c) rdm_disc_req 模板关键字段 ===" $h = (Get-Content "C:\Users\tonycao\work\light\enet-validator\samples\rdm_disc_req_1126.hex" -Raw).Trim() -replace '\s','' $b = H2B $h Write-Host (" len={0} 0x18-0x19={1} 0x20-0x23={2} 0x2A-0x3B={3}" -f $b.Length, (Hex $b[0x18..0x19]), (Hex $b[0x20..0x23]), (Hex $b[0x2A..0x3B])) # (d) 首个 .1→113 的 RDM 应答帧: 0x18 sub + 0x2A 起内容 Write-Host "`n=== (d) 首个 .1→113 RDM 应答 (sub@0x18, 0x2A 起 32B) ===" foreach ($l in $lines) { $p = $l -split "`t"; if ($p.Count -lt 5) { continue } if ($p[1] -ne "192.168.123.1") { continue } $b = H2B $p[4] if ($b.Length -ge 0x30 -and $b[4] -eq 4 -and ($b[0x2A] -eq 0xCC -or $b[0x2A] -eq 0xAA)) { Write-Host (" t={0} len={1} 0x18-0x19={2} 0x20-0x21={3} 0x28-0x29={4}" -f $p[0], $b.Length, (Hex $b[0x18..0x19]), (Hex $b[0x20..0x21]), (Hex $b[0x28..0x29])) Write-Host (" 0x2A+: " + (Hex $b[0x2A..([Math]::Min(0x4A, $b.Length-1))])) break } }