April 30, 2026
Converts a .csv file with codes to pulse timing hex codes.
convert-to-timing.ps1 "path\to\csv" "path\to\encodeir.exe"
param(
[Parameter(Mandatory = $true)]
[string]$CsvFile,
[Parameter(Mandatory = $true)]
[string]$EncodeIrPath
)
$unknownProtocols = @()
# Resolve full absolute paths safely
try {
$csvFullPath = (Resolve-Path -LiteralPath $CsvFile).Path
} catch {
throw "CSV file not found or invalid path: $CsvFile"
}
try {
$encodeirFullPath = (Resolve-Path -LiteralPath $EncodeIrPath).Path
} catch {
throw "encodeir path not found or invalid path: $EncodeIrPath"
}
# Output file in current directory
$outputFile = Join-Path (Get-Location) "timing-output.txt"
if (Test-Path $outputFile) {
Remove-Item $outputFile
}
Get-Content $csvFullPath | ForEach-Object {
$line = $_.Trim()
if ([string]::IsNullOrWhiteSpace($line)) {
return
}
$parts = $line -split ','
# Save first column (label)
$label = $parts[1]
# Transform remaining columns
# Second column (protocol) with custom rules
$protocol = $parts[1]
$protocolNormalized = switch ($protocol) {
"Proton" { "Proton" }
"NECx1" { "nec1" }
"NECx2" { "nec2" }
"Mitsubishi" { "Mitsubishi" }
"Sony12" { "Sony12" }
"Sony15" { "Sony15" }
default { $protocol.ToLower() }
}
# Rebuild line: replace second column only
$rest = $parts[2..($parts.Length - 1)]
$transformed = ($protocolNormalized + " " + ($rest -join ' ')).Trim()
$args = $transformed -split '\s+'
# Run encodeir
$result = & $encodeirFullPath @args
$resultLine = ($result | Out-String).Trim()
# Debug print (optional)
Write-Host "Running: $encodeirFullPath $transformed"
Write-Host "Output: $resultLine"
if ($resultLine -match "Error:\s*Unknown protocol") {
$unknownProtocols += $label
return
}
# Otherwise save result
Add-Content -Path $outputFile -Value $resultLine
}
Write-Host "Done. Output written to $outputFile"
Write-Host ""
Write-Host "Total unknown protocols: $($unknownProtocols.Count)"
Write-Host "List: $($unknownProtocols -join ', ')"