6 #include <QDBusMetaType>
13 using namespace swift::misc::physical_quantities;
14 using namespace swift::misc::math;
16 namespace swift::misc::aviation
18 void CComSystem::registerMetadata()
21 qDBusRegisterMetaType<ChannelSpacing>();
22 qDBusRegisterMetaType<ComUnit>();
25 void CComSystem::setFrequencyActiveMHz(
double frequencyMHz)
28 this->setFrequencyActive(f);
31 void CComSystem::setFrequencyStandbyMHz(
double frequencyMHz)
34 this->setFrequencyStandby(f);
37 void CComSystem::setFrequencyActive(
const CFrequency &frequency)
39 if (frequency == this->getFrequencyActive()) {
return; }
41 roundToChannelSpacing(fRounded, m_channelSpacing);
42 this->CModulator::setFrequencyActive(fRounded);
45 void CComSystem::setFrequencyStandby(
const CFrequency &frequency)
47 if (frequency == this->getFrequencyStandby()) {
return; }
49 roundToChannelSpacing(fRounded, m_channelSpacing);
50 this->CModulator::setFrequencyStandby(fRounded);
53 bool CComSystem::isActiveFrequencySameFrequency(
const CFrequency &comFrequency)
const
55 return isSameFrequency(this->getFrequencyActive(), comFrequency);
58 void CComSystem::setActiveUnicom()
60 this->toggleActiveStandby();
64 CComSystem CComSystem::getCom1System(
double activeFrequencyMHz,
double standbyFrequencyMHz)
66 return { CModulator::NameCom1(),
74 return { CModulator::NameCom1(), activeFrequency,
75 standbyFrequency.
isNull() ? activeFrequency : standbyFrequency };
78 CComSystem CComSystem::getCom2System(
double activeFrequencyMHz,
double standbyFrequencyMHz)
80 return { CModulator::NameCom2(),
88 return { CModulator::NameCom2(), activeFrequency,
89 standbyFrequency.
isNull() ? activeFrequency : standbyFrequency };
92 bool CComSystem::isValidCivilAviationFrequency(
const CFrequency &f)
94 if (f.
isNull())
return false;
98 return fr >= 118000 && fr <= 136990;
101 bool CComSystem::isValidMilitaryFrequency(
const CFrequency &f)
103 if (f.
isNull())
return false;
105 return fr >= 220000 && fr <= 399950;
110 if (f.
isNull()) {
return false; }
111 return isValidCivilAviationFrequency(f) || isValidMilitaryFrequency(f);
114 bool CComSystem::isValid8_33kHzChannel(
int fKHz)
116 const int lastDigits =
static_cast<int>(fKHz) % 100;
117 return fKHz % 5 == 0 && lastDigits != 20 && lastDigits != 45 && lastDigits != 70 && lastDigits != 95;
120 int CComSystem::round8_33kHzChannel(
int fKHz)
122 if (!isValid8_33kHzChannel(fKHz))
124 const int diff =
static_cast<int>(fKHz) % 5;
125 int lower = fKHz - diff;
126 if (!isValid8_33kHzChannel(lower)) { lower -= 5; }
127 Q_ASSERT_X(isValid8_33kHzChannel(lower), Q_FUNC_INFO,
"Lower frequency not valid");
129 int upper = fKHz + (5 - diff);
130 if (!isValid8_33kHzChannel(upper)) { upper += 5; }
131 Q_ASSERT_X(isValid8_33kHzChannel(upper), Q_FUNC_INFO,
"Upper frequency not valid");
133 const int lowerDiff = abs(fKHz - lower);
134 const int upperDiff = abs(fKHz - upper);
136 fKHz = lowerDiff < upperDiff ? lower : upper;
137 fKHz = std::clamp(fKHz, 118000, 136990);
144 if (frequency.
isNull()) {
return; }
145 const double channelSpacingKHz = CComSystem::channelSpacingToFrequencyKHz(channelSpacing);
148 if (channelSpacing == ChannelSpacing8_33KHz)
150 const int freqKHz = round8_33kHzChannel(fKHz);
156 const int dDown =
static_cast<int>(fKHz / channelSpacingKHz);
157 const double fDownKHz = dDown * channelSpacingKHz;
158 const double fUpKHz = (dDown + 1) * channelSpacingKHz;
159 const bool down = qAbs(fKHz - fDownKHz) < qAbs(fUpKHz - fKHz);
169 if (freqKHz < 118000 || freqKHz >= 137000 || !isValid8_33kHzChannel(freqKHz)) {
return false; }
170 return !isWithin25kHzChannel(freq);
181 using namespace swift::misc::physical_quantities::Literals;
187 if (freq_end == 20 || freq_end == 70) { freq += 5_kHz; }
191 CFrequency normalized_freq1 = normalize(freq1);
192 CFrequency normalized_freq2 = normalize(freq2);
194 if (normalized_freq1 == normalized_freq2) {
return true; }
223 roundToChannelSpacing(comFreq, ChannelSpacing8_33KHz);
227 double CComSystem::channelSpacingToFrequencyKHz(ChannelSpacing channelSpacing)
229 switch (channelSpacing)
231 case ChannelSpacing50KHz:
return 50.0;
232 case ChannelSpacing25KHz:
return 25.0;
233 case ChannelSpacing8_33KHz:
return 25.0 / 3.0;
234 default: qFatal(
"Wrong channel spacing");
return 0.0;
ChannelSpacing
Channel spacing frequency.
static double round(double value, int digits)
Utility round method.
static CFrequencyUnit MHz()
Megahertz.
static CFrequencyUnit kHz()
Kilohertz.
static const CFrequency & FrequencyUnicom()
Unicom frequency.
void parseFromString(const QString &value)
Parse value from string.
int valueInteger(MU unit) const
As integer value.
PQ & switchUnit(const MU &newUnit)
Change unit, and convert value to maintain the same quantity.
bool isNull() const
Is quantity null?
double value(MU unit) const
Value in given unit.
void setCurrentUnitValue(double value)
Set value in current unit.
static const CFrequency & null()
NULL PQ.
double valueRounded(MU unit, int digits=-1) const
Rounded value in given unit.
SeparatorMode
Number separators / group separators.
static double parseNumber(const QString &number, bool &success, SeparatorMode mode=SeparatorBestGuess)
Locale aware parsing.
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
bool isDigitsOnlyString(const QString &testString)
String with digits only.
bool isEmpty() const const
double toDouble(bool *ok) const const