diff --git a/src/AIModel/AISwiftAircraft.cpp b/src/AIModel/AISwiftAircraft.cpp index 80e090c2e..1ae7461e1 100644 --- a/src/AIModel/AISwiftAircraft.cpp +++ b/src/AIModel/AISwiftAircraft.cpp @@ -32,6 +32,7 @@ FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::str setCallSign(callsign); _searchOrder = PREFER_AI; } + void FGAISwiftAircraft::updatePosition(SGGeod& position, SGVec3& orientation, double groundspeed, bool initPos) { m_initPos = initPos; @@ -50,6 +51,7 @@ void FGAISwiftAircraft::update(double dt) FGAIBase::update(dt); Transform(); } + double FGAISwiftAircraft::getGroundElevation(const SGGeod& pos) const { if(!m_initPos) { return std::numeric_limits::quiet_NaN(); } @@ -62,4 +64,53 @@ double FGAISwiftAircraft::getGroundElevation(const SGGeod& pos) const return alt; return std::numeric_limits::quiet_NaN(); } + +void FGAISwiftAircraft::setPlaneSurface(double gear, double flaps, double spoilers, double speedBrake, double slats, + double wingSweeps, double thrust, double elevator, double rudder, double aileron, + bool landingLight, bool taxiLight, bool beaconLight, bool strobeLight, bool navLight, + int lightPattern) +{ + m_gearNode->setDoubleValue(gear); + m_flapsIdentNode->setDoubleValue(flaps); + m_spoilerNode->setDoubleValue(spoilers); + m_speedBrakeNode->setDoubleValue(speedBrake); + m_landLightNode->setBoolValue(landingLight); + m_taxiLightNode->setBoolValue(taxiLight); + m_beaconLightNode->setBoolValue(beaconLight); + m_strobeLightNode->setBoolValue(strobeLight); + m_navLightNode->setBoolValue(navLight); +} + +void FGAISwiftAircraft::setPlaneTransponder(int code, bool modeC, bool ident) +{ + m_transponderCodeNode->setIntValue(code); + m_transponderCModeNode->setBoolValue(modeC); + m_transponderIdentNode->setBoolValue(ident); +} + +void FGAISwiftAircraft::initProps() +{ + // Setup node properties + m_transponderCodeNode = _getProps()->getNode("swift/transponder/code", true); + m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true); + m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true); + + m_gearNode = _getProps()->getNode("controls/gear/gear-down", true); + m_flapsIdentNode = _getProps()->getNode("controls/flight/flaps", true); + m_spoilerNode = _getProps()->getNode("controls/flight/spoilers", true); + m_speedBrakeNode = _getProps()->getNode("controls/flight/speedbrake", true); + m_landLightNode = _getProps()->getNode("controls/lighting/landing-lights", true); + + // Untie NavLight property for explicit control (tied within FGAIBase) + m_navLightNode = _getProps()->getNode("controls/lighting/nav-lights", true); + if(m_navLightNode) + { + m_navLightNode->untie(); + } + + m_taxiLightNode = _getProps()->getNode("controls/lighting/taxi-light", true); + m_beaconLightNode = _getProps()->getNode("controls/lighting/beacon", true); + m_strobeLightNode = _getProps()->getNode("controls/lighting/strobe", true); +} + FGAISwiftAircraft::~FGAISwiftAircraft() = default; diff --git a/src/AIModel/AISwiftAircraft.h b/src/AIModel/AISwiftAircraft.h index 633679402..a313219ee 100644 --- a/src/AIModel/AISwiftAircraft.h +++ b/src/AIModel/AISwiftAircraft.h @@ -35,11 +35,39 @@ public: void updatePosition(SGGeod& position, SGVec3& orientation, double groundspeed, bool initPos); void update(double dt) override; double getGroundElevation(const SGGeod& pos) const; + void initProps(); + void setPlaneSurface(double gear, double flaps, double spoilers, double speedBrake, double slats, + double wingSweeps, double thrust, double elevator, double rudder, double aileron, + bool landingLight, bool taxiLight, bool beaconLight, bool strobeLight, bool navLight, + int lightPattern); + void setPlaneTransponder(int code, bool modeC, bool ident); const char* getTypeString() const override { return "swift"; } private: bool m_initPos = false; + // Property Nodes for transponder and parts + SGPropertyNode_ptr m_transponderCodeNode; + SGPropertyNode_ptr m_transponderCModeNode; + SGPropertyNode_ptr m_transponderIdentNode; + + SGPropertyNode_ptr m_gearNode; + SGPropertyNode_ptr m_flapsIdentNode; + SGPropertyNode_ptr m_spoilerNode; + SGPropertyNode_ptr m_speedBrakeNode; + //SGPropertyNode_ptr m_slatsNode; + //SGPropertyNode_ptr m_wingSweepNode; + //SGPropertyNode_ptr m_thrustNode; + //SGPropertyNode_ptr m_elevatorNode; + //SGPropertyNode_ptr m_rudderNode; + //SGPropertyNode_ptr m_aileronNode; + SGPropertyNode_ptr m_landLightNode; + SGPropertyNode_ptr m_taxiLightNode; + SGPropertyNode_ptr m_beaconLightNode; + SGPropertyNode_ptr m_strobeLightNode; + SGPropertyNode_ptr m_navLightNode; + //SGPropertyNode_ptr m_lightPatternNode; + }; diff --git a/src/Network/Swift/SwiftAircraftManager.cpp b/src/Network/Swift/SwiftAircraftManager.cpp index fc76dca61..07b217f72 100644 --- a/src/Network/Swift/SwiftAircraftManager.cpp +++ b/src/Network/Swift/SwiftAircraftManager.cpp @@ -42,6 +42,8 @@ bool FGSwiftAircraftManager::addPlane(const std::string& callsign, const std::st this->removePlane(callsign); // Remove plane if already exists e.g. when rematching is done. auto curAircraft = new FGAISwiftAircraft(callsign, modelString); globals->get_subsystem()->attach(curAircraft); + // Init props after prop-root is assigned + curAircraft->initProps(); aircraftByCallsign.insert(std::pair(callsign, curAircraft)); return true; @@ -123,3 +125,34 @@ double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsig // Aircraft not found in list return std::numeric_limits::quiet_NaN(); } + +void FGSwiftAircraftManager::setPlanesTransponders(std::vector callsigns, std::vector codes, std::vector modeCs, std::vector idents) +{ + for (long unsigned int i = 0; i < callsigns.size(); i++) + { + auto it = aircraftByCallsign.find(callsigns.at(i)); + if(it != aircraftByCallsign.end()) + { + it->second->setPlaneTransponder(codes.at(i), modeCs.at(i), idents.at(i)); + } + } +} + +void FGSwiftAircraftManager::setPlanesSurfaces(std::vector callsigns, std::vector gears, std::vector flaps, + std::vector spoilers ,std::vector speedBrakes, std::vector slats, + std::vector wingSweeps, std::vector thrusts, std::vector elevators, + std::vector rudders, std::vector ailerons, std::vector landLights, + std::vector taxiLights, std::vector beaconLights, std::vector strobeLights, + std::vector navLights, std::vector lightPatterns) +{ + for (long unsigned int i = 0; i < callsigns.size(); i++) + { + auto it = aircraftByCallsign.find(callsigns.at(i)); + if(it != aircraftByCallsign.end()) + { + it->second->setPlaneSurface(gears.at(i), flaps.at(i), spoilers.at(i), speedBrakes.at(i), slats.at(i), wingSweeps.at(i), thrusts.at(i), elevators.at(i), + rudders.at(i), ailerons.at(i), landLights.at(i), taxiLights.at(i), beaconLights.at(i), strobeLights.at(i), navLights.at(i), + lightPatterns.at(i)); + } + } +} diff --git a/src/Network/Swift/SwiftAircraftManager.h b/src/Network/Swift/SwiftAircraftManager.h index b11e63fb6..deb7cb674 100644 --- a/src/Network/Swift/SwiftAircraftManager.h +++ b/src/Network/Swift/SwiftAircraftManager.h @@ -38,8 +38,15 @@ public: std::vector& elevationsM, std::vector& verticalOffsets) const; void removePlane(const std::string& callsign); void removeAllPlanes(); + void setPlanesTransponders(std::vector callsigns, std::vector codes, std::vector modeCs, std::vector idents); double getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const; bool isInitialized() const; + void setPlanesSurfaces(std::vector callsigns, std::vector gears, std::vector flaps, + std::vector spoilers ,std::vector speedBrakes, std::vector slats, + std::vector wingSweeps, std::vector thrusts, std::vector elevators, + std::vector rudders, std::vector ailerons, std::vector landLights, + std::vector taxiLights, std::vector beaconLights, std::vector strobeLights, + std::vector navLights, std::vector lightPatterns); private: std::unordered_map aircraftByCallsign; diff --git a/src/Network/Swift/service.cpp b/src/Network/Swift/service.cpp index 2c718427b..fb2dfc057 100644 --- a/src/Network/Swift/service.cpp +++ b/src/Network/Swift/service.cpp @@ -23,7 +23,7 @@ #include #include -#define FGSWIFTBUS_API_VERSION 1; +#define FGSWIFTBUS_API_VERSION 2; namespace FGSwiftBus { diff --git a/src/Network/Swift/traffic.cpp b/src/Network/Swift/traffic.cpp index 8a86a549a..cc208a7f5 100644 --- a/src/Network/Swift/traffic.cpp +++ b/src/Network/Swift/traffic.cpp @@ -94,7 +94,6 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_) const std::string sender = message.getSender(); const dbus_uint32_t serial = message.getSerial(); const bool wantsReply = message.wantsReply(); - std::string test = message.getMethodName(); if (message.getInterfaceName() == DBUS_INTERFACE_INTROSPECTABLE) { if (message.getMethodName() == "Introspect") { @@ -206,8 +205,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_) reply.appendArgument(verticalOffsets); sendDBusMessage(reply); }); - } - else if (message.getMethodName() == "getElevationAtPosition") + } else if (message.getMethodName() == "getElevationAtPosition") { std::string callsign; double latitudeDeg; @@ -231,6 +229,65 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_) reply.appendArgument(elevation); sendDBusMessage(reply); }); + } else if (message.getMethodName() == "setPlanesTransponders") + { + maybeSendEmptyDBusReply(wantsReply, sender, serial); + std::vector callsigns; + std::vector codes; + std::vector modeCs; + std::vector idents; + message.beginArgumentRead(); + message.getArgument(callsigns); + message.getArgument(codes); + message.getArgument(modeCs); + message.getArgument(idents); + queueDBusCall([ = ]() + { + acm->setPlanesTransponders(callsigns, codes, modeCs, idents); + }); + } else if (message.getMethodName() == "setPlanesSurfaces") + { + maybeSendEmptyDBusReply(wantsReply, sender, serial); + std::vector callsigns; + std::vector gears; + std::vector flaps; + std::vector spoilers; + std::vector speedBrakes; + std::vector slats; + std::vector wingSweeps; + std::vector thrusts; + std::vector elevators; + std::vector rudders; + std::vector ailerons; + std::vector landLights; + std::vector taxiLights; + std::vector beaconLights; + std::vector strobeLights; + std::vector navLights; + std::vector lightPatterns; + message.beginArgumentRead(); + message.getArgument(callsigns); + message.getArgument(gears); + message.getArgument(flaps); + message.getArgument(spoilers); + message.getArgument(speedBrakes); + message.getArgument(slats); + message.getArgument(wingSweeps); + message.getArgument(thrusts); + message.getArgument(elevators); + message.getArgument(rudders); + message.getArgument(ailerons); + message.getArgument(landLights); + message.getArgument(taxiLights); + message.getArgument(beaconLights); + message.getArgument(strobeLights); + message.getArgument(navLights); + message.getArgument(lightPatterns); + queueDBusCall([ = ]() + { + acm->setPlanesSurfaces(callsigns, gears, flaps, spoilers, speedBrakes, slats, wingSweeps, thrusts, elevators, + rudders, ailerons, landLights, taxiLights, beaconLights, strobeLights, navLights, lightPatterns); + }); } else { // Unknown message. Tell DBus that we cannot handle it return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;