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

124 строки
4.1KB

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