mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 05:28:09 +08:00
refs #314, modulator based classes to latest style
* removed exceptions * removed tryGet methods * adjusted samples
This commit is contained in:
@@ -44,8 +44,7 @@ namespace BlackMiscTest
|
|||||||
qDebug() << c1;
|
qDebug() << c1;
|
||||||
|
|
||||||
// NAV system
|
// NAV system
|
||||||
CNavSystem nav1;
|
CNavSystem nav1 = CNavSystem::getNav1System(110.0);
|
||||||
CNavSystem::tryGetNav1System(nav1, 110.0);
|
|
||||||
qDebug() << nav1;
|
qDebug() << nav1;
|
||||||
|
|
||||||
// Transponder tests
|
// Transponder tests
|
||||||
|
|||||||
@@ -35,13 +35,10 @@ namespace BlackMisc
|
|||||||
CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits)
|
CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
//! \copydoc CValueObject::toQVariant
|
|
||||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
|
||||||
|
|
||||||
//! Valid aviation frequency?
|
//! Valid aviation frequency?
|
||||||
bool isValidFrequency(PhysicalQuantities::CFrequency f) const
|
static bool isValidFrequency(PhysicalQuantities::CFrequency f)
|
||||||
{
|
{
|
||||||
double fr = f.valueRounded(PhysicalQuantities::CFrequencyUnit::kHz(), this->m_digits);
|
double fr = f.valueRounded(PhysicalQuantities::CFrequencyUnit::kHz(), 3);
|
||||||
return fr >= 190.0 && fr <= 1750.0;
|
return fr >= 190.0 && fr <= 1750.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ namespace BlackMisc
|
|||||||
CModulator(name, activeFrequency, standbyFrequency, digits)
|
CModulator(name, activeFrequency, standbyFrequency, digits)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
//! \copydoc CValueObject::toQVariant
|
|
||||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
|
||||||
|
|
||||||
//! Set active frequency
|
//! Set active frequency
|
||||||
void setFrequencyActiveMHz(double frequencyMHz)
|
void setFrequencyActiveMHz(double frequencyMHz)
|
||||||
{
|
{
|
||||||
@@ -58,16 +55,16 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Valid civil aviation frequency?
|
//! Valid civil aviation frequency?
|
||||||
bool isValidCivilNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const
|
static bool isValidCivilNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f)
|
||||||
{
|
{
|
||||||
double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits);
|
double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), 3);
|
||||||
return fr >= 108.0 && fr <= 117.95;
|
return fr >= 108.0 && fr <= 117.95;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Valid military aviation frequency?
|
//! Valid military aviation frequency?
|
||||||
bool isValidMilitaryNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const
|
static bool isValidMilitaryNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f)
|
||||||
{
|
{
|
||||||
double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits);
|
double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), 3);
|
||||||
return fr >= 960.0 && fr <= 1215.0; // valid TACAN frequency
|
return fr >= 960.0 && fr <= 1215.0; // valid TACAN frequency
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +104,13 @@ namespace BlackMisc
|
|||||||
this->isValidMilitaryNavigationFrequency(this->getFrequencyStandby()));
|
this->isValidMilitaryNavigationFrequency(this->getFrequencyStandby()));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! Easy access to derived class (CRTP template parameter)
|
||||||
|
CNavSystem const *derived() const { return static_cast<CNavSystem const *>(this); }
|
||||||
|
|
||||||
|
//! Easy access to derived class (CRTP template parameter)
|
||||||
|
CNavSystem *derived() { return static_cast<CNavSystem *>(this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#ifndef BLACKMISC_AVIOTRANSPONDER_H
|
#ifndef BLACKMISC_AVIOTRANSPONDER_H
|
||||||
#define BLACKMISC_AVIOTRANSPONDER_H
|
#define BLACKMISC_AVIOTRANSPONDER_H
|
||||||
#include "blackmisc/aviobase.h"
|
#include "blackmisc/aviobase.h"
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -116,10 +115,7 @@ namespace BlackMisc
|
|||||||
QString getTransponderCodeAndModeFormatted() const;
|
QString getTransponderCodeAndModeFormatted() const;
|
||||||
|
|
||||||
//! Set transponder code
|
//! Set transponder code
|
||||||
void setTransponderCode(qint32 transponderCode)
|
void setTransponderCode(qint32 transponderCode) { this->m_transponderCode = transponderCode; }
|
||||||
{
|
|
||||||
this->m_transponderCode = transponderCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Set transponder code
|
//! Set transponder code
|
||||||
void setTransponderCode(const QString &transponderCode);
|
void setTransponderCode(const QString &transponderCode);
|
||||||
@@ -128,28 +124,16 @@ namespace BlackMisc
|
|||||||
static TransponderMode modeFromString(const QString &modeString);
|
static TransponderMode modeFromString(const QString &modeString);
|
||||||
|
|
||||||
//! Set transponder mode
|
//! Set transponder mode
|
||||||
void setTransponderMode(TransponderMode mode)
|
void setTransponderMode(TransponderMode mode) { this->m_transponderMode = mode ; }
|
||||||
{
|
|
||||||
this->m_transponderMode = mode ;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Set emergency
|
//! Set emergency
|
||||||
void setEmergency()
|
void setEmergency() { this->m_transponderCode = 7700; }
|
||||||
{
|
|
||||||
this->m_transponderCode = 7700;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Set VFR
|
//! Set VFR
|
||||||
void setVFR()
|
void setVFR() { this->m_transponderCode = 7000; }
|
||||||
{
|
|
||||||
this->m_transponderCode = 7000;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Set IFR
|
//! Set IFR
|
||||||
void setIFR()
|
void setIFR() { this->m_transponderCode = 2000; }
|
||||||
{
|
|
||||||
this->m_transponderCode = 2000;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! operator ==
|
//! operator ==
|
||||||
bool operator ==(const CTransponder &other) const
|
bool operator ==(const CTransponder &other) const
|
||||||
@@ -160,11 +144,8 @@ namespace BlackMisc
|
|||||||
this->CAvionicsBase::operator ==(other);
|
this->CAvionicsBase::operator ==(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! operator =!
|
//! operator !=
|
||||||
bool operator !=(const CTransponder &other) const
|
bool operator !=(const CTransponder &other) const { return !((*this) == other); }
|
||||||
{
|
|
||||||
return !((*this) == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Transponder unit
|
//! Transponder unit
|
||||||
static CTransponder getStandardTransponder(qint32 transponderCode, TransponderMode mode)
|
static CTransponder getStandardTransponder(qint32 transponderCode, TransponderMode mode)
|
||||||
|
|||||||
@@ -68,10 +68,8 @@ namespace BlackMiscTest
|
|||||||
QVERIFY2(c1 != c2, "COM system shall not be equal");
|
QVERIFY2(c1 != c2, "COM system shall not be equal");
|
||||||
c1 = c2;
|
c1 = c2;
|
||||||
QVERIFY2(c1 == c2, "COM system shall be equal");
|
QVERIFY2(c1 == c2, "COM system shall be equal");
|
||||||
CFrequency f(100.0, CFrequencyUnit::MHz());
|
QVERIFY2(CNavSystem::isValidCivilNavigationFrequency(CFrequency(110.0, CFrequencyUnit::MHz())), "Expect valid nav frequency");
|
||||||
CNavSystem nav1;
|
QVERIFY2(!CNavSystem::isValidCivilNavigationFrequency(CFrequency(200.0, CFrequencyUnit::MHz())), "Expect invalid nav frequency");
|
||||||
QVERIFY2(CNavSystem::tryGetNav1System(nav1, 110.0), "Expect NAV system");
|
|
||||||
QVERIFY2(!CNavSystem::tryGetNav1System(nav1, 200.0), "Expect no NAV system");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user