Group own aircraft DBus calls together

Previously all own aircraft values were request via single DBus calls.
Since DBus allows up to 8 values in its reply, use this mechanism
to group the requests and reduce the amount of single calls.
This commit is contained in:
Roland Winklmeier
2018-04-04 10:08:22 +02:00
parent d77931e5ec
commit b278d9ee2f
4 changed files with 62 additions and 39 deletions

View File

@@ -136,13 +136,7 @@ namespace BlackSimPlugin
{
if (this->isConnected())
{
m_serviceProxy->getLatitudeAsync(&m_xplaneData.latitude);
m_serviceProxy->getLongitudeAsync(&m_xplaneData.longitude);
m_serviceProxy->getAltitudeMSLAsync(&m_xplaneData.altitude);
m_serviceProxy->getGroundSpeedAsync(&m_xplaneData.groundspeed);
m_serviceProxy->getPitchAsync(&m_xplaneData.pitch);
m_serviceProxy->getRollAsync(&m_xplaneData.roll);
m_serviceProxy->getTrueHeadingAsync(&m_xplaneData.trueHeading);
m_serviceProxy->getOwnAircraftSituationData(&m_xplaneData);
m_serviceProxy->getCom1ActiveAsync(&m_xplaneData.com1Active);
m_serviceProxy->getCom1StandbyAsync(&m_xplaneData.com1Standby);
m_serviceProxy->getCom2ActiveAsync(&m_xplaneData.com2Active);
@@ -151,7 +145,6 @@ namespace BlackSimPlugin
m_serviceProxy->getTransponderModeAsync(&m_xplaneData.xpdrMode);
m_serviceProxy->getTransponderIdentAsync(&m_xplaneData.xpdrIdent);
m_serviceProxy->getAllWheelsOnGroundAsync(&m_xplaneData.onGroundAll);
m_serviceProxy->getQNHAsync(&m_xplaneData.seaLeveLPressure);
CAircraftSituation situation;
situation.setPosition({ m_xplaneData.latitude, m_xplaneData.longitude, 0 });

View File

@@ -68,6 +68,39 @@ namespace BlackSimPlugin
class CXSwiftBusTrafficProxy;
class CXSwiftBusWeatherProxy;
//! X-Plane data
//! \todo Add units to members? pitchDeg?, altitudeFt?
struct XPlaneData
{
QString aircraftModelPath; //!< Aircraft model path
QString aircraftIcaoCode; //!< Aircraft model path
double latitude; //!< Longitude [deg]
double longitude; //!< Latitude [deg]
double altitude; //!< Altitude [m]
double groundspeed; //!< Ground speed [m/s]
double pitch; //!< Pitch [deg]
double roll; //!< Roll [deg]
double trueHeading; //!< True heading [deg]
bool onGroundAll; //!< All wheels on ground?
int com1Active; //!< COM1 active [kHz]
int com1Standby; //!< COM1 standby [kHz]
int com2Active; //!< COM2 active [kHz]
int com2Standby; //!< COM2 standby [kHz]
int xpdrCode; //!< Transpondder code
int xpdrMode; //!< Transponder mode (off=0,stdby=1,on=2,test=3)
bool xpdrIdent; //!< Is transponder in ident?
bool beaconLightsOn; //!< Beacon lights on?
bool landingLightsOn; //!< Landing lights on?
bool navLightsOn; //!< NAV lights on?
bool strobeLightsOn; //!< Strobe lights on?
bool taxiLightsOn; //!< Taxi lights on?
double flapsReployRatio; //!< Flaps deployment ratio [%]
double gearReployRatio; //!< Gear deployment ratio [%]
QList<double> enginesN1Percentage; //!< N1 per engine [%]
double speedBrakeRatio; //!< Speed break ratio [%]
double seaLeveLPressure; //!< Sea level pressure [inhg]
};
//! X-Plane ISimulator implementation
class CSimulatorXPlane : public BlackCore::CSimulatorCommon
{
@@ -175,37 +208,7 @@ namespace BlackSimPlugin
CXPlaneMPAircraftObjects m_xplaneAircraftObjects; //!< XPlane multiplayer aircraft
int m_interpolationRequest = 0; //!< current interpolation request
//! \todo Add units to members? pitchDeg?, altitudeFt?
struct // data is written by DBus async method callbacks
{
QString aircraftModelPath;
QString aircraftIcaoCode;
double latitude;
double longitude;
double altitude;
double groundspeed;
double pitch;
double roll;
double trueHeading;
bool onGroundAll;
int com1Active;
int com1Standby;
int com2Active;
int com2Standby;
int xpdrCode;
int xpdrMode;
bool xpdrIdent;
bool beaconLightsOn;
bool landingLightsOn;
bool navLightsOn;
bool strobeLightsOn;
bool taxiLightsOn;
double flapsReployRatio;
double gearReployRatio;
QList<double> enginesN1Percentage;
double speedBrakeRatio;
double seaLeveLPressure;
} m_xplaneData;
XPlaneData m_xplaneData;
void resetXPlaneData()
{

View File

@@ -8,6 +8,7 @@
*/
#include "xswiftbusserviceproxy.h"
#include "simulatorxplane.h"
#include <QLatin1String>
@@ -25,6 +26,27 @@ namespace BlackSimPlugin
if (!dummy) { m_dbusInterface->relayParentSignals(); }
}
void CXSwiftBusServiceProxy::getOwnAircraftSituationData(XPlaneData *o_xplaneData)
{
std::function<void(QDBusPendingCallWatcher *)> callback = [this, o_xplaneData](QDBusPendingCallWatcher * watcher)
{
QDBusPendingReply<double, double, double, double, double, double, double, double> reply = *watcher;
if (!reply.isError())
{
o_xplaneData->latitude = reply.argumentAt<0>();
o_xplaneData->longitude = reply.argumentAt<1>();
o_xplaneData->altitude = reply.argumentAt<2>();
o_xplaneData->groundspeed = reply.argumentAt<3>();
o_xplaneData->pitch = reply.argumentAt<4>();
o_xplaneData->roll = reply.argumentAt<5>();
o_xplaneData->trueHeading = reply.argumentAt<6>();
o_xplaneData->seaLeveLPressure = reply.argumentAt<7>();
}
watcher->deleteLater();
};
m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftSituationData"), callback);
}
void CXSwiftBusServiceProxy::addTextMessage(const QString &text, double red, double green, double blue)
{
m_dbusInterface->callDBus(QLatin1String("addTextMessage"), text, red, green, blue);

View File

@@ -34,6 +34,8 @@ namespace BlackSimPlugin
{
namespace XPlane
{
struct XPlaneData;
/*!
* Proxy object connected to a real XSwiftBus::CService object via DBus
*/
@@ -94,6 +96,9 @@ namespace BlackSimPlugin
void airportsInRangeUpdated(const QStringList &icaoCodes, const QStringList &names, const QList<double> &lats, const QList<double> &lons, const QList<double> &alts);
public slots:
//! Get own aircraft situation data
void getOwnAircraftSituationData(XPlaneData *o_xplaneData);
//! \copydoc XSwiftBus::CService::addTextMessage
void addTextMessage(const QString &text, double red, double green, double blue);