summaryrefslogtreecommitdiff
path: root/WaitFeaturePolicy.hpp
blob: 27b1237d5a03bb2af385bde42f5e27e5ccf5d73b (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef WAITFEATUREPOLICY_HPP
#define WAITFEATUREPOLICY_HPP

#include <QString>

#include "SpecialOperatingActivity.hpp"

struct WaitFeatureContext
{
  WaitFeatureContext (QString const& mode,
                      SpecialOperatingActivity specialOperation,
                      bool waitFeaturesEnabled,
                      bool autoSequenceEnabled,
                      bool hasDxCall,
                      bool ncccSprint)
    : mode {mode}
    , specialOperation {specialOperation}
    , waitFeaturesEnabled {waitFeaturesEnabled}
    , autoSequenceEnabled {autoSequenceEnabled}
    , hasDxCall {hasDxCall}
    , ncccSprint {ncccSprint}
  {
  }

  QString mode;
  SpecialOperatingActivity specialOperation;
  bool waitFeaturesEnabled;
  bool autoSequenceEnabled;
  bool hasDxCall;
  bool ncccSprint;
};

enum class EnableTxWarning
{
  NONE,
  WAIT_AND_REPLY,
  NCCC_SPRINT,
  HOUND_AUTO_REPLY
};

inline bool slow_wait_feature_mode_supported (QString const& mode)
{
  return mode == "FT8" || mode == "FT4" || mode == "Q65" || mode == "FST4"
    || mode == "JT65" || mode == "JT9" || mode == "JT4";
}

inline bool wait_and_reply_mode_supported (QString const& mode)
{
  return slow_wait_feature_mode_supported (mode) || mode == "MSK144";
}

inline bool nccc_sprint_auto_reply (WaitFeatureContext const& context)
{
  return context.mode == "FT4"
    && context.specialOperation == SpecialOperatingActivity::NA_VHF
    && context.ncccSprint;
}

inline EnableTxWarning enable_tx_warning (WaitFeatureContext const& context)
{
  if (!context.hasDxCall || context.specialOperation == SpecialOperatingActivity::FOX)
    {
      return EnableTxWarning::NONE;
    }
  if (context.specialOperation == SpecialOperatingActivity::HOUND)
    {
      return context.mode == "FT8"
        ? EnableTxWarning::HOUND_AUTO_REPLY
        : EnableTxWarning::NONE;
    }
  if (nccc_sprint_auto_reply (context))
    {
      return EnableTxWarning::NCCC_SPRINT;
    }
  if (context.waitFeaturesEnabled && wait_and_reply_mode_supported (context.mode))
    {
      return EnableTxWarning::WAIT_AND_REPLY;
    }
  return EnableTxWarning::NONE;
}

inline bool wait_and_call_mode_supported (QString const& mode)
{
  return mode == "FT8" || mode == "FT4" || mode == "Q65" || mode == "FST4"
    || mode == "MSK144";
}

inline bool wait_and_call_arming_eligible (WaitFeatureContext const& context)
{
  auto const ordinaryWithCall = context.specialOperation == SpecialOperatingActivity::NONE
    && context.hasDxCall;
  auto const ft8Hound = context.mode == "FT8"
    && context.specialOperation == SpecialOperatingActivity::HOUND;
  return context.waitFeaturesEnabled
    && context.autoSequenceEnabled
    && wait_and_call_mode_supported (context.mode)
    && (ordinaryWithCall || ft8Hound);
}

inline bool wait_and_call_warning_eligible (WaitFeatureContext const& context)
{
  return context.hasDxCall && wait_and_call_arming_eligible (context);
}

#endif // WAITFEATUREPOLICY_HPP