[FS9] Implement time synchronisation

This commit is contained in:
Roland Rossgotterer
2019-03-12 16:26:34 +01:00
committed by Mat Sutcliffe
parent 464528da9a
commit 6a5e59b76a
5 changed files with 51 additions and 0 deletions

View File

@@ -315,6 +315,7 @@ namespace BlackSimPlugin
{
updateOwnAircraftFromSimulator(fsuipcAircraft);
}
synchronizeTime();
}
}
@@ -402,6 +403,26 @@ namespace BlackSimPlugin
}
}
void CSimulatorFs9::synchronizeTime()
{
if (!m_simTimeSynced) { return; }
if (!this->isConnected()) { return; }
if (!m_useFsuipc || !m_fsuipc) { return; }
if (!m_fsuipc->isOpened()) { return; }
QDateTime myDateTime = QDateTime::currentDateTimeUtc();
if (!m_syncTimeOffset.isZeroEpsilonConsidered())
{
int offsetSeconds = m_syncTimeOffset.valueInteger(CTimeUnit::s());
myDateTime = myDateTime.addSecs(offsetSeconds);
}
const QTime myTime = myDateTime.time();
const int h = myTime.hour();
const int m = myTime.minute();
m_fsuipc->setSimulatorTime(h, m);
}
void CSimulatorFs9::injectWeatherGrid(const Weather::CWeatherGrid &weatherGrid)
{
if (!m_useFsuipc || !m_fsuipc) { return; }

View File

@@ -100,6 +100,9 @@ namespace BlackSimPlugin
//! Disconnect all clients
void disconnectAllClients();
//! Sync time with user's computer
void synchronizeTime();
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
QMetaObject::Connection m_connectionHostMessages;
bool m_simConnected = false; //!< Is simulator connected?

View File

@@ -53,6 +53,9 @@ namespace BlackSimPlugin
//! Write weather grid to simulator
bool write(const BlackMisc::Weather::CWeatherGrid &weatherGrid);
//! Set simulator time
bool setSimulatorTime(int hour, int minute);
//! Get the version
QString getVersion() const;

View File

@@ -66,6 +66,13 @@ namespace BlackSimPlugin
return false;
}
bool CFsuipc::setSimulatorTime(int hour, int minute)
{
Q_UNUSED(hour);
Q_UNUSED(minute);
return false;
}
QString CFsuipc::getVersion() const
{
return QStringLiteral("N/A");

View File

@@ -330,6 +330,23 @@ namespace BlackSimPlugin
return true;
}
bool CFsuipc::setSimulatorTime(int hour, int minute)
{
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Open not threadsafe");
if (!this->isOpened()) { return false; }
// should be the same as writing via SimConnect data area
DWORD dwResult;
quint8 hourRaw = hour;
quint8 minuteRaw = minute;
const bool ok =
FSUIPC_Write(0x023b, 1, &hourRaw, &dwResult) &&
FSUIPC_Write(0x023c, 1, &minuteRaw, &dwResult);
if (ok) { FSUIPC_Process(&dwResult); }
return ok && dwResult == 0;
}
QString CFsuipc::getVersion() const
{
return m_fsuipcVersion;