From 417270158632c1eca8559a6b8db9de0d54ac3555 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 2 Nov 2018 17:03:21 +0100 Subject: [PATCH] Ref T422, functions to toggle/set XPDR mode --- src/blackcore/context/contextownaircraft.h | 6 +++ .../context/contextownaircraftempty.h | 15 +++++++ .../context/contextownaircraftimpl.cpp | 42 ++++++++++++++++--- .../context/contextownaircraftimpl.h | 6 +++ .../context/contextownaircraftproxy.cpp | 10 +++++ .../context/contextownaircraftproxy.h | 2 + src/blackmisc/aviation/transponder.cpp | 14 ++++++- src/blackmisc/aviation/transponder.h | 13 +++--- 8 files changed, 97 insertions(+), 11 deletions(-) diff --git a/src/blackcore/context/contextownaircraft.h b/src/blackcore/context/contextownaircraft.h index 47eaf20a5..3ad87a82d 100644 --- a/src/blackcore/context/contextownaircraft.h +++ b/src/blackcore/context/contextownaircraft.h @@ -128,6 +128,12 @@ namespace BlackCore //! Update own cockpit virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) = 0; + //! Toggle XPDR mode + virtual void toggleTransponderMode() = 0; + + //! Set XPDR mode + virtual bool setTransponderMode(BlackMisc::Aviation::CTransponder::TransponderMode mode) = 0; + //! Tune in a COM frequency virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) = 0; diff --git a/src/blackcore/context/contextownaircraftempty.h b/src/blackcore/context/contextownaircraftempty.h index 16ac9dcf3..0f0cae0a6 100644 --- a/src/blackcore/context/contextownaircraftempty.h +++ b/src/blackcore/context/contextownaircraftempty.h @@ -113,6 +113,21 @@ namespace BlackCore virtual void setAudioOutputVolume(int outputVolume) override { Q_UNUSED(outputVolume); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextOwnAircraft::toggleTransponderMode + virtual void toggleTransponderMode() override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextOwnAircraft::setTransponderMode + virtual bool setTransponderMode(BlackMisc::Aviation::CTransponder::TransponderMode mode) override + { + Q_UNUSED(mode); + logEmptyContextWarning(Q_FUNC_INFO); + return false; } //! \copydoc IContextOwnAircraft::setAudioVoiceRoomOverrideUrls diff --git a/src/blackcore/context/contextownaircraftimpl.cpp b/src/blackcore/context/contextownaircraftimpl.cpp index d5e64a002..bcc2c16f8 100644 --- a/src/blackcore/context/contextownaircraftimpl.cpp +++ b/src/blackcore/context/contextownaircraftimpl.cpp @@ -206,9 +206,11 @@ namespace BlackCore if (jumpDetected) { + { + QWriteLocker wl(&m_lockAircraft); + m_situationHistory.clear(); + } emit this->movedAircraft(); - QWriteLocker wl(&m_lockAircraft); - m_situationHistory.clear(); } } @@ -218,7 +220,7 @@ namespace BlackCore CAircraftModel CContextOwnAircraft::reverseLookupModel(const CAircraftModel &model) { bool modified = false; - CAircraftModel reverseModel = CDatabaseUtils::consolidateOwnAircraftModelWithDbData(model, false, &modified); + const CAircraftModel reverseModel = CDatabaseUtils::consolidateOwnAircraftModelWithDbData(model, false, &modified); return reverseModel; } @@ -298,7 +300,7 @@ namespace BlackCore return changed; } - bool CContextOwnAircraft::updateActiveComFrequency(const CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit, const CIdentifier &originator) + bool CContextOwnAircraft::updateActiveComFrequency(const CFrequency &frequency, CComSystem::ComUnit unit, const CIdentifier &originator) { if (unit != CComSystem::Com1 && unit != CComSystem::Com2) { return false; } if (!CComSystem::isValidComFrequency(frequency)) { return false; } @@ -318,7 +320,7 @@ namespace BlackCore { com2.setFrequencyActive(frequency); } - return updateCockpit(com1, com2, xpdr, originator); + return this->updateCockpit(com1, com2, xpdr, originator); } bool CContextOwnAircraft::updateOwnAircraftPilot(const CUser &pilot) @@ -332,6 +334,36 @@ namespace BlackCore return true; } + void CContextOwnAircraft::toggleTransponderMode() + { + CTransponder xpdr; + CComSystem com1; + CComSystem com2; + { + QReadLocker l(&m_lockAircraft); + com1 = m_ownAircraft.getCom1System(); + com2 = m_ownAircraft.getCom2System(); + xpdr = m_ownAircraft.getTransponder(); + } + xpdr.toggleTransponderMode(); + this->updateCockpit(com1, com2, xpdr, this->identifier()); + } + + bool CContextOwnAircraft::setTransponderMode(CTransponder::TransponderMode mode) + { + CTransponder xpdr; + CComSystem com1; + CComSystem com2; + { + QReadLocker l(&m_lockAircraft); + com1 = m_ownAircraft.getCom1System(); + com2 = m_ownAircraft.getCom2System(); + xpdr = m_ownAircraft.getTransponder(); + } + xpdr.setTransponderMode(mode); + return this->updateCockpit(com1, com2, xpdr, this->identifier()); + } + bool CContextOwnAircraft::updateOwnCallsign(const CCallsign &callsign) { { diff --git a/src/blackcore/context/contextownaircraftimpl.h b/src/blackcore/context/contextownaircraftimpl.h index 43c13649b..3fab4a0ca 100644 --- a/src/blackcore/context/contextownaircraftimpl.h +++ b/src/blackcore/context/contextownaircraftimpl.h @@ -141,6 +141,12 @@ namespace BlackCore //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) override; + //! \copydoc IContextOwnAircraft::toggleTransponderMode + virtual void toggleTransponderMode() override; + + //! \copydoc IContextOwnAircraft::setTransponderMode + virtual bool setTransponderMode(BlackMisc::Aviation::CTransponder::TransponderMode mode) override; + //! \copydoc IContextOwnAircraft::setAudioOutputVolume virtual void setAudioOutputVolume(int outputVolume) override; diff --git a/src/blackcore/context/contextownaircraftproxy.cpp b/src/blackcore/context/contextownaircraftproxy.cpp index 69089cc81..775b828ee 100644 --- a/src/blackcore/context/contextownaircraftproxy.cpp +++ b/src/blackcore/context/contextownaircraftproxy.cpp @@ -136,6 +136,16 @@ namespace BlackCore this->m_dBusInterface->callDBus(QLatin1String("enableAutomaticVoiceRoomResolution"), enable); } + void CContextOwnAircraftProxy::toggleTransponderMode() + { + this->m_dBusInterface->callDBus(QLatin1String("toggleTransponderMode")); + } + + bool CContextOwnAircraftProxy::setTransponderMode(CTransponder::TransponderMode mode) + { + return this->m_dBusInterface->callDBusRet(QLatin1String("setTransponderMode"), mode); + } + bool CContextOwnAircraftProxy::parseCommandLine(const QString &commandLine, const CIdentifier &originator) { return this->m_dBusInterface->callDBusRet(QLatin1String("parseCommandLine"), commandLine, originator); diff --git a/src/blackcore/context/contextownaircraftproxy.h b/src/blackcore/context/contextownaircraftproxy.h index 30594448f..fa232f214 100644 --- a/src/blackcore/context/contextownaircraftproxy.h +++ b/src/blackcore/context/contextownaircraftproxy.h @@ -75,6 +75,8 @@ namespace BlackCore virtual void setAudioOutputVolume(int outputVolume) override; virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) override; virtual void enableAutomaticVoiceRoomResolution(bool enable) override; + virtual void toggleTransponderMode() override; + virtual bool setTransponderMode(BlackMisc::Aviation::CTransponder::TransponderMode mode) override; virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; //! @} diff --git a/src/blackmisc/aviation/transponder.cpp b/src/blackmisc/aviation/transponder.cpp index 99b48f7a1..dbe8d94d0 100644 --- a/src/blackmisc/aviation/transponder.cpp +++ b/src/blackmisc/aviation/transponder.cpp @@ -59,7 +59,7 @@ namespace BlackMisc bool CTransponder::isInNormalSendingMode() const { - switch (m_transponderMode) + switch (this->getTransponderMode()) { case ModeA: case ModeC: @@ -76,6 +76,18 @@ namespace BlackMisc } } + void CTransponder::toggleTransponderMode() + { + if (this->getTransponderMode() == StateIdent || this->isInNormalSendingMode()) + { + this->setTransponderMode(StateStandby); + } + else + { + this->setTransponderMode(ModeC); + } + } + QString CTransponder::convertToQString(bool /* i18n */) const { return this->getTransponderCodeFormatted().append(" ").append(this->getModeAsString()); diff --git a/src/blackmisc/aviation/transponder.h b/src/blackmisc/aviation/transponder.h index 877b79fa2..3a0416e00 100644 --- a/src/blackmisc/aviation/transponder.h +++ b/src/blackmisc/aviation/transponder.h @@ -37,7 +37,7 @@ namespace BlackMisc enum TransponderMode { StateStandby = 0, //!< not a real mode, more a state - ModeMil1 = 1, ModeMil2 = 2, ModeMil3 = 3, ModeMil4 = 4, ModeMil5 = 5, + ModeMil1 = 1, ModeMil2 = 2, ModeMil3 = 3, ModeMil4 = 4, ModeMil5 = 5, //!< military modes StateIdent = 10, //!< not a real mode, more a state ModeA = 11, ModeC = 12, @@ -47,7 +47,7 @@ namespace BlackMisc //! Indexes enum ColumnIndex { - IndexMode = BlackMisc::CPropertyIndex::GlobalIndexCTransponder, + IndexMode = CPropertyIndex::GlobalIndexCTransponder, IndexModeAsString, IndexTransponderCode, IndexTransponderCodeFormatted, @@ -93,6 +93,9 @@ namespace BlackMisc //! Transponder mode TransponderMode getTransponderMode() const { return static_cast(m_transponderMode); } + //! Transponder mode toggled + void toggleTransponderMode(); + //! Transponder mode as string static const QString &modeAsString(TransponderMode mode); @@ -111,7 +114,7 @@ namespace BlackMisc //! Set transponder code void setTransponderCode(const QString &transponderCode); - //! Mode from string + //! Mode from string static TransponderMode modeFromString(const QString &modeString); //! Set transponder mode @@ -127,10 +130,10 @@ namespace BlackMisc void setIFR() { m_transponderCode = 2000; } //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + CVariant propertyByIndex(const CPropertyIndex &index) const; //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex - void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); + void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); //! \copydoc BlackMisc::Mixin::String::toQString QString convertToQString(bool i18n = false) const;