1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
29 11/09/07 HDW Added FlightGear Socket Interface
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 #include "input_output/FGXMLFileRead.h"
47 #include "input_output/net_fdm.hxx"
48 #include "input_output/FGfdmSocket.h"
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 #define ID_OUTPUT "$Id: FGOutput.h,v 1.19 2010/10/31 04:48:46 jberndt Exp $"
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 /** Handles simulation output.
69 OUTPUT section definition
71 The following specifies the way that JSBSim writes out data.
73 NAME is the filename you want the output to go to
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.
94 <output name="localhost" type="FLIGHTGEAR" port="5500" protocol="tcp" rate="10"/>
97 <output name="B737_datalog.csv" type="CSV" rate="20">
98 <property> velocities/vc-kts </property>
99 <velocities> ON </velocities>
104 The arguments that can be supplied, currently, are:
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.
110 The following parameters tell which subsystems of data to output:
122 ground_reactions ON|OFF
126 NOTE that Time is always output with the data.
127 @version $Id: FGOutput.h,v 1.19 2010/10/31 04:48:46 jberndt Exp $
130 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
134 class FGOutput : public FGModel, public FGXMLFileRead
137 FGOutput(FGFDMExec*);
140 bool InitModel(void);
143 void DelimitedOutput(const std::string&);
144 void SocketOutput(void);
145 void FlightGearSocketOutput(void);
146 void SocketStatusOutput(const std::string&);
147 void SocketDataFill(FGNetFDM* net);
149 void SetType(const std::string& type);
150 void SetProtocol(const std::string& protocol);
151 void SetPort(const std::string& port);
152 void SetStartNewFile(bool tt) {StartNewFile = tt;}
153 void SetSubsystems(int tt) {SubSystems = tt;}
154 void SetOutputFileName(const std::string& fname) {Filename = fname;}
155 void SetDirectivesFile(const std::string& fname) {DirectivesFile = fname;}
156 void SetRate(int rt);
157 void Enable(void) { enabled = true; }
158 void Disable(void) { enabled = false; }
159 bool Toggle(void) {enabled = !enabled; return enabled;}
161 bool Load(Element* el);
162 string GetOutputFileName(void) const {return Filename;}
164 /// Subsystem types for specifying which will be output in the FDM data logging
166 /** Subsystem: Simulation (= 1) */ ssSimulation = 1,
167 /** Subsystem: Aerosurfaces (= 2) */ ssAerosurfaces = 2,
168 /** Subsystem: Body rates (= 4) */ ssRates = 4,
169 /** Subsystem: Velocities (= 8) */ ssVelocities = 8,
170 /** Subsystem: Forces (= 16) */ ssForces = 16,
171 /** Subsystem: Moments (= 32) */ ssMoments = 32,
172 /** Subsystem: Atmosphere (= 64) */ ssAtmosphere = 64,
173 /** Subsystem: Mass Properties (= 128) */ ssMassProps = 128,
174 /** Subsystem: Coefficients (= 256) */ ssCoefficients = 256,
175 /** Subsystem: Propagate (= 512) */ ssPropagate = 512,
176 /** Subsystem: Ground Reactions (= 1024) */ ssGroundReactions = 1024,
177 /** Subsystem: FCS (= 2048) */ ssFCS = 2048,
178 /** Subsystem: Propulsion (= 4096) */ ssPropulsion = 4096
184 enum {otNone, otCSV, otTab, otSocket, otTerminal, otFlightGear, otUnknown} Type;
185 FGfdmSocket::ProtocolType Protocol;
186 bool sFirstPass, dFirstPass, enabled;
190 std::string output_file_name, delimeter, BaseFilename, Filename, DirectivesFile;
192 std::ofstream datafile;
194 std::vector <FGPropertyManager*> OutputProperties;
196 void Debug(int from);
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%