refs #77, handling commands (aka dot commands)

* network, aircraft context consume command line commands
* hooked up with keypad area
This commit is contained in:
Klaus Basan
2014-10-29 01:28:36 +01:00
committed by Roland Winklmeier
parent fe2fa65d36
commit cd69eebe8c
12 changed files with 115 additions and 8 deletions

View File

@@ -8,6 +8,7 @@
#include "context_audio.h"
#include "context_runtime.h"
#include "context_settings.h"
#include "blackmisc/simplecommandparser.h"
#include "blackmisc/logmessage.h"
using namespace BlackMisc;
@@ -247,4 +248,72 @@ namespace BlackCore
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