mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 21:05:31 +08:00
@@ -129,11 +129,48 @@ namespace BlackMisc::Aviation
|
|||||||
return isValidCivilAviationFrequency(f) || isValidMilitaryFrequency(f);
|
return isValidCivilAviationFrequency(f) || isValidMilitaryFrequency(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CComSystem::isValid8_33kHzChannel(int fKHz)
|
||||||
|
{
|
||||||
|
const int lastDigits = static_cast<int>(fKHz) % 100;
|
||||||
|
return fKHz % 5 == 0 && lastDigits != 20 && lastDigits != 45 && lastDigits != 70 && lastDigits != 95;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CComSystem::round8_33kHzChannel(int fKHz)
|
||||||
|
{
|
||||||
|
if (!isValid8_33kHzChannel(fKHz))
|
||||||
|
{
|
||||||
|
const int diff = static_cast<int>(fKHz) % 5;
|
||||||
|
int lower = fKHz - diff;
|
||||||
|
if (!isValid8_33kHzChannel(lower)) { lower -= 5; }
|
||||||
|
Q_ASSERT_X(isValid8_33kHzChannel(lower), Q_FUNC_INFO, "Lower frequency not valid");
|
||||||
|
|
||||||
|
int upper = fKHz + (5 - diff);
|
||||||
|
if (!isValid8_33kHzChannel(upper)) { upper += 5; }
|
||||||
|
Q_ASSERT_X(isValid8_33kHzChannel(upper), Q_FUNC_INFO, "Upper frequency not valid");
|
||||||
|
|
||||||
|
const int lowerDiff = abs(fKHz - lower);
|
||||||
|
const int upperDiff = abs(fKHz - upper);
|
||||||
|
|
||||||
|
fKHz = lowerDiff < upperDiff ? lower : upper;
|
||||||
|
fKHz = std::clamp(fKHz, 118000, 136990);
|
||||||
|
}
|
||||||
|
return fKHz;
|
||||||
|
}
|
||||||
|
|
||||||
void CComSystem::roundToChannelSpacing(CFrequency &frequency, ChannelSpacing channelSpacing)
|
void CComSystem::roundToChannelSpacing(CFrequency &frequency, ChannelSpacing channelSpacing)
|
||||||
{
|
{
|
||||||
if (frequency.isNull()) { return; }
|
if (frequency.isNull()) { return; }
|
||||||
const double channelSpacingKHz = CComSystem::channelSpacingToFrequencyKHz(channelSpacing);
|
const double channelSpacingKHz = CComSystem::channelSpacingToFrequencyKHz(channelSpacing);
|
||||||
const double fKHz = frequency.valueRounded(CFrequencyUnit::kHz(), 0);
|
const double fKHz = frequency.valueRounded(CFrequencyUnit::kHz(), 0);
|
||||||
|
|
||||||
|
if (channelSpacing == ChannelSpacing8_33KHz)
|
||||||
|
{
|
||||||
|
const int freqKHz = round8_33kHzChannel(fKHz);
|
||||||
|
frequency.switchUnit(CFrequencyUnit::kHz());
|
||||||
|
frequency.setCurrentUnitValue(freqKHz);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
const int dDown = static_cast<int>(fKHz / channelSpacingKHz);
|
const int dDown = static_cast<int>(fKHz / channelSpacingKHz);
|
||||||
const double fDownKHz = dDown * channelSpacingKHz;
|
const double fDownKHz = dDown * channelSpacingKHz;
|
||||||
const double fUpKHz = (dDown + 1) * channelSpacingKHz;
|
const double fUpKHz = (dDown + 1) * channelSpacingKHz;
|
||||||
@@ -142,6 +179,7 @@ namespace BlackMisc::Aviation
|
|||||||
frequency.switchUnit(CFrequencyUnit::MHz());
|
frequency.switchUnit(CFrequencyUnit::MHz());
|
||||||
frequency.setCurrentUnitValue(fMHz);
|
frequency.setCurrentUnitValue(fMHz);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CComSystem::isWithinChannelSpacing(const CFrequency &setFrequency, const CFrequency &compareFrequency, CComSystem::ChannelSpacing channelSpacing)
|
bool CComSystem::isWithinChannelSpacing(const CFrequency &setFrequency, const CFrequency &compareFrequency, CComSystem::ChannelSpacing channelSpacing)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -141,6 +141,13 @@ namespace BlackMisc::Aviation
|
|||||||
const PhysicalQuantities::CFrequency &compareFrequency,
|
const PhysicalQuantities::CFrequency &compareFrequency,
|
||||||
ChannelSpacing channelSpacing);
|
ChannelSpacing channelSpacing);
|
||||||
|
|
||||||
|
//! Is passed frequency in kHz a valid 8.33 channel. This does not check if
|
||||||
|
//! the frequency is within the correct bounds.
|
||||||
|
static bool isValid8_33kHzChannel(int fKHz);
|
||||||
|
|
||||||
|
//! Round passed frequency in kHz to 8.33 frequency spacing
|
||||||
|
static int round8_33kHzChannel(int fKHz);
|
||||||
|
|
||||||
//! Parses almost any shitty string to a valid COM frequency
|
//! Parses almost any shitty string to a valid COM frequency
|
||||||
static PhysicalQuantities::CFrequency parseComFrequency(const QString &input, PhysicalQuantities::CPqString::SeparatorMode sep);
|
static PhysicalQuantities::CFrequency parseComFrequency(const QString &input, PhysicalQuantities::CPqString::SeparatorMode sep);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user