From df1c0c65da31f3e31e4bcd6b1d0c2499d288497e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 14 Feb 2015 19:12:05 +0100 Subject: [PATCH] refs #384, allow subparts reading in FSUIPC and to disable FSUIPC (currently disable in FSX) --- src/plugins/simulator/fs9/simulator_fs9.cpp | 6 +- src/plugins/simulator/fscommon/fsuipc.cpp | 212 ++++++++++-------- src/plugins/simulator/fscommon/fsuipc.h | 8 +- .../simulator/fscommon/simulator_fscommon.h | 1 + src/plugins/simulator/fsx/simulator_fsx.cpp | 43 ++-- 5 files changed, 148 insertions(+), 122 deletions(-) diff --git a/src/plugins/simulator/fs9/simulator_fs9.cpp b/src/plugins/simulator/fs9/simulator_fs9.cpp index aebc33ab6..c176ccab1 100644 --- a/src/plugins/simulator/fs9/simulator_fs9.cpp +++ b/src/plugins/simulator/fs9/simulator_fs9.cpp @@ -72,7 +72,7 @@ namespace BlackSimPlugin bool CSimulatorFs9::connectTo() { 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 (m_isHosting) @@ -208,10 +208,10 @@ namespace BlackSimPlugin void CSimulatorFs9::ps_dispatch() { - if (m_fsuipc) + if (m_useFsuipc && m_fsuipc) { CSimulatedAircraft fsuipcAircraft(ownAircraft()); - bool ok = m_fsuipc->read(fsuipcAircraft); + bool ok = m_fsuipc->read(fsuipcAircraft, true, true, true); if (ok) { updateOwnAircraftFromSimulator(fsuipcAircraft); diff --git a/src/plugins/simulator/fscommon/fsuipc.cpp b/src/plugins/simulator/fscommon/fsuipc.cpp index 5a5698855..faaaf9ba7 100644 --- a/src/plugins/simulator/fscommon/fsuipc.cpp +++ b/src/plugins/simulator/fscommon/fsuipc.cpp @@ -86,7 +86,7 @@ namespace BlackSimPlugin return false; } - bool CFsuipc::read(CSimulatedAircraft &aircraft) + bool CFsuipc::read(CSimulatedAircraft &aircraft, bool cockpit, bool situation, bool aircraftParts) { DWORD dwResult; char localFsTimeRaw[3]; @@ -123,49 +123,54 @@ namespace BlackSimPlugin // http://squawkbox.ca/doc/sdk/fsuipc.php if (!this->isConnected()) { return false; } + if (!(aircraftParts || situation || cockpit)) { return false; } bool read = false; + bool cockpitN = !cockpit; + bool situationN = !situation; + bool aircraftPartsN = ! aircraftParts; + if (FSUIPC_Read(0x0238, 3, localFsTimeRaw, &dwResult) && // COM settings - FSUIPC_Read(0x034e, 2, &com1ActiveRaw, &dwResult) && - FSUIPC_Read(0x3118, 2, &com2ActiveRaw, &dwResult) && - FSUIPC_Read(0x311a, 2, &com1StandbyRaw, &dwResult) && - FSUIPC_Read(0x311c, 2, &com2StandbyRaw, &dwResult) && - FSUIPC_Read(0x0354, 2, &transponderCodeRaw, &dwResult) && + (cockpitN || FSUIPC_Read(0x034e, 2, &com1ActiveRaw, &dwResult)) && + (cockpitN || FSUIPC_Read(0x3118, 2, &com2ActiveRaw, &dwResult)) && + (cockpitN || FSUIPC_Read(0x311a, 2, &com1StandbyRaw, &dwResult)) && + (cockpitN || FSUIPC_Read(0x311c, 2, &com2StandbyRaw, &dwResult)) && + (cockpitN || FSUIPC_Read(0x0354, 2, &transponderCodeRaw, &dwResult)) && // COM Settings, transponder, SB3 - FSUIPC_Read(0x7b91, 1, &xpdrModeSb3Raw, &dwResult) && - FSUIPC_Read(0x7b93, 1, &xpdrIdentSb3Raw, &dwResult) && + (cockpitN || FSUIPC_Read(0x7b91, 1, &xpdrModeSb3Raw, &dwResult)) && + (cockpitN || FSUIPC_Read(0x7b93, 1, &xpdrIdentSb3Raw, &dwResult)) && // Speeds, situation - FSUIPC_Read(0x02b4, 4, &groundspeedRaw, &dwResult) && - FSUIPC_Read(0x0578, 4, &pitchRaw, &dwResult) && - FSUIPC_Read(0x057c, 4, &bankRaw, &dwResult) && - FSUIPC_Read(0x0580, 4, &headingRaw, &dwResult) && - FSUIPC_Read(0x0570, 8, &altitudeRaw, &dwResult) && + (situationN || FSUIPC_Read(0x02b4, 4, &groundspeedRaw, &dwResult)) && + (situationN || FSUIPC_Read(0x0578, 4, &pitchRaw, &dwResult)) && + (situationN || FSUIPC_Read(0x057c, 4, &bankRaw, &dwResult)) && + (situationN || FSUIPC_Read(0x0580, 4, &headingRaw, &dwResult)) && + (situationN || FSUIPC_Read(0x0570, 8, &altitudeRaw, &dwResult)) && // Position - FSUIPC_Read(0x0560, 8, &latitudeRaw, &dwResult) && - FSUIPC_Read(0x0568, 8, &longitudeRaw, &dwResult) && - FSUIPC_Read(0x0020, 4, &groundAltitudeRaw, &dwResult) && + (situationN || FSUIPC_Read(0x0560, 8, &latitudeRaw, &dwResult)) && + (situationN || FSUIPC_Read(0x0568, 8, &longitudeRaw, &dwResult)) && + (situationN || FSUIPC_Read(0x0020, 4, &groundAltitudeRaw, &dwResult)) && // model name - FSUIPC_Read(0x3d00, 256, &modelNameRaw, &dwResult) && + (aircraftPartsN || FSUIPC_Read(0x3d00, 256, &modelNameRaw, &dwResult)) && // aircraft parts - FSUIPC_Read(0x0D0C, 2, &lightsRaw, &dwResult) && - FSUIPC_Read(0x0366, 2, &onGroundRaw, &dwResult) && - FSUIPC_Read(0x0BDC, 4, &flapsControlRaw, &dwResult) && - FSUIPC_Read(0x0BE8, 4, &gearControlRaw, &dwResult) && - FSUIPC_Read(0x0BD0, 4, &spoilersControlRaw, &dwResult) && + (aircraftPartsN || FSUIPC_Read(0x0D0C, 2, &lightsRaw, &dwResult)) && + (aircraftPartsN || FSUIPC_Read(0x0366, 2, &onGroundRaw, &dwResult)) && + (aircraftPartsN || FSUIPC_Read(0x0BDC, 4, &flapsControlRaw, &dwResult)) && + (aircraftPartsN || FSUIPC_Read(0x0BE8, 4, &gearControlRaw, &dwResult)) && + (aircraftPartsN || FSUIPC_Read(0x0BD0, 4, &spoilersControlRaw, &dwResult)) && // engines - FSUIPC_Read(0x0AEC, 2, &numberOfEngines, &dwResult) && - FSUIPC_Read(0x0894, 2, &engine1CombustionFlag, &dwResult) && - FSUIPC_Read(0x092C, 2, &engine2CombustionFlag, &dwResult) && - FSUIPC_Read(0x09C4, 2, &engine3CombustionFlag, &dwResult) && - FSUIPC_Read(0x0A5C, 2, &engine4CombustionFlag, &dwResult) && + (aircraftPartsN || FSUIPC_Read(0x0AEC, 2, &numberOfEngines, &dwResult)) && + (aircraftPartsN || FSUIPC_Read(0x0894, 2, &engine1CombustionFlag, &dwResult)) && + (aircraftPartsN || FSUIPC_Read(0x092C, 2, &engine2CombustionFlag, &dwResult)) && + (aircraftPartsN || FSUIPC_Read(0x09C4, 2, &engine3CombustionFlag, &dwResult)) && + (aircraftPartsN || FSUIPC_Read(0x0A5C, 2, &engine4CombustionFlag, &dwResult)) && // If we wanted other reads/writes at the same time, we could put them here FSUIPC_Process(&dwResult)) @@ -176,86 +181,97 @@ namespace BlackSimPlugin QString fsTime; fsTime.sprintf("%02d:%02d:%02d", localFsTimeRaw[0], localFsTimeRaw[1], localFsTimeRaw[2]); - // model - const QString modelName = QString(modelNameRaw); // to be used to distinguish offsets for different models - aircraft.setModelString(modelName); - - // COMs - CComSystem com1 = aircraft.getCom1System(); - CComSystem com2 = aircraft.getCom2System(); - CTransponder xpdr = aircraft.getTransponder(); - - // 2710 => 12710 => / 100.0 => 127.1 - com1ActiveRaw = (10000 + CBcdConversions::bcd2Dec(com1ActiveRaw)); - com2ActiveRaw = (10000 + CBcdConversions::bcd2Dec(com2ActiveRaw)); - com1StandbyRaw = (10000 + CBcdConversions::bcd2Dec(com1StandbyRaw)); - com2StandbyRaw = (10000 + CBcdConversions::bcd2Dec(com2StandbyRaw)); - com1.setFrequencyActiveMHz(com1ActiveRaw / 100.0); - com2.setFrequencyActiveMHz(com2ActiveRaw / 100.0); - com1.setFrequencyStandbyMHz(com1StandbyRaw / 100.0); - com2.setFrequencyStandbyMHz(com2StandbyRaw / 100.0); - - transponderCodeRaw = CBcdConversions::bcd2Dec(transponderCodeRaw); - xpdr.setTransponderCode(transponderCodeRaw); - // Mode by SB3 - if (xpdrIdentSb3Raw != 0) + if (cockpit) { - //! \todo Reset value for FSUIPC - xpdr.setTransponderMode(CTransponder::StateIdent); - } - else + // COMs + CComSystem com1 = aircraft.getCom1System(); + CComSystem com2 = aircraft.getCom2System(); + CTransponder xpdr = aircraft.getTransponder(); + + // 2710 => 12710 => / 100.0 => 127.1 + com1ActiveRaw = (10000 + CBcdConversions::bcd2Dec(com1ActiveRaw)); + com2ActiveRaw = (10000 + CBcdConversions::bcd2Dec(com2ActiveRaw)); + com1StandbyRaw = (10000 + CBcdConversions::bcd2Dec(com1StandbyRaw)); + com2StandbyRaw = (10000 + CBcdConversions::bcd2Dec(com2StandbyRaw)); + com1.setFrequencyActiveMHz(com1ActiveRaw / 100.0); + com2.setFrequencyActiveMHz(com2ActiveRaw / 100.0); + com1.setFrequencyStandbyMHz(com1StandbyRaw / 100.0); + com2.setFrequencyStandbyMHz(com2StandbyRaw / 100.0); + + transponderCodeRaw = CBcdConversions::bcd2Dec(transponderCodeRaw); + xpdr.setTransponderCode(transponderCodeRaw); + // Mode by SB3 + if (xpdrIdentSb3Raw != 0) + { + //! \todo Reset value for FSUIPC + xpdr.setTransponderMode(CTransponder::StateIdent); + } + else + { + xpdr.setTransponderMode( + xpdrModeSb3Raw == 0 ? CTransponder::ModeC : CTransponder::StateStandby + ); + } + aircraft.setCockpit(com1, com2, xpdr); + } // cockpit + + if (situation) { - xpdr.setTransponderMode( - xpdrModeSb3Raw == 0 ? CTransponder::ModeC : CTransponder::StateStandby - ); - } - aircraft.setCockpit(com1, com2, xpdr); + // position + const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0); + const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0); + CAircraftSituation situation = aircraft.getSituation(); + CCoordinateGeodetic position = situation.getPosition(); + CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg()); + CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg()); + CLength groundAltitude(groundAltitudeRaw / 256.0, CLengthUnit::m()); + position.setLatitude(lat); + position.setLongitude(lon); + position.setGeodeticHeight(groundAltitude); + situation.setPosition(position); - // position - const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0); - const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0); - CAircraftSituation situation = aircraft.getSituation(); - CCoordinateGeodetic position = situation.getPosition(); - CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg()); - CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg()); - CLength groundAltitude(groundAltitudeRaw / 256.0, CLengthUnit::m()); - position.setLatitude(lat); - position.setLongitude(lon); - position.setGeodeticHeight(groundAltitude); - situation.setPosition(position); + // speeds, situation + const double angleCorrectionFactor = 360.0 / 65536.0 / 65536.0; // see FSUIPC docu + CAngle pitch = CAngle(pitchRaw * angleCorrectionFactor, CAngleUnit::deg()); + CAngle bank = CAngle(bankRaw * angleCorrectionFactor, CAngleUnit::deg()); + CHeading heading = CHeading(headingRaw * angleCorrectionFactor, CHeading::True, CAngleUnit::deg()); + CSpeed groundspeed(groundspeedRaw / 65536.0, CSpeedUnit::m_s()); + CAltitude altitude(altitudeRaw / (65536.0 * 65536.0), CAltitude::MeanSeaLevel, CLengthUnit::m()); + situation.setBank(bank); + situation.setHeading(heading); + situation.setPitch(pitch); + situation.setGroundspeed(groundspeed); + situation.setAltitude(altitude); + aircraft.setSituation(situation); - // speeds, situation - const double angleCorrectionFactor = 360.0 / 65536.0 / 65536.0; // see FSUIPC docu - CAngle pitch = CAngle(pitchRaw * angleCorrectionFactor, CAngleUnit::deg()); - CAngle bank = CAngle(bankRaw * angleCorrectionFactor, CAngleUnit::deg()); - CHeading heading = CHeading(headingRaw * angleCorrectionFactor, CHeading::True, CAngleUnit::deg()); - CSpeed groundspeed(groundspeedRaw / 65536.0, CSpeedUnit::m_s()); - CAltitude altitude(altitudeRaw / (65536.0 * 65536.0), CAltitude::MeanSeaLevel, CLengthUnit::m()); - situation.setBank(bank); - situation.setHeading(heading); - situation.setPitch(pitch); - situation.setGroundspeed(groundspeed); - situation.setAltitude(altitude); - aircraft.setSituation(situation); + } // situation - CAircraftLights lights (lightsRaw & (1 << 4), lightsRaw & (1 << 2), lightsRaw & (1 << 3), lightsRaw & (1 << 1), - lightsRaw & (1 << 0), lightsRaw & (1 << 8)); - - QList helperList { engine1CombustionFlag != 0, engine2CombustionFlag != 0, - engine3CombustionFlag != 0, engine4CombustionFlag != 0 }; - - CAircraftEngineList engines; - for (int index = 0; index < numberOfEngines; ++index) + if (aircraftParts) { - engines.push_back(CAircraftEngine(index + 1, helperList.at(index))); - } - CAircraftParts parts (lights, gearControlRaw == 16383, flapsControlRaw * 100 / 16383, - spoilersControlRaw == 16383, engines, onGroundRaw == 1); + // model + const QString modelName = QString(modelNameRaw); // to be used to distinguish offsets for different models + aircraft.setModelString(modelName); - aircraft.setParts(parts); + CAircraftLights lights(lightsRaw & (1 << 4), lightsRaw & (1 << 2), lightsRaw & (1 << 3), lightsRaw & (1 << 1), + lightsRaw & (1 << 0), lightsRaw & (1 << 8)); - } + QList helperList { engine1CombustionFlag != 0, engine2CombustionFlag != 0, + engine3CombustionFlag != 0, engine4CombustionFlag != 0 + }; + + CAircraftEngineList engines; + for (int index = 0; index < numberOfEngines; ++index) + { + engines.push_back(CAircraftEngine(index + 1, helperList.at(index))); + } + + CAircraftParts parts(lights, gearControlRaw == 16383, flapsControlRaw * 100 / 16383, + spoilersControlRaw == 16383, engines, onGroundRaw == 1); + + aircraft.setParts(parts); + } // parts + } // read return read; } diff --git a/src/plugins/simulator/fscommon/fsuipc.h b/src/plugins/simulator/fscommon/fsuipc.h index 3b0236f6b..914932baa 100644 --- a/src/plugins/simulator/fscommon/fsuipc.h +++ b/src/plugins/simulator/fscommon/fsuipc.h @@ -46,7 +46,13 @@ namespace BlackSimPlugin bool write(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); //! 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 static const QStringList &errorMessages() diff --git a/src/plugins/simulator/fscommon/simulator_fscommon.h b/src/plugins/simulator/fscommon/simulator_fscommon.h index b0653b8ec..4f20f9219 100644 --- a/src/plugins/simulator/fscommon/simulator_fscommon.h +++ b/src/plugins/simulator/fscommon/simulator_fscommon.h @@ -89,6 +89,7 @@ namespace BlackSimPlugin QString simulatorDetails; //!< describes version etc. QScopedPointer m_fsuipc; //!< FSUIPC + bool m_useFsuipc = true; //!< use FSUIPC bool m_simPaused = false; //!< Simulator paused? bool m_simTimeSynced = false; //!< Time synchronized? BlackMisc::PhysicalQuantities::CTime m_syncTimeOffset; //!< time offset diff --git a/src/plugins/simulator/fsx/simulator_fsx.cpp b/src/plugins/simulator/fsx/simulator_fsx.cpp index 38b558887..6e6c86df6 100644 --- a/src/plugins/simulator/fsx/simulator_fsx.cpp +++ b/src/plugins/simulator/fsx/simulator_fsx.cpp @@ -46,6 +46,7 @@ namespace BlackSimPlugin Q_ASSERT(renderedAircraftProvider); CFsxSimulatorSetup setup; 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()); } @@ -75,7 +76,7 @@ namespace BlackSimPlugin } else { - this->m_fsuipc->connect(); // connect FSUIPC too + if (m_useFsuipc) { this->m_fsuipc->connect(); } // connect FSUIPC too } initWhenConnected(); @@ -94,8 +95,8 @@ namespace BlackSimPlugin // simplified connect, timers and signals not in different thread auto asyncConnectFunc = [&]() -> bool { - if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0))) return false; - this->m_fsuipc->connect(); // FSUIPC too + if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0))) { return false; } + if (m_useFsuipc) { this->m_fsuipc->connect(); } // FSUIPC too return true; }; @@ -371,15 +372,16 @@ namespace BlackSimPlugin aircraftSituation.setAltitude(CAltitude(simulatorOwnAircraft.altitude, CAltitude::MeanSeaLevel, CLengthUnit::ft())); ownAircraft().setSituation(aircraftSituation); - CAircraftLights lights ( simulatorOwnAircraft.lightStrobe, - simulatorOwnAircraft.lightLanding, - simulatorOwnAircraft.lightTaxi, - simulatorOwnAircraft.lightBeacon, - simulatorOwnAircraft.lightNav, - simulatorOwnAircraft.lightLogo ); + CAircraftLights lights(simulatorOwnAircraft.lightStrobe, + simulatorOwnAircraft.lightLanding, + simulatorOwnAircraft.lightTaxi, + simulatorOwnAircraft.lightBeacon, + simulatorOwnAircraft.lightNav, + simulatorOwnAircraft.lightLogo); QList helperList { simulatorOwnAircraft.engine1Combustion != 0, simulatorOwnAircraft.engine2Combustion != 0, - simulatorOwnAircraft.engine3Combustion != 0, simulatorOwnAircraft.engine4Combustion != 0 }; + simulatorOwnAircraft.engine3Combustion != 0, simulatorOwnAircraft.engine4Combustion != 0 + }; CAircraftEngineList engines; for (int index = 0; index < simulatorOwnAircraft.numberOfEngines; ++index) @@ -387,11 +389,11 @@ namespace BlackSimPlugin engines.push_back(CAircraftEngine(index + 1, helperList.at(index))); } - CAircraftParts parts ( lights, simulatorOwnAircraft.gearHandlePosition, - simulatorOwnAircraft.flapsHandlePosition * 100, - simulatorOwnAircraft.spoilersHandlePosition, - engines, - simulatorOwnAircraft.simOnGround ); + CAircraftParts parts(lights, simulatorOwnAircraft.gearHandlePosition, + simulatorOwnAircraft.flapsHandlePosition * 100, + simulatorOwnAircraft.spoilersHandlePosition, + engines, + simulatorOwnAircraft.simOnGround); ownAircraft().setParts(parts); @@ -473,10 +475,11 @@ namespace BlackSimPlugin void CSimulatorFsx::ps_dispatch() { SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this); - if (m_fsuipc) + if (m_useFsuipc && m_fsuipc) { 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) { // do whatever is required @@ -599,7 +602,7 @@ namespace BlackSimPlugin SIMCONNECT_DATA_INITPOSITION position = aircraftSituationToFsxInitPosition(interpolator.getCurrentInterpolatedSituation(simObj.getCallsign())); CAircraftParts parts; - if(renderedAircraftParts().findBeforeNowMinusOffset(6000).containsCallsign(simObj.getCallsign())) + if (renderedAircraftParts().findBeforeNowMinusOffset(6000).containsCallsign(simObj.getCallsign())) parts = renderedAircraftParts().findBeforeNowMinusOffset(6000).latestValue(); position.OnGround = parts.isOnGround() ? 1 : 0; @@ -628,8 +631,8 @@ namespace BlackSimPlugin HRESULT hr = S_OK; hr += SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraft, - simObj.getObjectId(), 0, 0, - sizeof(DataDefinitionRemoteAircraft), &ddRemoteAircraft); + simObj.getObjectId(), 0, 0, + sizeof(DataDefinitionRemoteAircraft), &ddRemoteAircraft); if (hr != S_OK) CLogMessage(this).warning("Failed so set data on SimObject");