7 #include <QWriteLocker>
39 using namespace swift::misc::physical_quantities;
40 using namespace swift::misc::aviation;
41 using namespace swift::misc::network;
42 using namespace swift::misc::geo;
43 using namespace swift::misc::audio;
44 using namespace swift::misc::simulation;
48 namespace swift::core::context
55 connect(&m_historyTimer, &QTimer::timeout,
this, &CContextOwnAircraft::evaluateUpdateHistory);
56 this->setObjectName(
"CContextOwnAircraft");
57 m_historyTimer.setObjectName(this->objectName() +
"::historyTimer");
58 m_historyTimer.start(2500);
59 m_situationHistory.
setSortHint(CAircraftSituationList::TimestampLatestFirst);
66 &CContextOwnAircraft::allSwiftWebDataRead);
70 this->initOwnAircraft();
78 QReadLocker l(&m_lockAircraft);
85 QReadLocker l(&m_lockAircraft);
92 QReadLocker l(&m_lockAircraft);
98 QReadLocker l(&m_lockAircraft);
104 QReadLocker l(&m_lockAircraft);
110 QReadLocker l(&m_lockAircraft);
116 QReadLocker l(&m_lockAircraft);
122 QReadLocker l(&m_lockAircraft);
131 void CContextOwnAircraft::initOwnAircraft()
137 QReadLocker rl(&m_lockAircraft);
138 ownAircraft = m_ownAircraft;
144 ownAircraft.
setPilot(m_currentNetworkServer.
get().getUser());
158 QWriteLocker l(&m_lockAircraft);
159 m_ownAircraft = ownAircraft;
163 void CContextOwnAircraft::evaluateUpdateHistory()
165 if (!m_history) {
return; }
169 QReadLocker rl(&m_lockAircraft);
173 constexpr
int minElements = qRound(MaxHistoryElements * 0.75);
174 if (m_situationHistory.
size() < minElements) {
return; }
179 static const CLength maxDistance(25, CLengthUnit::km());
188 QWriteLocker wl(&m_lockAircraft);
189 m_situationHistory.
clear();
197 bool modified =
false;
199 CDatabaseUtils::consolidateOwnAircraftModelWithDbData(model,
false, &modified);
212 QWriteLocker l(&m_lockAircraft);
213 const bool changed = (m_ownAircraft.
getModel() != updateModel);
214 if (!changed) {
return false; }
215 m_ownAircraft.
setModel(updateModel);
219 emit this->ps_changedModel(updateModel,
identifier);
225 QWriteLocker l(&m_lockAircraft);
229 if (m_situationHistory.
isEmpty() ||
233 if (m_situationHistory.
size() > MaxHistoryElements) { m_situationHistory.
pop_back(); }
240 QWriteLocker l(&m_lockAircraft);
241 const bool changed = (m_ownAircraft.
getParts() != parts);
242 if (!changed) {
return false; }
249 QWriteLocker l(&m_lockAircraft);
250 const bool changed = (m_ownAircraft.
getModel().
getCG() != cg);
251 if (!changed) {
return false; }
252 m_ownAircraft.
setCG(cg);
264 QWriteLocker l(&m_lockAircraft);
265 bool changed = (m_ownAircraft.
getPosition() != position);
266 if (changed) { m_ownAircraft.
setPosition(position); }
291 QWriteLocker l(&m_lockAircraft);
293 if (changed) { m_ownAircraft.
setCockpit(com1, com2, transponder); }
308 QWriteLocker l(&m_lockAircraft);
318 if (unit != CComSystem::Com1 && unit != CComSystem::Com2) {
return false; }
319 if (!CComSystem::isValidComFrequency(frequency)) {
return false; }
323 QReadLocker l(&m_lockAircraft);
331 const bool changed = this->
updateCockpit(com1, com2, xpdr, originator);
338 QWriteLocker l(&m_lockAircraft);
339 if (m_ownAircraft.
getPilot() == pilot) {
return false; }
352 QReadLocker l(&m_lockAircraft);
369 QWriteLocker l(&m_lockAircraft);
370 if (m_ownAircraft.
getCallsign() == callsign) {
return false; }
381 QWriteLocker l(&m_lockAircraft);
382 if (!m_ownAircraft.
setIcaoCodes(aircraftIcaoCode, airlineIcaoCode)) {
return false; }
391 QWriteLocker l(&m_lockAircraft);
392 if (m_ownAircraft.
getSelcal() == selcal) {
return false; }
404 void CContextOwnAircraft::xCtxChangedSimulatorStatus(
int status)
406 const ISimulator::SimulatorStatus s =
static_cast<ISimulator::SimulatorStatus
>(status);
414 QWriteLocker l(&m_lockAircraft);
415 m_situationHistory.
clear();
419 void CContextOwnAircraft::actionToggleTransponder(
bool keydown)
421 if (!keydown) {
return; }
425 void CContextOwnAircraft::actionIdent(
bool keydown)
432 void CContextOwnAircraft::allSwiftWebDataRead()
441 if (commandLine.isEmpty()) {
return false; }
446 parser.
parse(commandLine);
447 if (!parser.isKnownCommand()) {
return false; }
450 if (parser.matchesCommand(
".x",
".xpdr") && parser.countParts() > 1)
453 int xprCode = parser.toInt(1);
454 if (CTransponder::isValidTransponderCode(xprCode))
472 else if (parser.commandStartsWith(
"com") || parser.commandStartsWith(
"c"))
474 CFrequency frequency(parser.toDouble(1), CFrequencyUnit::MHz());
475 if (CComSystem::isValidComFrequency(frequency))
481 else {
return false; }
486 else if (parser.matchesCommand(
".selcal"))
488 if (CSelcal::isValidCode(parser.part(1)))
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
CWebDataServices * getWebDataServices() const
Get the web data services.
ContextMode
How to handle a given context.
The class providing facades (the contexts) for all DBus relevant operations.
void swiftDbAllDataRead()
All swift DB data have been read.
static bool isAnyConnectedStatus(SimulatorStatus status)
Any connected status?
virtual bool setTransponderMode(swift::misc::aviation::CTransponder::TransponderMode mode)
Set XPDR mode.
virtual swift::misc::simulation::CAircraftModel getOwnAircraftModel() const
Own aircraft model.
virtual 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.
virtual swift::misc::aviation::CAircraftSituation getOwnAircraftSituation() const
Get own aircraft.
virtual swift::misc::physical_quantities::CLength getDistanceToOwnAircraft(const swift::misc::geo::ICoordinateGeodetic &position) const
Distance to own aircraft.
virtual bool updateTransponderMode(const swift::misc::aviation::CTransponder::TransponderMode &transponderMode, const swift::misc::CIdentifier &originator)
Update own transponder mode.
virtual bool updateOwnPosition(const swift::misc::geo::CCoordinateGeodetic &position, const swift::misc::aviation::CAltitude &altitude, const swift::misc::aviation::CAltitude &pressureAltitude)
Update position.
virtual swift::misc::aviation::CTransponder getOwnTransponder() const
Get own transponder.
virtual bool updateOwnCallsign(const swift::misc::aviation::CCallsign &callsign)
Set callsign.
virtual ~CContextOwnAircraft()
Destructor.
virtual bool updateOwnIcaoCodes(const swift::misc::aviation::CAircraftIcaoCode &aircraftIcaoCode, const swift::misc::aviation::CAirlineIcaoCode &airlineIcaoCode)
Set ICAO data.
virtual swift::misc::geo::CCoordinateGeodetic getOwnAircraftPosition() const
Own aircraft's position.
virtual swift::misc::simulation::CSimulatedAircraft getOwnAircraft() const
Get own aircraft.
virtual swift::misc::aviation::CCallsign getOwnCallsign() const
Own aircraft's callsign.
virtual bool updateOwnSituation(const swift::misc::aviation::CAircraftSituation &situation)
Update own situation.
virtual void toggleTransponderMode()
Toggle XPDR mode.
virtual 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.
virtual bool updateOwnModel(const swift::misc::simulation::CAircraftModel &model)
Update model.
virtual bool updateOwnParts(const swift::misc::aviation::CAircraftParts &parts)
Update own parts.
virtual swift::misc::aviation::CAircraftParts getOwnAircraftParts() const
Own aircraft's parts.
virtual bool updateOwnCG(const swift::misc::physical_quantities::CLength &cg)
Update own parts.
virtual bool updateOwnAircraftPilot(const swift::misc::network::CUser &pilot)
Set current pilot.
virtual swift::misc::aviation::CComSystem getOwnComSystem(swift::misc::aviation::CComSystem::ComUnit unit) const
Get own COM system.
virtual bool updateSelcal(const swift::misc::aviation::CSelcal &selcal, const swift::misc::CIdentifier &originator)
Own SELCAL code.
static void registerHelp()
Register help.
CCoreFacade * getRuntime()
Runtime.
const IContextSimulator * getIContextSimulator() const
Context for simulator.
bool isDebugEnabled() const
Debug enabled?
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.
T get() const
Get a copy of the current value.
Base class with a member CIdentifier to be inherited by a class which has an identity in the environm...
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.
size_type size() const
Returns number of elements in the sequence.
void pop_back()
Removes an element at the end of the sequence.
reference front()
Access the first element.
void clear()
Removes all elements in the sequence.
bool isEmpty() const
Synonym for empty.
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.
void setSortHint(HintTimestampSort hint)
Set the hint.
void push_frontKeepLatestAdjustedFirst(const OBJ &value, bool replaceSameTimestamp=true, int maxElements=-1)
Insert as first element by keeping maxElements and the latest first.
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.
List of aircraft situations.
Value object for ICAO classification.
Altitude as used in aviation, can be AGL or MSL altitude.
Value object encapsulating information of a callsign.
void setFrequencyActive(const physical_quantities::CFrequency &frequency)
Set active frequency.
void setTransponderCode(int transponderCode)
Set transponder code.
bool setTransponderMode(TransponderMode mode)
Set transponder mode.
void toggleTransponderMode()
Transponder mode toggled.
TransponderMode
Transponder codes.
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.
Value object encapsulating information of a user.
Physical unit length (length)
Aircraft model (used by another pilot, my models on disk)
const physical_quantities::CLength & getCG() const
Get center of gravity.
Comprehensive information of an aircraft.
void setCallsign(const aviation::CCallsign &callsign)
Set callsign.
const aviation::CSelcal getSelcal() const
SELCAL.
void setModel(const CAircraftModel &model)
Set model.
void initTransponder()
Meaningful default settings for Transponder.
const aviation::CAircraftSituation & getSituation() const
Get situation.
void setCockpit(const CSimulatedAircraft &aircraft)
Set COM unit (all values + transponder and SELCAL)
const aviation::CComSystem & getCom2System() const
Get COM2 system.
void initComSystems()
Meaningful default settings for COM Systems.
const aviation::CTransponder & getTransponder() const
Get transponder.
bool setTransponderMode(aviation::CTransponder::TransponderMode mode)
Set transponder mode.
bool setCG(const physical_quantities::CLength &cg)
Set the center of gravity.
void setSelcal(const aviation::CSelcal &selcal)
Own SELCAL code.
const aviation::CAltitude & getPressureAltitude() const
Get pressure altitude.
void setPosition(const geo::CCoordinateGeodetic &position)
Set position.
void setSituation(const aviation::CAircraftSituation &situation)
Set situation. Won't overwrite the velocity unless it held the default value.
void setPressureAltitude(const aviation::CAltitude &altitude)
Set pressure altitude.
const network::CUser & getPilot() const
Get user.
const aviation::CCallsign & getCallsign() const
Get callsign.
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Get aircraft ICAO info.
bool hasChangedCockpitData(const aviation::CComSystem &com1, const aviation::CComSystem &com2, const aviation::CTransponder &transponder) const
Changed cockpit data?
geo::CCoordinateGeodetic getPosition() const
Get position.
bool hasValidCallsign() const
Valid callsign?
const simulation::CAircraftModel & getModel() const
Get model (model used for mapping)
aviation::CComSystem getComSystem(aviation::CComSystem::ComUnit unit) const
Get COM unit.
void setParts(const aviation::CAircraftParts &parts)
Set aircraft parts.
bool setIcaoCodes(const aviation::CAircraftIcaoCode &aircraftIcaoCode, const aviation::CAirlineIcaoCode &airlineIcaoCode)
Set ICAO info.
const aviation::CAltitude & getAltitude() const
Get altitude.
const aviation::CComSystem & getCom1System() const
Get COM1 system.
const aviation::CAircraftParts & getParts() const
Get aircraft parts.
void setPilot(const network::CUser &user)
Set pilot.
void setAltitude(const aviation::CAltitude &altitude)
Set altitude.
virtual bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator)
Parse a given command line.
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.