| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGOutput.h |
| 4 | Author: Jon Berndt |
| 5 | Date started: 12/2/98 |
| 6 | |
| 7 | ------------- Copyright (C) 1999 Jon S. Berndt ([email protected]) ------------- |
| 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 |
| 11 | Software Foundation; either version 2 of the License, or (at your option) any |
| 12 | later 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 |
| 20 | with this program; if not, write to the Free Software Foundation, Inc., 59 |
| 21 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | |
| 23 | Further information about the GNU Lesser General Public License can also be |
| 24 | found on 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 | 09/10/11 BC Broke Down the Code in Several Classes |
| 31 | |
| 32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 33 | SENTRY |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 35 | |
| 36 | #ifndef FGOUTPUT_H |
| 37 | #define FGOUTPUT_H |
| 38 | |
| 39 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 40 | INCLUDES |
| 41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 42 | |
| 43 | #include "FGModel.h" |
| 44 | #include "input_output/FGOutputType.h" |
| 45 | |
| 46 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 47 | FORWARD DECLARATIONS |
| 48 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 49 | |
| 50 | namespace JSBSim { |
| 51 | |
| 52 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 53 | CLASS DOCUMENTATION |
| 54 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 55 | |
| 56 | /** Handles simulation output. |
| 57 | OUTPUT section definition |
| 58 | |
| 59 | The following specifies the way that JSBSim writes out data. |
| 60 | <pre> |
| 61 | NAME is the filename you want the output to go to |
| 62 | |
| 63 | TYPE can be: |
| 64 | CSV Comma separated data. If a filename is supplied then the |
| 65 | data goes to that file. If "COUT" or "cout" is specified, the |
| 66 | data goes to stdout. If the filename is a null filename the |
| 67 | data goes to stdout, as well. |
| 68 | SOCKET Will eventually send data to a socket output, where NAME |
| 69 | would then be the IP address of the machine the data should |
| 70 | be sent to. DON'T USE THIS YET! |
| 71 | FLIGHTGEAR A socket is created for sending binary data packets to |
| 72 | an external instance of FlightGear for visuals. Parameters |
| 73 | defining the socket are given on the \<output> line. |
| 74 | TABULAR Columnar data. |
| 75 | TERMINAL Output to terminal. NOT IMPLEMENTED YET! |
| 76 | NONE Specifies to do nothing. This setting makes it easy to turn on |
| 77 | and off the data output without having to mess with anything |
| 78 | else. |
| 79 | |
| 80 | Examples: |
| 81 | </pre> |
| 82 | @code |
| 83 | <output name="localhost" type="FLIGHTGEAR" port="5500" protocol="tcp" rate="10"/> |
| 84 | @endcode |
| 85 | @code |
| 86 | <output name="B737_datalog.csv" type="CSV" rate="20"> |
| 87 | <property> velocities/vc-kts </property> |
| 88 | <velocities> ON </velocities> |
| 89 | </output> |
| 90 | @endcode |
| 91 | <br> |
| 92 | <pre> |
| 93 | The arguments that can be supplied, currently, are: |
| 94 | |
| 95 | RATE_IN_HZ An integer rate in times-per-second that the data is output. |
| 96 | This value may not be *exactly* what you want, due to the |
| 97 | dependence on dt, the cycle rate for the FDM. |
| 98 | |
| 99 | The following parameters tell which subsystems of data to output: |
| 100 | |
| 101 | simulation ON|OFF |
| 102 | atmosphere ON|OFF |
| 103 | massprops ON|OFF |
| 104 | aerosurfaces ON|OFF |
| 105 | rates ON|OFF |
| 106 | velocities ON|OFF |
| 107 | forces ON|OFF |
| 108 | moments ON|OFF |
| 109 | position ON|OFF |
| 110 | coefficients ON|OFF |
| 111 | ground_reactions ON|OFF |
| 112 | fcs ON|OFF |
| 113 | propulsion ON|OFF |
| 114 | </pre> |
| 115 | NOTE that Time is always output with the data. |
| 116 | |
| 117 | The class FGOutput is the manager of the outputs requested by the user. It |
| 118 | manages a list of instances derived from the abstract class FGOutputType. |
| 119 | */ |
| 120 | |
| 121 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 122 | CLASS DECLARATION |
| 123 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 124 | |
| 125 | class JSBSIM_API FGOutput : public FGModel |
| 126 | { |
| 127 | public: |
| 128 | FGOutput(FGFDMExec*); |
| 129 | ~FGOutput() override; |
| 130 | |
| 131 | /** Initializes the instance. This method is called by FGFDMExec::RunIC(). |
| 132 | This is were the initialization of all classes derived from FGOutputType |
| 133 | takes place. It is important that this method is not called prior |
| 134 | to FGFDMExec::RunIC() so that the initialization process can be executed |
| 135 | properly. |
| 136 | @result true if the execution succeeded. */ |
| 137 | bool InitModel(void) override; |
| 138 | /** Runs the Output model; called by the Executive. |
| 139 | Can pass in a value indicating if the executive is directing the |
| 140 | simulation to Hold. |
| 141 | @param Holding if true, the executive has been directed to hold the sim |
| 142 | from advancing time. Some models may ignore this flag, such |
| 143 | as the Input model, which may need to be active to listen |
| 144 | on a socket for the "Resume" command to be given. |
| 145 | @return false if no error */ |
| 146 | bool Run(bool Holding) override; |
| 147 | /** Makes all the output instances to generate their ouput. This method does |
| 148 | not check that the time step at which the output is requested is |
| 149 | consistent with the output rate RATE_IN_HZ. Although Print is not a |
| 150 | relevant name for outputs like SOCKET or FLIGHGEAR, it has been kept for |
| 151 | backward compatibility. */ |
| 152 | void Print(void); |
| 153 | /** Force an output instance to generate its output. The code executed is |
| 154 | basically the same than the code of the method Print() except that the |
| 155 | ouput is limited to the instance identified by the parameter of the |
| 156 | method. |
| 157 | @param idx ID of the instance that will generate its ouput */ |
| 158 | void ForceOutput(int idx); |
| 159 | /** Reset the output prior to a restart of the simulation. This method should |
| 160 | be called when the simulation is restarted with, for example, new initial |
| 161 | conditions. When this method is executed the output instances can take |
| 162 | special actions such as closing the current output file and open a new |
| 163 | one with a different name. */ |
| 164 | void SetStartNewOutput(void); |
| 165 | /** Overwrites the name identifier under which the output will be logged. |
| 166 | This method is taken into account if it is called between Load() and |
| 167 | FGFDMExec::RunIC() otherwise it is ignored until the next call to |
| 168 | SetStartNewOutput(). |
| 169 | @param idx ID of the instance which name identifier will be changed |
| 170 | @param name new name |
| 171 | @result false if the instance does not exists. */ |
| 172 | bool SetOutputName(unsigned int idx, const std::string& name); |
| 173 | /** Adds a new output instance to the Output Manager. The definition of the |
| 174 | new output instance is read from a file. |
| 175 | @param fname the name of the file from which the ouput directives should |
| 176 | be read. |
| 177 | @return true if the execution succeeded. */ |
| 178 | bool SetDirectivesFile(const SGPath& fname); |
| 179 | /// Enables the output generation for all output instances. |
| 180 | void Enable(void) { enabled = true; } |
| 181 | /// Disables the output generation for all output instances. |
| 182 | void Disable(void) { enabled = false; } |
| 183 | /** Toggles the output generation of each ouput instance. |
| 184 | @param idx ID of the output instance which output generation will be |
| 185 | toggled. |
| 186 | @result false if the instance does not exist otherwise returns the status |
| 187 | of the output generation (i.e. true if the output has been |
| 188 | enabled, false if the output has been disabled) */ |
| 189 | bool Toggle(int idx); |
| 190 | /** Modifies the output rate for all output instances. |
| 191 | @param rate new output rate in Hz */ |
| 192 | void SetRateHz(double rate); |
| 193 | /** Load the output directives and adds a new output instance to the Output |
| 194 | Manager list. |
| 195 | @param el XMLElement that is pointing to the output directives |
| 196 | @param dir optional directory path to load included files from |
| 197 | @result true if the execution succeeded. */ |
| 198 | bool Load(Element* el, const SGPath& dir = SGPath()); |
| 199 | /** Load the output directives and adds a new output instance to the Output |
| 200 | Manager list. Unlike the Load() method, the new output instance is not |
| 201 | generated from output directives read in a XML file but from a list of |
| 202 | parameters. |
| 203 | @param subSystems bitfield that describes the activated subsystems |
| 204 | @param protocol network protocol for outputs directed to sockets |
| 205 | @param type type of output |
| 206 | @param port port to which the socket will be directed |
| 207 | @param name file name to which the output will be directed |
| 208 | @param outRate output rate in Hz |
| 209 | @param outputProperties list of properties that should be output |
| 210 | @result true if the execution succeeded. */ |
| 211 | bool Load(int subSystems, std::string protocol, std::string type, |
| 212 | std::string port, std::string name, double outRate, |
| 213 | std::vector<FGPropertyNode_ptr> & outputProperties); |
| 214 | /** Get the name identifier to which the output will be directed. |
| 215 | @param idx ID of the output instance from which the name identifier must |
| 216 | be obtained |
| 217 | @result the name identifier.*/ |
| 218 | std::string GetOutputName(unsigned int idx) const; |
| 219 | |
| 220 | SGPath FindFullPathName(const SGPath& path) const override; |
| 221 | |
| 222 | private: |
| 223 | std::vector<FGOutputType*> OutputTypes; |
| 224 | bool enabled; |
| 225 | SGPath includePath; |
| 226 | |
| 227 | void Debug(int from) override; |
| 228 | }; |
| 229 | } |
| 230 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 231 | #endif |