]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.cpp
Sync with latest JSBSim.
[flightgear.git] / src / FDM / JSBSim / JSBSim.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
2 \r
3  Module:       JSBSim.cpp\r
4  Author:       Jon S. Berndt\r
5  Date started: 08/17/99\r
6  Purpose:      Standalone version of JSBSim.\r
7  Called by:    The USER.\r
8 \r
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------\r
10 \r
11  This program is free software; you can redistribute it and/or modify it under\r
12  the terms of the GNU General Public License as published by the Free Software\r
13  Foundation; either version 2 of the License, or (at your option) any later\r
14  version.\r
15 \r
16  This program is distributed in the hope that it will be useful, but WITHOUT\r
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
18  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
19  details.\r
20 \r
21  You should have received a copy of the GNU General Public License along with\r
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple\r
23  Place - Suite 330, Boston, MA  02111-1307, USA.\r
24 \r
25  Further information about the GNU General Public License can also be found on\r
26  the world wide web at http://www.gnu.org.\r
27 \r
28 FUNCTIONAL DESCRIPTION\r
29 --------------------------------------------------------------------------------\r
30 \r
31 This class Handles calling JSBSim standalone. It is set up for compilation under\r
32 Borland C+Builder or other compiler.\r
33 \r
34 HISTORY\r
35 --------------------------------------------------------------------------------\r
36 08/17/99   JSB   Created\r
37 \r
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
39 INCLUDES\r
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
41 \r
42 #include "FGFDMExec.h"\r
43 #include "FGRotation.h"\r
44 #include "FGAtmosphere.h"\r
45 #include "FGState.h"\r
46 #include "FGFCS.h"\r
47 #include "FGAircraft.h"\r
48 #include "FGTranslation.h"\r
49 #include "FGPosition.h"\r
50 #include "FGAuxiliary.h"\r
51 #include "FGOutput.h"\r
52 #include "FGConfigFile.h"\r
53 \r
54 #ifdef FGFS\r
55 #include <simgear/compiler.h>\r
56 #include STL_IOSTREAM\r
57 #  ifdef SG_HAVE_STD_INCLUDES\r
58 #    include <ctime>\r
59 #  else\r
60 #    include <time.h>\r
61 #  endif\r
62 #else\r
63 #  if defined(sgi) && !defined(__GNUC__)\r
64 #    include <iostream.h>\r
65 #    include <time.h>\r
66 #  else\r
67 #    include <iostream>\r
68 #    include <ctime>\r
69 #  endif\r
70 #endif\r
71 \r
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
73 DEFINITIONS\r
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
75 \r
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
77 GLOBAL DATA\r
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
79 \r
80 static const char *IdSrc = "$Id$";\r
81 \r
82 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
83 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]\r
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
85 \r
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
87 DOCUMENTATION\r
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
89 \r
90 /** Standalone JSBSim main program\r
91     This is the wrapper program used to instantiate the JSBSim system and control\r
92     it. Use this program to build a version of JSBSim that can be run from the\r
93     command line. To get any use out of this, you will have to create a script\r
94     to run a test case and specify what kind of output you would like.\r
95     @author Jon S. Berndt\r
96     @version $Id$\r
97     @see -\r
98 */\r
99 \r
100 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
101 IMPLEMENTATION\r
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
103 \r
104 int main(int argc, char** argv)\r
105 {\r
106   FGFDMExec* FDMExec;\r
107   float cmd = 0.0;\r
108   bool result = false;\r
109   bool scripted = false;\r
110 \r
111   if (argc == 2) {\r
112     FGConfigFile testFile(argv[1]);\r
113 \r
114     if (!testFile.IsOpen()) {\r
115       cout << "Script file not opened" << endl;\r
116       exit(-1); \r
117     }\r
118 \r
119     testFile.GetNextConfigLine();\r
120     if (testFile.GetValue("runscript").length() <= 0) {\r
121       cout << "File: " << argv[1] << " is not a script file" << endl;\r
122       exit(-1); \r
123     }\r
124     scripted = true;\r
125   } else if (argc != 3) {\r
126     cout << endl\r
127          << "  You must enter the name of a registered aircraft and reset point:"\r
128          << endl << endl << "  FDM <aircraft name> <reset file>" << endl;\r
129     cout << endl << "  Alternatively, you may specify only the name of a script file:"\r
130          << endl << endl << "  FDM <script file>" << endl << endl;\r
131     exit(0);\r
132   }\r
133 \r
134   FDMExec = new FGFDMExec();\r
135 \r
136   if (scripted) { // form jsbsim <scriptfile>\r
137     result = FDMExec->LoadScript(argv[1]);\r
138     if (!result) {\r
139       cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;\r
140       exit(-1);\r
141     }\r
142   } else {        // form jsbsim <acname> <resetfile>\r
143     if ( ! FDMExec->LoadModel("aircraft", "engine", string(argv[1]))) {\r
144         cerr << "  JSBSim could not be started" << endl << endl;\r
145       exit(-1);\r
146     }                   \r
147 \r
148     FGInitialCondition IC(FDMExec);\r
149     if ( ! IC.Load("aircraft",string(argv[1]),string(argv[2]))) {\r
150         cerr << "Initialization unsuccessful" << endl;\r
151       exit(-1);\r
152     }\r
153   }\r
154 \r
155   FGJSBBase::Message* msg;\r
156   while (FDMExec->Run()) {\r
157     while (FDMExec->ReadMessage()) {\r
158       msg = FDMExec->ProcessMessage();\r
159       switch (msg->type) {\r
160       case FGJSBBase::Message::eText:\r
161         cout << msg->messageId << ": " << msg->text << endl;\r
162         break;\r
163       case FGJSBBase::Message::eBool:\r
164         cout << msg->messageId << ": " << msg->text << " " << msg->bVal << endl;\r
165         break;\r
166       case FGJSBBase::Message::eInteger:\r
167         cout << msg->messageId << ": " << msg->text << " " << msg->iVal << endl;\r
168         break;\r
169       case FGJSBBase::Message::eDouble:\r
170         cout << msg->messageId << ": " << msg->text << " " << msg->dVal << endl;\r
171         break;\r
172       default:\r
173         cerr << "Unrecognized message type." << endl;\r
174               break;\r
175       }\r
176     }\r
177   }\r
178 \r
179   delete FDMExec;\r
180 \r
181   return 0;\r
182 }\r