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

127 строки
4.5KB

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