mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T290, XPlane refactoring
* typo getRemoteAircraftsData -> getRemoteAircraftData (no "s") * typo getEelevationAtPosition (double "Ee") * get functions "const" * added unit for some variables such as latitudeDeg
This commit is contained in:
@@ -971,8 +971,8 @@ namespace BlackMisc
|
||||
if (this->hasGroundElevation())
|
||||
{
|
||||
static const CLength threshold(400, CLengthUnit::m());
|
||||
const CLength a = this->getHeightAboveGround();
|
||||
if (!a.isNull() && a >= threshold) { return true; } // too high for ground
|
||||
const CLength aboveGround = this->getHeightAboveGround();
|
||||
if (!aboveGround.isNull() && aboveGround >= threshold) { return true; } // too high for ground
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -820,6 +820,7 @@ namespace BlackSimPlugin
|
||||
CCallsignSet callsigns = m_xplaneAircraftObjects.getAllCallsigns();
|
||||
const CCallsignSet remove = this->getLastSentCanLikelySkipNearGroundInterpolation().getCallsigns();
|
||||
callsigns.remove(remove);
|
||||
if (!callsigns.isEmpty()) { this->requestRemoteAircraftDataFromXPlane(callsigns); }
|
||||
}
|
||||
|
||||
void CSimulatorXPlane::requestRemoteAircraftDataFromXPlane(const CCallsignSet &callsigns)
|
||||
@@ -827,9 +828,9 @@ namespace BlackSimPlugin
|
||||
if (callsigns.isEmpty()) { return; }
|
||||
if (this->isShuttingDown()) { return; }
|
||||
const QStringList csStrings = callsigns.getCallsignStrings();
|
||||
m_trafficProxy->getRemoteAircraftData(csStrings, [ = ](const QStringList & callsigns, const QDoubleList & latitudesDeg, const QDoubleList & longitudesDeg, const QDoubleList & elevationsM, const QDoubleList & verticalOffsets)
|
||||
m_trafficProxy->getRemoteAircraftData(csStrings, [ = ](const QStringList & callsigns, const QDoubleList & latitudesDeg, const QDoubleList & longitudesDeg, const QDoubleList & elevationsMeters, const QDoubleList & verticalOffsetsMeters)
|
||||
{
|
||||
updateRemoteAircraftFromSimulator(callsigns, latitudesDeg, longitudesDeg, elevationsM, verticalOffsets);
|
||||
this->updateRemoteAircraftFromSimulator(callsigns, latitudesDeg, longitudesDeg, elevationsMeters, verticalOffsetsMeters);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -846,18 +847,28 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorXPlane::updateRemoteAircraftFromSimulator(
|
||||
const QStringList &callsigns, const QDoubleList &latitudesDeg, const QDoubleList &longitudesDeg,
|
||||
const QDoubleList &elevationsM, const QDoubleList &verticalOffsets)
|
||||
const QDoubleList &elevationsMeters, const QDoubleList &verticalOffsetsMeters)
|
||||
{
|
||||
for (int i = 0; i < callsigns.size(); i++)
|
||||
const int size = callsigns.size();
|
||||
|
||||
// we skip if we are not near ground
|
||||
if (CBuildConfig::isLocalDeveloperDebugBuild())
|
||||
{
|
||||
Q_ASSERT_X(elevationsMeters.size() == size, Q_FUNC_INFO, "Wrong elevations");
|
||||
Q_ASSERT_X(latitudesDeg.size() == size, Q_FUNC_INFO, "Wrong latitudesDeg");
|
||||
Q_ASSERT_X(longitudesDeg.size() == size, Q_FUNC_INFO, "Wrong longitudesDeg");
|
||||
Q_ASSERT_X(verticalOffsetsMeters.size() == size, Q_FUNC_INFO, "Wrong CG");
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
const CCallsign cs(callsigns[i]);
|
||||
if (!m_xplaneAircraftObjects.contains(cs)) { continue; }
|
||||
|
||||
// we skip if we are not near ground
|
||||
const CXPlaneMPAircraft xpAircraft = m_xplaneAircraftObjects[cs];
|
||||
const CAltitude elevationAlt(elevationsM[i], CLengthUnit::m(), CLengthUnit::ft());
|
||||
const CAltitude elevationAlt(elevationsMeters[i], CLengthUnit::m(), CLengthUnit::ft());
|
||||
const CElevationPlane elevation(CLatitude(latitudesDeg[i], CAngleUnit::deg()), CLongitude(longitudesDeg[i], CAngleUnit::deg()), elevationAlt, CElevationPlane::singlePointRadius());
|
||||
const CLength cg(verticalOffsets[i], CLengthUnit::m(), CLengthUnit::ft());
|
||||
const CLength cg(verticalOffsetsMeters[i], CLengthUnit::m(), CLengthUnit::ft());
|
||||
this->rememberElevationAndCG(cs, xpAircraft.getAircraftModelString(), elevation, cg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace BlackSimPlugin
|
||||
void onRemoteAircraftAdded(const QString &callsign);
|
||||
void onRemoteAircraftAddingFailed(const QString &callsign);
|
||||
void updateRemoteAircraftFromSimulator(const QStringList &callsigns, const QDoubleList &latitudesDeg, const QDoubleList &longitudesDeg,
|
||||
const QDoubleList &elevationsM, const QDoubleList &verticalOffsets);
|
||||
const QDoubleList &elevationsMeters, const QDoubleList &verticalOffsetsMeters);
|
||||
//! @}
|
||||
|
||||
//! Dsiconnect from DBus
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace BlackSimPlugin
|
||||
m_dbusInterface->callDBus(QLatin1String("setInterpolatorMode"), callsign, spline);
|
||||
}
|
||||
|
||||
void CXSwiftBusTrafficProxy::getRemoteAircraftsData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter)
|
||||
void CXSwiftBusTrafficProxy::getRemoteAircraftData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter) const
|
||||
{
|
||||
std::function<void(QDBusPendingCallWatcher *)> callback = [ = ](QDBusPendingCallWatcher * watcher)
|
||||
{
|
||||
@@ -128,11 +128,11 @@ namespace BlackSimPlugin
|
||||
}
|
||||
watcher->deleteLater();
|
||||
};
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getRemoteAircraftsData"), callback, callsigns);
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getRemoteAircraftData"), callback, callsigns);
|
||||
}
|
||||
|
||||
void CXSwiftBusTrafficProxy::getEelevationAtPosition(const CCallsign &callsign, double latitude, double longitude, double altitude,
|
||||
const ElevationCallback &setter)
|
||||
void CXSwiftBusTrafficProxy::getElevationAtPosition(const CCallsign &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters,
|
||||
const ElevationCallback &setter) const
|
||||
{
|
||||
std::function<void(QDBusPendingCallWatcher *)> callback = [ = ](QDBusPendingCallWatcher * watcher)
|
||||
{
|
||||
@@ -142,14 +142,14 @@ namespace BlackSimPlugin
|
||||
const CCallsign cs(reply.argumentAt<0>());
|
||||
const double elevationMeters = reply.argumentAt<1>();
|
||||
const CAltitude elevationAlt(elevationMeters, CLengthUnit::m(), CLengthUnit::ft());
|
||||
const CElevationPlane elevation(CLatitude(latitude, CAngleUnit::deg()),
|
||||
CLongitude(longitude, CAngleUnit::deg()),
|
||||
const CElevationPlane elevation(CLatitude(latitudeDeg, CAngleUnit::deg()),
|
||||
CLongitude(longitudeDeg, CAngleUnit::deg()),
|
||||
elevationAlt, CElevationPlane::singlePointRadius());
|
||||
setter(elevation, cs);
|
||||
}
|
||||
watcher->deleteLater();
|
||||
};
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getEelevationAtPosition"), callback, callsign.asString(), latitude, longitude, altitude);
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getElevationAtPosition"), callback, callsign.asString(), latitudeDeg, longitudeDeg, altitudeMeters);
|
||||
}
|
||||
|
||||
void CXSwiftBusTrafficProxy::setFollowedAircraft(const QString &callsign)
|
||||
|
||||
@@ -178,12 +178,12 @@ namespace BlackSimPlugin
|
||||
//! \deprecated XSwiftBus::CTraffic::setInterpolatorMode
|
||||
void setInterpolatorMode(const QString &callsign, bool spline);
|
||||
|
||||
//! \copydoc XSwiftBus::CTraffic::getRemoteAircraftsData
|
||||
void getRemoteAircraftsData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter);
|
||||
//! \copydoc XSwiftBus::CTraffic::getRemoteAircraftData
|
||||
void getRemoteAircraftData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter) const;
|
||||
|
||||
//! \copydoc XSwiftBus::CTraffic::getEelevationAtPosition
|
||||
void getEelevationAtPosition(const BlackMisc::Aviation::CCallsign &callsign, double latitude, double longitude, double altitude,
|
||||
const ElevationCallback &setter);
|
||||
//! \copydoc XSwiftBus::CTraffic::getElevationAtPosition
|
||||
void getElevationAtPosition(const BlackMisc::Aviation::CCallsign &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters,
|
||||
const ElevationCallback &setter) const;
|
||||
|
||||
//! \copydoc XSwiftBus::CTraffic::setFollowedAircraft
|
||||
void setFollowedAircraft(const QString &callsign);
|
||||
|
||||
@@ -76,7 +76,7 @@ R"(<node>
|
||||
<arg name="modeC" type="b" direction="in"/>
|
||||
<arg name="ident" type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="getEelevationAtPosition">
|
||||
<method name="getElevationAtPosition">
|
||||
<arg name="callsign" type="s" direction="in"/>
|
||||
<arg name="latitude" type="d" direction="in"/>
|
||||
<arg name="longitude" type="d" direction="in"/>
|
||||
|
||||
@@ -383,8 +383,8 @@ namespace XSwiftBus
|
||||
else { plane->xpdr.mode = xpmpTransponderMode_Standby; }
|
||||
}
|
||||
|
||||
void CTraffic::getRemoteAircraftsData(std::vector<std::string> &callsigns, std::vector<double> &latitudesDeg, std::vector<double> &longitudesDeg,
|
||||
std::vector<double> &elevationsM, std::vector<double> &verticalOffsets)
|
||||
void CTraffic::getRemoteAircraftData(std::vector<std::string> &callsigns, std::vector<double> &latitudesDeg, std::vector<double> &longitudesDeg,
|
||||
std::vector<double> &elevationsM, std::vector<double> &verticalOffsets) const
|
||||
{
|
||||
if (callsigns.empty() || m_planesByCallsign.empty()) { return; }
|
||||
|
||||
@@ -403,32 +403,32 @@ namespace XSwiftBus
|
||||
Plane *plane = planeIt->second;
|
||||
assert(plane);
|
||||
|
||||
double lat = plane->position.lat;
|
||||
double lon = plane->position.lon;
|
||||
double groundElevation = plane->terrainProbe.getElevation(lat, lon, plane->position.elevation);
|
||||
double latDeg = plane->position.lat;
|
||||
double lonDeg = plane->position.lon;
|
||||
double groundElevation = plane->terrainProbe.getElevation(latDeg, lonDeg, plane->position.elevation);
|
||||
if (std::isnan(groundElevation)) { groundElevation = 0.0; }
|
||||
double fudgeFactor = 3.0;
|
||||
XPMPGetVerticalOffset(plane->id, &fudgeFactor);
|
||||
|
||||
callsigns.push_back(requestedCallsign);
|
||||
latitudesDeg.push_back(lat);
|
||||
longitudesDeg.push_back(lon);
|
||||
latitudesDeg.push_back(latDeg);
|
||||
longitudesDeg.push_back(lonDeg);
|
||||
elevationsM.push_back(groundElevation);
|
||||
verticalOffsets.push_back(fudgeFactor);
|
||||
}
|
||||
}
|
||||
|
||||
double CTraffic::getEelevationAtPosition(const std::string &callsign, double latitude, double longitude, double altitude)
|
||||
double CTraffic::getElevationAtPosition(const std::string &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters) const
|
||||
{
|
||||
auto planeIt = m_planesByCallsign.find(callsign);
|
||||
if (planeIt != m_planesByCallsign.end())
|
||||
{
|
||||
Plane *plane = planeIt->second;
|
||||
return plane->terrainProbe.getElevation(latitude, longitude, altitude);
|
||||
return plane->terrainProbe.getElevation(latitudeDeg, longitudeDeg, altitudeMeters);
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_terrainProbe.getElevation(latitude, longitude, altitude);
|
||||
return m_terrainProbe.getElevation(latitudeDeg, longitudeDeg, altitudeMeters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,7 +659,7 @@ namespace XSwiftBus
|
||||
setPlaneTransponder(callsign, code, modeC, ident);
|
||||
});
|
||||
}
|
||||
else if (message.getMethodName() == "getRemoteAircraftsData")
|
||||
else if (message.getMethodName() == "getRemoteAircraftData")
|
||||
{
|
||||
std::vector<std::string> requestedcallsigns;
|
||||
message.beginArgumentRead();
|
||||
@@ -671,7 +671,7 @@ namespace XSwiftBus
|
||||
std::vector<double> longitudesDeg;
|
||||
std::vector<double> elevationsM;
|
||||
std::vector<double> verticalOffsets;
|
||||
getRemoteAircraftsData(callsigns, latitudesDeg, longitudesDeg, elevationsM, verticalOffsets);
|
||||
getRemoteAircraftData(callsigns, latitudesDeg, longitudesDeg, elevationsM, verticalOffsets);
|
||||
CDBusMessage reply = CDBusMessage::createReply(sender, serial);
|
||||
reply.beginArgumentWrite();
|
||||
reply.appendArgument(callsigns);
|
||||
@@ -682,23 +682,23 @@ namespace XSwiftBus
|
||||
sendDBusMessage(reply);
|
||||
});
|
||||
}
|
||||
else if (message.getMethodName() == "getEelevationAtPosition")
|
||||
else if (message.getMethodName() == "getElevationAtPosition")
|
||||
{
|
||||
std::string callsign;
|
||||
double latitude;
|
||||
double longitude;
|
||||
double altitude;
|
||||
double latitudeDeg;
|
||||
double longitudeDeg;
|
||||
double elevationMeters;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(callsign);
|
||||
message.getArgument(latitude);
|
||||
message.getArgument(longitude);
|
||||
message.getArgument(altitude);
|
||||
message.getArgument(latitudeDeg);
|
||||
message.getArgument(longitudeDeg);
|
||||
message.getArgument(elevationMeters);
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
CDBusMessage reply = CDBusMessage::createReply(sender, serial);
|
||||
reply.beginArgumentWrite();
|
||||
reply.appendArgument(callsign);
|
||||
reply.appendArgument(getEelevationAtPosition(callsign, latitude, longitude, altitude));
|
||||
reply.appendArgument(getElevationAtPosition(callsign, latitudeDeg, longitudeDeg, elevationMeters));
|
||||
; sendDBusMessage(reply);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,24 +97,24 @@ namespace XSwiftBus
|
||||
|
||||
//! Set the position of multiple traffic aircrafts
|
||||
void setPlanesPositions(const std::vector<std::string> &callsigns, std::vector<double> latitudes, std::vector<double> longitudes, std::vector<double> altitudes,
|
||||
std::vector<double> pitches, std::vector<double> rolls, std::vector<double> headings);
|
||||
std::vector<double> pitches, std::vector<double> rolls, std::vector<double> headings);
|
||||
|
||||
//! Set the flight control surfaces and lights of multiple traffic aircrafts
|
||||
void setPlanesSurfaces(const std::vector<std::string> &callsigns, const std::vector<double> &gears, const std::vector<double> &flaps, const std::vector<double> &spoilers,
|
||||
const std::vector<double> &speedBrakes, const std::vector<double> &slats, const std::vector<double> &wingSweeps, const std::vector<double> &thrusts,
|
||||
const std::vector<double> &elevators, const std::vector<double> &rudders, const std::vector<double> &ailerons, const std::vector<bool> &landLights,
|
||||
const std::vector<bool> &beaconLights, const std::vector<bool> &strobeLights, const std::vector<bool> &navLights, const std::vector<int> &lightPatterns,
|
||||
const std::vector<bool> &onGrounds);
|
||||
const std::vector<double> &speedBrakes, const std::vector<double> &slats, const std::vector<double> &wingSweeps, const std::vector<double> &thrusts,
|
||||
const std::vector<double> &elevators, const std::vector<double> &rudders, const std::vector<double> &ailerons, const std::vector<bool> &landLights,
|
||||
const std::vector<bool> &beaconLights, const std::vector<bool> &strobeLights, const std::vector<bool> &navLights, const std::vector<int> &lightPatterns,
|
||||
const std::vector<bool> &onGrounds);
|
||||
|
||||
//! Set the transponder of a traffic aircraft
|
||||
void setPlaneTransponder(const std::string &callsign, int code, bool modeC, bool ident);
|
||||
|
||||
//! Get remote aircrafts data (lat, lon, elevation and CG)
|
||||
void getRemoteAircraftsData(std::vector<std::string> &callsigns, std::vector<double> &latitudesDeg, std::vector<double> &longitudesDeg,
|
||||
std::vector<double> &elevationsM, std::vector<double> &verticalOffsets);
|
||||
void getRemoteAircraftData(std::vector<std::string> &callsigns, std::vector<double> &latitudesDeg, std::vector<double> &longitudesDeg,
|
||||
std::vector<double> &elevationsM, std::vector<double> &verticalOffsets) const;
|
||||
|
||||
//! Get the ground elevation at an arbitrary position
|
||||
double getEelevationAtPosition(const std::string &callsign, double latitude, double longitude, double altitude);
|
||||
double getElevationAtPosition(const std::string &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters) const;
|
||||
|
||||
//! Sets the aircraft with callsign to be followed in plane view
|
||||
void setFollowedAircraft(const std::string &callsign);
|
||||
@@ -192,7 +192,7 @@ namespace XSwiftBus
|
||||
else { traffic->emitPlaneAddingFailed(planeIt->second->callsign); }
|
||||
}
|
||||
};
|
||||
}
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user