Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

103 lines
2.3KB

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