mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T241, misc. logger improvements
* string formatting of logger info * display longer in simulator * better formatting of message
This commit is contained in:
@@ -811,8 +811,15 @@ namespace BlackCore
|
||||
|
||||
QString dm;
|
||||
static const QString sep("\n");
|
||||
if (s.tsCurrent > 0) { dm = QStringLiteral("Situation: ") % s.toQString(true, true, true, true, true, true, sep); }
|
||||
if (p.tsCurrent > 0) { dm += (dm.isEmpty() ? QStringLiteral("") : "\n\n") % QStringLiteral("Parts: ") % p.toQString(sep); }
|
||||
if (s.tsCurrent > 0)
|
||||
{
|
||||
dm = QStringLiteral("Hints: ") % s.usedHints.asString(false, true) %
|
||||
QStringLiteral("\n") %
|
||||
QStringLiteral("Setup: ") % s.usedSetup.toQString(true) %
|
||||
QStringLiteral("\n\n") %
|
||||
QStringLiteral("Situation: ") % s.toQString(false, false, true, true, true, true, sep);
|
||||
}
|
||||
if (p.tsCurrent > 0) { dm += (dm.isEmpty() ? QStringLiteral("") : QStringLiteral("\n\n")) % QStringLiteral("Parts: ") % p.toQString(sep); }
|
||||
if (!dm.isEmpty()) { this->displayStatusMessage(CStatusMessage(this).info(dm)); }
|
||||
|
||||
const int t = 4500 + (qrand() % 1000); // makes sure not always using the same time difference
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace BlackCore
|
||||
void callPhysicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &remoteCallsign);
|
||||
|
||||
//! Display a logged situation in simulator
|
||||
void displayLoggedSituationInSimulator(const BlackMisc::Aviation::CCallsign &cs, bool stopLogging, int times = 10);
|
||||
void displayLoggedSituationInSimulator(const BlackMisc::Aviation::CCallsign &cs, bool stopLogging, int times = 25);
|
||||
|
||||
bool m_blinkCycle = false; //!< used for highlighting
|
||||
qint64 m_highlightEndTimeMsEpoch = 0; //!< end highlighting
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "interpolationhints.h"
|
||||
#include "interpolationlogger.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
@@ -29,22 +30,54 @@ namespace BlackMisc
|
||||
m_isVtol(isVtolAircraft), m_hasParts(hasParts), m_logInterpolation(log)
|
||||
{ }
|
||||
|
||||
CAltitude CInterpolationHints::getGroundElevation(const CAircraftSituation &situation, bool useProvider, bool forceProvider) const
|
||||
CAltitude CInterpolationHints::getGroundElevation(const CAircraftSituation &situation, bool useProvider, bool forceProvider, SituationLog *log) const
|
||||
{
|
||||
const bool validPlane = m_elevationPlane.isWithinRange(situation);
|
||||
Q_ASSERT_X(!(forceProvider && !useProvider), Q_FUNC_INFO, "Invalid parameter combination");
|
||||
if (forceProvider && useProvider && m_elevationProvider) { return m_elevationProvider(situation); }
|
||||
if (!validPlane && useProvider && m_elevationProvider) { return m_elevationProvider(situation); }
|
||||
return validPlane ? this->m_elevationPlane.getAltitude() : CAltitude::null();
|
||||
static const CLength null = CLength(0, CLengthUnit::nullUnit());
|
||||
return this->getGroundElevation(situation, null, useProvider, forceProvider, log);
|
||||
}
|
||||
|
||||
CAltitude CInterpolationHints::getGroundElevation(const CAircraftSituation &situation, const CLength &validRadius, bool useProvider, bool forceProvider) const
|
||||
CAltitude CInterpolationHints::getGroundElevation(const CAircraftSituation &situation, const CLength &validRadius, bool useProvider, bool forceProvider, SituationLog *log) const
|
||||
{
|
||||
const bool validPlane = m_elevationPlane.isWithinRange(situation, CLength::maxValue(validRadius, m_elevationPlane.getRadius()));
|
||||
Q_ASSERT_X(!(forceProvider && !useProvider), Q_FUNC_INFO, "Invalid parameter combination");
|
||||
if (forceProvider && useProvider && m_elevationProvider) { return m_elevationProvider(situation); }
|
||||
if (!validPlane && useProvider && m_elevationProvider) { return m_elevationProvider(situation); }
|
||||
return validPlane ? this->m_elevationPlane.getAltitude() : CAltitude::null();
|
||||
if (forceProvider && useProvider && m_elevationProvider)
|
||||
{
|
||||
if (log)
|
||||
{
|
||||
static const QString lm("By provider (forced)");
|
||||
log->elevationInfo = lm;
|
||||
}
|
||||
return m_elevationProvider(situation);
|
||||
}
|
||||
|
||||
const CLength radius = CLength::maxValue(validRadius, m_elevationPlane.getRadius());
|
||||
const bool validPlane = m_elevationPlane.isWithinRange(situation, radius);
|
||||
if (!validPlane && useProvider && m_elevationProvider)
|
||||
{
|
||||
if (log)
|
||||
{
|
||||
static const QString lm("By provider (no valid plane)");
|
||||
log->elevationInfo = lm;
|
||||
}
|
||||
return m_elevationProvider(situation);
|
||||
}
|
||||
|
||||
if (validPlane)
|
||||
{
|
||||
if (log)
|
||||
{
|
||||
static const QString lm("Using elevation plane, radius: %1");
|
||||
log->elevationInfo = lm.arg(radius.valueRoundedWithUnit(CLengthUnit::m(), 1));
|
||||
}
|
||||
return m_elevationPlane.getAltitude();
|
||||
}
|
||||
|
||||
if (log)
|
||||
{
|
||||
static const QString lm("Not using provider, no valid plane");
|
||||
log->elevationInfo = lm;
|
||||
}
|
||||
|
||||
return CAltitude::null();
|
||||
}
|
||||
|
||||
void CInterpolationHints::resetElevationPlane()
|
||||
@@ -81,8 +114,8 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexCenterOfGravity: return this->m_cgAboveGround.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexElevationPlane: return this->m_elevationPlane.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexCenterOfGravity: return m_cgAboveGround.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexElevationPlane: return m_elevationPlane.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexIsVtolAircraft: return CVariant::fromValue(m_isVtol);
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
@@ -95,13 +128,13 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexCenterOfGravity:
|
||||
this->m_cgAboveGround.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
m_cgAboveGround.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexElevationPlane:
|
||||
this->m_elevationPlane.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
m_elevationPlane.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexIsVtolAircraft:
|
||||
this->m_isVtol = variant.toBool();
|
||||
m_isVtol = variant.toBool();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
@@ -121,10 +154,10 @@ namespace BlackMisc
|
||||
) %
|
||||
QStringLiteral(" CG: ") % m_cgAboveGround.valueRoundedWithUnit(CLengthUnit::m(), 1) %
|
||||
QStringLiteral(" elv.plane: ") % m_elevationPlane.toQString(i18n) %
|
||||
QStringLiteral(" elv.pr: ") % boolToYesNo(m_elevationProvider ? true : false);
|
||||
QStringLiteral(" elv.pr.: ") % boolToYesNo(m_elevationProvider ? true : false);
|
||||
}
|
||||
|
||||
QString CInterpolationHints::debugInfo(const Geo::CElevationPlane &deltaElevation) const
|
||||
QString CInterpolationHints::debugInfo(const CElevationPlane &deltaElevation) const
|
||||
{
|
||||
static const QString s("Lat: %1 Lng: %2 Elv: %3");
|
||||
if (m_elevationPlane.isNull() || deltaElevation.isNull()) return "null";
|
||||
|
||||
@@ -22,9 +22,10 @@ namespace BlackMisc
|
||||
namespace Aviation { class CAircraftSituation; }
|
||||
namespace Simulation
|
||||
{
|
||||
struct SituationLog;
|
||||
|
||||
//! Hints for interpolator such as ground elevation
|
||||
class BLACKMISC_EXPORT CInterpolationHints :
|
||||
public CValueObject<CInterpolationHints>
|
||||
class BLACKMISC_EXPORT CInterpolationHints : public CValueObject<CInterpolationHints>
|
||||
{
|
||||
public:
|
||||
//! Property indexes
|
||||
@@ -56,16 +57,17 @@ namespace BlackMisc
|
||||
|
||||
//! Get elevation from CInterpolationHints::getElevationProvider or CInterpolationHints::getElevation
|
||||
//! \remark avoid unnecessary calls on XPlane (calling elevation provider)
|
||||
//! @param situation
|
||||
//! @param useProvider using the provider if available
|
||||
//! @param forceProvider use the provider and ignore any plane
|
||||
//! \param situation where to check
|
||||
//! \param useProvider using the provider if available
|
||||
//! \param forceProvider use the provider and ignore any elevation plane
|
||||
//! \param log optional chance to write info about elevation
|
||||
//! \see setElevationProvider
|
||||
//! \see setElevationPlane
|
||||
Aviation::CAltitude getGroundElevation(const Aviation::CAircraftSituation &situation, bool useProvider, bool forceProvider = false) const;
|
||||
Aviation::CAltitude getGroundElevation(const Aviation::CAircraftSituation &situation, bool useProvider, bool forceProvider = false, SituationLog *log = nullptr) const;
|
||||
|
||||
//! Get elevation from CInterpolationHints::getElevationProvider or CInterpolationHints::getElevation
|
||||
//! \remark if validRadius is >= Geo::CElevationPlane::radius use validRadius
|
||||
Aviation::CAltitude getGroundElevation(const Aviation::CAircraftSituation &situation, const PhysicalQuantities::CLength &validRadius, bool useProvider, bool forceProvider = false) const;
|
||||
Aviation::CAltitude getGroundElevation(const Aviation::CAircraftSituation &situation, const PhysicalQuantities::CLength &validRadius, bool useProvider, bool forceProvider = false, SituationLog *log = nullptr) const;
|
||||
|
||||
//! Check if elevation is within radius and can be used
|
||||
bool isWithinRange(const Geo::ICoordinateGeodetic &coordinate) const;
|
||||
@@ -107,7 +109,7 @@ namespace BlackMisc
|
||||
//! Function object that can obtain ground elevation
|
||||
using ElevationProvider = std::function<Aviation::CAltitude(const Aviation::CAircraftSituation &)>;
|
||||
|
||||
//! Has elevation provider
|
||||
//! Has elevation provider?
|
||||
bool hasElevationProvider() const;
|
||||
|
||||
//! Set function object that can obtain ground elevation
|
||||
@@ -131,9 +133,9 @@ namespace BlackMisc
|
||||
private:
|
||||
bool m_isVtol = false; //!< VTOL aircraft?
|
||||
bool m_hasParts = false; //!< Has valid aircraft parts?
|
||||
bool m_logInterpolation = false; //!< log interpolation
|
||||
bool m_logInterpolation = false; //!< Log.interpolation
|
||||
Aviation::CAircraftParts m_aircraftParts; //!< Aircraft parts
|
||||
Geo::CElevationPlane m_elevationPlane; //!< aircraft's elevation if available
|
||||
Geo::CElevationPlane m_elevationPlane; //!< Aircraft's elevation if available
|
||||
ElevationProvider m_elevationProvider; //!< Provider of ground elevation (lazy computation)
|
||||
PhysicalQuantities::CLength m_cgAboveGround { 0, nullptr }; //!< center of gravity above ground
|
||||
|
||||
|
||||
@@ -406,8 +406,9 @@ namespace BlackMisc
|
||||
return s3.arg(msSinceEpochToTime(t1), msSinceEpochToTime(t2), msSinceEpochToTime(t3));
|
||||
}
|
||||
|
||||
QString CInterpolationLogger::SituationLog::toQString(
|
||||
bool withCurrentSituation, bool withHints, bool withSetup,
|
||||
QString SituationLog::toQString(
|
||||
bool withHints, bool withSetup,
|
||||
bool withCurrentSituation,
|
||||
bool withElevation, bool withOtherPositions, bool withDeltaTimes, const QString &separator) const
|
||||
{
|
||||
const CAircraftSituation situationOldInterpolation = this->oldestInterpolationSituation();
|
||||
@@ -431,7 +432,9 @@ namespace BlackMisc
|
||||
(
|
||||
withElevation ?
|
||||
separator %
|
||||
QStringLiteral("transf.elv.: ") % QString::number(noTransferredElevations) :
|
||||
QStringLiteral("Elev.: ") %
|
||||
QStringLiteral("transf.elv.: ") % QString::number(noTransferredElevations) %
|
||||
QStringLiteral(" | elv.info: ") % elevationInfo :
|
||||
QStringLiteral("")
|
||||
) %
|
||||
(
|
||||
@@ -467,6 +470,7 @@ namespace BlackMisc
|
||||
{
|
||||
return QStringLiteral("CS: ") % callsign.asString() % separator %
|
||||
QStringLiteral("ts: ") % CInterpolationLogger::msSinceEpochToTimeAndTimestamp(tsCurrent) %
|
||||
QStringLiteral(" | #nw.parts: ") % QString::number(noNetworkParts) %
|
||||
separator %
|
||||
QStringLiteral("parts: ") % parts.toQString(true);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,9 @@ namespace BlackMisc
|
||||
|
||||
// this code is used by linear and spline interpolator
|
||||
status.reset();
|
||||
CInterpolationLogger::SituationLog log;
|
||||
const bool doLogging = this->hasAttachedLogger() && hints.isLoggingInterpolation();
|
||||
SituationLog log;
|
||||
SituationLog *logP = doLogging ? &log : nullptr;
|
||||
|
||||
// any data at all?
|
||||
if (m_aircraftSituations.isEmpty()) { return CAircraftSituation(m_callsign); }
|
||||
@@ -77,7 +79,7 @@ namespace BlackMisc
|
||||
// * for FSX/P3D provided as hints.getElevation which is set to current position of remote aircraft in simulator
|
||||
// * As XP uses lazy init we will call getGroundElevation only when needed
|
||||
// * default here via getElevationPlane
|
||||
CAltitude currentGroundElevation(hints.getGroundElevation(currentSituation, currentSituation.getDistancePerTime(1000), false, false));
|
||||
CAltitude currentGroundElevation(hints.getGroundElevation(currentSituation, currentSituation.getDistancePerTime(1000), true, false, logP));
|
||||
currentSituation.setGroundElevation(currentGroundElevation); // set as default
|
||||
|
||||
// data, split situations by time
|
||||
@@ -122,7 +124,7 @@ namespace BlackMisc
|
||||
// if not having an ground elevation yet, we fetch from provider (if there is a provider)
|
||||
if (!currentGroundElevation.isNull())
|
||||
{
|
||||
currentGroundElevation = hints.getGroundElevation(currentSituation, true); // "expensive on XPlane" if provider is called
|
||||
currentGroundElevation = hints.getGroundElevation(currentSituation, true, false, logP); // "expensive on XPlane" if provider is called
|
||||
}
|
||||
|
||||
if (!currentGroundElevation.isNull())
|
||||
@@ -298,8 +300,9 @@ namespace BlackMisc
|
||||
void CInterpolator<Derived>::logParts(qint64 timestamp, const CAircraftParts &parts, bool empty, bool log) const
|
||||
{
|
||||
if (!log || !m_logger) { return; }
|
||||
CInterpolationLogger::PartsLog logInfo;
|
||||
PartsLog logInfo;
|
||||
logInfo.callsign = m_callsign;
|
||||
logInfo.noNetworkParts = m_aircraftParts.size();
|
||||
logInfo.tsCurrent = timestamp;
|
||||
logInfo.parts = parts;
|
||||
logInfo.empty = empty;
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace BlackMisc
|
||||
return m_remoteAircraftProvider->getRemoteAircraftSupportingPartsCount();
|
||||
}
|
||||
|
||||
bool CRemoteAircraftAware::updateAircraftEnabled(const Aviation::CCallsign &callsign, bool enabledForRedering)
|
||||
bool CRemoteAircraftAware::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering)
|
||||
{
|
||||
Q_ASSERT_X(m_remoteAircraftProvider, Q_FUNC_INFO, "No object available");
|
||||
return m_remoteAircraftProvider->updateAircraftEnabled(callsign, enabledForRedering);
|
||||
@@ -132,10 +132,10 @@ namespace BlackMisc
|
||||
|
||||
void IRemoteAircraftProvider::removeOutdatedParts(CAircraftPartsList &partsList)
|
||||
{
|
||||
// remove all outdated parts but one
|
||||
const auto predicate = [now = partsList.front().getMSecsSinceEpoch()](const auto & p) { return p.getMSecsSinceEpoch() >= now - PartsPerCallsignMaxAgeInSeconds * 1000; };
|
||||
const auto newEnd = std::find_if(partsList.rbegin(), partsList.rend(), predicate).base();
|
||||
if (newEnd != partsList.end()) { partsList.erase(newEnd + 1, partsList.end()); }
|
||||
// remove all outdated parts, but keep at least one
|
||||
if (partsList.isEmpty()) { return; }
|
||||
const qint64 ts = partsList.front().getMSecsSinceEpoch() - MaxPartsAgePerCallsignSecs * 1000;
|
||||
partsList.removeBefore(ts);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user