Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

116 Zeilen
3.0KB

  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. UseGPUFFT bool `yaml:"use_gpu_fft" json:"use_gpu_fft"`
  25. AGC bool `yaml:"agc" json:"agc"`
  26. DCBlock bool `yaml:"dc_block" json:"dc_block"`
  27. IQBalance bool `yaml:"iq_balance" json:"iq_balance"`
  28. Detector DetectorConfig `yaml:"detector" json:"detector"`
  29. WebAddr string `yaml:"web_addr" json:"web_addr"`
  30. EventPath string `yaml:"event_path" json:"event_path"`
  31. FrameRate int `yaml:"frame_rate" json:"frame_rate"`
  32. WaterfallLines int `yaml:"waterfall_lines" json:"waterfall_lines"`
  33. WebRoot string `yaml:"web_root" json:"web_root"`
  34. }
  35. func Default() Config {
  36. return Config{
  37. Bands: []Band{
  38. {Name: "example", StartHz: 99.5e6, EndHz: 100.5e6},
  39. },
  40. CenterHz: 100.0e6,
  41. SampleRate: 2_048_000,
  42. FFTSize: 2048,
  43. GainDb: 30,
  44. TunerBwKHz: 1536,
  45. UseGPUFFT: false,
  46. AGC: false,
  47. DCBlock: false,
  48. IQBalance: false,
  49. Detector: DetectorConfig{ThresholdDb: -20, MinDurationMs: 250, HoldMs: 500},
  50. WebAddr: ":8080",
  51. EventPath: "data/events.jsonl",
  52. FrameRate: 15,
  53. WaterfallLines: 200,
  54. WebRoot: "web",
  55. }
  56. }
  57. func Load(path string) (Config, error) {
  58. cfg := Default()
  59. b, err := os.ReadFile(path)
  60. if err != nil {
  61. return cfg, err
  62. }
  63. if err := yaml.Unmarshal(b, &cfg); err != nil {
  64. return cfg, err
  65. }
  66. if cfg.Detector.MinDurationMs <= 0 {
  67. cfg.Detector.MinDurationMs = 250
  68. }
  69. if cfg.Detector.HoldMs <= 0 {
  70. cfg.Detector.HoldMs = 500
  71. }
  72. if cfg.FrameRate <= 0 {
  73. cfg.FrameRate = 15
  74. }
  75. if cfg.WaterfallLines <= 0 {
  76. cfg.WaterfallLines = 200
  77. }
  78. if cfg.WebRoot == "" {
  79. cfg.WebRoot = "web"
  80. }
  81. if cfg.WebAddr == "" {
  82. cfg.WebAddr = ":8080"
  83. }
  84. if cfg.EventPath == "" {
  85. cfg.EventPath = "data/events.jsonl"
  86. }
  87. if cfg.SampleRate <= 0 {
  88. cfg.SampleRate = 2_048_000
  89. }
  90. if cfg.FFTSize <= 0 {
  91. cfg.FFTSize = 2048
  92. }
  93. if cfg.TunerBwKHz <= 0 {
  94. cfg.TunerBwKHz = 1536
  95. }
  96. if cfg.CenterHz == 0 {
  97. cfg.CenterHz = 100.0e6
  98. }
  99. return cfg, nil
  100. }
  101. func (c Config) FrameInterval() time.Duration {
  102. fps := c.FrameRate
  103. if fps <= 0 {
  104. fps = 15
  105. }
  106. return time.Second / time.Duration(fps)
  107. }