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

639 строки
22KB

  1. package config
  2. import (
  3. "math"
  4. "os"
  5. "strings"
  6. "time"
  7. "gopkg.in/yaml.v3"
  8. )
  9. type Band struct {
  10. Name string `yaml:"name" json:"name"`
  11. StartHz float64 `yaml:"start_hz" json:"start_hz"`
  12. EndHz float64 `yaml:"end_hz" json:"end_hz"`
  13. }
  14. type MonitorWindow struct {
  15. Label string `yaml:"label" json:"label"`
  16. StartHz float64 `yaml:"start_hz" json:"start_hz"`
  17. EndHz float64 `yaml:"end_hz" json:"end_hz"`
  18. CenterHz float64 `yaml:"center_hz" json:"center_hz"`
  19. SpanHz float64 `yaml:"span_hz" json:"span_hz"`
  20. }
  21. type DetectorConfig struct {
  22. ThresholdDb float64 `yaml:"threshold_db" json:"threshold_db"`
  23. MinDurationMs int `yaml:"min_duration_ms" json:"min_duration_ms"`
  24. HoldMs int `yaml:"hold_ms" json:"hold_ms"`
  25. EmaAlpha float64 `yaml:"ema_alpha" json:"ema_alpha"`
  26. HysteresisDb float64 `yaml:"hysteresis_db" json:"hysteresis_db"`
  27. MinStableFrames int `yaml:"min_stable_frames" json:"min_stable_frames"`
  28. GapToleranceMs int `yaml:"gap_tolerance_ms" json:"gap_tolerance_ms"`
  29. CFARMode string `yaml:"cfar_mode" json:"cfar_mode"`
  30. CFARGuardHz float64 `yaml:"cfar_guard_hz" json:"cfar_guard_hz"`
  31. CFARTrainHz float64 `yaml:"cfar_train_hz" json:"cfar_train_hz"`
  32. CFARGuardCells int `yaml:"cfar_guard_cells,omitempty" json:"cfar_guard_cells,omitempty"`
  33. CFARTrainCells int `yaml:"cfar_train_cells,omitempty" json:"cfar_train_cells,omitempty"`
  34. CFARRank int `yaml:"cfar_rank" json:"cfar_rank"`
  35. CFARScaleDb float64 `yaml:"cfar_scale_db" json:"cfar_scale_db"`
  36. CFARWrapAround bool `yaml:"cfar_wrap_around" json:"cfar_wrap_around"`
  37. EdgeMarginDb float64 `yaml:"edge_margin_db" json:"edge_margin_db"`
  38. MaxSignalBwHz float64 `yaml:"max_signal_bw_hz" json:"max_signal_bw_hz"`
  39. MergeGapHz float64 `yaml:"merge_gap_hz" json:"merge_gap_hz"`
  40. ClassHistorySize int `yaml:"class_history_size" json:"class_history_size"`
  41. ClassSwitchRatio float64 `yaml:"class_switch_ratio" json:"class_switch_ratio"`
  42. // Deprecated (backward compatibility)
  43. CFAREnabled *bool `yaml:"cfar_enabled,omitempty" json:"cfar_enabled,omitempty"`
  44. }
  45. type RecorderConfig struct {
  46. Enabled bool `yaml:"enabled" json:"enabled"`
  47. MinSNRDb float64 `yaml:"min_snr_db" json:"min_snr_db"`
  48. MinDuration string `yaml:"min_duration" json:"min_duration"`
  49. MaxDuration string `yaml:"max_duration" json:"max_duration"`
  50. PrerollMs int `yaml:"preroll_ms" json:"preroll_ms"`
  51. RecordIQ bool `yaml:"record_iq" json:"record_iq"`
  52. RecordAudio bool `yaml:"record_audio" json:"record_audio"`
  53. AutoDemod bool `yaml:"auto_demod" json:"auto_demod"`
  54. AutoDecode bool `yaml:"auto_decode" json:"auto_decode"`
  55. MaxDiskMB int `yaml:"max_disk_mb" json:"max_disk_mb"`
  56. OutputDir string `yaml:"output_dir" json:"output_dir"`
  57. ClassFilter []string `yaml:"class_filter" json:"class_filter"`
  58. RingSeconds int `yaml:"ring_seconds" json:"ring_seconds"`
  59. // Audio quality settings (AQ-2, AQ-3, AQ-5)
  60. DeemphasisUs float64 `yaml:"deemphasis_us" json:"deemphasis_us"` // De-emphasis time constant in µs. 50=Europe, 75=US/Japan, 0=disabled. Default: 50
  61. ExtractionTaps int `yaml:"extraction_fir_taps" json:"extraction_fir_taps"` // FIR tap count for extraction filter. Default: 101, max 301
  62. ExtractionBwMult float64 `yaml:"extraction_bw_mult" json:"extraction_bw_mult"` // BW multiplier for extraction. Default: 1.2 (20% wider than detected)
  63. }
  64. type DecoderConfig struct {
  65. FT8Cmd string `yaml:"ft8_cmd" json:"ft8_cmd"`
  66. WSPRCmd string `yaml:"wspr_cmd" json:"wspr_cmd"`
  67. DMRCmd string `yaml:"dmr_cmd" json:"dmr_cmd"`
  68. DStarCmd string `yaml:"dstar_cmd" json:"dstar_cmd"`
  69. FSKCmd string `yaml:"fsk_cmd" json:"fsk_cmd"`
  70. PSKCmd string `yaml:"psk_cmd" json:"psk_cmd"`
  71. }
  72. type PipelineGoalConfig struct {
  73. Intent string `yaml:"intent" json:"intent"`
  74. MonitorStartHz float64 `yaml:"monitor_start_hz" json:"monitor_start_hz"`
  75. MonitorEndHz float64 `yaml:"monitor_end_hz" json:"monitor_end_hz"`
  76. MonitorSpanHz float64 `yaml:"monitor_span_hz" json:"monitor_span_hz"`
  77. MonitorWindows []MonitorWindow `yaml:"monitor_windows" json:"monitor_windows"`
  78. SignalPriorities []string `yaml:"signal_priorities" json:"signal_priorities"`
  79. AutoRecordClasses []string `yaml:"auto_record_classes" json:"auto_record_classes"`
  80. AutoDecodeClasses []string `yaml:"auto_decode_classes" json:"auto_decode_classes"`
  81. }
  82. type PipelineConfig struct {
  83. Mode string `yaml:"mode" json:"mode"`
  84. Profile string `yaml:"profile,omitempty" json:"profile,omitempty"`
  85. Goals PipelineGoalConfig `yaml:"goals" json:"goals"`
  86. }
  87. type SurveillanceConfig struct {
  88. AnalysisFFTSize int `yaml:"analysis_fft_size" json:"analysis_fft_size"`
  89. FrameRate int `yaml:"frame_rate" json:"frame_rate"`
  90. Strategy string `yaml:"strategy" json:"strategy"`
  91. DisplayBins int `yaml:"display_bins" json:"display_bins"`
  92. DisplayFPS int `yaml:"display_fps" json:"display_fps"`
  93. DerivedDetection string `yaml:"derived_detection" json:"derived_detection"`
  94. }
  95. type RefinementConfig struct {
  96. Enabled bool `yaml:"enabled" json:"enabled"`
  97. MaxConcurrent int `yaml:"max_concurrent" json:"max_concurrent"`
  98. DetailFFTSize int `yaml:"detail_fft_size" json:"detail_fft_size"`
  99. MinCandidateSNRDb float64 `yaml:"min_candidate_snr_db" json:"min_candidate_snr_db"`
  100. MinSpanHz float64 `yaml:"min_span_hz" json:"min_span_hz"`
  101. MaxSpanHz float64 `yaml:"max_span_hz" json:"max_span_hz"`
  102. AutoSpan *bool `yaml:"auto_span" json:"auto_span"`
  103. }
  104. type ResourceConfig struct {
  105. PreferGPU bool `yaml:"prefer_gpu" json:"prefer_gpu"`
  106. MaxRefinementJobs int `yaml:"max_refinement_jobs" json:"max_refinement_jobs"`
  107. MaxRecordingStreams int `yaml:"max_recording_streams" json:"max_recording_streams"`
  108. MaxDecodeJobs int `yaml:"max_decode_jobs" json:"max_decode_jobs"`
  109. DecisionHoldMs int `yaml:"decision_hold_ms" json:"decision_hold_ms"`
  110. }
  111. type ProfileConfig struct {
  112. Name string `yaml:"name" json:"name"`
  113. Description string `yaml:"description" json:"description"`
  114. Pipeline *PipelineConfig `yaml:"pipeline,omitempty" json:"pipeline,omitempty"`
  115. Surveillance *SurveillanceConfig `yaml:"surveillance,omitempty" json:"surveillance,omitempty"`
  116. Refinement *RefinementConfig `yaml:"refinement,omitempty" json:"refinement,omitempty"`
  117. Resources *ResourceConfig `yaml:"resources,omitempty" json:"resources,omitempty"`
  118. }
  119. type Config struct {
  120. Bands []Band `yaml:"bands" json:"bands"`
  121. CenterHz float64 `yaml:"center_hz" json:"center_hz"`
  122. SampleRate int `yaml:"sample_rate" json:"sample_rate"`
  123. FFTSize int `yaml:"fft_size" json:"fft_size"`
  124. GainDb float64 `yaml:"gain_db" json:"gain_db"`
  125. TunerBwKHz int `yaml:"tuner_bw_khz" json:"tuner_bw_khz"`
  126. UseGPUFFT bool `yaml:"use_gpu_fft" json:"use_gpu_fft"`
  127. ClassifierMode string `yaml:"classifier_mode" json:"classifier_mode"`
  128. AGC bool `yaml:"agc" json:"agc"`
  129. DCBlock bool `yaml:"dc_block" json:"dc_block"`
  130. IQBalance bool `yaml:"iq_balance" json:"iq_balance"`
  131. Pipeline PipelineConfig `yaml:"pipeline" json:"pipeline"`
  132. Surveillance SurveillanceConfig `yaml:"surveillance" json:"surveillance"`
  133. Refinement RefinementConfig `yaml:"refinement" json:"refinement"`
  134. Resources ResourceConfig `yaml:"resources" json:"resources"`
  135. Profiles []ProfileConfig `yaml:"profiles" json:"profiles"`
  136. Detector DetectorConfig `yaml:"detector" json:"detector"`
  137. Recorder RecorderConfig `yaml:"recorder" json:"recorder"`
  138. Decoder DecoderConfig `yaml:"decoder" json:"decoder"`
  139. WebAddr string `yaml:"web_addr" json:"web_addr"`
  140. EventPath string `yaml:"event_path" json:"event_path"`
  141. FrameRate int `yaml:"frame_rate" json:"frame_rate"`
  142. WaterfallLines int `yaml:"waterfall_lines" json:"waterfall_lines"`
  143. WebRoot string `yaml:"web_root" json:"web_root"`
  144. }
  145. func Default() Config {
  146. return Config{
  147. Bands: []Band{
  148. {Name: "example", StartHz: 99.5e6, EndHz: 100.5e6},
  149. },
  150. CenterHz: 100.0e6,
  151. SampleRate: 2_048_000,
  152. FFTSize: 2048,
  153. GainDb: 30,
  154. TunerBwKHz: 1536,
  155. UseGPUFFT: false,
  156. ClassifierMode: "combined",
  157. AGC: false,
  158. DCBlock: false,
  159. IQBalance: false,
  160. Pipeline: PipelineConfig{
  161. Mode: "legacy",
  162. Goals: PipelineGoalConfig{
  163. Intent: "general-monitoring",
  164. },
  165. },
  166. Surveillance: SurveillanceConfig{
  167. AnalysisFFTSize: 2048,
  168. FrameRate: 15,
  169. Strategy: "single-resolution",
  170. DisplayBins: 2048,
  171. DisplayFPS: 15,
  172. DerivedDetection: "auto",
  173. },
  174. Refinement: RefinementConfig{
  175. Enabled: true,
  176. MaxConcurrent: 8,
  177. DetailFFTSize: 0,
  178. MinCandidateSNRDb: 0,
  179. MinSpanHz: 0,
  180. MaxSpanHz: 0,
  181. AutoSpan: boolPtr(true),
  182. },
  183. Resources: ResourceConfig{
  184. PreferGPU: true,
  185. MaxRefinementJobs: 8,
  186. MaxRecordingStreams: 16,
  187. MaxDecodeJobs: 16,
  188. DecisionHoldMs: 2000,
  189. },
  190. Profiles: []ProfileConfig{
  191. {
  192. Name: "legacy",
  193. Description: "Current single-band pipeline behavior",
  194. Pipeline: &PipelineConfig{Mode: "legacy", Profile: "legacy", Goals: PipelineGoalConfig{Intent: "general-monitoring"}},
  195. Surveillance: &SurveillanceConfig{
  196. AnalysisFFTSize: 2048,
  197. FrameRate: 15,
  198. Strategy: "single-resolution",
  199. DisplayBins: 2048,
  200. DisplayFPS: 15,
  201. DerivedDetection: "auto",
  202. },
  203. Refinement: &RefinementConfig{
  204. Enabled: true,
  205. MaxConcurrent: 8,
  206. DetailFFTSize: 0,
  207. MinCandidateSNRDb: 0,
  208. MinSpanHz: 0,
  209. MaxSpanHz: 0,
  210. AutoSpan: boolPtr(true),
  211. },
  212. Resources: &ResourceConfig{
  213. PreferGPU: false,
  214. MaxRefinementJobs: 8,
  215. MaxRecordingStreams: 16,
  216. MaxDecodeJobs: 16,
  217. DecisionHoldMs: 2000,
  218. },
  219. },
  220. {
  221. Name: "wideband-balanced",
  222. Description: "Baseline multi-resolution wideband surveillance",
  223. Pipeline: &PipelineConfig{Mode: "wideband-balanced", Profile: "wideband-balanced", Goals: PipelineGoalConfig{
  224. Intent: "wideband-surveillance",
  225. SignalPriorities: []string{"digital", "wfm"},
  226. }},
  227. Surveillance: &SurveillanceConfig{
  228. AnalysisFFTSize: 4096,
  229. FrameRate: 12,
  230. Strategy: "multi-resolution",
  231. DisplayBins: 2048,
  232. DisplayFPS: 12,
  233. DerivedDetection: "auto",
  234. },
  235. Refinement: &RefinementConfig{
  236. Enabled: true,
  237. MaxConcurrent: 16,
  238. DetailFFTSize: 0,
  239. MinCandidateSNRDb: 0,
  240. MinSpanHz: 4000,
  241. MaxSpanHz: 200000,
  242. AutoSpan: boolPtr(true),
  243. },
  244. Resources: &ResourceConfig{
  245. PreferGPU: true,
  246. MaxRefinementJobs: 16,
  247. MaxRecordingStreams: 16,
  248. MaxDecodeJobs: 12,
  249. DecisionHoldMs: 2000,
  250. },
  251. },
  252. {
  253. Name: "wideband-aggressive",
  254. Description: "Higher surveillance/refinement budgets for dense wideband monitoring",
  255. Pipeline: &PipelineConfig{Mode: "wideband-aggressive", Profile: "wideband-aggressive", Goals: PipelineGoalConfig{
  256. Intent: "high-density-wideband-surveillance",
  257. SignalPriorities: []string{"digital", "wfm", "trunk"},
  258. }},
  259. Surveillance: &SurveillanceConfig{
  260. AnalysisFFTSize: 8192,
  261. FrameRate: 10,
  262. Strategy: "multi-resolution",
  263. DisplayBins: 4096,
  264. DisplayFPS: 10,
  265. DerivedDetection: "auto",
  266. },
  267. Refinement: &RefinementConfig{
  268. Enabled: true,
  269. MaxConcurrent: 32,
  270. DetailFFTSize: 0,
  271. MinCandidateSNRDb: 0,
  272. MinSpanHz: 6000,
  273. MaxSpanHz: 250000,
  274. AutoSpan: boolPtr(true),
  275. },
  276. Resources: &ResourceConfig{
  277. PreferGPU: true,
  278. MaxRefinementJobs: 32,
  279. MaxRecordingStreams: 24,
  280. MaxDecodeJobs: 16,
  281. DecisionHoldMs: 2000,
  282. },
  283. },
  284. {
  285. Name: "archive",
  286. Description: "Record-first monitoring profile",
  287. Pipeline: &PipelineConfig{Mode: "archive", Profile: "archive", Goals: PipelineGoalConfig{
  288. Intent: "archive-and-triage",
  289. SignalPriorities: []string{"wfm", "nfm", "digital"},
  290. }},
  291. Surveillance: &SurveillanceConfig{
  292. AnalysisFFTSize: 4096,
  293. FrameRate: 12,
  294. Strategy: "single-resolution",
  295. DisplayBins: 2048,
  296. DisplayFPS: 12,
  297. DerivedDetection: "auto",
  298. },
  299. Refinement: &RefinementConfig{
  300. Enabled: true,
  301. MaxConcurrent: 12,
  302. DetailFFTSize: 0,
  303. MinCandidateSNRDb: 0,
  304. MinSpanHz: 4000,
  305. MaxSpanHz: 200000,
  306. AutoSpan: boolPtr(true),
  307. },
  308. Resources: &ResourceConfig{
  309. PreferGPU: true,
  310. MaxRefinementJobs: 12,
  311. MaxRecordingStreams: 24,
  312. MaxDecodeJobs: 12,
  313. DecisionHoldMs: 2500,
  314. },
  315. },
  316. {
  317. Name: "digital-hunting",
  318. Description: "Digital-first refinement and decode focus",
  319. Pipeline: &PipelineConfig{Mode: "digital-hunting", Profile: "digital-hunting", Goals: PipelineGoalConfig{
  320. Intent: "digital-surveillance",
  321. SignalPriorities: []string{"ft8", "wspr", "fsk", "psk", "dmr"},
  322. }},
  323. Surveillance: &SurveillanceConfig{
  324. AnalysisFFTSize: 4096,
  325. FrameRate: 12,
  326. Strategy: "multi-resolution",
  327. DisplayBins: 2048,
  328. DisplayFPS: 12,
  329. DerivedDetection: "auto",
  330. },
  331. Refinement: &RefinementConfig{
  332. Enabled: true,
  333. MaxConcurrent: 16,
  334. DetailFFTSize: 0,
  335. MinCandidateSNRDb: 0,
  336. MinSpanHz: 3000,
  337. MaxSpanHz: 120000,
  338. AutoSpan: boolPtr(true),
  339. },
  340. Resources: &ResourceConfig{
  341. PreferGPU: true,
  342. MaxRefinementJobs: 16,
  343. MaxRecordingStreams: 12,
  344. MaxDecodeJobs: 16,
  345. DecisionHoldMs: 2000,
  346. },
  347. },
  348. },
  349. Detector: DetectorConfig{
  350. ThresholdDb: -20,
  351. MinDurationMs: 250,
  352. HoldMs: 500,
  353. EmaAlpha: 0.2,
  354. HysteresisDb: 3,
  355. MinStableFrames: 3,
  356. GapToleranceMs: 500,
  357. CFARMode: "GOSCA",
  358. CFARGuardHz: 500,
  359. CFARTrainHz: 5000,
  360. CFARGuardCells: 3,
  361. CFARTrainCells: 24,
  362. CFARRank: 36,
  363. CFARScaleDb: 6,
  364. CFARWrapAround: true,
  365. EdgeMarginDb: 3.0,
  366. MaxSignalBwHz: 150000,
  367. MergeGapHz: 5000,
  368. ClassHistorySize: 10,
  369. ClassSwitchRatio: 0.6,
  370. },
  371. Recorder: RecorderConfig{
  372. Enabled: false,
  373. MinSNRDb: 10,
  374. MinDuration: "1s",
  375. MaxDuration: "300s",
  376. PrerollMs: 500,
  377. RecordIQ: true,
  378. RecordAudio: false,
  379. AutoDemod: true,
  380. AutoDecode: false,
  381. MaxDiskMB: 0,
  382. OutputDir: "data/recordings",
  383. RingSeconds: 8,
  384. DeemphasisUs: 50,
  385. ExtractionTaps: 101,
  386. ExtractionBwMult: 1.2,
  387. },
  388. Decoder: DecoderConfig{},
  389. WebAddr: ":8080",
  390. EventPath: "data/events.jsonl",
  391. FrameRate: 15,
  392. WaterfallLines: 200,
  393. WebRoot: "web",
  394. }
  395. }
  396. func Load(path string) (Config, error) {
  397. cfg := Default()
  398. if b, err := os.ReadFile(autosavePath(path)); err == nil {
  399. if err := yaml.Unmarshal(b, &cfg); err == nil {
  400. return applyDefaults(cfg), nil
  401. }
  402. }
  403. b, err := os.ReadFile(path)
  404. if err != nil {
  405. return cfg, err
  406. }
  407. if err := yaml.Unmarshal(b, &cfg); err != nil {
  408. return cfg, err
  409. }
  410. return applyDefaults(cfg), nil
  411. }
  412. func applyDefaults(cfg Config) Config {
  413. if cfg.Detector.MinDurationMs <= 0 {
  414. cfg.Detector.MinDurationMs = 250
  415. }
  416. if cfg.Detector.HoldMs <= 0 {
  417. cfg.Detector.HoldMs = 500
  418. }
  419. if cfg.Detector.MinStableFrames <= 0 {
  420. cfg.Detector.MinStableFrames = 3
  421. }
  422. if cfg.Detector.GapToleranceMs <= 0 {
  423. cfg.Detector.GapToleranceMs = cfg.Detector.HoldMs
  424. }
  425. if cfg.Detector.CFARMode == "" {
  426. if cfg.Detector.CFAREnabled != nil {
  427. if *cfg.Detector.CFAREnabled {
  428. cfg.Detector.CFARMode = "OS"
  429. } else {
  430. cfg.Detector.CFARMode = "OFF"
  431. }
  432. } else {
  433. cfg.Detector.CFARMode = "GOSCA"
  434. }
  435. }
  436. if cfg.Detector.CFARGuardHz <= 0 && cfg.Detector.CFARGuardCells > 0 {
  437. cfg.Detector.CFARGuardHz = float64(cfg.Detector.CFARGuardCells) * 62.5
  438. }
  439. if cfg.Detector.CFARTrainHz <= 0 && cfg.Detector.CFARTrainCells > 0 {
  440. cfg.Detector.CFARTrainHz = float64(cfg.Detector.CFARTrainCells) * 62.5
  441. }
  442. if cfg.Detector.CFARGuardHz <= 0 {
  443. cfg.Detector.CFARGuardHz = 500
  444. }
  445. if cfg.Detector.CFARTrainHz <= 0 {
  446. cfg.Detector.CFARTrainHz = 5000
  447. }
  448. if cfg.Detector.CFARGuardCells <= 0 {
  449. cfg.Detector.CFARGuardCells = 3
  450. }
  451. if cfg.Detector.CFARTrainCells <= 0 {
  452. cfg.Detector.CFARTrainCells = 24
  453. }
  454. if cfg.Detector.CFARRank <= 0 || cfg.Detector.CFARRank > 2*cfg.Detector.CFARTrainCells {
  455. cfg.Detector.CFARRank = int(math.Round(0.75 * float64(2*cfg.Detector.CFARTrainCells)))
  456. if cfg.Detector.CFARRank <= 0 {
  457. cfg.Detector.CFARRank = 1
  458. }
  459. }
  460. if cfg.Detector.CFARScaleDb <= 0 {
  461. cfg.Detector.CFARScaleDb = 6
  462. }
  463. if cfg.Detector.EdgeMarginDb <= 0 {
  464. cfg.Detector.EdgeMarginDb = 3.0
  465. }
  466. if cfg.Detector.MaxSignalBwHz <= 0 {
  467. cfg.Detector.MaxSignalBwHz = 150000
  468. }
  469. if cfg.Detector.MergeGapHz <= 0 {
  470. cfg.Detector.MergeGapHz = 5000
  471. }
  472. if cfg.Detector.ClassHistorySize <= 0 {
  473. cfg.Detector.ClassHistorySize = 10
  474. }
  475. if cfg.Detector.ClassSwitchRatio <= 0 || cfg.Detector.ClassSwitchRatio > 1 {
  476. cfg.Detector.ClassSwitchRatio = 0.6
  477. }
  478. if cfg.Pipeline.Mode == "" {
  479. cfg.Pipeline.Mode = "legacy"
  480. }
  481. if cfg.Pipeline.Goals.Intent == "" {
  482. cfg.Pipeline.Goals.Intent = "general-monitoring"
  483. }
  484. if cfg.Pipeline.Goals.MonitorSpanHz <= 0 && cfg.Pipeline.Goals.MonitorStartHz != 0 && cfg.Pipeline.Goals.MonitorEndHz != 0 && cfg.Pipeline.Goals.MonitorEndHz > cfg.Pipeline.Goals.MonitorStartHz {
  485. cfg.Pipeline.Goals.MonitorSpanHz = cfg.Pipeline.Goals.MonitorEndHz - cfg.Pipeline.Goals.MonitorStartHz
  486. }
  487. if cfg.Surveillance.AnalysisFFTSize <= 0 {
  488. cfg.Surveillance.AnalysisFFTSize = cfg.FFTSize
  489. }
  490. if cfg.Surveillance.FrameRate <= 0 {
  491. cfg.Surveillance.FrameRate = cfg.FrameRate
  492. }
  493. if cfg.Surveillance.Strategy == "" {
  494. cfg.Surveillance.Strategy = "single-resolution"
  495. }
  496. if cfg.Surveillance.DerivedDetection == "" {
  497. cfg.Surveillance.DerivedDetection = "auto"
  498. }
  499. switch strings.ToLower(strings.TrimSpace(cfg.Surveillance.DerivedDetection)) {
  500. case "auto", "on", "off", "true", "false", "enabled", "disabled", "enable", "disable":
  501. default:
  502. cfg.Surveillance.DerivedDetection = "auto"
  503. }
  504. if cfg.Surveillance.DisplayBins <= 0 {
  505. cfg.Surveillance.DisplayBins = cfg.FFTSize
  506. }
  507. if cfg.Surveillance.DisplayFPS <= 0 {
  508. cfg.Surveillance.DisplayFPS = cfg.FrameRate
  509. }
  510. if !cfg.Refinement.Enabled {
  511. // keep explicit false if user disabled it; enable by default only when unset-like zero config
  512. if cfg.Refinement.MaxConcurrent == 0 && cfg.Refinement.MinCandidateSNRDb == 0 {
  513. cfg.Refinement.Enabled = true
  514. }
  515. }
  516. if cfg.Refinement.MaxConcurrent <= 0 {
  517. cfg.Refinement.MaxConcurrent = 8
  518. }
  519. if cfg.Refinement.DetailFFTSize <= 0 {
  520. cfg.Refinement.DetailFFTSize = cfg.Surveillance.AnalysisFFTSize
  521. }
  522. if cfg.Refinement.DetailFFTSize&(cfg.Refinement.DetailFFTSize-1) != 0 {
  523. cfg.Refinement.DetailFFTSize = cfg.Surveillance.AnalysisFFTSize
  524. }
  525. if cfg.Refinement.MinSpanHz < 0 {
  526. cfg.Refinement.MinSpanHz = 0
  527. }
  528. if cfg.Refinement.MaxSpanHz < 0 {
  529. cfg.Refinement.MaxSpanHz = 0
  530. }
  531. if cfg.Refinement.MaxSpanHz > 0 && cfg.Refinement.MinSpanHz > cfg.Refinement.MaxSpanHz {
  532. cfg.Refinement.MaxSpanHz = cfg.Refinement.MinSpanHz
  533. }
  534. if cfg.Refinement.AutoSpan == nil {
  535. cfg.Refinement.AutoSpan = boolPtr(true)
  536. }
  537. if cfg.Resources.MaxRefinementJobs <= 0 {
  538. cfg.Resources.MaxRefinementJobs = cfg.Refinement.MaxConcurrent
  539. }
  540. if cfg.Resources.MaxRecordingStreams <= 0 {
  541. cfg.Resources.MaxRecordingStreams = 16
  542. }
  543. if cfg.Resources.DecisionHoldMs < 0 {
  544. cfg.Resources.DecisionHoldMs = 0
  545. }
  546. if cfg.Resources.DecisionHoldMs == 0 {
  547. cfg.Resources.DecisionHoldMs = 2000
  548. }
  549. if cfg.FrameRate <= 0 {
  550. cfg.FrameRate = 15
  551. }
  552. if cfg.WaterfallLines <= 0 {
  553. cfg.WaterfallLines = 200
  554. }
  555. if cfg.WebRoot == "" {
  556. cfg.WebRoot = "web"
  557. }
  558. if cfg.WebAddr == "" {
  559. cfg.WebAddr = ":8080"
  560. }
  561. if cfg.EventPath == "" {
  562. cfg.EventPath = "data/events.jsonl"
  563. }
  564. if cfg.SampleRate <= 0 {
  565. cfg.SampleRate = 2_048_000
  566. }
  567. if cfg.ClassifierMode == "" {
  568. cfg.ClassifierMode = "combined"
  569. }
  570. switch cfg.ClassifierMode {
  571. case "rule", "math", "combined":
  572. default:
  573. cfg.ClassifierMode = "combined"
  574. }
  575. if cfg.FFTSize <= 0 {
  576. cfg.FFTSize = 2048
  577. }
  578. if cfg.Surveillance.AnalysisFFTSize > 0 {
  579. cfg.FFTSize = cfg.Surveillance.AnalysisFFTSize
  580. } else {
  581. cfg.Surveillance.AnalysisFFTSize = cfg.FFTSize
  582. }
  583. if cfg.TunerBwKHz <= 0 {
  584. cfg.TunerBwKHz = 1536
  585. }
  586. if cfg.CenterHz == 0 {
  587. cfg.CenterHz = 100.0e6
  588. }
  589. if cfg.Recorder.OutputDir == "" {
  590. cfg.Recorder.OutputDir = "data/recordings"
  591. }
  592. if cfg.Recorder.RingSeconds <= 0 {
  593. cfg.Recorder.RingSeconds = 8
  594. }
  595. if cfg.Recorder.DeemphasisUs == 0 {
  596. cfg.Recorder.DeemphasisUs = 50
  597. }
  598. if cfg.Recorder.ExtractionTaps <= 0 {
  599. cfg.Recorder.ExtractionTaps = 101
  600. }
  601. if cfg.Recorder.ExtractionTaps > 301 {
  602. cfg.Recorder.ExtractionTaps = 301
  603. }
  604. if cfg.Recorder.ExtractionTaps%2 == 0 {
  605. cfg.Recorder.ExtractionTaps++ // must be odd
  606. }
  607. if cfg.Recorder.ExtractionBwMult <= 0 {
  608. cfg.Recorder.ExtractionBwMult = 1.2
  609. }
  610. return cfg
  611. }
  612. func (c Config) FrameInterval() time.Duration {
  613. fps := c.FrameRate
  614. if fps <= 0 {
  615. fps = 15
  616. }
  617. return time.Second / time.Duration(fps)
  618. }