mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-11 06:25:33 +08:00
refs #77, handling commands (aka dot commands)
* network, aircraft context consume command line commands * hooked up with keypad area
This commit is contained in:
committed by
Roland Winklmeier
parent
fe2fa65d36
commit
cd69eebe8c
@@ -165,6 +165,9 @@ namespace BlackCore
|
|||||||
//! Load flight plan (from network)
|
//! Load flight plan (from network)
|
||||||
virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const = 0;
|
virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const = 0;
|
||||||
|
|
||||||
|
//! Command line was entered
|
||||||
|
virtual bool parseCommandLine(const QString &commandLine) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Get METAR, if not available request it
|
* Get METAR, if not available request it
|
||||||
* \param airportIcaoCode such as EDDF, KLAX
|
* \param airportIcaoCode such as EDDF, KLAX
|
||||||
|
|||||||
@@ -173,6 +173,14 @@ namespace BlackCore
|
|||||||
if (m_log) { qDebug() << Q_FUNC_INFO << number; }
|
if (m_log) { qDebug() << Q_FUNC_INFO << number; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \copydoc IContextNetwork::parseCommandLine
|
||||||
|
virtual bool parseCommandLine(const QString &commandLine) override
|
||||||
|
{
|
||||||
|
if (m_log) { qDebug() << Q_FUNC_INFO << commandLine; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_log = true;
|
bool m_log = true;
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "blackmisc/networkutils.h"
|
#include "blackmisc/networkutils.h"
|
||||||
#include "blackmisc/avatcstationlist.h"
|
#include "blackmisc/avatcstationlist.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackmisc/simplecommandparser.h"
|
||||||
|
|
||||||
#include <QtXml/QDomElement>
|
#include <QtXml/QDomElement>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
@@ -185,6 +186,15 @@ namespace BlackCore
|
|||||||
return INetwork::isPendingStatus(this->m_currentStatus);
|
return INetwork::isPendingStatus(this->m_currentStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Command line entered
|
||||||
|
*/
|
||||||
|
bool CContextNetwork::parseCommandLine(const QString &commandLine)
|
||||||
|
{
|
||||||
|
Q_UNUSED(commandLine);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send text messages
|
* Send text messages
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
bool isPendingConnection() const;
|
bool isPendingConnection() const;
|
||||||
|
|
||||||
|
//! \copydoc IContextNetwork::parseCommandLine
|
||||||
|
virtual bool parseCommandLine(const QString &commandLine) override;
|
||||||
|
|
||||||
//! \copydoc IContextNetwork::sendTextMessages()
|
//! \copydoc IContextNetwork::sendTextMessages()
|
||||||
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override;
|
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override;
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,11 @@ namespace BlackCore
|
|||||||
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("isConnected"));
|
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("isConnected"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CContextNetworkProxy::parseCommandLine(const QString &commandLine)
|
||||||
|
{
|
||||||
|
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("commandLineEntered"), commandLine);
|
||||||
|
}
|
||||||
|
|
||||||
void CContextNetworkProxy::sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages)
|
void CContextNetworkProxy::sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages)
|
||||||
{
|
{
|
||||||
this->m_dBusInterface->callDBus(QLatin1Literal("sendTextMessages"), textMessages);
|
this->m_dBusInterface->callDBus(QLatin1Literal("sendTextMessages"), textMessages);
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextNetwork::isConnected()
|
//! \copydoc IContextNetwork::isConnected()
|
||||||
virtual bool isConnected() const override;
|
virtual bool isConnected() const override;
|
||||||
|
|
||||||
|
//! \copydoc IContextNetwork::parseCommandLine
|
||||||
|
virtual bool parseCommandLine(const QString &commandLine) override;
|
||||||
|
|
||||||
//! \copydoc IContextNetwork::sendTextMessages()
|
//! \copydoc IContextNetwork::sendTextMessages()
|
||||||
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override;
|
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override;
|
||||||
|
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ namespace BlackCore
|
|||||||
//! Automatic voice room resolution for frequencies
|
//! Automatic voice room resolution for frequencies
|
||||||
virtual void enableAutomaticVoiceRoomResolution(bool enable) = 0;
|
virtual void enableAutomaticVoiceRoomResolution(bool enable) = 0;
|
||||||
|
|
||||||
|
//! Parse command line
|
||||||
|
virtual bool parseCommandLine(const QString &commandLine) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
IContextOwnAircraft(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}
|
IContextOwnAircraft(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "context_audio.h"
|
#include "context_audio.h"
|
||||||
#include "context_runtime.h"
|
#include "context_runtime.h"
|
||||||
#include "context_settings.h"
|
#include "context_settings.h"
|
||||||
|
#include "blackmisc/simplecommandparser.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
@@ -247,4 +248,72 @@ namespace BlackCore
|
|||||||
return this->m_ownAircraft;
|
return this->m_ownAircraft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Command line entered
|
||||||
|
*/
|
||||||
|
bool CContextOwnAircraft::parseCommandLine(const QString &commandLine)
|
||||||
|
{
|
||||||
|
static CSimpleCommandParser parser(
|
||||||
|
{
|
||||||
|
".x", ".xpdr", // transponder
|
||||||
|
".com1", ".com2", // com1, com2 frequencies
|
||||||
|
".selcal"
|
||||||
|
});
|
||||||
|
if (commandLine.isEmpty()) return false;
|
||||||
|
parser.parse(commandLine);
|
||||||
|
if (!parser.isKnownCommand()) return false;
|
||||||
|
|
||||||
|
CAircraft ownAircraft = this->getOwnAircraft();
|
||||||
|
if (parser.matchesCommand(".x", ".xpdr") && parser.countParts() > 1)
|
||||||
|
{
|
||||||
|
CTransponder transponder = ownAircraft.getTransponder();
|
||||||
|
int xprCode = parser.toInt(1);
|
||||||
|
if (CTransponder::isValidTransponderCode(xprCode))
|
||||||
|
{
|
||||||
|
transponder.setTransponderCode(xprCode);
|
||||||
|
this->updateOwnCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), transponder, "commandline");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CTransponder::TransponderMode mode = CTransponder::modeFromString(parser.part(1));
|
||||||
|
transponder.setTransponderMode(mode);
|
||||||
|
this->updateOwnCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), transponder, "commandline");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (parser.commandStartsWith("com"))
|
||||||
|
{
|
||||||
|
CFrequency frequency(parser.toDouble(1), CFrequencyUnit::MHz());
|
||||||
|
if (CComSystem::isValidComFrequency(frequency))
|
||||||
|
{
|
||||||
|
CComSystem com1 = ownAircraft.getCom1System();
|
||||||
|
CComSystem com2 = ownAircraft.getCom2System();
|
||||||
|
if (parser.commandEndsWith("1"))
|
||||||
|
{
|
||||||
|
com1.setFrequencyActive(frequency);
|
||||||
|
}
|
||||||
|
else if (parser.commandEndsWith("2"))
|
||||||
|
{
|
||||||
|
com2.setFrequencyActive(frequency);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this->updateOwnCockpit(com1, com2, ownAircraft.getTransponder(), "commandline");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (parser.matchesCommand(".selcal"))
|
||||||
|
{
|
||||||
|
if (CSelcal::isValidCode(parser.part(1)))
|
||||||
|
{
|
||||||
|
this->updateSelcal(parser.part(1), "commandline");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -86,4 +86,9 @@ namespace BlackCore
|
|||||||
this->m_dBusInterface->callDBus(QLatin1Literal("enableAutomaticVoiceRoomResolution"), enable);
|
this->m_dBusInterface->callDBus(QLatin1Literal("enableAutomaticVoiceRoomResolution"), enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CContextOwnAircraftProxy::parseCommandLine(const QString &commandLine)
|
||||||
|
{
|
||||||
|
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("parseCommandLine"), commandLine);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextOwnAircraft::enableAutomaticVoiceRoomResolution
|
//! \copydoc IContextOwnAircraft::enableAutomaticVoiceRoomResolution
|
||||||
virtual void enableAutomaticVoiceRoomResolution(bool enable);
|
virtual void enableAutomaticVoiceRoomResolution(bool enable);
|
||||||
|
|
||||||
|
//! \copydoc IContextOwnAircraft::parseCommandLine
|
||||||
|
virtual bool parseCommandLine(const QString &commandLine) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ namespace BlackGui
|
|||||||
Q_ASSERT(this->getIContextOwnAircraft());
|
Q_ASSERT(this->getIContextOwnAircraft());
|
||||||
Q_ASSERT(this->getIContextNetwork());
|
Q_ASSERT(this->getIContextNetwork());
|
||||||
connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged);
|
connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged);
|
||||||
|
connect(this, &CMainKeypadAreaComponent::commandEntered, this->getIContextNetwork(), &IContextNetwork::parseCommandLine);
|
||||||
connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged);
|
connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged);
|
||||||
|
connect(this, &CMainKeypadAreaComponent::commandEntered, this->getIContextOwnAircraft(), &IContextOwnAircraft::parseCommandLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainKeypadAreaComponent::ps_buttonPressed()
|
void CMainKeypadAreaComponent::ps_buttonPressed()
|
||||||
@@ -97,11 +99,6 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainKeypadAreaComponent::ps_buttonDoubleClicked()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMainKeypadAreaComponent::ps_connectionStatusChanged(uint from, uint to, const QString &message)
|
void CMainKeypadAreaComponent::ps_connectionStatusChanged(uint from, uint to, const QString &message)
|
||||||
{
|
{
|
||||||
INetwork::ConnectionStatus statusFrom = static_cast<INetwork::ConnectionStatus>(from);
|
INetwork::ConnectionStatus statusFrom = static_cast<INetwork::ConnectionStatus>(from);
|
||||||
@@ -128,6 +125,7 @@ namespace BlackGui
|
|||||||
QString c = this->ui->le_CommandLineInput->text().trimmed();
|
QString c = this->ui->le_CommandLineInput->text().trimmed();
|
||||||
if (c.isEmpty()) return;
|
if (c.isEmpty()) return;
|
||||||
emit this->commandEntered(c);
|
emit this->commandEntered(c);
|
||||||
|
this->ui->le_CommandLineInput->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged(const CAircraft &aircraft, const QString &originator)
|
void CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged(const CAircraft &aircraft, const QString &originator)
|
||||||
|
|||||||
@@ -65,9 +65,6 @@ namespace BlackGui
|
|||||||
//! Button was clicked
|
//! Button was clicked
|
||||||
void ps_buttonPressed();
|
void ps_buttonPressed();
|
||||||
|
|
||||||
//! Button was double clicked
|
|
||||||
void ps_buttonDoubleClicked();
|
|
||||||
|
|
||||||
//! \copydoc BlackCore::IContextNetwork::connectionStatusChanged
|
//! \copydoc BlackCore::IContextNetwork::connectionStatusChanged
|
||||||
void ps_connectionStatusChanged(uint from, uint to, const QString &message);
|
void ps_connectionStatusChanged(uint from, uint to, const QString &message);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user