flipper-zero-tutorials/subghz/scripts/SUB2CSV
2023-07-02 10:19:56 -05:00
..
README.md r15ch13 contribution 2023-07-02 10:19:56 -05:00

Richard Kuhnt wrote the following:

I watched your video about the CSV conversion and that inspired me to write a small PowerShell function to do that.

# Converts Flipper SubGhz RAW Files to PSCustomObject[]
function ConvertFrom-SubGhzRAW {
    param(
        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
        [String] $Path
    )

    process {
        $data = Get-Content $Path
        if(!$data.Contains("Filetype: Flipper SubGhz RAW File")) {
            throw "$Path is not a Flipper SubGhz RAW File"
        }
        $data | Select-Object -Skip 5
        | ForEach-Object { $_.Replace("RAW_Data: ", "") }
        | Join-String -Separator " "
        | Select-String -Pattern '(\d+)\s(-\d+)' -AllMatches
        | ForEach-Object { $_.Matches }
        | ForEach-Object { [PSCustomObject]@{ Tone = $_.Groups[1]; Silence = $_.Groups[2] } }
    }
}

Copy and paste to console hit <Enter>, then run:

# convert one file
ConvertFrom-SubGhzRAW mysubfile.sub | ConvertTo-Csv | Out-File mycsvfile.csv
# convert every *.sub file in a directory
Get-ChildItem *.sub | ForEach-Object { ConvertFrom-Sub -Path $_ | ConvertTo-Csv | Out-File "$($_.BaseName).csv" }