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)
67 CModulator::NameCom1(),
75 return CComSystem(CModulator::NameCom1(), activeFrequency,
76 standbyFrequency.
isNull() ? activeFrequency : standbyFrequency);
79 CComSystem CComSystem::getCom2System(
double activeFrequencyMHz,
double standbyFrequencyMHz)
82 CModulator::NameCom2(),
90 return CComSystem(CModulator::NameCom2(), activeFrequency,
91 standbyFrequency.
isNull() ? activeFrequency : standbyFrequency);
94 bool CComSystem::isValidCivilAviationFrequency(
const CFrequency &f)
96 if (f.
isNull())
return false;
100 return fr >= 118000 && fr <= 136990;
103 bool CComSystem::isValidMilitaryFrequency(
const CFrequency &f)
105 if (f.
isNull())
return false;
107 return fr >= 220000 && fr <= 399950;
112 if (f.
isNull()) {
return false; }
113 return isValidCivilAviationFrequency(f) || isValidMilitaryFrequency(f);
116 bool CComSystem::isValid8_33kHzChannel(
int fKHz)
118 const int lastDigits =
static_cast<int>(fKHz) % 100;
119 return fKHz % 5 == 0 && lastDigits != 20 && lastDigits != 45 && lastDigits != 70 && lastDigits != 95;
122 int CComSystem::round8_33kHzChannel(
int fKHz)
124 if (!isValid8_33kHzChannel(fKHz))
126 const int diff =
static_cast<int>(fKHz) % 5;
127 int lower = fKHz - diff;
128 if (!isValid8_33kHzChannel(lower)) { lower -= 5; }
129 Q_ASSERT_X(isValid8_33kHzChannel(lower), Q_FUNC_INFO,
"Lower frequency not valid");
131 int upper = fKHz + (5 - diff);
132 if (!isValid8_33kHzChannel(upper)) { upper += 5; }
133 Q_ASSERT_X(isValid8_33kHzChannel(upper), Q_FUNC_INFO,
"Upper frequency not valid");
135 const int lowerDiff = abs(fKHz - lower);
136 const int upperDiff = abs(fKHz - upper);
138 fKHz = lowerDiff < upperDiff ? lower : upper;
139 fKHz = std::clamp(fKHz, 118000, 136990);
146 if (frequency.
isNull()) {
return; }
147 const double channelSpacingKHz = CComSystem::channelSpacingToFrequencyKHz(channelSpacing);
150 if (channelSpacing == ChannelSpacing8_33KHz)
152 const int freqKHz = round8_33kHzChannel(fKHz);
158 const int dDown =
static_cast<int>(fKHz / channelSpacingKHz);
159 const double fDownKHz = dDown * channelSpacingKHz;
160 const double fUpKHz = (dDown + 1) * channelSpacingKHz;
161 const bool down = qAbs(fKHz - fDownKHz) < qAbs(fUpKHz - fKHz);
171 if (freqKHz < 118000 || freqKHz >= 137000 || !isValid8_33kHzChannel(freqKHz)) {
return false; }
172 return !isWithin25kHzChannel(freq);
183 using namespace swift::misc::physical_quantities::Literals;
189 if (freq_end == 20 || freq_end == 70) { freq += 5_kHz; }
193 CFrequency normalized_freq1 = normalize(freq1);
194 CFrequency normalized_freq2 = normalize(freq2);
196 if (normalized_freq1 == normalized_freq2) {
return true; }
209 const double f = input.toDouble();
225 roundToChannelSpacing(comFreq, ChannelSpacing8_33KHz);
229 double CComSystem::channelSpacingToFrequencyKHz(ChannelSpacing channelSpacing)
231 switch (channelSpacing)
233 case ChannelSpacing50KHz:
return 50.0;
234 case ChannelSpacing25KHz:
return 25.0;
235 case ChannelSpacing8_33KHz:
return 25.0 / 3.0;
236 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.