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

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