]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/JSBSim.cpp
Initial revision.
[flightgear.git] / src / FDM / JSBSim / JSBSim.cpp
index 499be681732646519a6074bbfa9a4cce612ec18d..8d3db58bcdf61d784ffdb72c3041e5d16882f1a2 100644 (file)
@@ -54,14 +54,12 @@ INCLUDES
 #ifdef FGFS
 #include <simgear/compiler.h>
 #include STL_IOSTREAM
-#  ifdef FG_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
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -128,23 +126,52 @@ int main(int argc, char** argv)
 
   FDMExec = new FGFDMExec();
 
-  if (scripted) {
+  if (scripted) { // form jsbsim <scriptfile>
     result = FDMExec->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);
+  } 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;
+  while (FDMExec->Run()) {
+    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;
+      }
+    }
+  }
 
   delete FDMExec;