Wideband autonomous SDR analysis engine forked from sdr-visual-suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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