]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGOutput.h
Merge branch 'next' of git://gitorious.org/fg/flightgear into next
[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 (jon@jsbsim.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 #include <fstream>
45
46 #include "input_output/FGXMLFileRead.h"
47 #include "input_output/net_fdm.hxx"
48 #include "input_output/FGfdmSocket.h"
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 DEFINITIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 #define ID_OUTPUT "$Id: FGOutput.h,v 1.23 2011/05/20 03:18:36 jberndt Exp $"
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 FORWARD DECLARATIONS
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 namespace JSBSim {
61
62 class FGfdmSocket;
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 CLASS DOCUMENTATION
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68 /** Handles simulation output.
69     OUTPUT section definition
70
71     The following specifies the way that JSBSim writes out data.
72 <pre>
73     NAME is the filename you want the output to go to
74
75     TYPE can be:
76       CSV         Comma separated data. If a filename is supplied then the
77                   data goes to that file. If "COUT" or "cout" is specified, the
78                   data goes to stdout. If the filename is a null filename the
79                   data goes to stdout, as well.
80       SOCKET      Will eventually send data to a socket output, where NAME
81                   would then be the IP address of the machine the data should
82                   be sent to. DON'T USE THIS YET!
83       FLIGHTGEAR  A socket is created for sending binary data packets to
84                   an external instance of FlightGear for visuals.  Parameters
85                   defining the socket are given on the \<output> line.
86       TABULAR     Columnar data.
87       TERMINAL    Output to terminal. NOT IMPLEMENTED YET!
88       NONE        Specifies to do nothing. This setting makes it easy to turn on and
89                   off the data output without having to mess with anything else.
90
91       Examples:
92 </pre>
93 @code
94         <output name="localhost" type="FLIGHTGEAR" port="5500" protocol="tcp" rate="10"/>
95 @endcode
96 @code
97         <output name="B737_datalog.csv" type="CSV" rate="20">
98            <property> velocities/vc-kts </property>
99            <velocities> ON </velocities>
100         </output>
101 @endcode
102 <br>
103 <pre>
104     The arguments that can be supplied, currently, are:
105
106     RATE_IN_HZ  An integer rate in times-per-second that the data is output. This
107                 value may not be *exactly* what you want, due to the dependence
108                 on dt, the cycle rate for the FDM.
109
110     The following parameters tell which subsystems of data to output:
111
112     simulation       ON|OFF
113     atmosphere       ON|OFF
114     massprops        ON|OFF
115     aerosurfaces     ON|OFF
116     rates            ON|OFF
117     velocities       ON|OFF
118     forces           ON|OFF
119     moments          ON|OFF
120     position         ON|OFF
121     coefficients     ON|OFF
122     ground_reactions ON|OFF
123     fcs              ON|OFF
124     propulsion       ON|OFF
125 </pre>
126     NOTE that Time is always output with the data.
127     @version $Id: FGOutput.h,v 1.23 2011/05/20 03:18:36 jberndt Exp $
128  */
129
130 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 CLASS DECLARATION
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
133
134 class FGOutput : public FGModel, public FGXMLFileRead
135 {
136 public:
137   FGOutput(FGFDMExec*);
138   ~FGOutput();
139
140   bool InitModel(void);
141   /** Runs the Output model; called by the Executive
142       Can pass in a value indicating if the executive is directing the simulation to Hold.
143       @param Holding if true, the executive has been directed to hold the sim from 
144                      advancing time. Some models may ignore this flag, such as the Input
145                      model, which may need to be active to listen on a socket for the
146                      "Resume" command to be given.
147       @return false if no error */
148   bool Run(bool Holding);
149
150   void Print(void);
151   void DelimitedOutput(const std::string&);
152   void SocketOutput(void);
153   void FlightGearSocketOutput(void);
154   void SocketStatusOutput(const std::string&);
155   void SocketDataFill(FGNetFDM* net);
156
157   void SetType(const std::string& type);
158   void SetProtocol(const std::string& protocol);
159   void SetPort(const std::string& port);
160   void SetStartNewFile(bool tt) {StartNewFile = tt;}
161   void SetSubsystems(int tt) {SubSystems = tt;}
162   void SetOutputFileName(const std::string& fname) {Filename = fname;}
163   void SetDirectivesFile(const std::string& fname) {DirectivesFile = fname;}
164   void SetRate(double rt);
165   void Enable(void) { enabled = true; }
166   void Disable(void) { enabled = false; }
167   bool Toggle(void) {enabled = !enabled; return enabled;}
168
169   bool Load(Element* el);
170   string GetOutputFileName(void) const {return Filename;}
171
172   /// Subsystem types for specifying which will be output in the FDM data logging
173   enum  eSubSystems {
174     /** Subsystem: Simulation (= 1)          */ ssSimulation      = 1,
175     /** Subsystem: Aerosurfaces (= 2)        */ ssAerosurfaces    = 2,
176     /** Subsystem: Body rates (= 4)          */ ssRates           = 4,
177     /** Subsystem: Velocities (= 8)          */ ssVelocities      = 8,
178     /** Subsystem: Forces (= 16)             */ ssForces          = 16,
179     /** Subsystem: Moments (= 32)            */ ssMoments         = 32,
180     /** Subsystem: Atmosphere (= 64)         */ ssAtmosphere      = 64,
181     /** Subsystem: Mass Properties (= 128)   */ ssMassProps       = 128,
182     /** Subsystem: Coefficients (= 256)      */ ssAeroFunctions    = 256,
183     /** Subsystem: Propagate (= 512)         */ ssPropagate       = 512,
184     /** Subsystem: Ground Reactions (= 1024) */ ssGroundReactions = 1024,
185     /** Subsystem: FCS (= 2048)              */ ssFCS             = 2048,
186     /** Subsystem: Propulsion (= 4096)       */ ssPropulsion      = 4096
187   } subsystems;
188
189   FGNetFDM fgSockBuf;
190
191 private:
192   enum {otNone, otCSV, otTab, otSocket, otTerminal, otFlightGear, otUnknown} Type;
193   FGfdmSocket::ProtocolType Protocol;
194   bool sFirstPass, dFirstPass, enabled;
195   int SubSystems;
196   int runID_postfix;
197   bool StartNewFile;
198   std::string output_file_name, delimeter, BaseFilename, Filename, DirectivesFile;
199   std::string Port;
200   std::ofstream datafile;
201   FGfdmSocket* socket;
202   std::vector <FGPropertyManager*> OutputProperties;
203
204   void Debug(int from);
205 };
206 }
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 #endif
209