summaryrefslogtreecommitdiff
path: root/FoxGuardBands.cpp
blob: 18375e1f9e75c51f3d945ee0f4b21ba319474375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "FoxGuardBands.hpp"

#include <QtGlobal>

namespace
{
  using Radio::Frequency;

  FoxGuardBands::Match no_match ()
  {
    return {false, FoxGuardBands::GuardKind::None, 0};
  }
}

namespace FoxGuardBands
{
  Match check (Frequency dial_frequency,
               std::initializer_list<Frequency> standard_ft8_guards,
               std::initializer_list<Frequency> wspr_guards)
  {
    for (auto guard_frequency : standard_ft8_guards)
    {
      auto const offset = static_cast<qint64> (dial_frequency) - static_cast<qint64> (guard_frequency);
      if (qAbs (offset) < 3000)
      {
        return {true, GuardKind::StandardFT8, guard_frequency};
      }
    }

    for (auto guard_frequency : wspr_guards)
    {
      auto const offset = static_cast<qint64> (dial_frequency) - static_cast<qint64> (guard_frequency);
      if (offset > -3500 && offset < 300)
      {
        return {true, GuardKind::WSPR, guard_frequency};
      }
    }

    return no_match ();
  }

  Match check (Frequency dial_frequency)
  {
    return check (dial_frequency,
                  {
                    1840000, 3573000, 7074000, 10136000, 14074000, 18100000,
                    21074000, 24915000, 28074000, 50313000, 70154000
                  },
                  {
                    1836600, 5364700, 3568600, 7038600, 10138700, 14095600,
                    18104600, 21094600, 24924600, 28124600
                  });
  }
}