mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
COM frequency rounding + testcase
This commit is contained in:
@@ -125,14 +125,14 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
if (frequency.isNull()) { return; }
|
if (frequency.isNull()) { return; }
|
||||||
const double channelSpacingKHz = CComSystem::channelSpacingToFrequencyKHz(channelSpacing);
|
const double channelSpacingKHz = CComSystem::channelSpacingToFrequencyKHz(channelSpacing);
|
||||||
const double f = frequency.valueRounded(CFrequencyUnit::kHz(), 0);
|
const double fKHz = frequency.valueRounded(CFrequencyUnit::kHz(), 0);
|
||||||
const quint32 d = static_cast<quint32>(f / channelSpacingKHz);
|
const int dDown = static_cast<int>(fKHz / channelSpacingKHz);
|
||||||
|
const double fDownKHz = dDown * channelSpacingKHz;
|
||||||
|
const double fUpKHz = (dDown + 1) * channelSpacingKHz;
|
||||||
|
const bool down = qAbs(fKHz - fDownKHz) < qAbs(fUpKHz - fKHz); // which is the closest value
|
||||||
|
const double fMHz(CMathUtils::round((down ? fDownKHz : fUpKHz) / 1000.0, 3));
|
||||||
frequency.switchUnit(CFrequencyUnit::MHz());
|
frequency.switchUnit(CFrequencyUnit::MHz());
|
||||||
const double f0 = frequency.valueRounded(CFrequencyUnit::MHz(), 3);
|
frequency.setCurrentUnitValue(fMHz);
|
||||||
const double f1 = CMathUtils::round(d * (channelSpacingKHz / 1000.0), 3);
|
|
||||||
const double f2 = CMathUtils::round((d + 1) * (channelSpacingKHz / 1000.0), 3);
|
|
||||||
const bool down = qAbs(f1 - f0) < qAbs(f2 - f0); // which is the closest value
|
|
||||||
frequency.setCurrentUnitValue(down ? f1 : f2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CComSystem::isWithinChannelSpacing(const CFrequency &setFrequency, const CFrequency &compareFrequency, CComSystem::ChannelSpacing channelSpacing)
|
bool CComSystem::isWithinChannelSpacing(const CFrequency &setFrequency, const CFrequency &compareFrequency, CComSystem::ChannelSpacing channelSpacing)
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ namespace BlackMiscTest
|
|||||||
//! COM and NAV units
|
//! COM and NAV units
|
||||||
void comAndNav();
|
void comAndNav();
|
||||||
|
|
||||||
|
//! COM frequency rounding
|
||||||
|
void comFrequencyRounding();
|
||||||
|
|
||||||
//! Transponder
|
//! Transponder
|
||||||
void transponder();
|
void transponder();
|
||||||
|
|
||||||
@@ -108,6 +111,25 @@ namespace BlackMiscTest
|
|||||||
QVERIFY2(!CNavSystem::isValidCivilNavigationFrequency(CFrequency(200.0, CFrequencyUnit::MHz())), "Expect invalid nav frequency");
|
QVERIFY2(!CNavSystem::isValidCivilNavigationFrequency(CFrequency(200.0, CFrequencyUnit::MHz())), "Expect invalid nav frequency");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CTestAviation::comFrequencyRounding()
|
||||||
|
{
|
||||||
|
const CFrequency f1 = CFrequency(122.8, CFrequencyUnit::MHz());
|
||||||
|
const CFrequency f2 = CFrequency(122.795, CFrequencyUnit::MHz());
|
||||||
|
const CFrequency f3 = CFrequency(122.805, CFrequencyUnit::MHz());
|
||||||
|
|
||||||
|
QVERIFY2(f1 == f1, "Ups, how can this fail");
|
||||||
|
QVERIFY2(f1 != f2, "Ups, how can this fail");
|
||||||
|
QVERIFY2(f1 != f3, "Ups, how can this fail");
|
||||||
|
|
||||||
|
CFrequency up(f2);
|
||||||
|
CComSystem::roundToChannelSpacing(up, CComSystem::ChannelSpacing25KHz);
|
||||||
|
QVERIFY2(up == f1, "Expect rounding up");
|
||||||
|
|
||||||
|
CFrequency down(f3);
|
||||||
|
CComSystem::roundToChannelSpacing(down, CComSystem::ChannelSpacing25KHz);
|
||||||
|
QVERIFY2(down == f1, "Expect rounding up");
|
||||||
|
}
|
||||||
|
|
||||||
void CTestAviation::transponder()
|
void CTestAviation::transponder()
|
||||||
{
|
{
|
||||||
CTransponder t1 = CTransponder::getStandardTransponder(7000, CTransponder::StateStandby);
|
CTransponder t1 = CTransponder::getStandardTransponder(7000, CTransponder::StateStandby);
|
||||||
|
|||||||
Reference in New Issue
Block a user