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

127 строки
3.8KB

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