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

122 строки
4.0KB

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