]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/JSBSim.cpp
Updated to latest JSBSim, including preliminary support for
[flightgear.git] / src / FDM / JSBSim / JSBSim.cpp
index 400b6088b63ea20f2e47e9170d9874eb303e2735..e79d96fc78c212208482d3a64cc857af6f641831 100644 (file)
@@ -50,69 +50,17 @@ INCLUDES
 #include "FGAuxiliary.h"
 #include "FGOutput.h"
 #include "FGConfigFile.h"
+#include "FGScript.h"
 
 #ifdef FGFS
 #include <simgear/compiler.h>
 #include STL_IOSTREAM
-#  ifdef SG_HAVE_STD_INCLUDES
-#    include <ctime>
+#else
+#  if defined(sgi) && !defined(__GNUC__)
+#    include <iostream.h>
 #  else
-#    include <time.h>
+#    include <iostream>
 #  endif
-#else
-#include <iostream>
-#include <ctime>
-#endif
-
-#if __BORLANDC__ > 0x540
-#include <condefs.h>
-USEUNIT("FGUtility.cpp");
-USEUNIT("FGAircraft.cpp");
-USEUNIT("FGAtmosphere.cpp");
-USEUNIT("FGAuxiliary.cpp");
-USEUNIT("FGCoefficient.cpp");
-USEUNIT("FGConfigFile.cpp");
-USEUNIT("FGEngine.cpp");
-USEUNIT("FGFCS.cpp");
-USEUNIT("FGFDMExec.cpp");
-USEUNIT("FGfdmSocket.cpp");
-USEUNIT("FGForce.cpp");
-USEUNIT("FGGroundReactions.cpp");
-USEUNIT("FGInertial.cpp");
-USEUNIT("FGInitialCondition.cpp");
-USEUNIT("FGLGear.cpp");
-USEUNIT("FGMassBalance.cpp");
-USEUNIT("FGMatrix.cpp");
-USEUNIT("FGModel.cpp");
-USEUNIT("FGNozzle.cpp");
-USEUNIT("FGOutput.cpp");
-USEUNIT("FGPiston.cpp");
-USEUNIT("FGPosition.cpp");
-USEUNIT("FGPropeller.cpp");
-USEUNIT("FGPropulsion.cpp");
-USEUNIT("FGRocket.cpp");
-USEUNIT("FGRotation.cpp");
-USEUNIT("FGRotor.cpp");
-USEUNIT("FGState.cpp");
-USEUNIT("FGTable.cpp");
-USEUNIT("FGTank.cpp");
-USEUNIT("FGThruster.cpp");
-USEUNIT("FGTranslation.cpp");
-USEUNIT("FGTrim.cpp");
-USEUNIT("FGTrimAxis.cpp");
-USEUNIT("FGTurboJet.cpp");
-USEUNIT("FGTurboProp.cpp");
-USEUNIT("FGTurboShaft.cpp");
-USEUNIT("FGAerodynamics.cpp");
-USEUNIT("filtersjb\FGSwitch.cpp");
-USEUNIT("filtersjb\FGFCSComponent.cpp");
-USEUNIT("filtersjb\FGFilter.cpp");
-USEUNIT("filtersjb\FGFlaps.cpp");
-USEUNIT("filtersjb\FGGain.cpp");
-USEUNIT("filtersjb\FGGradient.cpp");
-USEUNIT("filtersjb\FGSummer.cpp");
-USEUNIT("filtersjb\FGDeadBand.cpp");
-//---------------------------------------------------------------------------
 #endif
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -150,52 +98,81 @@ IMPLEMENTATION
 int main(int argc, char** argv)
 {
   FGFDMExec* FDMExec;
-  float cmd = 0.0;
   bool result = false;
-  bool scripted = false;
-
-  if (argc == 2) {
-    FGConfigFile testFile(argv[1]);
+  bool Scripted = false;
+  FGScript* Script;
 
-    if (!testFile.IsOpen()) {
-      cout << "Script file not opened" << endl;
-      exit(-1); 
-    }
-
-    testFile.GetNextConfigLine();
-    if (testFile.GetValue("runscript").length() <= 0) {
-      cout << "File: " << argv[1] << " is not a script file" << endl;
-      exit(-1); 
-    }
-    scripted = true;
-  } else if (argc != 3) {
-    cout << endl
+  if (argc != 3 && argc != 2) {
+    cerr << endl
          << "  You must enter the name of a registered aircraft and reset point:"
          << endl << endl << "  FDM <aircraft name> <reset file>" << endl;
-    cout << endl << "  Alternatively, you may specify only the name of a script file:"
+    cerr << endl << "  Alternatively, you may specify only the name of a script file:"
          << endl << endl << "  FDM <script file>" << endl << endl;
     exit(0);
   }
 
   FDMExec = new FGFDMExec();
 
-  if (scripted) {
-    result = FDMExec->LoadScript(argv[1]);
+  if (argc == 2) { // SCRIPTED CASE
+
+    Script = new FGScript(FDMExec);
+    result = Script->LoadScript(argv[1]);
+
     if (!result) {
       cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
       exit(-1);
     }
-  } else {
-    result = FDMExec->LoadModel("aircraft", "engine", string(argv[1]));
-    if (!result) {
-       cerr << "Aircraft file " << argv[1] << " was not found" << endl;
-           exit(-1);
+
+    Scripted = true;
+
+  } else {        // form jsbsim <acname> <resetfile>
+
+    if ( ! FDMExec->LoadModel("aircraft", "engine", string(argv[1]))) {
+       cerr << "  JSBSim could not be started" << endl << endl;
+      exit(-1);
+    }                   
+
+    FGInitialCondition IC(FDMExec);
+    if ( ! IC.Load("aircraft",string(argv[1]),string(argv[2]))) {
+       cerr << "Initialization unsuccessful" << endl;
+      exit(-1);
     }
-    if ( ! FDMExec->GetState()->Reset("aircraft", string(argv[1]), string(argv[2])))
-                   FDMExec->GetState()->Initialize(2000,0,0,0,0,0,0.5,0.5,40000);
   }
 
-  while (FDMExec->Run()) {}
+//
+// RUN loop. MESSAGES are read inside the Run() loop and output as necessary.
+//
+
+  FGJSBBase::Message* msg;
+  result = FDMExec->Run();
+  while (result) {
+    while (FDMExec->ReadMessage()) {
+      msg = FDMExec->ProcessMessage();
+      switch (msg->type) {
+      case FGJSBBase::Message::eText:
+        cout << msg->messageId << ": " << msg->text << endl;
+        break;
+      case FGJSBBase::Message::eBool:
+        cout << msg->messageId << ": " << msg->text << " " << msg->bVal << endl;
+        break;
+      case FGJSBBase::Message::eInteger:
+        cout << msg->messageId << ": " << msg->text << " " << msg->iVal << endl;
+        break;
+      case FGJSBBase::Message::eDouble:
+        cout << msg->messageId << ": " << msg->text << " " << msg->dVal << endl;
+        break;
+      default:
+        cerr << "Unrecognized message type." << endl;
+             break;
+      }
+    }
+
+    if (Scripted) {
+      if (!Script->RunScript()) break;
+    }
+
+    result = FDMExec->Run();
+  }
 
   delete FDMExec;