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

630 строки
21KB

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