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

120 строки
3.6KB

  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. Refinement *RefinementDebug `json:"refinement,omitempty"`
  19. Decisions *DecisionDebug `json:"decisions,omitempty"`
  20. }
  21. type RefinementWindowStats struct {
  22. Count int `json:"count"`
  23. MinSpan float64 `json:"min_span_hz"`
  24. MaxSpan float64 `json:"max_span_hz"`
  25. AvgSpan float64 `json:"avg_span_hz"`
  26. Sources map[string]int `json:"sources,omitempty"`
  27. }
  28. type RefinementDebug struct {
  29. Plan *pipeline.RefinementPlan `json:"plan,omitempty"`
  30. Request *pipeline.RefinementRequest `json:"request,omitempty"`
  31. WorkItems []pipeline.RefinementWorkItem `json:"work_items,omitempty"`
  32. Windows *RefinementWindowStats `json:"windows,omitempty"`
  33. Queue decisionQueueStats `json:"queue,omitempty"`
  34. Budgets *pipeline.BudgetModel `json:"budgets,omitempty"`
  35. Arbitration *ArbitrationSnapshot `json:"arbitration,omitempty"`
  36. }
  37. type DecisionDebug struct {
  38. Summary decisionSummary `json:"summary"`
  39. Items []compactDecision `json:"items,omitempty"`
  40. }
  41. type ArbitrationSnapshot struct {
  42. Budgets *pipeline.BudgetModel `json:"budgets,omitempty"`
  43. RefinementPlan *pipeline.RefinementPlan `json:"refinement_plan,omitempty"`
  44. Queue decisionQueueStats `json:"queue,omitempty"`
  45. DecisionSummary decisionSummary `json:"decision_summary,omitempty"`
  46. DecisionItems []compactDecision `json:"decision_items,omitempty"`
  47. }
  48. type SpectrumFrame struct {
  49. Timestamp int64 `json:"ts"`
  50. CenterHz float64 `json:"center_hz"`
  51. SampleHz int `json:"sample_rate"`
  52. FFTSize int `json:"fft_size"`
  53. Spectrum []float64 `json:"spectrum_db"`
  54. Signals []detector.Signal `json:"signals"`
  55. Debug *SpectrumDebug `json:"debug,omitempty"`
  56. }
  57. type client struct {
  58. conn *websocket.Conn
  59. send chan []byte
  60. done chan struct{}
  61. closeOnce sync.Once
  62. // Per-client settings (set via initial config message)
  63. binary bool // send binary spectrum frames instead of JSON
  64. maxBins int // target bin count (0 = full resolution)
  65. targetFps int // target frame rate (0 = full rate)
  66. frameSkip int // skip counter: send every N-th frame
  67. frameN int // current frame counter
  68. }
  69. type hub struct {
  70. mu sync.Mutex
  71. clients map[*client]struct{}
  72. frameCnt int64
  73. lastLogTs time.Time
  74. }
  75. type gpuStatus struct {
  76. mu sync.RWMutex
  77. Available bool `json:"available"`
  78. Active bool `json:"active"`
  79. Error string `json:"error"`
  80. }
  81. type signalSnapshot struct {
  82. mu sync.RWMutex
  83. signals []detector.Signal
  84. }
  85. type sourceManager struct {
  86. mu sync.RWMutex
  87. src sdr.Source
  88. newSource func(cfg config.Config) (sdr.Source, error)
  89. }
  90. type extractionManager struct {
  91. mu sync.Mutex
  92. runner *gpudemod.BatchRunner
  93. maxSamples int
  94. }
  95. type dspUpdate struct {
  96. cfg config.Config
  97. det *detector.Detector
  98. window []float64
  99. dcBlock bool
  100. iqBalance bool
  101. useGPUFFT bool
  102. }