]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGOutput.h
Update to the latest version of JSBSim which supports Lighter Than Air craft
[flightgear.git] / src / FDM / JSBSim / models / FGOutput.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGOutput.h
4  Author:       Jon Berndt
5  Date started: 12/2/98
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 12/02/98   JSB   Created
29 11/09/07   HDW   Added FlightGear Socket Interface
30
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 SENTRY
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34
35 #ifndef FGOUTPUT_H
36 #define FGOUTPUT_H
37
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42 #include "FGModel.h"
43
44 #ifdef FGFS
45 #  include <simgear/compiler.h>
46 #  include STL_IOSTREAM
47 #  include STL_FSTREAM
48 #else
49 #  if defined(sgi) && !defined(__GNUC__) && (_COMPILER_VERSION < 740)
50 #    include <iostream.h>
51 #    include <fstream.h>
52 #  else
53 #    include <iostream>
54 #    include <fstream>
55 #  endif
56 #endif
57
58 #include "input_output/FGfdmSocket.h"
59 #include "input_output/FGXMLFileRead.h"
60 #include "input_output/net_fdm.hxx"
61
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 DEFINITIONS
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 #define ID_OUTPUT "$Id$"
68
69 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 FORWARD DECLARATIONS
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72
73 namespace JSBSim {
74
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 CLASS DOCUMENTATION
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78
79 /** Handles simulation output.
80     OUTPUT section definition
81
82     The following specifies the way that JSBSim writes out data.
83 <pre>
84     NAME is the filename you want the output to go to
85
86     TYPE can be:
87       CSV         Comma separated data. If a filename is supplied then the
88                   data goes to that file. If "COUT" or "cout" is specified, the
89                   data goes to stdout. If the filename is a null filename the
90                   data goes to stdout, as well.
91       SOCKET      Will eventually send data to a socket output, where NAME
92                   would then be the IP address of the machine the data should
93                   be sent to. DON'T USE THIS YET!
94       FLIGHTGEAR  A socket is created for sending binary data packets to
95                   an external instance of FlightGear for visuals.  Parameters
96                   defining the socket are given on the \<output> line.
97       TABULAR     Columnar data. NOT IMPLEMENTED YET!
98       TERMINAL    Output to terminal. NOT IMPLEMENTED YET!
99       NONE        Specifies to do nothing. This setting makes it easy to turn on and
100                   off the data output without having to mess with anything else.
101
102       Examples:
103 </pre>
104 @code
105         <output name="localhost" type="FLIGHTGEAR" port="5500" protocol="tcp" rate="10"></output>
106 @endcode
107 @code
108         <output name="B737_datalog.csv" type="CSV" rate="20">
109            <property> velocities/vc-kts </property>
110            <velocities> ON </velocities>
111         </output>
112 @endcode
113 <br>
114 <pre>
115     The arguments that can be supplied, currently, are:
116
117     RATE_IN_HZ  An integer rate in times-per-second that the data is output. This
118                 value may not be *exactly* what you want, due to the dependence
119                 on dt, the cycle rate for the FDM.
120
121     The following parameters tell which subsystems of data to output:
122
123     simulation       ON|OFF
124     atmosphere       ON|OFF
125     massprops        ON|OFF
126     aerosurfaces     ON|OFF
127     rates            ON|OFF
128     velocities       ON|OFF
129     forces           ON|OFF
130     moments          ON|OFF
131     position         ON|OFF
132     coefficients     ON|OFF
133     ground_reactions ON|OFF
134     fcs              ON|OFF
135     propulsion       ON|OFF
136 </pre>
137     NOTE that Time is always output with the data.
138     @version $Id$
139  */
140
141 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 CLASS DECLARATION
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
144
145 class FGOutput : public FGModel, public FGXMLFileRead
146 {
147 public:
148   FGOutput(FGFDMExec*);
149   ~FGOutput();
150
151   bool InitModel(void);
152   bool Run(void);
153
154   void DelimitedOutput(string);
155   void SocketOutput(void);
156   void FlightGearSocketOutput(void);
157   void SocketStatusOutput(string);
158   void SocketDataFill(FGNetFDM* net);
159
160
161   void SetType(string);
162   void SetSubsystems(int tt) {SubSystems = tt;}
163   inline void Enable(void) { enabled = true; }
164   inline void Disable(void) { enabled = false; }
165   inline bool Toggle(void) {enabled = !enabled; return enabled;}
166   bool Load(Element* el);
167   void SetOutputFileName(string fname) {Filename = fname;}
168   void SetDirectivesFile(string fname) {DirectivesFile = fname;}
169   string GetOutputFileName(void) const {return Filename;}
170
171   /// Subsystem types for specifying which will be output in the FDM data logging
172   enum  eSubSystems {
173     /** Subsystem: Simulation (= 1)          */ ssSimulation      = 1,
174     /** Subsystem: Aerosurfaces (= 2)        */ ssAerosurfaces    = 2,
175     /** Subsystem: Body rates (= 4)          */ ssRates           = 4,
176     /** Subsystem: Velocities (= 8)          */ ssVelocities      = 8,
177     /** Subsystem: Forces (= 16)             */ ssForces          = 16,
178     /** Subsystem: Moments (= 32)            */ ssMoments         = 32,
179     /** Subsystem: Atmosphere (= 64)         */ ssAtmosphere      = 64,
180     /** Subsystem: Mass Properties (= 128)   */ ssMassProps       = 128,
181     /** Subsystem: Coefficients (= 256)      */ ssCoefficients    = 256,
182     /** Subsystem: Propagate (= 512)         */ ssPropagate       = 512,
183     /** Subsystem: Ground Reactions (= 1024) */ ssGroundReactions = 1024,
184     /** Subsystem: FCS (= 2048)              */ ssFCS             = 2048,
185     /** Subsystem: Propulsion (= 4096)       */ ssPropulsion      = 4096
186   } subsystems;
187
188
189   FGNetFDM fgSockBuf;
190
191 private:
192   enum {otNone, otCSV, otTab, otSocket, otTerminal, otFlightGear, otUnknown} Type;
193   bool sFirstPass, dFirstPass, enabled;
194   int SubSystems;
195   string output_file_name, delimeter, Filename, DirectivesFile;
196   ofstream datafile;
197   FGfdmSocket* socket;
198   FGfdmSocket* flightGearSocket;
199   vector <FGPropertyManager*> OutputProperties;
200
201   void Debug(int from);
202 };
203 }
204 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 #endif
206