Procházet zdrojové kódy

Add on-demand decode endpoint

master
Jan Svabenik před 3 dny
rodič
revize
effb5d9f2d
3 změnil soubory, kde provedl 52 přidání a 0 odebrání
  1. +20
    -0
      cmd/sdrd/main.go
  2. +14
    -0
      internal/recorder/decode_on_demand.go
  3. +18
    -0
      internal/recorder/readmeta.go

+ 20
- 0
cmd/sdrd/main.go Zobrazit soubor

@@ -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"))
})


+ 14
- 0
internal/recorder/decode_on_demand.go Zobrazit soubor

@@ -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)
}

+ 18
- 0
internal/recorder/readmeta.go Zobrazit soubor

@@ -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
}

Načítá se…
Zrušit
Uložit