mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
refs #395, integrated aircraft airspace snapshot / analyzer into remote provider
* added snapshot class * added snapshot in analyzer, signal for new snapshot * made all provider signals available in CSimulator * added finders in CSimulatedAircraftList * moved COwnAircraftProviderDummy into own file
This commit is contained in:
committed by
Mathew Sutcliffe
parent
6570a0c966
commit
018c5ae1bf
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "airspace_analyzer.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
@@ -17,7 +18,6 @@ using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
CAirspaceAnalyzer::CAirspaceAnalyzer(IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, INetwork *network, QObject *parent) :
|
||||
CContinuousWorker(parent, "CAirspaceAnalyzer"),
|
||||
COwnAircraftAware(ownAircraftProvider),
|
||||
@@ -25,8 +25,18 @@ namespace BlackCore
|
||||
{
|
||||
Q_ASSERT_X(network, Q_FUNC_INFO, "Network object required to connect");
|
||||
|
||||
// start in thread
|
||||
this->setObjectName("CAirspaceAnalyzer");
|
||||
|
||||
// all in new thread from here on
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setObjectName(this->objectName().append(":m_timer"));
|
||||
m_timer->start(5000);
|
||||
bool c = connect(m_timer, &QTimer::timeout, this, &CAirspaceAnalyzer::ps_timeout);
|
||||
Q_ASSERT(c);
|
||||
|
||||
// disconnect
|
||||
bool c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign);
|
||||
c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign);
|
||||
Q_ASSERT(c);
|
||||
c = connect(network, &INetwork::atcDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAtcCallsign);
|
||||
Q_ASSERT(c);
|
||||
@@ -38,9 +48,19 @@ namespace BlackCore
|
||||
Q_ASSERT(c);
|
||||
|
||||
// network
|
||||
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::ps_onConnectionStatusChanged);
|
||||
// If I do not explicitly set Qt::QueuedConnection here, I get a warning message when such a signal is sent:
|
||||
// "INetwork::NetworkConenctionStatus is not registered" (similar to https://forum.qt.io/topic/27083/signal-slot-between-threads-qt-5/9)
|
||||
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::ps_onConnectionStatusChanged, Qt::QueuedConnection);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
|
||||
this->start();
|
||||
}
|
||||
|
||||
CAirspaceAircraftSnapshot CAirspaceAnalyzer::getLatestAirspaceAircraftSnapshot() const
|
||||
{
|
||||
QReadLocker l(&m_lockSnapshot);
|
||||
return m_latestAircraftSnapshot;
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::ps_watchdogTouchAircraftCallsign(const CAircraftSituation &situation, const CTransponder &transponder)
|
||||
@@ -58,19 +78,31 @@ namespace BlackCore
|
||||
m_atcCallsignTimestamps[callsign] = QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::ps_onConnectionStatusChanged(INetwork::ConnectionStatus oldStatus, INetwork::ConnectionStatus newStatus)
|
||||
void CAirspaceAnalyzer::ps_onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus)
|
||||
{
|
||||
Q_UNUSED(oldStatus);
|
||||
if (newStatus == INetwork::Disconnected)
|
||||
{
|
||||
this->clear();
|
||||
this->m_timer->stop();
|
||||
}
|
||||
else if (newStatus == INetwork::Connected)
|
||||
{
|
||||
this->m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::ps_timeout()
|
||||
{
|
||||
this->analyzeAirspace();
|
||||
this->watchdogCheckTimeouts();
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::clear()
|
||||
{
|
||||
m_aircraftCallsignTimestamps.clear();
|
||||
m_atcCallsignTimestamps.clear();
|
||||
m_latestAircraftSnapshot = CAirspaceAircraftSnapshot();
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign(const CCallsign &callsign)
|
||||
@@ -85,9 +117,17 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceAnalyzer::watchdogCheckTimeouts()
|
||||
{
|
||||
qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch;
|
||||
qint64 callThresholdMs = m_timer->interval() * 1.5;
|
||||
m_lastWatchdogCallMsSinceEpoch = currentTimeMsEpoch;
|
||||
|
||||
// this is a trick to not remove everything while debugging
|
||||
if (callDiffMs > callThresholdMs) { return; }
|
||||
|
||||
qint64 aircraftTimeoutMs = m_timeoutAircraft.valueInteger(CTimeUnit::ms());
|
||||
qint64 atcTimeoutMs = m_timeoutAtc.valueInteger(CTimeUnit::ms());
|
||||
qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
qint64 timeoutAircraftEpochMs = currentTimeMsEpoch - aircraftTimeoutMs;
|
||||
qint64 timeoutAtcEpochMs = currentTimeMsEpoch - atcTimeoutMs;
|
||||
|
||||
@@ -107,4 +147,18 @@ namespace BlackCore
|
||||
emit timeoutAtc(callsign);
|
||||
}
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::analyzeAirspace()
|
||||
{
|
||||
CAirspaceAircraftSnapshot snapshot(getAircraftInRange()); // thread safe copy
|
||||
|
||||
// lock block
|
||||
{
|
||||
QWriteLocker l(&m_lockSnapshot);
|
||||
m_latestAircraftSnapshot = snapshot;
|
||||
}
|
||||
|
||||
emit airspaceAircraftSnapshot(snapshot);
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKCORE_AIRSPACE_ANALYZER_H
|
||||
|
||||
#include "blackcore/network.h"
|
||||
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
|
||||
#include "blackmisc/simulation/remoteaircraftprovider.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
#include "blackmisc/worker.h"
|
||||
@@ -23,7 +24,6 @@
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
//! Class monitoring and analyzing (closests aircraft, outdated aircraft / watchdog) airspace
|
||||
//! in background.
|
||||
//!
|
||||
@@ -47,6 +47,10 @@ namespace BlackCore
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
INetwork *network, QObject *parent);
|
||||
|
||||
//! Get the latest snapshot
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const;
|
||||
|
||||
public slots:
|
||||
//! Clear
|
||||
void clear();
|
||||
@@ -58,6 +62,9 @@ namespace BlackCore
|
||||
//! Callsign has timed out
|
||||
void timeoutAtc(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! New aircraft snapshot
|
||||
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
|
||||
|
||||
private slots:
|
||||
//! Remove callsign from watch list
|
||||
void ps_watchdogRemoveAircraftCallsign(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
@@ -73,17 +80,30 @@ namespace BlackCore
|
||||
const BlackMisc::Geo::CCoordinateGeodetic &pos, const BlackMisc::PhysicalQuantities::CLength &range);
|
||||
|
||||
//! Connection status of network changed
|
||||
void ps_onConnectionStatusChanged(INetwork::ConnectionStatus oldStatus, INetwork::ConnectionStatus newStatus);
|
||||
void ps_onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus);
|
||||
|
||||
//! Run a check
|
||||
void ps_timeout();
|
||||
|
||||
private:
|
||||
//! Check for time outs
|
||||
void watchdogCheckTimeouts();
|
||||
|
||||
CCallsignTimestampSet m_aircraftCallsignTimestamps;
|
||||
CCallsignTimestampSet m_atcCallsignTimestamps;
|
||||
//! Analyze the airspace
|
||||
void analyzeAirspace();
|
||||
|
||||
QTimer *m_timer = nullptr; //!< multi purpose timer for snapshots and watchdog
|
||||
|
||||
// watchdog
|
||||
CCallsignTimestampSet m_aircraftCallsignTimestamps; //!< for watchdog (pilots)
|
||||
CCallsignTimestampSet m_atcCallsignTimestamps; //!< for watchdog (ATC)
|
||||
BlackMisc::PhysicalQuantities::CTime m_timeoutAircraft = {15, BlackMisc::PhysicalQuantities::CTimeUnit::s() }; //!< Timeout value for watchdog functionality
|
||||
BlackMisc::PhysicalQuantities::CTime m_timeoutAtc = {50, BlackMisc::PhysicalQuantities::CTimeUnit::s() }; //!< Timeout value for watchdog functionality
|
||||
qint64 m_lastWatchdogCallMsSinceEpoch;
|
||||
|
||||
// snapshot
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot m_latestAircraftSnapshot;
|
||||
mutable QReadWriteLock m_lockSnapshot; //!< lock snapshot
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -81,6 +81,12 @@ namespace BlackCore
|
||||
return m_aircraftInRange.size();
|
||||
}
|
||||
|
||||
CAirspaceAircraftSnapshot CAirspaceMonitor::getLatestAirspaceAircraftSnapshot() const
|
||||
{
|
||||
Q_ASSERT_X(this->m_analyzer, Q_FUNC_INFO, "No analyzer");
|
||||
return this->m_analyzer->getLatestAirspaceAircraftSnapshot();
|
||||
}
|
||||
|
||||
CAircraftSituationList CAirspaceMonitor::remoteAircraftSituations(const CCallsign &callsign) const
|
||||
{
|
||||
QReadLocker l(&m_lockSituations);
|
||||
@@ -124,9 +130,11 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
bool CAirspaceMonitor::connectRemoteAircraftProviderSignals(
|
||||
std::function<void(const CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const CAircraftParts &)> partsSlot,
|
||||
std::function<void(const CCallsign &)> removedAircraftSlot)
|
||||
std::function<void(const CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const CAircraftParts &)> partsSlot,
|
||||
std::function<void(const CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
)
|
||||
{
|
||||
bool s1 = connect(this, &CAirspaceMonitor::addedAircraftSituation, situationSlot);
|
||||
Q_ASSERT(s1);
|
||||
@@ -134,7 +142,10 @@ namespace BlackCore
|
||||
Q_ASSERT(s2);
|
||||
bool s3 = connect(this, &CAirspaceMonitor::removedAircraft, removedAircraftSlot);
|
||||
Q_ASSERT(s3);
|
||||
return s1 && s2 && s3;
|
||||
bool s4 = connect(this->m_analyzer, &CAirspaceAnalyzer::airspaceAircraftSnapshot, aircraftSnapshotSlot);
|
||||
Q_ASSERT(s4);
|
||||
|
||||
return s1 && s2 && s3 && s4;
|
||||
}
|
||||
|
||||
bool CAirspaceMonitor::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const QString &originator)
|
||||
|
||||
@@ -56,6 +56,10 @@ namespace BlackCore
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual int getAircraftInRangeCount() const override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::getLatestAirspaceAircraftSnapshot
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::remoteAircraftSituations
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual BlackMisc::Aviation::CAircraftSituationList remoteAircraftSituations(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||
@@ -142,12 +146,12 @@ namespace BlackCore
|
||||
//! Test injected aircraft parts
|
||||
void testAddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts, bool incremental);
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::connectSignals
|
||||
//! \copydoc IRemoteAircraftProvider::connectSignals
|
||||
//! \copydoc IRemoteAircraftProvider::connectRemoteAircraftProviderSignals
|
||||
virtual bool connectRemoteAircraftProviderSignals(
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> partsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> addedSituationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> addedPartsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
) override;
|
||||
|
||||
//! Is interim position sending enabled?
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "blackcorefreefunctions.h"
|
||||
#include "voice_channel.h"
|
||||
#include "network.h"
|
||||
#include "simulator.h"
|
||||
#include <QThread>
|
||||
|
||||
@@ -13,12 +14,13 @@ namespace BlackCore
|
||||
void registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<BlackCore::IVoiceChannel::ConnectionStatus>();
|
||||
qRegisterMetaType<BlackCore::INetwork::ConnectionStatus>();
|
||||
}
|
||||
|
||||
bool isCurrentThreadCreatingThread(QObject *toBeTested)
|
||||
{
|
||||
if (!toBeTested) return false;
|
||||
if (!toBeTested->thread()) return false;
|
||||
if (!toBeTested) { return false; }
|
||||
if (!toBeTested->thread()) { return false; }
|
||||
return (QThread::currentThreadId() == toBeTested->thread()->currentThreadId());
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace BlackCore
|
||||
//! \note this is the function which relays CLogMessage via DBus
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::Event::COriginator &origin) { Q_UNUSED(message); Q_UNUSED(origin); }
|
||||
|
||||
//! \brief Ping a token, used to check if application is alive
|
||||
//! Ping a token, used to check if application is alive
|
||||
virtual qint64 ping(qint64 token) const = 0;
|
||||
|
||||
//! A component has changed its state
|
||||
|
||||
@@ -128,10 +128,11 @@ namespace BlackCore
|
||||
bool CContextNetwork::connectRemoteAircraftProviderSignals(
|
||||
std::function<void (const CAircraftSituation &)> situationSlot,
|
||||
std::function<void (const CAircraftParts &)> partsSlot,
|
||||
std::function<void (const CCallsign &)> removedAircraftSlot)
|
||||
std::function<void (const CCallsign &)> removedAircraftSlot,
|
||||
std::function<void (const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot)
|
||||
{
|
||||
Q_ASSERT(this->m_airspace);
|
||||
return this->m_airspace->connectRemoteAircraftProviderSignals(situationSlot, partsSlot, removedAircraftSlot);
|
||||
return this->m_airspace->connectRemoteAircraftProviderSignals(situationSlot, partsSlot, removedAircraftSlot, aircraftSnapshotSlot);
|
||||
}
|
||||
|
||||
void CContextNetwork::gracefulShutdown()
|
||||
@@ -580,6 +581,11 @@ namespace BlackCore
|
||||
this->m_airspace->updateMarkAllAsNotRendered(originator);
|
||||
}
|
||||
|
||||
CAirspaceAircraftSnapshot CContextNetwork::getLatestAirspaceAircraftSnapshot() const
|
||||
{
|
||||
return this->m_airspace->getLatestAirspaceAircraftSnapshot();
|
||||
}
|
||||
|
||||
bool CContextNetwork::isFastPositionSendingEnabled() const
|
||||
{
|
||||
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
|
||||
@@ -74,9 +74,10 @@ namespace BlackCore
|
||||
//! \copydoc IRemoteAircraftProvider::connectSignals
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual bool connectRemoteAircraftProviderSignals(
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> partsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> addedSituationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> addedPartsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
) override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::updateAircraftRendered
|
||||
@@ -87,6 +88,10 @@ namespace BlackCore
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual void updateMarkAllAsNotRendered(const QString &originator) override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::getLatestAirspaceAircraftSnapshot
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const override;
|
||||
|
||||
public slots:
|
||||
//! \copydoc IContextNetwork::updateAircraftEnabled
|
||||
//! \ingroup remoteaircraftprovider
|
||||
|
||||
@@ -64,16 +64,19 @@ namespace BlackCore
|
||||
//! Current interpolated situation
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
|
||||
const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc, bool isVtolAircraft, InterpolationStatus &status) const = 0;
|
||||
const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc,
|
||||
bool isVtolAircraft, InterpolationStatus &status) const = 0;
|
||||
|
||||
//! Parts before given offset time (aka pending parts)
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime(const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTime, PartsStatus &partsStatus);
|
||||
virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime(
|
||||
const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTime,
|
||||
PartsStatus &partsStatus);
|
||||
|
||||
//! Enable debug messages
|
||||
void enableDebugMessages(bool enabled);
|
||||
|
||||
static const qint64 TimeOffsetMs = 6000; //!< offset for interpolation
|
||||
static const qint64 TimeOffsetMs = 6000; //!< offset for interpolation
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace BlackCore
|
||||
{
|
||||
CAircraftSituation CInterpolatorLinear::getInterpolatedSituation(const CCallsign &callsign, qint64 currentTimeMsSinceEpoc, bool vtolAiracraft, InterpolationStatus &status) const
|
||||
{
|
||||
// has to be thread safe
|
||||
|
||||
static const CAircraftSituation empty;
|
||||
status.reset();
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ namespace BlackCore
|
||||
|
||||
//! Log category
|
||||
static QString getMessageCategory() { return "swift.interpolatorlinear"; }
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
|
||||
@@ -552,4 +552,6 @@ namespace BlackCore
|
||||
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::INetwork::ConnectionStatus)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -20,19 +20,6 @@ using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
void ISimulator::emitSimulatorCombinedStatus()
|
||||
{
|
||||
int status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
;
|
||||
emit simulatorStatusChanged(status);
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
CSimulatorCommon::CSimulatorCommon(const CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
@@ -44,12 +31,45 @@ namespace BlackCore
|
||||
{
|
||||
this->setObjectName(info.getIdentifier());
|
||||
m_oneSecondTimer = new QTimer(this);
|
||||
m_oneSecondTimer->setObjectName(this->objectName().append(":OneSecondTimer"));
|
||||
m_oneSecondTimer->setObjectName(this->objectName().append(":m_oneSecondTimer"));
|
||||
connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer);
|
||||
m_oneSecondTimer->start(1000);
|
||||
|
||||
// provider signals
|
||||
bool c = remoteAircraftProvider->connectRemoteAircraftProviderSignals(
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderAddAircraftSituation, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorCommon::ps_remoteProvideraddAircraftParts, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderRemovedAircraft, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderAircraftSnapshot, this, std::placeholders::_1)
|
||||
);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
|
||||
// info
|
||||
CLogMessage(this).info("Initialized simulator driver %1") << m_simulatorPluginInfo.toQString();
|
||||
}
|
||||
|
||||
void ISimulator::ps_remoteProviderAddAircraftSituation(const CAircraftSituation &situation)
|
||||
{ Q_UNUSED(situation); }
|
||||
|
||||
void ISimulator::ps_remoteProvideraddAircraftParts(const CAircraftParts &parts)
|
||||
{ Q_UNUSED(parts); }
|
||||
|
||||
void ISimulator::ps_remoteProviderRemovedAircraft(const CCallsign &callsign)
|
||||
{ Q_UNUSED(callsign); }
|
||||
|
||||
void ISimulator::ps_remoteProviderAircraftSnapshot(const CAirspaceAircraftSnapshot &aircraftSnapshot)
|
||||
{ Q_UNUSED(aircraftSnapshot); }
|
||||
|
||||
void ISimulator::emitSimulatorCombinedStatus()
|
||||
{
|
||||
int status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0));
|
||||
emit simulatorStatusChanged(status);
|
||||
}
|
||||
|
||||
void CSimulatorCommon::blinkHighlightedAircraft()
|
||||
{
|
||||
if (m_highlightedAircraft.isEmpty() || m_highlightEndTimeMsEpoch < 1) { return; }
|
||||
@@ -202,11 +222,10 @@ namespace BlackCore
|
||||
return !m_maxRenderedDistance.isNull();
|
||||
}
|
||||
|
||||
void CSimulatorCommon::enableDebugMessages(bool driver, bool interpolator)
|
||||
void CSimulatorCommon::enableDebugMessages(bool driverMessages, bool interpolatorMessages)
|
||||
{
|
||||
this->m_debugMessages = driver;
|
||||
Q_UNUSED(interpolator);
|
||||
|
||||
this->m_debugMessages = driverMessages;
|
||||
Q_UNUSED(interpolatorMessages);
|
||||
}
|
||||
|
||||
int CSimulatorCommon::getInstalledModelsCount() const
|
||||
@@ -239,16 +258,6 @@ namespace BlackCore
|
||||
return this->isMaxDistanceRestricted() || this->isMaxAircraftRestricted();
|
||||
}
|
||||
|
||||
const CSimulatorPluginInfo &CSimulatorCommon::getSimulatorPluginInfo() const
|
||||
{
|
||||
return m_simulatorPluginInfo;
|
||||
}
|
||||
|
||||
const CSimulatorSetup &CSimulatorCommon::getSimulatorSetup() const
|
||||
{
|
||||
return m_simulatorSetup;
|
||||
}
|
||||
|
||||
void CSimulatorCommon::deleteAllRenderingRestrictions()
|
||||
{
|
||||
if (!isRenderingEnabled()) { return; }
|
||||
@@ -269,4 +278,17 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
const CSimulatorPluginInfo &CSimulatorCommon::getSimulatorPluginInfo() const
|
||||
{
|
||||
return m_simulatorPluginInfo;
|
||||
}
|
||||
|
||||
const CSimulatorSetup &CSimulatorCommon::getSimulatorSetup() const
|
||||
{
|
||||
return m_simulatorSetup;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -194,6 +194,19 @@ namespace BlackCore
|
||||
//! Installed aircraft models ready or changed
|
||||
void installedAircraftModelsChanged();
|
||||
|
||||
protected slots:
|
||||
//! Provider added situation
|
||||
virtual void ps_remoteProviderAddAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Provider added parts
|
||||
virtual void ps_remoteProvideraddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts);
|
||||
|
||||
//! Provider removed aircraft
|
||||
virtual void ps_remoteProviderRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! Provider aircraft snapshot
|
||||
virtual void ps_remoteProviderAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &aircraftSnapshot);
|
||||
|
||||
protected:
|
||||
//! Default constructor
|
||||
ISimulator(QObject *parent = nullptr) : QObject(parent) {}
|
||||
@@ -201,15 +214,11 @@ namespace BlackCore
|
||||
//! Emit the combined status
|
||||
//! \sa simulatorStatusChanged;
|
||||
void emitSimulatorCombinedStatus();
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
* Interface to a simulator listener.
|
||||
*
|
||||
* The simulator listener is responsible for letting the core know when
|
||||
* the corresponding simulator is started.
|
||||
*/
|
||||
//! Interface to a simulator listener.
|
||||
//! The simulator listener is responsible for letting the core know when
|
||||
//! the corresponding simulator is started.
|
||||
class BLACKCORE_EXPORT ISimulatorListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -246,14 +255,12 @@ namespace BlackCore
|
||||
//! ISimulatorVirtual destructor
|
||||
virtual ~ISimulatorFactory() {}
|
||||
|
||||
//!
|
||||
//! Create a new instance of a driver
|
||||
//! \param info metadata about simulator
|
||||
//! \param ownAircraftProvider in memory access to own aircraft data
|
||||
//! \param renderedAircraftProvider in memory access to rendered aircraft data such as situation history and aircraft itself
|
||||
//! \param parent QObject
|
||||
//! \return driver instance
|
||||
//!
|
||||
virtual ISimulator *create(
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
@@ -297,7 +304,7 @@ namespace BlackCore
|
||||
virtual bool isMaxDistanceRestricted() const override;
|
||||
|
||||
//! \copydoc ISimulator::enableDebuggingMessages
|
||||
virtual void enableDebugMessages(bool driver, bool interpolator) override;
|
||||
virtual void enableDebugMessages(bool driverMessages, bool interpolatorMessages) override;
|
||||
|
||||
//! \copydoc ISimulator::getInstalledModelsCount
|
||||
virtual int getInstalledModelsCount() const override;
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace BlackCore
|
||||
class BLACKCORE_EXPORT IVoiceChannel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(ConnectionStatus)
|
||||
|
||||
public:
|
||||
//! Com status
|
||||
@@ -37,7 +38,7 @@ namespace BlackCore
|
||||
DisconnectedError, //!< Disconnected due to socket error
|
||||
Connecting, //!< Connection initiated but not established
|
||||
Connected, //!< Connection established
|
||||
ConnectingFailed, //!< Failed to connect
|
||||
ConnectingFailed //!< Failed to connect
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
@@ -98,7 +99,7 @@ namespace BlackCore
|
||||
protected:
|
||||
|
||||
};
|
||||
}
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::IVoiceChannel::ConnectionStatus)
|
||||
|
||||
|
||||
@@ -139,8 +139,11 @@ namespace BlackCore
|
||||
else emit audioStopped();
|
||||
}
|
||||
|
||||
void CVoiceChannelVatlib::updateRoomStatus(VatVoiceChannel /* channel */, VatConnectionStatus /** oldVatStatus **/, VatConnectionStatus newVatStatus)
|
||||
void CVoiceChannelVatlib::updateRoomStatus(VatVoiceChannel channel, VatConnectionStatus oldVatStatus, VatConnectionStatus newVatStatus)
|
||||
{
|
||||
Q_UNUSED(channel);
|
||||
Q_UNUSED(oldVatStatus);
|
||||
|
||||
IVoiceChannel::ConnectionStatus oldStatus = m_roomStatus;
|
||||
switch (newVatStatus)
|
||||
{
|
||||
@@ -202,4 +205,4 @@ namespace BlackCore
|
||||
auto obj = cbvar_cast_voiceChannel(cbVar);
|
||||
obj->updateRoomStatus(channel, oldStatus, newStatus);
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace BlackCore
|
||||
void userJoinedVoiceRoom(VatVoiceChannel, int id, const char *name);
|
||||
void userLeftVoiceRoom(VatVoiceChannel, int id, const char *name);
|
||||
void transmissionChanged(VatVoiceChannel, VatVoiceTransmissionStatus status);
|
||||
void updateRoomStatus(VatVoiceChannel channel, VatConnectionStatus /** oldStatus **/, VatConnectionStatus newStatus);
|
||||
void updateRoomStatus(VatVoiceChannel channel, VatConnectionStatus oldStatus, VatConnectionStatus newStatus);
|
||||
|
||||
static void processUserJoined(VatVoiceChannel channel, int id, const char *name, void *cbVar);
|
||||
static void processUserLeft(VatVoiceChannel channel, int id, const char *name, void *cbVar);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/simulation/simulatorinfolist.h"
|
||||
#include "blackmisc/simulation/setsimulator.h"
|
||||
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
|
||||
#include "blackmisc/simulation/simulatorsetup.h"
|
||||
#include "blackmisc/simulation/fsx/simconnectutilities.h"
|
||||
#include "blackmisc/simulation/fscommon/aircraftcfgentrieslist.h"
|
||||
@@ -41,4 +42,5 @@ void BlackMisc::Simulation::registerMetadata()
|
||||
CSimulatedAircraft::registerMetadata();
|
||||
CSimulatedAircraftList::registerMetadata();
|
||||
CSimulatorSetup::registerMetadata();
|
||||
CAirspaceAircraftSnapshot::registerMetadata();
|
||||
}
|
||||
|
||||
59
src/blackmisc/simulation/airspaceaircraftsnapshot.cpp
Normal file
59
src/blackmisc/simulation/airspaceaircraftsnapshot.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "airspaceaircraftsnapshot.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
CAirspaceAircraftSnapshot::CAirspaceAircraftSnapshot()
|
||||
{ }
|
||||
|
||||
CAirspaceAircraftSnapshot::CAirspaceAircraftSnapshot(const CSimulatedAircraftList &allAircraft)
|
||||
{
|
||||
if (!allAircraft.isEmpty())
|
||||
{
|
||||
CSimulatedAircraftList aircraft(allAircraft);
|
||||
aircraft.sortByDistanceToOwnAircraft();
|
||||
CSimulatedAircraftList vtolAircraft(aircraft.findByVtol(true));
|
||||
m_aircraftCallsignsByDistance = aircraft.getCallsigns();
|
||||
m_enabledAircraftCallsignsByDistance = aircraft.findByEnabled(true).getCallsigns();
|
||||
m_disabledAircraftCallsignsByDistance = aircraft.findByEnabled(false).getCallsigns();
|
||||
m_vtolAircraftCallsignsByDistance = vtolAircraft.getCallsigns();
|
||||
m_enabledVtolAircraftCallsignsByDistance = vtolAircraft.findByEnabled(true).getCallsigns();
|
||||
}
|
||||
}
|
||||
|
||||
CVariant CAirspaceAircraftSnapshot::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->toCVariant(); }
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
|
||||
void CAirspaceAircraftSnapshot::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself())
|
||||
{
|
||||
this->convertFromCVariant(variant);
|
||||
return;
|
||||
}
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
}
|
||||
|
||||
QString CAirspaceAircraftSnapshot::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
return this->getTimestamp().toString();
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
91
src/blackmisc/simulation/airspaceaircraftsnapshot.h
Normal file
91
src/blackmisc/simulation/airspaceaircraftsnapshot.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMULATION_AIRSPACEAIRCRAFTANALYZER_H
|
||||
#define BLACKMISC_SIMULATION_AIRSPACEAIRCRAFTANALYZER_H
|
||||
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/aviation/callsignset.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include <QDateTime>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
//! Current situation in the sky analyzed.
|
||||
class CAirspaceAircraftSnapshot : public CValueObject<CAirspaceAircraftSnapshot>
|
||||
{
|
||||
public:
|
||||
//! Default constructor
|
||||
CAirspaceAircraftSnapshot();
|
||||
|
||||
//! Constructor
|
||||
CAirspaceAircraftSnapshot(const BlackMisc::Simulation::CSimulatedAircraftList &allAircraft);
|
||||
|
||||
//! Time when snapshot was taken
|
||||
const QDateTime getTimestamp() const { return QDateTime::fromMSecsSinceEpoch(m_timestampMsSinceEpoch); }
|
||||
|
||||
//! Callsigns by distance
|
||||
const BlackMisc::Aviation::CCallsignSet &getAircraftCallsignsByDistance() const { return m_aircraftCallsignsByDistance; }
|
||||
|
||||
//! Callsigns by distance, only enabled aircraft
|
||||
const BlackMisc::Aviation::CCallsignSet &getEnabledAircraftCallsignsByDistance() const { return m_enabledAircraftCallsignsByDistance; }
|
||||
|
||||
//! Callsigns by distance, only disabled aircraft
|
||||
const BlackMisc::Aviation::CCallsignSet &getDisabledAircraftCallsignsByDistance() const { return m_disabledAircraftCallsignsByDistance; }
|
||||
|
||||
//! VTOL aircraft callsigns by distance, only enabled aircraft
|
||||
const BlackMisc::Aviation::CCallsignSet &getVtolAircraftCallsignsByDistance() const { return m_vtolAircraftCallsignsByDistance; }
|
||||
|
||||
//! VTOL aircraft callsigns by distance, only enabled aircraft
|
||||
const BlackMisc::Aviation::CCallsignSet &getEnabledVtolAircraftCallsignsByDistance() const { return m_enabledVtolAircraftCallsignsByDistance; }
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
virtual void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) override;
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
virtual QString convertToQString(bool i18n = false) const override;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CAirspaceAircraftSnapshot)
|
||||
qint64 m_timestampMsSinceEpoch;
|
||||
|
||||
// remark closest aircraft always first
|
||||
BlackMisc::Aviation::CCallsignSet m_aircraftCallsignsByDistance;
|
||||
|
||||
BlackMisc::Aviation::CCallsignSet m_enabledAircraftCallsignsByDistance;
|
||||
BlackMisc::Aviation::CCallsignSet m_disabledAircraftCallsignsByDistance;
|
||||
|
||||
BlackMisc::Aviation::CCallsignSet m_vtolAircraftCallsignsByDistance;
|
||||
BlackMisc::Aviation::CCallsignSet m_enabledVtolAircraftCallsignsByDistance;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot, (
|
||||
attr(o.m_timestampMsSinceEpoch),
|
||||
attr(o.m_aircraftCallsignsByDistance, flags<DisabledForComparison>()),
|
||||
attr(o.m_enabledAircraftCallsignsByDistance, flags <DisabledForComparison> ()),
|
||||
attr(o.m_disabledAircraftCallsignsByDistance, flags<DisabledForComparison>()),
|
||||
attr(o.m_vtolAircraftCallsignsByDistance, flags <DisabledForComparison> ()),
|
||||
attr(o.m_enabledVtolAircraftCallsignsByDistance, flags<DisabledForComparison>())
|
||||
))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAirspaceAircraftSnapshot)
|
||||
|
||||
#endif
|
||||
@@ -96,88 +96,5 @@ namespace BlackMisc
|
||||
return this->m_ownAircraftProvider->updateOwnIcaoData(icaoData);
|
||||
}
|
||||
|
||||
Geo::CCoordinateGeodetic COwnAircraftProviderDummy::getOwnAircraftPosition() const
|
||||
{
|
||||
return m_ownAircraft.getPosition();
|
||||
}
|
||||
|
||||
CAircraftParts COwnAircraftProviderDummy::getOwnAircraftParts() const
|
||||
{
|
||||
return m_ownAircraft.getParts();
|
||||
}
|
||||
|
||||
CAircraftModel COwnAircraftProviderDummy::getOwnAircraftModel() const
|
||||
{
|
||||
return m_ownAircraft.getModel();
|
||||
}
|
||||
|
||||
CLength COwnAircraftProviderDummy::getDistanceToOwnAircraft(const Geo::ICoordinateGeodetic &position) const
|
||||
{
|
||||
return m_ownAircraft.calculateGreatCircleDistance(position);
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateCockpit(const Aviation::CComSystem &com1, const Aviation::CComSystem &com2, const Aviation::CTransponder &transponder, const QString &originator)
|
||||
{
|
||||
m_ownAircraft.setCom1System(com1);
|
||||
m_ownAircraft.setCom2System(com2);
|
||||
m_ownAircraft.setTransponder(transponder);
|
||||
Q_UNUSED(originator);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateActiveComFrequency(const PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator)
|
||||
{
|
||||
if (!CComSystem::isValidComFrequency(frequency)) { return false; }
|
||||
CComSystem::ComUnit comUnitEnum = static_cast<CComSystem::ComUnit>(comUnit);
|
||||
CComSystem com = m_ownAircraft.getComSystem(comUnitEnum);
|
||||
com.setFrequencyActive(frequency);
|
||||
m_ownAircraft.setComSystem(com, comUnitEnum);
|
||||
Q_UNUSED(originator);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateSelcal(const CSelcal &selcal, const QString &originator)
|
||||
{
|
||||
m_ownAircraft.setSelcal(selcal);
|
||||
Q_UNUSED(originator);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnModel(const CAircraftModel &model)
|
||||
{
|
||||
m_ownAircraft.setModel(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnSituation(const CAircraftSituation &situation)
|
||||
{
|
||||
m_ownAircraft.setSituation(situation);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnParts(const CAircraftParts &parts)
|
||||
{
|
||||
m_ownAircraft.setParts(parts);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnCallsign(const CCallsign &callsign)
|
||||
{
|
||||
m_ownAircraft.setCallsign(callsign);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnIcaoData(const CAircraftIcao &icaoData)
|
||||
{
|
||||
m_ownAircraft.setIcaoInfo(icaoData);
|
||||
return true;
|
||||
}
|
||||
|
||||
COwnAircraftProviderDummy *COwnAircraftProviderDummy::instance()
|
||||
{
|
||||
static COwnAircraftProviderDummy *dummy = new COwnAircraftProviderDummy();
|
||||
return dummy;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
104
src/blackmisc/simulation/ownaircraftproviderdummy.cpp
Normal file
104
src/blackmisc/simulation/ownaircraftproviderdummy.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "ownaircraftproviderdummy.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
|
||||
Geo::CCoordinateGeodetic COwnAircraftProviderDummy::getOwnAircraftPosition() const
|
||||
{
|
||||
return m_ownAircraft.getPosition();
|
||||
}
|
||||
|
||||
CAircraftParts COwnAircraftProviderDummy::getOwnAircraftParts() const
|
||||
{
|
||||
return m_ownAircraft.getParts();
|
||||
}
|
||||
|
||||
CAircraftModel COwnAircraftProviderDummy::getOwnAircraftModel() const
|
||||
{
|
||||
return m_ownAircraft.getModel();
|
||||
}
|
||||
|
||||
CLength COwnAircraftProviderDummy::getDistanceToOwnAircraft(const Geo::ICoordinateGeodetic &position) const
|
||||
{
|
||||
return m_ownAircraft.calculateGreatCircleDistance(position);
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateCockpit(const Aviation::CComSystem &com1, const Aviation::CComSystem &com2, const Aviation::CTransponder &transponder, const QString &originator)
|
||||
{
|
||||
m_ownAircraft.setCom1System(com1);
|
||||
m_ownAircraft.setCom2System(com2);
|
||||
m_ownAircraft.setTransponder(transponder);
|
||||
Q_UNUSED(originator);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateActiveComFrequency(const PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator)
|
||||
{
|
||||
if (!CComSystem::isValidComFrequency(frequency)) { return false; }
|
||||
CComSystem::ComUnit comUnitEnum = static_cast<CComSystem::ComUnit>(comUnit);
|
||||
CComSystem com = m_ownAircraft.getComSystem(comUnitEnum);
|
||||
com.setFrequencyActive(frequency);
|
||||
m_ownAircraft.setComSystem(com, comUnitEnum);
|
||||
Q_UNUSED(originator);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateSelcal(const CSelcal &selcal, const QString &originator)
|
||||
{
|
||||
m_ownAircraft.setSelcal(selcal);
|
||||
Q_UNUSED(originator);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnModel(const CAircraftModel &model)
|
||||
{
|
||||
m_ownAircraft.setModel(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnSituation(const CAircraftSituation &situation)
|
||||
{
|
||||
m_ownAircraft.setSituation(situation);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnParts(const CAircraftParts &parts)
|
||||
{
|
||||
m_ownAircraft.setParts(parts);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnCallsign(const CCallsign &callsign)
|
||||
{
|
||||
m_ownAircraft.setCallsign(callsign);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COwnAircraftProviderDummy::updateOwnIcaoData(const CAircraftIcao &icaoData)
|
||||
{
|
||||
m_ownAircraft.setIcaoInfo(icaoData);
|
||||
return true;
|
||||
}
|
||||
|
||||
COwnAircraftProviderDummy *COwnAircraftProviderDummy::instance()
|
||||
{
|
||||
static COwnAircraftProviderDummy *dummy = new COwnAircraftProviderDummy();
|
||||
return dummy;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
82
src/blackmisc/simulation/ownaircraftproviderdummy.h
Normal file
82
src/blackmisc/simulation/ownaircraftproviderdummy.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMULATION_OWNAIRCRAFTPROVIDERDUMMY_H
|
||||
#define BLACKMISC_SIMULATION_OWNAIRCRAFTPROVIDERDUMMY_H
|
||||
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
//! For testing, thread safety not implemented in this class
|
||||
class COwnAircraftProviderDummy :
|
||||
public QObject,
|
||||
public IOwnAircraftProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
COwnAircraftProviderDummy() = default;
|
||||
|
||||
//! Singleton
|
||||
static COwnAircraftProviderDummy *instance();
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::getOwnAircraft
|
||||
virtual CSimulatedAircraft getOwnAircraft() const override { return this->m_ownAircraft; }
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::getOwnAircraftPosition
|
||||
virtual BlackMisc::Geo::CCoordinateGeodetic getOwnAircraftPosition() const override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::getOwnAircraftParts
|
||||
virtual BlackMisc::Aviation::CAircraftParts getOwnAircraftParts() const override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::getOwnAircraftModel
|
||||
virtual BlackMisc::Simulation::CAircraftModel getOwnAircraftModel() const;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::getDistanceToOwnAircraft
|
||||
virtual BlackMisc::PhysicalQuantities::CLength getDistanceToOwnAircraft(const BlackMisc::Geo::ICoordinateGeodetic &position) const override;
|
||||
|
||||
public slots:
|
||||
//! \copydoc IOwnAircraftProvider::updateCockpit
|
||||
virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::updateComFrequency
|
||||
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator) override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::updateSelcal
|
||||
virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const QString &originator) override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::updateOwnCallsign
|
||||
virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::updateOwnModel
|
||||
virtual bool updateOwnModel(const BlackMisc::Simulation::CAircraftModel &model) override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::updateOwnIcaoData
|
||||
virtual bool updateOwnIcaoData(const BlackMisc::Aviation::CAircraftIcao &icaoData) override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::updateOwnSituation
|
||||
virtual bool updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override;
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::updateOwnParts
|
||||
virtual bool updateOwnParts(const BlackMisc::Aviation::CAircraftParts &parts) override;
|
||||
|
||||
private:
|
||||
BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
@@ -34,6 +34,11 @@ namespace BlackMisc
|
||||
return m_aircraft.findFirstByCallsign(callsign);
|
||||
}
|
||||
|
||||
CAirspaceAircraftSnapshot CRemoteAircraftProviderDummy::getLatestAirspaceAircraftSnapshot() const
|
||||
{
|
||||
return CAirspaceAircraftSnapshot(m_aircraft);
|
||||
}
|
||||
|
||||
CAircraftPartsList CRemoteAircraftProviderDummy::remoteAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTimeBefore) const
|
||||
{
|
||||
if (cutoffTimeBefore < 0) { return m_parts.findByCallsign(callsign); }
|
||||
@@ -60,12 +65,19 @@ namespace BlackMisc
|
||||
return remoteAircraftParts(callsign).size() > 0;
|
||||
}
|
||||
|
||||
bool CRemoteAircraftProviderDummy::connectRemoteAircraftProviderSignals(std::function<void (const CAircraftSituation &)> situationSlot, std::function<void (const CAircraftParts &)> partsSlot, std::function<void (const CCallsign &)> removedAircraftSlot)
|
||||
bool CRemoteAircraftProviderDummy::connectRemoteAircraftProviderSignals(
|
||||
std::function<void (const CAircraftSituation &)> situationSlot,
|
||||
std::function<void (const CAircraftParts &)> partsSlot,
|
||||
std::function<void (const CCallsign &)> removedAircraftSlot,
|
||||
std::function<void (const CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
)
|
||||
{
|
||||
bool s1 = connect(this, &CRemoteAircraftProviderDummy::addedRemoteAircraftSituation, situationSlot);
|
||||
bool s2 = connect(this, &CRemoteAircraftProviderDummy::addedRemoteAircraftParts, partsSlot);
|
||||
bool s3 = connect(this, &CRemoteAircraftProviderDummy::removedRemoteAircraft, removedAircraftSlot);
|
||||
return s1 && s2 && s3;
|
||||
bool s4 = connect(this, &CRemoteAircraftProviderDummy::airspaceAircraftSnapshot, aircraftSnapshotSlot);
|
||||
|
||||
return s1 && s2 && s3 && s4;
|
||||
}
|
||||
|
||||
bool CRemoteAircraftProviderDummy::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRendering, const QString &originator)
|
||||
|
||||
@@ -41,6 +41,9 @@ namespace BlackMisc
|
||||
//! IRemoteAircraftProvider::getAircraftInRangeForCallsign
|
||||
virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::getLatestAirspaceAircraftSnapshot
|
||||
virtual BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::remoteAircraftParts
|
||||
virtual BlackMisc::Aviation::CAircraftPartsList remoteAircraftParts(const Aviation::CCallsign &callsign, qint64 cutoffTimeBefore = -1) const override;
|
||||
|
||||
@@ -58,9 +61,10 @@ namespace BlackMisc
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::connectRemoteAircraftProviderSignals
|
||||
virtual bool connectRemoteAircraftProviderSignals(
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> partsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> addedSituationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> addedPartsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
) override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::updateAircraftEnabled
|
||||
@@ -97,6 +101,9 @@ namespace BlackMisc
|
||||
//! Added aircraft
|
||||
void removedRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! New aircraft snapshot
|
||||
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
|
||||
|
||||
private:
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_aircraft;
|
||||
BlackMisc::Aviation::CAircraftSituationList m_situations;
|
||||
|
||||
@@ -44,6 +44,16 @@ namespace BlackMisc
|
||||
return this->findBy(Predicates::MemberValid(&CSimulatedAircraft::getPilot)).transform(Predicates::MemberTransform(&CSimulatedAircraft::getPilot));
|
||||
}
|
||||
|
||||
CSimulatedAircraftList CSimulatedAircraftList::findByEnabled(bool enabled) const
|
||||
{
|
||||
return this->findBy(&CSimulatedAircraft::isEnabled, enabled);
|
||||
}
|
||||
|
||||
CSimulatedAircraftList CSimulatedAircraftList::findByVtol(bool vtol) const
|
||||
{
|
||||
return this->findBy(&CSimulatedAircraft::isVtol, vtol);
|
||||
}
|
||||
|
||||
CCallsignSet CSimulatedAircraftList::getCallsignsWithSyncronizedParts() const
|
||||
{
|
||||
CCallsignSet csl;
|
||||
|
||||
@@ -44,6 +44,12 @@ namespace BlackMisc
|
||||
//! All pilots (with valid data)
|
||||
BlackMisc::Network::CUserList getPilots() const;
|
||||
|
||||
//! Enabled / disabled aircraft
|
||||
CSimulatedAircraftList findByEnabled(bool enabled) const;
|
||||
|
||||
//! VTOL / non VTOL aircraft
|
||||
CSimulatedAircraftList findByVtol(bool vtol) const;
|
||||
|
||||
//! Callsigns of aircraft with synchronized parts
|
||||
BlackMisc::Aviation::CCallsignSet getCallsignsWithSyncronizedParts() const;
|
||||
|
||||
|
||||
@@ -651,7 +651,7 @@ namespace BlackSimPlugin
|
||||
CAircraftPartsList parts;
|
||||
if (partsStatus.supportsParts)
|
||||
{
|
||||
this->m_interpolator->getPartsBeforeTime(callsign, currentTimestamp - IInterpolator::TimeOffsetMs, partsStatus);
|
||||
this->m_interpolator->getPartsBeforeTime(callsign, currentTimestamp - this->m_interpolator->TimeOffsetMs, partsStatus);
|
||||
}
|
||||
|
||||
if (interpolatorStatus.allTrue())
|
||||
|
||||
@@ -58,16 +58,7 @@ namespace BlackSimPlugin
|
||||
connect(m_slowTimer, &QTimer::timeout, this, &CSimulatorXPlane::ps_slowTimerTimeout);
|
||||
m_fastTimer->start(100);
|
||||
m_slowTimer->start(1000);
|
||||
|
||||
resetData();
|
||||
|
||||
bool c = remoteAircraftProvider->connectRemoteAircraftProviderSignals(
|
||||
std::bind(&CSimulatorXPlane::ps_addAircraftSituation, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorXPlane::ps_addAircraftParts, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorXPlane::ps_removedAircraft, this, std::placeholders::_1)
|
||||
);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
}
|
||||
|
||||
// convert xplane squawk mode to swift squawk mode
|
||||
@@ -381,27 +372,27 @@ namespace BlackSimPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSimulatorXPlane::ps_addAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situ)
|
||||
void CSimulatorXPlane::ps_remoteProviderAddAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation)
|
||||
{
|
||||
Q_ASSERT(isConnected());
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
m_traffic->setPlanePosition(situ.getCallsign().asString(),
|
||||
situ.latitude().value(CAngleUnit::deg()),
|
||||
situ.longitude().value(CAngleUnit::deg()),
|
||||
situ.getAltitude().value(CLengthUnit::ft()),
|
||||
situ.getPitch().value(CAngleUnit::deg()),
|
||||
situ.getBank().value(CAngleUnit::deg()),
|
||||
situ.getHeading().value(CAngleUnit::deg()));
|
||||
m_traffic->setPlanePosition(situation.getCallsign().asString(),
|
||||
situation.latitude().value(CAngleUnit::deg()),
|
||||
situation.longitude().value(CAngleUnit::deg()),
|
||||
situation.getAltitude().value(CLengthUnit::ft()),
|
||||
situation.getPitch().value(CAngleUnit::deg()),
|
||||
situation.getBank().value(CAngleUnit::deg()),
|
||||
situation.getHeading().value(CAngleUnit::deg()));
|
||||
}
|
||||
|
||||
void CSimulatorXPlane::ps_addAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts)
|
||||
void CSimulatorXPlane::ps_remoteProvideraddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts)
|
||||
{
|
||||
Q_ASSERT(isConnected());
|
||||
m_traffic->setPlaneSurfaces(parts.getCallsign().asString(), true, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, true, true, true, 0); // TODO landing gear, lights, control surfaces
|
||||
m_traffic->setPlaneTransponder(parts.getCallsign().asString(), 2000, true, false); // TODO transponder
|
||||
}
|
||||
|
||||
void CSimulatorXPlane::ps_removedAircraft(const CCallsign &callsign)
|
||||
void CSimulatorXPlane::ps_remoteProviderRemovedAircraft(const CCallsign &callsign)
|
||||
{
|
||||
Q_UNUSED(callsign);
|
||||
//! \todo call removeRemoteAircraft or just let removeRemoteAircraft handle it?
|
||||
|
||||
@@ -26,9 +26,7 @@ namespace BlackSimPlugin
|
||||
class CXBusServiceProxy;
|
||||
class CXBusTrafficProxy;
|
||||
|
||||
/*!
|
||||
* X-Plane ISimulator implementation
|
||||
*/
|
||||
//! X-Plane ISimulator implementation
|
||||
class CSimulatorXPlane : public BlackCore::CSimulatorCommon
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -112,6 +110,16 @@ namespace BlackSimPlugin
|
||||
//! \copydoc ISimulator::isRenderedAircraft
|
||||
virtual bool isRenderedAircraft(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||
|
||||
protected slots:
|
||||
//! \copydoc CSimulatorCommon::ps_remoteProviderAddAircraftSituation
|
||||
virtual void ps_remoteProviderAddAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override;
|
||||
|
||||
//! \copydoc CSimulatorCommon::ps_remoteProvideraddAircraftParts
|
||||
virtual void ps_remoteProvideraddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts) override;
|
||||
|
||||
//! \copydoc CSimulatorCommon::ps_remoteProviderRemovedAircraft
|
||||
virtual void ps_remoteProviderRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
|
||||
private slots:
|
||||
void ps_serviceUnregistered();
|
||||
void ps_setAirportsInRange(const QStringList &icaoCodes, const QStringList &names, const BlackMisc::CSequence<double> &lats, const BlackMisc::CSequence<double> &lons, const BlackMisc::CSequence<double> &alts);
|
||||
@@ -119,10 +127,6 @@ namespace BlackSimPlugin
|
||||
void ps_fastTimerTimeout();
|
||||
void ps_slowTimerTimeout();
|
||||
|
||||
void ps_addAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situ);
|
||||
void ps_addAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts);
|
||||
void ps_removedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
private:
|
||||
QDBusConnection m_conn { "default" };
|
||||
QDBusServiceWatcher *m_watcher { nullptr };
|
||||
|
||||
Reference in New Issue
Block a user