39using namespace swift::misc::physical_quantities;
40using namespace swift::misc::aviation;
41using namespace swift::misc::network;
42using namespace swift::misc::geo;
43using namespace swift::misc::audio;
44using namespace swift::misc::simulation;
48namespace swift::core::context
57 m_historyTimer.setObjectName(this->
objectName() +
"::historyTimer");
58 m_historyTimer.start(2500);
59 m_situationHistory.setSortHint(CAircraftSituationList::TimestampLatestFirst);
63 if (sApp && sApp->getWebDataServices())
66 &CContextOwnAircraft::allSwiftWebDataRead);
70 this->initOwnAircraft();
90 return m_ownAircraft.getComSystem(unit);
100 return m_ownAircraft.getTransponder();
106 return m_ownAircraft.getCallsign();
112 return m_ownAircraft.getPosition();
118 return m_ownAircraft.getSituation();
124 return m_ownAircraft.getParts();
130 return m_ownAircraft.getModel();
138 void CContextOwnAircraft::initOwnAircraft()
145 ownAircraft = m_ownAircraft;
169 m_ownAircraft = ownAircraft;
173 void CContextOwnAircraft::evaluateUpdateHistory()
188 QReadLocker rl(&m_lockAircraft);
189 const CAircraftSituationList situations = m_situationHistory;
192 constexpr int minElements = qRound(MaxHistoryElements * 0.75);
193 if (m_situationHistory.size() < minElements)
202 const CAircraftSituation latest = situations.
front();
207 const CAircraftSituationList ownDistances = situations.
findFarthest(1, latest);
210 QWriteLocker wl(&m_lockAircraft);
211 m_situationHistory.clear();
217 CAircraftModel CContextOwnAircraft::reverseLookupModel(
const CAircraftModel &model)
219 bool modified =
false;
220 const CAircraftModel reverseModel =
235 const bool changed = (m_ownAircraft.
getModel() != updateModel);
240 m_ownAircraft.
setModel(updateModel);
244 emit this->ps_changedModel(updateModel,
identifier);
252 m_ownAircraft.setSituation(situation);
254 if (m_situationHistory.isEmpty() ||
257 m_situationHistory.push_frontKeepLatestAdjustedFirst(situation,
true);
258 if (m_situationHistory.size() > MaxHistoryElements)
260 m_situationHistory.pop_back();
269 const bool changed = (m_ownAircraft.getParts() != parts);
274 m_ownAircraft.setParts(parts);
281 const bool changed = (m_ownAircraft.getModel().getCG() != cg);
286 m_ownAircraft.setCG(cg);
299 bool changed = (m_ownAircraft.getPosition() != position);
302 m_ownAircraft.setPosition(position);
305 if (m_ownAircraft.getAltitude() != altitude)
308 m_ownAircraft.setAltitude(altitude);
311 if (m_ownAircraft.getPressureAltitude() != pressureAltitude)
314 m_ownAircraft.setPressureAltitude(pressureAltitude);
329 changed = m_ownAircraft.hasChangedCockpitData(com1, com2, transponder);
332 m_ownAircraft.setCockpit(com1, com2, transponder);
352 changed = m_ownAircraft.setTransponderMode(transponderMode);
364 if (unit != CComSystem::Com1 && unit != CComSystem::Com2)
378 xpdr = m_ownAircraft.getTransponder();
380 if (unit == CComSystem::Com1)
389 const bool changed = this->
updateCockpit(com1, com2, xpdr, originator);
396 if (unit != CComSystem::Com1 && unit != CComSystem::Com2)
410 xpdr = m_ownAircraft.getTransponder();
412 if (unit == CComSystem::Com1)
421 const bool changed = this->
updateCockpit(com1, com2, xpdr, originator);
429 if (m_ownAircraft.getPilot() == pilot)
433 m_ownAircraft.setPilot(pilot);
448 xpdr = m_ownAircraft.getTransponder();
463 if (m_ownAircraft.getCallsign() == callsign)
467 m_ownAircraft.setCallsign(callsign);
478 if (!m_ownAircraft.setIcaoCodes(aircraftIcaoCode, airlineIcaoCode))
491 if (m_ownAircraft.getSelcal() == selcal)
495 m_ownAircraft.setSelcal(selcal);
506 void CContextOwnAircraft::xCtxChangedSimulatorStatus(
int status)
508 const ISimulator::SimulatorStatus s =
static_cast<ISimulator::SimulatorStatus
>(status);
517 m_situationHistory.
clear();
521 void CContextOwnAircraft::actionToggleTransponder(
bool keydown)
530 void CContextOwnAircraft::actionIdent(
bool keydown)
540 void CContextOwnAircraft::allSwiftWebDataRead()
557 parser.
parse(commandLine);
558 if (!parser.isKnownCommand())
564 if (parser.matchesCommand(
".x",
".xpdr") && parser.countParts() > 1)
567 int xprCode = parser.toInt(1);
586 else if (parser.commandStartsWith(
"com") || parser.commandStartsWith(
"c"))
593 if (parser.commandEndsWith(
"1"))
597 else if (parser.commandEndsWith(
"2"))
609 else if (parser.matchesCommand(
".selcal"))
static CFrequencyUnit MHz()
Megahertz.
ContextMode
How to handle a given context.
void swiftDbAllDataRead()
All swift DB data have been read.
static bool isAnyConnectedStatus(SimulatorStatus status)
Any connected status?
bool setTransponderMode(swift::misc::aviation::CTransponder::TransponderMode mode)
Set XPDR mode.
swift::misc::simulation::CAircraftModel getOwnAircraftModel() const
Own aircraft model.
bool updateActiveComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, swift::misc::aviation::CComSystem::ComUnit comUnit, const swift::misc::CIdentifier &originator)
Tune in a COM frequency (active).
swift::misc::aviation::CAircraftSituation getOwnAircraftSituation() const
Get own aircraft.
swift::misc::physical_quantities::CLength getDistanceToOwnAircraft(const swift::misc::geo::ICoordinateGeodetic &position) const
Distance to own aircraft.
bool updateTransponderMode(const swift::misc::aviation::CTransponder::TransponderMode &transponderMode, const swift::misc::CIdentifier &originator)
Update own transponder mode.
bool updateOwnPosition(const swift::misc::geo::CCoordinateGeodetic &position, const swift::misc::aviation::CAltitude &altitude, const swift::misc::aviation::CAltitude &pressureAltitude)
Update position.
swift::misc::aviation::CTransponder getOwnTransponder() const
Get own transponder.
bool updateOwnCallsign(const swift::misc::aviation::CCallsign &callsign)
Set callsign.
bool updateOwnIcaoCodes(const swift::misc::aviation::CAircraftIcaoCode &aircraftIcaoCode, const swift::misc::aviation::CAirlineIcaoCode &airlineIcaoCode)
Set ICAO data.
swift::misc::geo::CCoordinateGeodetic getOwnAircraftPosition() const
Own aircraft's position.
swift::misc::simulation::CSimulatedAircraft getOwnAircraft() const
Get own aircraft.
swift::misc::aviation::CCallsign getOwnCallsign() const
Own aircraft's callsign.
bool updateOwnSituation(const swift::misc::aviation::CAircraftSituation &situation)
Update own situation.
void toggleTransponderMode()
Toggle XPDR mode.
bool updateCockpit(const swift::misc::aviation::CComSystem &com1, const swift::misc::aviation::CComSystem &com2, const swift::misc::aviation::CTransponder &transponder, const swift::misc::CIdentifier &originator)
Update own cockpit.
bool updateOwnModel(const swift::misc::simulation::CAircraftModel &model)
Update model.
CContextOwnAircraft(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime)
Constructor, with link to runtime.
bool updateOwnParts(const swift::misc::aviation::CAircraftParts &parts)
Update own parts.
swift::misc::aviation::CAircraftParts getOwnAircraftParts() const
Own aircraft's parts.
bool updateOwnCG(const swift::misc::physical_quantities::CLength &cg)
Update own parts.
bool updateOwnAircraftPilot(const swift::misc::network::CUser &pilot)
Set current pilot.
bool updateStandbyComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, swift::misc::aviation::CComSystem::ComUnit comUnit, const swift::misc::CIdentifier &originator)
Tune in a COM frequency (standby).
swift::misc::aviation::CComSystem getOwnComSystem(swift::misc::aviation::CComSystem::ComUnit unit) const
Get own COM system.
bool updateSelcal(const swift::misc::aviation::CSelcal &selcal, const swift::misc::CIdentifier &originator)
Own SELCAL code.
static void registerHelp()
Register help.
const IContextSimulator * getIContextSimulator() const
Context for simulator.
bool isDebugEnabled() const
Debug enabled?
CCoreFacade * getRuntime()
Runtime.
void changedAircraftCockpit(const swift::misc::simulation::CSimulatedAircraft &aircraft, const swift::misc::CIdentifier &originator)
Aircraft cockpit update.
void changedPilot(const swift::misc::network::CUser &pilot)
Own pilot (aka the swift user) changed.
void changedCallsign(const swift::misc::aviation::CCallsign &callsign)
Own callsign was changed.
void changedAircraftIcaoCodes(const swift::misc::aviation::CAircraftIcaoCode &aircraftIcaoCode, const swift::misc::aviation::CAirlineIcaoCode &airlineIcaoCode)
Own ICAO was changed.
void movedAircraft(const swift::misc::physical_quantities::CLength &distance)
Aircraft has been moved from one location to another (changed scenery).
static swift::misc::simulation::CAircraftModel getDefaultOwnAircraftModel()
Default own aircraft.
static const swift::misc::aviation::CAircraftSituation & getDefaultSituation()
Default situation.
void changedSelcal(const swift::misc::aviation::CSelcal &selcal, const swift::misc::CIdentifier &originator)
Changed SELCAL code.
static swift::misc::simulation::CAircraftModel consolidateOwnAircraftModelWithDbData(const swift::misc::simulation::CAircraftModel &model, bool force, bool *modified=nullptr)
Consolidate own (aircraft) model data with DB data.
T get() const
Get a copy of the current value.
CIdentifiable(const QString &objectName)
Use literal based object name.
const CIdentifier & identifier() const
Get identifier.
Value object encapsulating information identifying a component of a modular distributed swift process...
static const QString & contextSlot()
Context slots.
Class for emitting a log message.
Derived & debug()
Set the severity to debug.
reference front()
Access the first element.
void clear()
Removes all elements in the sequence.
Utility methods for simple line parsing used with the command line.
void parse(const QString &commandLine)
Parse.
qint64 getTimeDifferenceMs(qint64 compareTime) const
Time difference in ms.
Value object for ICAO classification.
bool hasValidDesignator() const
Valid aircraft designator?
Value object encapsulating information of aircraft's parts.
Value object encapsulating information of an aircraft's situation.
Value object for ICAO classification.
Altitude as used in aviation, can be AGL or MSL altitude.
Value object encapsulating information of a callsign.
COM system (aka "radio").
static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz=-1)
COM1 unit.
void setFrequencyStandby(const physical_quantities::CFrequency &frequency)
Set active frequency.
static bool isValidComFrequency(const physical_quantities::CFrequency &f)
Valid COM frequency (either civil or military).
void setFrequencyActive(const physical_quantities::CFrequency &frequency)
Set active frequency.
static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz=-1)
COM2 unit.
static bool isValidCode(const QString &code)
Valid SELCAL code?
static bool isValidTransponderCode(const QString &transponderCode)
Is valid transponder code?
void setTransponderCode(int transponderCode)
Set transponder code.
static TransponderMode modeFromString(const QString &modeString)
Mode from string.
bool setTransponderMode(TransponderMode mode)
Set transponder mode.
void toggleTransponderMode()
Transponder mode toggled.
TransponderMode
Transponder codes.
@ StateIdent
not a real mode, more a state
Geodetic coordinate, a position in 3D space relative to the reference geoid.
physical_quantities::CLength calculateGreatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const
Great circle distance.
bool containsObjectOutsideRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Any object in range?
CONTAINER findFarthest(int number, const ICoordinateGeodetic &coordinate) const
Find 0..n objects farthest to the given coordinate.
const CUser & getUser() const
Get user.
Value object encapsulating information of a user.
Physical unit length (length).
static CLengthUnit km()
Kilometer km.
Aircraft model (used by another pilot, my models on disk).
Comprehensive information of an aircraft.
void setCallsign(const aviation::CCallsign &callsign)
Set callsign.
void setModel(const CAircraftModel &model)
Set model.
const aviation::CComSystem & getCom2System() const
Get COM2 system.
void initTransponder()
Meaningful default settings for Transponder.
const aviation::CComSystem & getCom1System() const
Get COM1 system.
void initComSystems()
Meaningful default settings for COM Systems.
void setSituation(const aviation::CAircraftSituation &situation)
Set situation. Won't overwrite the velocity unless it held the default value.
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Get aircraft ICAO info.
bool hasValidCallsign() const
Valid callsign?
const aviation::CTransponder & getTransponder() const
Get transponder.
const simulation::CAircraftModel & getModel() const
Get model (model used for mapping).
void setPilot(const network::CUser &user)
Set pilot.
bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator)
Classes interacting with the swift database (aka "datastore").
Backend services of the swift project, like dealing with the network or the simulators.
Free functions in swift::misc.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
bool isEmpty() const const