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

601 строка
20KB

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