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

114 строки
2.9KB

  1. package config
  2. import (
  3. "os"
  4. "time"
  5. "gopkg.in/yaml.v3"
  6. )
  7. type Band struct {
  8. Name string `yaml:"name" json:"name"`
  9. StartHz float64 `yaml:"start_hz" json:"start_hz"`
  10. EndHz float64 `yaml:"end_hz" json:"end_hz"`
  11. }
  12. type DetectorConfig struct {
  13. ThresholdDb float64 `yaml:"threshold_db" json:"threshold_db"`
  14. MinDurationMs int `yaml:"min_duration_ms" json:"min_duration_ms"`
  15. HoldMs int `yaml:"hold_ms" json:"hold_ms"`
  16. }
  17. type Config struct {
  18. Bands []Band `yaml:"bands" json:"bands"`
  19. CenterHz float64 `yaml:"center_hz" json:"center_hz"`
  20. SampleRate int `yaml:"sample_rate" json:"sample_rate"`
  21. FFTSize int `yaml:"fft_size" json:"fft_size"`
  22. GainDb float64 `yaml:"gain_db" json:"gain_db"`
  23. TunerBwKHz int `yaml:"tuner_bw_khz" json:"tuner_bw_khz"`
  24. AGC bool `yaml:"agc" json:"agc"`
  25. DCBlock bool `yaml:"dc_block" json:"dc_block"`
  26. IQBalance bool `yaml:"iq_balance" json:"iq_balance"`
  27. Detector DetectorConfig `yaml:"detector" json:"detector"`
  28. WebAddr string `yaml:"web_addr" json:"web_addr"`
  29. EventPath string `yaml:"event_path" json:"event_path"`
  30. FrameRate int `yaml:"frame_rate" json:"frame_rate"`
  31. WaterfallLines int `yaml:"waterfall_lines" json:"waterfall_lines"`
  32. WebRoot string `yaml:"web_root" json:"web_root"`
  33. }
  34. func Default() Config {
  35. return Config{
  36. Bands: []Band{
  37. {Name: "example", StartHz: 99.5e6, EndHz: 100.5e6},
  38. },
  39. CenterHz: 100.0e6,
  40. SampleRate: 2_048_000,
  41. FFTSize: 2048,
  42. GainDb: 30,
  43. TunerBwKHz: 1536,
  44. AGC: false,
  45. DCBlock: false,
  46. IQBalance: false,
  47. Detector: DetectorConfig{ThresholdDb: -20, MinDurationMs: 250, HoldMs: 500},
  48. WebAddr: ":8080",
  49. EventPath: "data/events.jsonl",
  50. FrameRate: 15,
  51. WaterfallLines: 200,
  52. WebRoot: "web",
  53. }
  54. }
  55. func Load(path string) (Config, error) {
  56. cfg := Default()
  57. b, err := os.ReadFile(path)
  58. if err != nil {
  59. return cfg, err
  60. }
  61. if err := yaml.Unmarshal(b, &cfg); err != nil {
  62. return cfg, err
  63. }
  64. if cfg.Detector.MinDurationMs <= 0 {
  65. cfg.Detector.MinDurationMs = 250
  66. }
  67. if cfg.Detector.HoldMs <= 0 {
  68. cfg.Detector.HoldMs = 500
  69. }
  70. if cfg.FrameRate <= 0 {
  71. cfg.FrameRate = 15
  72. }
  73. if cfg.WaterfallLines <= 0 {
  74. cfg.WaterfallLines = 200
  75. }
  76. if cfg.WebRoot == "" {
  77. cfg.WebRoot = "web"
  78. }
  79. if cfg.WebAddr == "" {
  80. cfg.WebAddr = ":8080"
  81. }
  82. if cfg.EventPath == "" {
  83. cfg.EventPath = "data/events.jsonl"
  84. }
  85. if cfg.SampleRate <= 0 {
  86. cfg.SampleRate = 2_048_000
  87. }
  88. if cfg.FFTSize <= 0 {
  89. cfg.FFTSize = 2048
  90. }
  91. if cfg.TunerBwKHz <= 0 {
  92. cfg.TunerBwKHz = 1536
  93. }
  94. if cfg.CenterHz == 0 {
  95. cfg.CenterHz = 100.0e6
  96. }
  97. return cfg, nil
  98. }
  99. func (c Config) FrameInterval() time.Duration {
  100. fps := c.FrameRate
  101. if fps <= 0 {
  102. fps = 15
  103. }
  104. return time.Second / time.Duration(fps)
  105. }