Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

95 рядки
2.4KB

  1. package main
  2. import (
  3. "sync"
  4. "time"
  5. "github.com/gorilla/websocket"
  6. "sdr-wideband-suite/internal/config"
  7. "sdr-wideband-suite/internal/demod/gpudemod"
  8. "sdr-wideband-suite/internal/detector"
  9. "sdr-wideband-suite/internal/pipeline"
  10. "sdr-wideband-suite/internal/sdr"
  11. )
  12. type SpectrumDebug struct {
  13. Thresholds []float64 `json:"thresholds,omitempty"`
  14. NoiseFloor float64 `json:"noise_floor,omitempty"`
  15. Scores []map[string]any `json:"scores,omitempty"`
  16. RefinementPlan *pipeline.RefinementPlan `json:"refinement_plan,omitempty"`
  17. Windows *RefinementWindowStats `json:"refinement_windows,omitempty"`
  18. }
  19. type RefinementWindowStats struct {
  20. Count int `json:"count"`
  21. MinSpan float64 `json:"min_span_hz"`
  22. MaxSpan float64 `json:"max_span_hz"`
  23. AvgSpan float64 `json:"avg_span_hz"`
  24. Sources map[string]int `json:"sources,omitempty"`
  25. }
  26. type SpectrumFrame struct {
  27. Timestamp int64 `json:"ts"`
  28. CenterHz float64 `json:"center_hz"`
  29. SampleHz int `json:"sample_rate"`
  30. FFTSize int `json:"fft_size"`
  31. Spectrum []float64 `json:"spectrum_db"`
  32. Signals []detector.Signal `json:"signals"`
  33. Debug *SpectrumDebug `json:"debug,omitempty"`
  34. }
  35. type client struct {
  36. conn *websocket.Conn
  37. send chan []byte
  38. done chan struct{}
  39. closeOnce sync.Once
  40. // Per-client settings (set via initial config message)
  41. binary bool // send binary spectrum frames instead of JSON
  42. maxBins int // target bin count (0 = full resolution)
  43. targetFps int // target frame rate (0 = full rate)
  44. frameSkip int // skip counter: send every N-th frame
  45. frameN int // current frame counter
  46. }
  47. type hub struct {
  48. mu sync.Mutex
  49. clients map[*client]struct{}
  50. frameCnt int64
  51. lastLogTs time.Time
  52. }
  53. type gpuStatus struct {
  54. mu sync.RWMutex
  55. Available bool `json:"available"`
  56. Active bool `json:"active"`
  57. Error string `json:"error"`
  58. }
  59. type signalSnapshot struct {
  60. mu sync.RWMutex
  61. signals []detector.Signal
  62. }
  63. type sourceManager struct {
  64. mu sync.RWMutex
  65. src sdr.Source
  66. newSource func(cfg config.Config) (sdr.Source, error)
  67. }
  68. type extractionManager struct {
  69. mu sync.Mutex
  70. runner *gpudemod.BatchRunner
  71. maxSamples int
  72. }
  73. type dspUpdate struct {
  74. cfg config.Config
  75. det *detector.Detector
  76. window []float64
  77. dcBlock bool
  78. iqBalance bool
  79. useGPUFFT bool
  80. }