From effb5d9f2db2a5a9041ddf196d8c43ad9ab09372 Mon Sep 17 00:00:00 2001 From: Jan Svabenik Date: Wed, 18 Mar 2026 07:38:51 +0100 Subject: [PATCH] Add on-demand decode endpoint --- cmd/sdrd/main.go | 20 ++++++++++++++++++++ internal/recorder/decode_on_demand.go | 14 ++++++++++++++ internal/recorder/readmeta.go | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 internal/recorder/decode_on_demand.go create mode 100644 internal/recorder/readmeta.go diff --git a/cmd/sdrd/main.go b/cmd/sdrd/main.go index 31640e0..9f0ae22 100644 --- a/cmd/sdrd/main.go +++ b/cmd/sdrd/main.go @@ -524,6 +524,26 @@ func main() { http.ServeFile(w, r, filepath.Join(base, "signal.cf32")) return } + if r.URL.Path == "/api/recordings/"+id+"/decode" { + mode := r.URL.Query().Get("mode") + cmd := buildDecoderMap(cfgManager.Snapshot())[mode] + if cmd == "" { + http.Error(w, "decoder not configured", http.StatusBadRequest) + return + } + meta, err := recorder.ReadMeta(filepath.Join(base, "meta.json")) + if err != nil { + http.Error(w, "meta read failed", http.StatusInternalServerError) + return + } + res, err := recorder.DecodeOnDemand(cmd, filepath.Join(base, "signal.cf32"), meta.SampleRate) + if err != nil { + http.Error(w, res.Stderr, http.StatusInternalServerError) + return + } + _ = json.NewEncoder(w).Encode(res) + return + } // default: meta.json http.ServeFile(w, r, filepath.Join(base, "meta.json")) }) diff --git a/internal/recorder/decode_on_demand.go b/internal/recorder/decode_on_demand.go new file mode 100644 index 0000000..96fdaa2 --- /dev/null +++ b/internal/recorder/decode_on_demand.go @@ -0,0 +1,14 @@ +package recorder + +import ( + "errors" + + "sdr-visual-suite/internal/decoder" +) + +func DecodeOnDemand(cmd string, iqPath string, sampleRate int) (decoder.Result, error) { + if cmd == "" { + return decoder.Result{}, errors.New("decoder command empty") + } + return decoder.Run(cmd, iqPath, sampleRate) +} diff --git a/internal/recorder/readmeta.go b/internal/recorder/readmeta.go new file mode 100644 index 0000000..e82c6fc --- /dev/null +++ b/internal/recorder/readmeta.go @@ -0,0 +1,18 @@ +package recorder + +import ( + "encoding/json" + "os" +) + +func ReadMeta(path string) (Meta, error) { + b, err := os.ReadFile(path) + if err != nil { + return Meta{}, err + } + var m Meta + if err := json.Unmarshal(b, &m); err != nil { + return Meta{}, err + } + return m, nil +}