mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 18:25:42 +08:00
refs #384, allow subparts reading in FSUIPC and to disable FSUIPC (currently disable in FSX)
This commit is contained in:
@@ -72,7 +72,7 @@ namespace BlackSimPlugin
|
|||||||
bool CSimulatorFs9::connectTo()
|
bool CSimulatorFs9::connectTo()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_fsuipc);
|
Q_ASSERT(m_fsuipc);
|
||||||
m_fsuipc->connect(); // connect FSUIPC too
|
if (m_useFsuipc) { m_fsuipc->connect(); } // connect FSUIPC too
|
||||||
|
|
||||||
// If we are already hosting, connect FS0 through lobby connection
|
// If we are already hosting, connect FS0 through lobby connection
|
||||||
if (m_isHosting)
|
if (m_isHosting)
|
||||||
@@ -208,10 +208,10 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void CSimulatorFs9::ps_dispatch()
|
void CSimulatorFs9::ps_dispatch()
|
||||||
{
|
{
|
||||||
if (m_fsuipc)
|
if (m_useFsuipc && m_fsuipc)
|
||||||
{
|
{
|
||||||
CSimulatedAircraft fsuipcAircraft(ownAircraft());
|
CSimulatedAircraft fsuipcAircraft(ownAircraft());
|
||||||
bool ok = m_fsuipc->read(fsuipcAircraft);
|
bool ok = m_fsuipc->read(fsuipcAircraft, true, true, true);
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
updateOwnAircraftFromSimulator(fsuipcAircraft);
|
updateOwnAircraftFromSimulator(fsuipcAircraft);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace BlackSimPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFsuipc::read(CSimulatedAircraft &aircraft)
|
bool CFsuipc::read(CSimulatedAircraft &aircraft, bool cockpit, bool situation, bool aircraftParts)
|
||||||
{
|
{
|
||||||
DWORD dwResult;
|
DWORD dwResult;
|
||||||
char localFsTimeRaw[3];
|
char localFsTimeRaw[3];
|
||||||
@@ -123,49 +123,54 @@ namespace BlackSimPlugin
|
|||||||
// http://squawkbox.ca/doc/sdk/fsuipc.php
|
// http://squawkbox.ca/doc/sdk/fsuipc.php
|
||||||
|
|
||||||
if (!this->isConnected()) { return false; }
|
if (!this->isConnected()) { return false; }
|
||||||
|
if (!(aircraftParts || situation || cockpit)) { return false; }
|
||||||
|
|
||||||
bool read = false;
|
bool read = false;
|
||||||
|
bool cockpitN = !cockpit;
|
||||||
|
bool situationN = !situation;
|
||||||
|
bool aircraftPartsN = ! aircraftParts;
|
||||||
|
|
||||||
if (FSUIPC_Read(0x0238, 3, localFsTimeRaw, &dwResult) &&
|
if (FSUIPC_Read(0x0238, 3, localFsTimeRaw, &dwResult) &&
|
||||||
|
|
||||||
// COM settings
|
// COM settings
|
||||||
FSUIPC_Read(0x034e, 2, &com1ActiveRaw, &dwResult) &&
|
(cockpitN || FSUIPC_Read(0x034e, 2, &com1ActiveRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x3118, 2, &com2ActiveRaw, &dwResult) &&
|
(cockpitN || FSUIPC_Read(0x3118, 2, &com2ActiveRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x311a, 2, &com1StandbyRaw, &dwResult) &&
|
(cockpitN || FSUIPC_Read(0x311a, 2, &com1StandbyRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x311c, 2, &com2StandbyRaw, &dwResult) &&
|
(cockpitN || FSUIPC_Read(0x311c, 2, &com2StandbyRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0354, 2, &transponderCodeRaw, &dwResult) &&
|
(cockpitN || FSUIPC_Read(0x0354, 2, &transponderCodeRaw, &dwResult)) &&
|
||||||
|
|
||||||
// COM Settings, transponder, SB3
|
// COM Settings, transponder, SB3
|
||||||
FSUIPC_Read(0x7b91, 1, &xpdrModeSb3Raw, &dwResult) &&
|
(cockpitN || FSUIPC_Read(0x7b91, 1, &xpdrModeSb3Raw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x7b93, 1, &xpdrIdentSb3Raw, &dwResult) &&
|
(cockpitN || FSUIPC_Read(0x7b93, 1, &xpdrIdentSb3Raw, &dwResult)) &&
|
||||||
|
|
||||||
// Speeds, situation
|
// Speeds, situation
|
||||||
FSUIPC_Read(0x02b4, 4, &groundspeedRaw, &dwResult) &&
|
(situationN || FSUIPC_Read(0x02b4, 4, &groundspeedRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0578, 4, &pitchRaw, &dwResult) &&
|
(situationN || FSUIPC_Read(0x0578, 4, &pitchRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x057c, 4, &bankRaw, &dwResult) &&
|
(situationN || FSUIPC_Read(0x057c, 4, &bankRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0580, 4, &headingRaw, &dwResult) &&
|
(situationN || FSUIPC_Read(0x0580, 4, &headingRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0570, 8, &altitudeRaw, &dwResult) &&
|
(situationN || FSUIPC_Read(0x0570, 8, &altitudeRaw, &dwResult)) &&
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
FSUIPC_Read(0x0560, 8, &latitudeRaw, &dwResult) &&
|
(situationN || FSUIPC_Read(0x0560, 8, &latitudeRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0568, 8, &longitudeRaw, &dwResult) &&
|
(situationN || FSUIPC_Read(0x0568, 8, &longitudeRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0020, 4, &groundAltitudeRaw, &dwResult) &&
|
(situationN || FSUIPC_Read(0x0020, 4, &groundAltitudeRaw, &dwResult)) &&
|
||||||
|
|
||||||
// model name
|
// model name
|
||||||
FSUIPC_Read(0x3d00, 256, &modelNameRaw, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x3d00, 256, &modelNameRaw, &dwResult)) &&
|
||||||
|
|
||||||
// aircraft parts
|
// aircraft parts
|
||||||
FSUIPC_Read(0x0D0C, 2, &lightsRaw, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x0D0C, 2, &lightsRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0366, 2, &onGroundRaw, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x0366, 2, &onGroundRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0BDC, 4, &flapsControlRaw, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x0BDC, 4, &flapsControlRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0BE8, 4, &gearControlRaw, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x0BE8, 4, &gearControlRaw, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0BD0, 4, &spoilersControlRaw, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x0BD0, 4, &spoilersControlRaw, &dwResult)) &&
|
||||||
|
|
||||||
// engines
|
// engines
|
||||||
FSUIPC_Read(0x0AEC, 2, &numberOfEngines, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x0AEC, 2, &numberOfEngines, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0894, 2, &engine1CombustionFlag, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x0894, 2, &engine1CombustionFlag, &dwResult)) &&
|
||||||
FSUIPC_Read(0x092C, 2, &engine2CombustionFlag, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x092C, 2, &engine2CombustionFlag, &dwResult)) &&
|
||||||
FSUIPC_Read(0x09C4, 2, &engine3CombustionFlag, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x09C4, 2, &engine3CombustionFlag, &dwResult)) &&
|
||||||
FSUIPC_Read(0x0A5C, 2, &engine4CombustionFlag, &dwResult) &&
|
(aircraftPartsN || FSUIPC_Read(0x0A5C, 2, &engine4CombustionFlag, &dwResult)) &&
|
||||||
|
|
||||||
// If we wanted other reads/writes at the same time, we could put them here
|
// If we wanted other reads/writes at the same time, we could put them here
|
||||||
FSUIPC_Process(&dwResult))
|
FSUIPC_Process(&dwResult))
|
||||||
@@ -176,10 +181,8 @@ namespace BlackSimPlugin
|
|||||||
QString fsTime;
|
QString fsTime;
|
||||||
fsTime.sprintf("%02d:%02d:%02d", localFsTimeRaw[0], localFsTimeRaw[1], localFsTimeRaw[2]);
|
fsTime.sprintf("%02d:%02d:%02d", localFsTimeRaw[0], localFsTimeRaw[1], localFsTimeRaw[2]);
|
||||||
|
|
||||||
// model
|
if (cockpit)
|
||||||
const QString modelName = QString(modelNameRaw); // to be used to distinguish offsets for different models
|
{
|
||||||
aircraft.setModelString(modelName);
|
|
||||||
|
|
||||||
// COMs
|
// COMs
|
||||||
CComSystem com1 = aircraft.getCom1System();
|
CComSystem com1 = aircraft.getCom1System();
|
||||||
CComSystem com2 = aircraft.getCom2System();
|
CComSystem com2 = aircraft.getCom2System();
|
||||||
@@ -210,7 +213,10 @@ namespace BlackSimPlugin
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
aircraft.setCockpit(com1, com2, xpdr);
|
aircraft.setCockpit(com1, com2, xpdr);
|
||||||
|
} // cockpit
|
||||||
|
|
||||||
|
if (situation)
|
||||||
|
{
|
||||||
// position
|
// position
|
||||||
const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0);
|
const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0);
|
||||||
const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0);
|
const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0);
|
||||||
@@ -238,11 +244,21 @@ namespace BlackSimPlugin
|
|||||||
situation.setAltitude(altitude);
|
situation.setAltitude(altitude);
|
||||||
aircraft.setSituation(situation);
|
aircraft.setSituation(situation);
|
||||||
|
|
||||||
CAircraftLights lights (lightsRaw & (1 << 4), lightsRaw & (1 << 2), lightsRaw & (1 << 3), lightsRaw & (1 << 1),
|
} // situation
|
||||||
|
|
||||||
|
if (aircraftParts)
|
||||||
|
{
|
||||||
|
|
||||||
|
// model
|
||||||
|
const QString modelName = QString(modelNameRaw); // to be used to distinguish offsets for different models
|
||||||
|
aircraft.setModelString(modelName);
|
||||||
|
|
||||||
|
CAircraftLights lights(lightsRaw & (1 << 4), lightsRaw & (1 << 2), lightsRaw & (1 << 3), lightsRaw & (1 << 1),
|
||||||
lightsRaw & (1 << 0), lightsRaw & (1 << 8));
|
lightsRaw & (1 << 0), lightsRaw & (1 << 8));
|
||||||
|
|
||||||
QList<bool> helperList { engine1CombustionFlag != 0, engine2CombustionFlag != 0,
|
QList<bool> helperList { engine1CombustionFlag != 0, engine2CombustionFlag != 0,
|
||||||
engine3CombustionFlag != 0, engine4CombustionFlag != 0 };
|
engine3CombustionFlag != 0, engine4CombustionFlag != 0
|
||||||
|
};
|
||||||
|
|
||||||
CAircraftEngineList engines;
|
CAircraftEngineList engines;
|
||||||
for (int index = 0; index < numberOfEngines; ++index)
|
for (int index = 0; index < numberOfEngines; ++index)
|
||||||
@@ -250,12 +266,12 @@ namespace BlackSimPlugin
|
|||||||
engines.push_back(CAircraftEngine(index + 1, helperList.at(index)));
|
engines.push_back(CAircraftEngine(index + 1, helperList.at(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftParts parts (lights, gearControlRaw == 16383, flapsControlRaw * 100 / 16383,
|
CAircraftParts parts(lights, gearControlRaw == 16383, flapsControlRaw * 100 / 16383,
|
||||||
spoilersControlRaw == 16383, engines, onGroundRaw == 1);
|
spoilersControlRaw == 16383, engines, onGroundRaw == 1);
|
||||||
|
|
||||||
aircraft.setParts(parts);
|
aircraft.setParts(parts);
|
||||||
|
} // parts
|
||||||
}
|
} // read
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,13 @@ namespace BlackSimPlugin
|
|||||||
bool write(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
bool write(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||||
|
|
||||||
//! Read data from FSUIPC
|
//! Read data from FSUIPC
|
||||||
bool read(BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
//! \param aircraft object to be updated
|
||||||
|
//! \param cockpit update cockpit data
|
||||||
|
//! \param situation update situation data
|
||||||
|
//! \param aircraftParts update parts
|
||||||
|
//! \return read
|
||||||
|
//!
|
||||||
|
bool read(BlackMisc::Simulation::CSimulatedAircraft &aircraft, bool cockpit, bool situation, bool aircraftParts);
|
||||||
|
|
||||||
//! Error messages
|
//! Error messages
|
||||||
static const QStringList &errorMessages()
|
static const QStringList &errorMessages()
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
QString simulatorDetails; //!< describes version etc.
|
QString simulatorDetails; //!< describes version etc.
|
||||||
QScopedPointer<FsCommon::CFsuipc> m_fsuipc; //!< FSUIPC
|
QScopedPointer<FsCommon::CFsuipc> m_fsuipc; //!< FSUIPC
|
||||||
|
bool m_useFsuipc = true; //!< use FSUIPC
|
||||||
bool m_simPaused = false; //!< Simulator paused?
|
bool m_simPaused = false; //!< Simulator paused?
|
||||||
bool m_simTimeSynced = false; //!< Time synchronized?
|
bool m_simTimeSynced = false; //!< Time synchronized?
|
||||||
BlackMisc::PhysicalQuantities::CTime m_syncTimeOffset; //!< time offset
|
BlackMisc::PhysicalQuantities::CTime m_syncTimeOffset; //!< time offset
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ namespace BlackSimPlugin
|
|||||||
Q_ASSERT(renderedAircraftProvider);
|
Q_ASSERT(renderedAircraftProvider);
|
||||||
CFsxSimulatorSetup setup;
|
CFsxSimulatorSetup setup;
|
||||||
setup.init(); // this fetches important settings on local side
|
setup.init(); // this fetches important settings on local side
|
||||||
|
m_useFsuipc = false; // do not use FSUIPC at the moment with FSX
|
||||||
this->m_simulatorInfo.setSimulatorSetup(setup.getSettings());
|
this->m_simulatorInfo.setSimulatorSetup(setup.getSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->m_fsuipc->connect(); // connect FSUIPC too
|
if (m_useFsuipc) { this->m_fsuipc->connect(); } // connect FSUIPC too
|
||||||
}
|
}
|
||||||
|
|
||||||
initWhenConnected();
|
initWhenConnected();
|
||||||
@@ -94,8 +95,8 @@ namespace BlackSimPlugin
|
|||||||
// simplified connect, timers and signals not in different thread
|
// simplified connect, timers and signals not in different thread
|
||||||
auto asyncConnectFunc = [&]() -> bool
|
auto asyncConnectFunc = [&]() -> bool
|
||||||
{
|
{
|
||||||
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0))) return false;
|
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0))) { return false; }
|
||||||
this->m_fsuipc->connect(); // FSUIPC too
|
if (m_useFsuipc) { this->m_fsuipc->connect(); } // FSUIPC too
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -371,15 +372,16 @@ namespace BlackSimPlugin
|
|||||||
aircraftSituation.setAltitude(CAltitude(simulatorOwnAircraft.altitude, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
|
aircraftSituation.setAltitude(CAltitude(simulatorOwnAircraft.altitude, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
|
||||||
ownAircraft().setSituation(aircraftSituation);
|
ownAircraft().setSituation(aircraftSituation);
|
||||||
|
|
||||||
CAircraftLights lights ( simulatorOwnAircraft.lightStrobe,
|
CAircraftLights lights(simulatorOwnAircraft.lightStrobe,
|
||||||
simulatorOwnAircraft.lightLanding,
|
simulatorOwnAircraft.lightLanding,
|
||||||
simulatorOwnAircraft.lightTaxi,
|
simulatorOwnAircraft.lightTaxi,
|
||||||
simulatorOwnAircraft.lightBeacon,
|
simulatorOwnAircraft.lightBeacon,
|
||||||
simulatorOwnAircraft.lightNav,
|
simulatorOwnAircraft.lightNav,
|
||||||
simulatorOwnAircraft.lightLogo );
|
simulatorOwnAircraft.lightLogo);
|
||||||
|
|
||||||
QList<bool> helperList { simulatorOwnAircraft.engine1Combustion != 0, simulatorOwnAircraft.engine2Combustion != 0,
|
QList<bool> helperList { simulatorOwnAircraft.engine1Combustion != 0, simulatorOwnAircraft.engine2Combustion != 0,
|
||||||
simulatorOwnAircraft.engine3Combustion != 0, simulatorOwnAircraft.engine4Combustion != 0 };
|
simulatorOwnAircraft.engine3Combustion != 0, simulatorOwnAircraft.engine4Combustion != 0
|
||||||
|
};
|
||||||
|
|
||||||
CAircraftEngineList engines;
|
CAircraftEngineList engines;
|
||||||
for (int index = 0; index < simulatorOwnAircraft.numberOfEngines; ++index)
|
for (int index = 0; index < simulatorOwnAircraft.numberOfEngines; ++index)
|
||||||
@@ -387,11 +389,11 @@ namespace BlackSimPlugin
|
|||||||
engines.push_back(CAircraftEngine(index + 1, helperList.at(index)));
|
engines.push_back(CAircraftEngine(index + 1, helperList.at(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftParts parts ( lights, simulatorOwnAircraft.gearHandlePosition,
|
CAircraftParts parts(lights, simulatorOwnAircraft.gearHandlePosition,
|
||||||
simulatorOwnAircraft.flapsHandlePosition * 100,
|
simulatorOwnAircraft.flapsHandlePosition * 100,
|
||||||
simulatorOwnAircraft.spoilersHandlePosition,
|
simulatorOwnAircraft.spoilersHandlePosition,
|
||||||
engines,
|
engines,
|
||||||
simulatorOwnAircraft.simOnGround );
|
simulatorOwnAircraft.simOnGround);
|
||||||
|
|
||||||
ownAircraft().setParts(parts);
|
ownAircraft().setParts(parts);
|
||||||
|
|
||||||
@@ -473,10 +475,11 @@ namespace BlackSimPlugin
|
|||||||
void CSimulatorFsx::ps_dispatch()
|
void CSimulatorFsx::ps_dispatch()
|
||||||
{
|
{
|
||||||
SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this);
|
SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this);
|
||||||
if (m_fsuipc)
|
if (m_useFsuipc && m_fsuipc)
|
||||||
{
|
{
|
||||||
CSimulatedAircraft fsuipcAircraft(ownAircraft());
|
CSimulatedAircraft fsuipcAircraft(ownAircraft());
|
||||||
bool ok = m_fsuipc->read(fsuipcAircraft);
|
//! \todo split in high / low frequency reads
|
||||||
|
bool ok = m_fsuipc->read(fsuipcAircraft, true, true, true);
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
// do whatever is required
|
// do whatever is required
|
||||||
@@ -599,7 +602,7 @@ namespace BlackSimPlugin
|
|||||||
SIMCONNECT_DATA_INITPOSITION position = aircraftSituationToFsxInitPosition(interpolator.getCurrentInterpolatedSituation(simObj.getCallsign()));
|
SIMCONNECT_DATA_INITPOSITION position = aircraftSituationToFsxInitPosition(interpolator.getCurrentInterpolatedSituation(simObj.getCallsign()));
|
||||||
|
|
||||||
CAircraftParts parts;
|
CAircraftParts parts;
|
||||||
if(renderedAircraftParts().findBeforeNowMinusOffset(6000).containsCallsign(simObj.getCallsign()))
|
if (renderedAircraftParts().findBeforeNowMinusOffset(6000).containsCallsign(simObj.getCallsign()))
|
||||||
parts = renderedAircraftParts().findBeforeNowMinusOffset(6000).latestValue();
|
parts = renderedAircraftParts().findBeforeNowMinusOffset(6000).latestValue();
|
||||||
|
|
||||||
position.OnGround = parts.isOnGround() ? 1 : 0;
|
position.OnGround = parts.isOnGround() ? 1 : 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user