From de0a827f8732718674532c845e0bc7d1414b3da6 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 30 May 2018 22:15:21 +0200 Subject: [PATCH] Ref T270, also display update aircraft (interpolation) request time * made some ISimulator functions public, so they can be used in UI * added members for request times * better "shutdown" / "disconnect" detection --- src/blackcore/simulator.h | 18 +++--- src/blackcore/simulatorcommon.cpp | 7 ++- src/blackcore/simulatorcommon.h | 8 ++- .../components/interpolationlogdisplay.cpp | 54 +++++++++++++--- .../components/interpolationlogdisplay.h | 12 ++++ .../components/interpolationlogdisplay.ui | 63 +++++++++++++------ 6 files changed, 122 insertions(+), 40 deletions(-) diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 73b379a0f..9ffd6983e 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -173,6 +173,15 @@ namespace BlackCore //! Driver will be unloaded virtual void unload() = 0; + //! Are we connected to the simulator? + virtual bool isConnected() const = 0; + + //! Simulator paused? + virtual bool isPaused() const = 0; + + //! Simulator running? + virtual bool isSimulating() const = 0; + //! Clear all aircraft related data virtual void clearAllRemoteAircraftData() = 0; @@ -252,15 +261,6 @@ namespace BlackCore BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); - //! Are we connected to the simulator? - virtual bool isConnected() const = 0; - - //! Simulator paused? - virtual bool isPaused() const = 0; - - //! Simulator running? - virtual bool isSimulating() const = 0; - //! Add new remote aircraft physically to the simulator //! \sa changeRemoteAircraftEnabled to hide a remote aircraft virtual bool physicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) = 0; diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index 571e3fc11..4d0ef1a20 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -587,6 +587,8 @@ namespace BlackCore m_statsUpdateAircraftTimeTotalMs = 0; m_statsPhysicallyAddedAircraft = 0; m_statsPhysicallyRemovedAircraft = 0; + m_statsLastUpdateAircraftRequested = 0; + m_statsUpdateAircraftRequestedDeltaMs = 0; } CStatusMessageList CSimulatorCommon::debugVerifyStateAfterAllAircraftRemoved() const @@ -638,11 +640,14 @@ namespace BlackCore void CSimulatorCommon::setStatsRemoteAircraftUpdate(qint64 startTime) { - const qint64 dt = QDateTime::currentMSecsSinceEpoch() - startTime; + const qint64 now = QDateTime::currentMSecsSinceEpoch(); + const qint64 dt = now - startTime; m_statsUpdateAircraftTimeTotalMs += dt; m_statsUpdateAircraftRuns++; m_statsUpdateAircraftTimeAvgMs = static_cast(m_statsUpdateAircraftTimeTotalMs) / static_cast(m_statsUpdateAircraftRuns); m_updateRemoteAircraftInProgress = false; + if (m_statsLastUpdateAircraftRequested > 0) { m_statsUpdateAircraftRequestedDeltaMs = startTime - m_statsLastUpdateAircraftRequested; } + m_statsLastUpdateAircraftRequested = startTime; } void CSimulatorCommon::onRecalculatedRenderedAircraft(const CAirspaceAircraftSnapshot &snapshot) diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index f87ce17e0..4ea10bd65 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -123,6 +123,9 @@ namespace BlackCore //! Total update time in ms qint64 getStatisticsTotalUpdateTimeMs() const { return m_statsUpdateAircraftTimeTotalMs; } + //! Time between two update requests + qint64 getStatisticsAircraftUpdatedRequestedDeltaMs() const { return m_statsUpdateAircraftRequestedDeltaMs; } + //! Access to logger const BlackMisc::Simulation::CInterpolationLogger &interpolationLogger() const { return m_interpolationLogger; } @@ -239,8 +242,11 @@ namespace BlackCore bool m_updateRemoteAircraftInProgress = false; //!< currently updating remote aircraft int m_timerId = -1; //!< dispatch timer id int m_statsUpdateAircraftRuns = 0; //!< statistics update count - qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics total update time double m_statsUpdateAircraftTimeAvgMs = 0; //!< statistics average update time + qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics total update time + qint64 m_statsLastUpdateAircraftRequested = 0; //!< when was the last aircraft update requested + qint64 m_statsUpdateAircraftRequestedDeltaMs = 0; //!< delta time between 2 aircrat updates + BlackMisc::Simulation::CSimulatorInternals m_simulatorInternals; //!< setup object BlackMisc::Simulation::CInterpolationLogger m_interpolationLogger; //!< log.interpolation QMap m_clampedLogMsg; //!< when logged last so there, can be used so there is no log message overflow diff --git a/src/blackgui/components/interpolationlogdisplay.cpp b/src/blackgui/components/interpolationlogdisplay.cpp index a0b45041b..598b0739e 100644 --- a/src/blackgui/components/interpolationlogdisplay.cpp +++ b/src/blackgui/components/interpolationlogdisplay.cpp @@ -32,15 +32,13 @@ namespace BlackGui QFrame(parent), ui(new Ui::CInterpolationLogDisplay) { + Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui"); + ui->setupUi(this); ui->tw_LogTabs->setCurrentIndex(TabFlow); constexpr int timeSecs = 5; ui->hs_UpdateTime->setValue(timeSecs); this->onSliderChanged(timeSecs); - connect(&m_updateTimer, &QTimer::timeout, this, &CInterpolationLogDisplay::updateLog); - connect(ui->hs_UpdateTime, &QSlider::valueChanged, this, &CInterpolationLogDisplay::onSliderChanged); - connect(ui->pb_StartStop, &QPushButton::released, this, &CInterpolationLogDisplay::toggleStartStop); - connect(ui->comp_CallsignCompleter, &CCallsignCompleter::validCallsignEntered, this, &CInterpolationLogDisplay::onCallsignEntered); CLedWidget::LedShape shape = CLedWidget::Rounded; ui->led_Parts->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Parts received", "", 14); @@ -49,6 +47,13 @@ namespace BlackGui ui->led_Running->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Running", "Stopped", 14); m_callsign = ui->comp_CallsignCompleter->getCallsign(); + + connect(&m_updateTimer, &QTimer::timeout, this, &CInterpolationLogDisplay::updateLog); + connect(ui->comp_CallsignCompleter, &CCallsignCompleter::validCallsignEntered, this, &CInterpolationLogDisplay::onCallsignEntered); + connect(ui->hs_UpdateTime, &QSlider::valueChanged, this, &CInterpolationLogDisplay::onSliderChanged); + connect(ui->pb_StartStop, &QPushButton::released, this, &CInterpolationLogDisplay::toggleStartStop); + connect(ui->pb_ResetStats, &QPushButton::released, this, &CInterpolationLogDisplay::resetStatistics); + connect(sGui, &CGuiApplication::aboutToShutdown, this, &CInterpolationLogDisplay::onAboutToShutdown); } CInterpolationLogDisplay::~CInterpolationLogDisplay() @@ -65,8 +70,11 @@ namespace BlackGui m_simulatorCommon->disconnect(this); } m_simulatorCommon = simulatorCommon; + if (!simulatorCommon) { return; } connect(m_simulatorCommon, &CSimulatorCommon::receivedRequestedElevation, this, &CInterpolationLogDisplay::onElevationReceived); connect(m_simulatorCommon, &CSimulatorCommon::requestedElevation, this, &CInterpolationLogDisplay::onElevationRequested); + connect(m_simulatorCommon, &CSimulatorCommon::destroyed, this, &CInterpolationLogDisplay::onSimulatorUnloaded); + connect(m_simulatorCommon, &CSimulatorCommon::simulatorStatusChanged, this, &CInterpolationLogDisplay::onSimulatorStatusChanged); } void CInterpolationLogDisplay::setAirspaceMonitor(CAirspaceMonitor *airspaceMonitor) @@ -86,7 +94,7 @@ namespace BlackGui void CInterpolationLogDisplay::updateLog() { if (!sGui || sGui->isShuttingDown()) { return; } - const bool hasLogger = m_simulatorCommon && m_airspaceMonitor; + const bool hasLogger = m_airspaceMonitor && m_simulatorCommon && m_simulatorCommon->isConnected() && !m_simulatorCommon->isShuttingDown(); if (!hasLogger || m_callsign.isEmpty()) { ui->te_TextLog->setText("No logger attached or no callsign"); @@ -106,9 +114,10 @@ namespace BlackGui ui->le_CG->home(false); ui->le_Parts->setText(boolToYesNo(m_airspaceMonitor->isRemoteAircraftSupportingParts(m_callsign))); - static const QString avgUpdateTime("%1ms"); + static const QString msTimeStr("%1ms"); const QString avgUpdateTimeRounded = QString::number(m_simulatorCommon->getStatisticsAverageUpdateTimeMs(), 'f', 2); - ui->le_AvgUpdateTimeMs->setText(avgUpdateTime.arg(avgUpdateTimeRounded)); + ui->le_AvgUpdateTimeMs->setText(msTimeStr.arg(avgUpdateTimeRounded)); + ui->le_UpdateAircraftReqTimeMs->setText(msTimeStr.arg(m_simulatorCommon->getStatisticsAircraftUpdatedRequestedDeltaMs())); const CClient client = m_airspaceMonitor->getClientOrDefaultForCallsign(m_callsign); ui->le_GndFlag->setText(boolToYesNo(client.hasGndFlagCapability())); @@ -149,6 +158,7 @@ namespace BlackGui m_callsign = cs; m_simulatorCommon->setLogInterpolation(true, cs); + this->start(); } void CInterpolationLogDisplay::toggleStartStop() @@ -181,6 +191,26 @@ namespace BlackGui return true; } + void CInterpolationLogDisplay::onAboutToShutdown() + { + m_updateTimer.stop(); + m_simulatorCommon = nullptr; + } + + void CInterpolationLogDisplay::onSimulatorUnloaded() + { + m_updateTimer.stop(); + m_simulatorCommon = nullptr; + this->resetStatistics(); + } + + void CInterpolationLogDisplay::onSimulatorStatusChanged(ISimulator::SimulatorStatus status) + { + Q_UNUSED(status); + m_updateTimer.stop(); + this->resetStatistics(); + } + void CInterpolationLogDisplay::onSituationAdded(const CAircraftSituation &situation) { const CCallsign cs = situation.getCallsign(); @@ -204,16 +234,21 @@ namespace BlackGui if (!this->logCallsign(callsign)) { return; } m_elvReceived++; ui->le_Elevation->setText(plane.toQString()); - ui->led_Elevation->blink(); ui->le_ElevationRec->setText(QString::number(m_elvReceived)); + ui->led_Elevation->blink(); } void CInterpolationLogDisplay::onElevationRequested(const CCallsign &callsign) { if (!this->logCallsign(callsign)) { return; } m_elvRequested++; - ui->led_Elevation->blink(); ui->le_ElevationReq->setText(QString::number(m_elvRequested)); + ui->led_Elevation->blink(); + } + + void CInterpolationLogDisplay::resetStatistics() + { + if (m_simulatorCommon) { m_simulatorCommon->resetAircraftStatistics(); } } void CInterpolationLogDisplay::clear() @@ -227,6 +262,7 @@ namespace BlackGui ui->le_ElevationReq->clear(); ui->le_Parts->clear(); ui->le_AvgUpdateTimeMs->clear(); + ui->le_UpdateAircraftReqTimeMs->clear(); m_elvReceived = m_elvRequested = 0; } diff --git a/src/blackgui/components/interpolationlogdisplay.h b/src/blackgui/components/interpolationlogdisplay.h index bce85def5..e2b401cd7 100644 --- a/src/blackgui/components/interpolationlogdisplay.h +++ b/src/blackgui/components/interpolationlogdisplay.h @@ -78,18 +78,30 @@ namespace BlackGui //! Log the current callsign bool logCallsign(const BlackMisc::Aviation::CCallsign &cs) const; + //! About to shutdown + void onAboutToShutdown(); + + //! Simulator unloaded + void onSimulatorUnloaded(); + //! \copydoc BlackCore::CAirspaceMonitor::addedAircraftSituation void onSituationAdded(const BlackMisc::Aviation::CAircraftSituation &situation); //! \copydoc BlackCore::CAirspaceMonitor::addedAircraftSituation void onPartsAdded(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts); + //! \copydoc BlackCore::CSimulatorCommon::simulatorStatusChanged + void onSimulatorStatusChanged(BlackCore::ISimulator::SimulatorStatus status); + //! \copydoc BlackCore::CSimulatorCommon::receivedRequestedElevation void onElevationReceived(const BlackMisc::Geo::CElevationPlane &plane, const BlackMisc::Aviation::CCallsign &callsign); //! \copydoc BlackCore::CSimulatorCommon::requestedElevation void onElevationRequested(const BlackMisc::Aviation::CCallsign &callsign); + //! \copydoc BlackCore::CSimulatorCommon::resetAircraftStatistics + void resetStatistics(); + //! Clear void clear(); diff --git a/src/blackgui/components/interpolationlogdisplay.ui b/src/blackgui/components/interpolationlogdisplay.ui index 04b932cc0..09e931607 100644 --- a/src/blackgui/components/interpolationlogdisplay.ui +++ b/src/blackgui/components/interpolationlogdisplay.ui @@ -31,7 +31,7 @@ Log. callsign - + 3 @@ -77,6 +77,13 @@ + + + + reset stats. + + + @@ -226,23 +233,6 @@ 0 - - - - CG: - - - - - - - true - - - CG - - - @@ -277,6 +267,23 @@ + + + + update aircraft req.time + + + Update req. + + + + + + + true + + + @@ -336,7 +343,7 @@ - + 0 @@ -349,6 +356,23 @@ 0 + + + + CG: + + + + + + + true + + + CG + + + @@ -442,7 +466,6 @@ comp_CallsignCompleter le_UpdateTime hs_UpdateTime - le_CG le_Parts le_GndFlag le_ElevationReq