mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 19:35:32 +08:00
Implement CSimulatorFs9::updateOwnSimulatorCockpit
This commit is contained in:
committed by
Mat Sutcliffe
parent
04787bbf39
commit
b0fd4e03b2
@@ -240,7 +240,10 @@ namespace BlackSimPlugin
|
|||||||
if (newTransponder.getTransponderCode() != m_simTransponder.getTransponderCode()) { changed = true; }
|
if (newTransponder.getTransponderCode() != m_simTransponder.getTransponderCode()) { changed = true; }
|
||||||
if (newTransponder.getTransponderMode() != m_simTransponder.getTransponderMode()) { changed = true; }
|
if (newTransponder.getTransponderMode() != m_simTransponder.getTransponderMode()) { changed = true; }
|
||||||
|
|
||||||
//! \todo KB 8/2017 set FS9 cockpit values
|
m_fsuipc->write(ownAircraft);
|
||||||
|
|
||||||
|
// avoid changes of cockpit back to old values due to an outdated read back value
|
||||||
|
if (changed) { m_skipCockpitUpdateCycles = SkipUpdateCyclesForCockpit; }
|
||||||
|
|
||||||
// bye
|
// bye
|
||||||
return changed;
|
return changed;
|
||||||
@@ -371,11 +374,22 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void CSimulatorFs9::updateOwnAircraftFromSimulator(const CSimulatedAircraft &simDataOwnAircraft)
|
void CSimulatorFs9::updateOwnAircraftFromSimulator(const CSimulatedAircraft &simDataOwnAircraft)
|
||||||
{
|
{
|
||||||
this->updateCockpit(
|
// When I change cockpit values in the sim (from GUI to simulator, not originating from simulator)
|
||||||
simDataOwnAircraft.getCom1System(),
|
// it takes a little while before these values are set in the simulator.
|
||||||
simDataOwnAircraft.getCom2System(),
|
// To avoid jitters, I wait some update cylces to stabilize the values
|
||||||
simDataOwnAircraft.getTransponder(),
|
if (m_skipCockpitUpdateCycles < 1)
|
||||||
this->identifier());
|
{
|
||||||
|
this->updateCockpit(
|
||||||
|
simDataOwnAircraft.getCom1System(),
|
||||||
|
simDataOwnAircraft.getCom2System(),
|
||||||
|
simDataOwnAircraft.getTransponder(),
|
||||||
|
this->identifier());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_skipCockpitUpdateCycles--;
|
||||||
|
}
|
||||||
|
|
||||||
this->updateOwnSituation(simDataOwnAircraft.getSituation());
|
this->updateOwnSituation(simDataOwnAircraft.getSituation());
|
||||||
reverseLookupAndUpdateOwnAircraftModel(simDataOwnAircraft.getModelString());
|
reverseLookupAndUpdateOwnAircraftModel(simDataOwnAircraft.getModelString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ namespace BlackSimPlugin
|
|||||||
bool m_simConnected = false; //!< Is simulator connected?
|
bool m_simConnected = false; //!< Is simulator connected?
|
||||||
QSharedPointer<CFs9Host> m_fs9Host;
|
QSharedPointer<CFs9Host> m_fs9Host;
|
||||||
QSharedPointer<CLobbyClient> m_lobbyClient;
|
QSharedPointer<CLobbyClient> m_lobbyClient;
|
||||||
|
int m_skipCockpitUpdateCycles = 0; //!< skip some update cycles to allow changes in simulator cockpit to be set
|
||||||
|
|
||||||
|
static constexpr int SkipUpdateCyclesForCockpit = 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Listener for FS9
|
//! Listener for FS9
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ namespace BlackSimPlugin
|
|||||||
//! Really open, means connected and data can be sent
|
//! Really open, means connected and data can be sent
|
||||||
bool isOpen() const;
|
bool isOpen() const;
|
||||||
|
|
||||||
|
//! Write aircraft
|
||||||
|
bool write(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||||
|
|
||||||
//! Write variables
|
//! Write variables
|
||||||
bool write(const BlackMisc::Aviation::CTransponder &xpdr);
|
bool write(const BlackMisc::Aviation::CTransponder &xpdr);
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,12 @@ namespace BlackSimPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CFsuipc::write(const CSimulatedAircraft &aircraft)
|
||||||
|
{
|
||||||
|
Q_UNUSED(aircraft);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CFsuipc::write(const CTransponder &xpdr)
|
bool CFsuipc::write(const CTransponder &xpdr)
|
||||||
{
|
{
|
||||||
Q_UNUSED(xpdr);
|
Q_UNUSED(xpdr);
|
||||||
|
|||||||
@@ -148,6 +148,38 @@ namespace BlackSimPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CFsuipc::write(const CSimulatedAircraft &aircraft)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Open not threadsafe");
|
||||||
|
if (!this->isOpened()) { return false; }
|
||||||
|
|
||||||
|
quint16 com1ActiveRaw = aircraft.getCom1System().getFrequencyActive().value(CFrequencyUnit::MHz()) * 100;
|
||||||
|
quint16 com2ActiveRaw = aircraft.getCom2System().getFrequencyActive().value(CFrequencyUnit::MHz()) * 100;
|
||||||
|
quint16 com1StandbyRaw = aircraft.getCom1System().getFrequencyStandby().value(CFrequencyUnit::MHz()) * 100;
|
||||||
|
quint16 com2StandbyRaw = aircraft.getCom2System().getFrequencyStandby().value(CFrequencyUnit::MHz()) * 100;
|
||||||
|
com1ActiveRaw = CBcdConversions::dec2Bcd(com1ActiveRaw - 10000);
|
||||||
|
com2ActiveRaw = CBcdConversions::dec2Bcd(com2ActiveRaw - 10000);
|
||||||
|
com1StandbyRaw = CBcdConversions::dec2Bcd(com1StandbyRaw - 10000);
|
||||||
|
com2StandbyRaw = CBcdConversions::dec2Bcd(com2StandbyRaw - 10000);
|
||||||
|
quint16 transponderCodeRaw = static_cast<quint16>(aircraft.getTransponderCode());
|
||||||
|
|
||||||
|
transponderCodeRaw = CBcdConversions::dec2Bcd(transponderCodeRaw);
|
||||||
|
|
||||||
|
DWORD dwResult = 0;
|
||||||
|
|
||||||
|
bool ok =
|
||||||
|
FSUIPC_Write(0x034e, 2, &com1ActiveRaw, &dwResult) &&
|
||||||
|
FSUIPC_Write(0x3118, 2, &com2ActiveRaw, &dwResult) &&
|
||||||
|
FSUIPC_Write(0x311a, 2, &com1StandbyRaw, &dwResult) &&
|
||||||
|
FSUIPC_Write(0x311c, 2, &com2StandbyRaw, &dwResult) &&
|
||||||
|
FSUIPC_Write(0x0354, 2, &transponderCodeRaw, &dwResult);
|
||||||
|
if (ok) { FSUIPC_Process(&dwResult); }
|
||||||
|
|
||||||
|
ok = ok && write(aircraft.getTransponder());
|
||||||
|
|
||||||
|
return ok && dwResult == 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool CFsuipc::write(const CTransponder &xpdr)
|
bool CFsuipc::write(const CTransponder &xpdr)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Open not threadsafe");
|
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Open not threadsafe");
|
||||||
|
|||||||
Reference in New Issue
Block a user