]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/FGOutput.cpp
Merge branch 'next' of http://git.gitorious.org/fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / FGOutput.cpp
index a974915f4cfd72106cdd10f8810ae7dca7810d07..ab70cb2d2de6098afa0957099c56824fc0e6ef49 100644 (file)
@@ -61,9 +61,6 @@ INCLUDES
 #include <cstring>
 #include <cstdlib>
 
-#include "input_output/net_fdm.hxx"
-#include "input_output/FGfdmSocket.h"
-
 #if defined(WIN32) && !defined(__CYGWIN__)
 #  include <windows.h>
 #else
@@ -77,7 +74,7 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGOutput.cpp,v 1.48 2010/04/12 12:25:19 jberndt Exp $";
+static const char *IdSrc = "$Id: FGOutput.cpp,v 1.54 2011/03/11 13:02:26 jberndt Exp $";
 static const char *IdHdr = ID_OUTPUT;
 
 // (stolen from FGFS native_fdm.cxx)
@@ -132,7 +129,6 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
   Name = "FGOutput";
   sFirstPass = dFirstPass = true;
   socket = 0;
-  flightGearSocket = 0;
   runID_postfix = 0;
   Type = otNone;
   SubSystems = 0;
@@ -153,7 +149,6 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
 FGOutput::~FGOutput()
 {
   delete socket;
-  delete flightGearSocket;
   OutputProperties.clear();
   Debug(1);
 }
@@ -187,21 +182,9 @@ bool FGOutput::Run(void)
 {
   if (FGModel::Run()) return true;
 
-  if (enabled && !FDMExec->IntegrationSuspended()&& !FDMExec->Holding()) {
+  if (enabled && !FDMExec->IntegrationSuspended() && !FDMExec->Holding()) {
     RunPreFunctions();
-    if (Type == otSocket) {
-      SocketOutput();
-    } else if (Type == otFlightGear) {
-      FlightGearSocketOutput();
-    } else if (Type == otCSV || Type == otTab) {
-      DelimitedOutput(Filename);
-    } else if (Type == otTerminal) {
-      // Not done yet
-    } else if (Type == otNone) {
-      // Do nothing
-    } else {
-      // Not a valid type of output
-    }
+    Print();
     RunPostFunctions();
   }
   return false;
@@ -209,6 +192,25 @@ bool FGOutput::Run(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+void FGOutput::Print(void)
+{
+  if (Type == otSocket) {
+    SocketOutput();
+  } else if (Type == otFlightGear) {
+    FlightGearSocketOutput();
+  } else if (Type == otCSV || Type == otTab) {
+    DelimitedOutput(Filename);
+  } else if (Type == otTerminal) {
+    // Not done yet
+  } else if (Type == otNone) {
+    // Do nothing
+  } else {
+    // Not a valid type of output
+  }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 void FGOutput::SetType(const string& type)
 {
   if (type == "CSV") {
@@ -231,8 +233,30 @@ void FGOutput::SetType(const string& type)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+void FGOutput::SetProtocol(const string& protocol)
+{
+  if (protocol == "UDP") Protocol = FGfdmSocket::ptUDP;
+  else if (protocol == "TCP") Protocol = FGfdmSocket::ptTCP;
+  else Protocol = FGfdmSocket::ptTCP; // Default to TCP
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 void FGOutput::DelimitedOutput(const string& fname)
 {
+  const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+  const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+  const FGAircraft* Aircraft = FDMExec->GetAircraft();
+  const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
+  const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+  const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+  const FGPropagate* Propagate = FDMExec->GetPropagate();
+  const FGFCS* FCS = FDMExec->GetFCS();
+  const FGInertial* Inertial = FDMExec->GetInertial();
+  const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
+  const FGExternalReactions* ExternalReactions = FDMExec->GetExternalReactions();
+  const FGBuoyantForces* BuoyantForces = FDMExec->GetBuoyantForces();
+
   streambuf* buffer;
   string scratch = "";
 
@@ -279,6 +303,7 @@ void FGOutput::DelimitedOutput(const string& fname)
       outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
       outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
       outstream << "V_{X_{inertial}} (ft/s)" + delimeter + "V_{Y_{inertial}} (ft/s)" + delimeter + "V_{Z_{inertial}} (ft/s)" + delimeter;
+      outstream << "V_{X_{ecef}} (ft/s)" + delimeter + "V_{Y_{ecef}} (ft/s)" + delimeter + "V_{Z_{ecef}} (ft/s)" + delimeter;
       outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
     }
     if (SubSystems & ssForces) {
@@ -342,8 +367,8 @@ void FGOutput::DelimitedOutput(const string& fname)
       outstream << "Distance AGL (ft)" + delimeter;
       outstream << "Terrain Elevation (ft)";
     }
-    if (SubSystems & ssCoefficients) {
-      scratch = Aerodynamics->GetCoefficientStrings(delimeter);
+    if (SubSystems & ssAeroFunctions) {
+      scratch = Aerodynamics->GetAeroFunctionStrings(delimeter);
       if (scratch.length() != 0) outstream << delimeter << scratch;
     }
     if (SubSystems & ssFCS) {
@@ -398,6 +423,7 @@ void FGOutput::DelimitedOutput(const string& fname)
     outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
     outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
     outstream << Propagate->GetInertialVelocity().Dump(delimeter) << delimeter;
+    outstream << Propagate->GetECEFVelocity().Dump(delimeter) << delimeter;
     outstream << Propagate->GetVel().Dump(delimeter);
     outstream.precision(10);
   }
@@ -458,8 +484,8 @@ void FGOutput::DelimitedOutput(const string& fname)
     outstream << Propagate->GetTerrainElevation();
     outstream.precision(10);
   }
-  if (SubSystems & ssCoefficients) {
-    scratch = Aerodynamics->GetCoefficientValues(delimeter);
+  if (SubSystems & ssAeroFunctions) {
+    scratch = Aerodynamics->GetAeroFunctionValues(delimeter);
     if (scratch.length() != 0) outstream << delimeter << scratch;
   }
   if (SubSystems & ssFCS) {
@@ -489,6 +515,13 @@ void FGOutput::DelimitedOutput(const string& fname)
 
 void FGOutput::SocketDataFill(FGNetFDM* net)
 {
+  const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+  const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+  const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+  const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+  const FGPropagate* Propagate = FDMExec->GetPropagate();
+  const FGFCS* FCS = FDMExec->GetFCS();
+  const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
     unsigned int i;
 
     // Version
@@ -566,7 +599,6 @@ void FGOutput::SocketDataFill(FGNetFDM* net)
        }
     }
 
-
     // Consumables
     net->num_tanks = Propulsion->GetNumTanks();   // Max number of fuel tanks
 
@@ -574,7 +606,6 @@ void FGOutput::SocketDataFill(FGNetFDM* net)
        net->fuel_quantity[i] = (float)(((FGTank *)Propulsion->GetTank(i))->GetContents());
     }
 
-
     // Gear status
     net->num_wheels  = GroundReactions->GetNumGearUnits();
 
@@ -588,13 +619,11 @@ void FGOutput::SocketDataFill(FGNetFDM* net)
        net->gear_compression[i] = (float)(GroundReactions->GetGearUnit(i)->GetCompLen());
     }
 
-
     // Environment
-    net->cur_time    = (long int)1234567890;   // Friday, Feb 13, 2009, 23:31:30 UTC (not processed by FGFS anyway)
+    net->cur_time    = (long int)1234567890;    // Friday, Feb 13, 2009, 23:31:30 UTC (not processed by FGFS anyway)
     net->warp        = 0;                       // offset in seconds to unix time
     net->visibility  = 25000.0;                 // visibility in meters (for env. effects)
 
-
     // Control surface positions (normalized values)
     net->elevator          = (float)(FCS->GetDePos(ofNorm));    // Norm Elevator Pos, --
     net->elevator_trim_tab = (float)(FCS->GetPitchTrimCmd());   // Norm Elev Trim Tab Pos, --
@@ -607,7 +636,6 @@ void FGOutput::SocketDataFill(FGNetFDM* net)
     net->speedbrake        = (float)(FCS->GetDsbPos(ofNorm));   // Norm Speedbrake Pos, --
     net->spoilers          = (float)(FCS->GetDspPos(ofNorm));   // Norm Spoiler Pos, --
 
-
     // Convert the net buffer to network format
     if ( isLittleEndian ) {
         net->version = htonl(net->version);
@@ -691,18 +719,27 @@ void FGOutput::FlightGearSocketOutput(void)
 {
   int length = sizeof(fgSockBuf);
 
-
-  if (flightGearSocket == NULL) return;
-  if (!flightGearSocket->GetConnectStatus()) return;
+  if (socket == NULL) return;
+  if (!socket->GetConnectStatus()) return;
 
   SocketDataFill(&fgSockBuf);
-  flightGearSocket->Send((char *)&fgSockBuf, length);
+  socket->Send((char *)&fgSockBuf, length);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 void FGOutput::SocketOutput(void)
 {
+  const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+  const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+  const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+  const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+  const FGPropagate* Propagate = FDMExec->GetPropagate();
+  const FGFCS* FCS = FDMExec->GetFCS();
+  const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
+  const FGAircraft* Aircraft = FDMExec->GetAircraft();
+  const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
+
   string asciiData, scratch;
 
   if (socket == NULL) return;
@@ -798,8 +835,8 @@ void FGOutput::SocketOutput(void)
         socket->Append("Latitude (deg)");
         socket->Append("Longitude (deg)");
     }
-    if (SubSystems & ssCoefficients) {
-      scratch = Aerodynamics->GetCoefficientStrings(",");
+    if (SubSystems & ssAeroFunctions) {
+      scratch = Aerodynamics->GetAeroFunctionStrings(",");
       if (scratch.length() != 0) socket->Append(scratch);
     }
     if (SubSystems & ssFCS) {
@@ -904,8 +941,8 @@ void FGOutput::SocketOutput(void)
     socket->Append(Propagate->GetLocation().GetLatitudeDeg());
     socket->Append(Propagate->GetLocation().GetLongitudeDeg());
   }
-  if (SubSystems & ssCoefficients) {
-    scratch = Aerodynamics->GetCoefficientValues(",");
+  if (SubSystems & ssAeroFunctions) {
+    scratch = Aerodynamics->GetAeroFunctionValues(",");
     if (scratch.length() != 0) socket->Append(scratch);
   }
   if (SubSystems & ssFCS) {
@@ -944,11 +981,9 @@ void FGOutput::SocketStatusOutput(const string& out_str)
 
 bool FGOutput::Load(Element* element)
 {
-  string type="", parameter="";
+  string parameter="";
   string name="";
-  string protocol="tcp";
-  int OutRate = 0;
-  string property;
+  double OutRate = 0.0;
   unsigned int port;
   Element *property_element;
 
@@ -967,24 +1002,17 @@ bool FGOutput::Load(Element* element)
   if (!document) return false;
 
   name = FDMExec->GetRootDir() + document->GetAttributeValue("name");
-  type = document->GetAttributeValue("type");
-  SetType(type);
-  if (!document->GetAttributeValue("port").empty() && type == string("SOCKET")) {
-    port = atoi(document->GetAttributeValue("port").c_str());
-    socket = new FGfdmSocket(name, port);
-  } else if (!document->GetAttributeValue("port").empty() && type == string("FLIGHTGEAR")) {
-    port = atoi(document->GetAttributeValue("port").c_str());
-    if (!document->GetAttributeValue("protocol").empty())
-       protocol = document->GetAttributeValue("protocol");
-    if (protocol == "udp")
-       flightGearSocket = new FGfdmSocket(name, port, FGfdmSocket::ptUDP);  // create udp socket
-    else
-       flightGearSocket = new FGfdmSocket(name, port, FGfdmSocket::ptTCP);  // create tcp socket (default)
+  SetType(document->GetAttributeValue("type"));
+  Port = document->GetAttributeValue("port");
+  if (!Port.empty() && (Type == otSocket || Type == otFlightGear)) {
+    port = atoi(Port.c_str());
+    SetProtocol(document->GetAttributeValue("protocol"));
+    socket = new FGfdmSocket(name, port, Protocol);
   } else {
     BaseFilename = Filename = name;
   }
   if (!document->GetAttributeValue("rate").empty()) {
-    OutRate = (int)document->GetAttributeValueAsNumber("rate");
+    OutRate = document->GetAttributeValueAsNumber("rate");
   } else {
     OutRate = 1;
   }
@@ -1008,7 +1036,7 @@ bool FGOutput::Load(Element* element)
   if (document->FindElementValue("position") == string("ON"))
     SubSystems += ssPropagate;
   if (document->FindElementValue("coefficients") == string("ON"))
-    SubSystems += ssCoefficients;
+    SubSystems += ssAeroFunctions;
   if (document->FindElementValue("ground_reactions") == string("ON"))
     SubSystems += ssGroundReactions;
   if (document->FindElementValue("fcs") == string("ON"))
@@ -1039,7 +1067,7 @@ bool FGOutput::Load(Element* element)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGOutput::SetRate(int rtHz)
+void FGOutput::SetRate(double rtHz)
 {
   rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
   if (rtHz > 0) {
@@ -1109,7 +1137,7 @@ void FGOutput::Debug(int from)
       if (SubSystems & ssMoments)         cout << "    Moments parameters logged" << endl;
       if (SubSystems & ssAtmosphere)      cout << "    Atmosphere parameters logged" << endl;
       if (SubSystems & ssMassProps)       cout << "    Mass parameters logged" << endl;
-      if (SubSystems & ssCoefficients)    cout << "    Coefficient parameters logged" << endl;
+      if (SubSystems & ssAeroFunctions)    cout << "    Coefficient parameters logged" << endl;
       if (SubSystems & ssPropagate)       cout << "    Propagate parameters logged" << endl;
       if (SubSystems & ssGroundReactions) cout << "    Ground parameters logged" << endl;
       if (SubSystems & ssFCS)             cout << "    FCS parameters logged" << endl;