jamisonderek / flipper-zero-tutorials

See README.md for link to Discord & YouTube. I will use this repository for my Flipper Zero projects & wiki.
MIT License
768 stars 59 forks source link

PowerShell function for converting Flipper SubGhz RAW Files #10

Closed r15ch13 closed 1 year ago

r15ch13 commented 1 year ago

I watched your video about the CSV conversion and that inspired me to write a small PowerShell function to do that. (Tried to comment on the video but it got deleted because of the link, I guess)

https://gist.github.com/r15ch13/0f82e368003a1e0150f97dc585fa2527

# 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" }
jamisonderek commented 1 year ago

Thanks again for the script. I'm closing this issue, as I have https://github.com/jamisonderek/flipper-zero-tutorials/tree/main/subghz/scripts/SUB2CSV in the main branch.