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

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