| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGInput.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 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 | 19/01/15 PCH Split the code in several classes (see input_output dir) |
| 30 | |
| 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 32 | SENTRY |
| 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 34 | |
| 35 | #ifndef FGINPUT_H |
| 36 | #define FGINPUT_H |
| 37 | |
| 38 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 39 | INCLUDES |
| 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 41 | |
| 42 | #include "FGModel.h" |
| 43 | #include "input_output/FGInputType.h" |
| 44 | |
| 45 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 46 | FORWARD DECLARATIONS |
| 47 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 48 | |
| 49 | namespace JSBSim { |
| 50 | |
| 51 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 52 | CLASS DOCUMENTATION |
| 53 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 54 | |
| 55 | /** Handles simulation input. |
| 56 | INPUT section definition |
| 57 | |
| 58 | The following specifies the way that JSBSim writes out data. |
| 59 | <pre> |
| 60 | NAME is the filename you want the input to come from |
| 61 | |
| 62 | TYPE can be: |
| 63 | SOCKET Will eventually send data to a socket input, where NAME |
| 64 | would then be the IP address of the machine the data should |
| 65 | be sent to. DON'T USE THIS YET! |
| 66 | NONE Specifies to do nothing. This setting makes it easy to turn on and |
| 67 | off the data input without having to mess with anything else. |
| 68 | |
| 69 | Examples: |
| 70 | </pre> |
| 71 | @code |
| 72 | <input type="SOCKET" port="4321"/> |
| 73 | @endcode |
| 74 | <br> |
| 75 | |
| 76 | The class FGInput is the manager of the inputs requested by the user. It |
| 77 | manages a list of instances derived from the abstract class FGInputType. |
| 78 | */ |
| 79 | |
| 80 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 81 | CLASS DECLARATION |
| 82 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 83 | |
| 84 | class FGInput : public FGModel |
| 85 | { |
| 86 | public: |
| 87 | FGInput(FGFDMExec*); |
| 88 | ~FGInput() override; |
| 89 | |
| 90 | /** Load the input directives and adds a new input instance to the Input |
| 91 | Manager list. |
| 92 | @param el XMLElement that is pointing to the input directives |
| 93 | @result true if the execution succeeded. */ |
| 94 | bool Load(Element* el) override; |
| 95 | |
| 96 | /** Initializes the instance. This method is called by FGFDMExec::RunIC(). |
| 97 | This is were the initialization of all classes derived from FGInputType |
| 98 | takes place. It is important that this method is not called prior |
| 99 | to FGFDMExec::RunIC() so that the initialization process can be executed |
| 100 | properly. |
| 101 | @result true if the execution succeeded. */ |
| 102 | bool InitModel(void) override; |
| 103 | |
| 104 | /** Runs the Input model; called by the Executive |
| 105 | Can pass in a value indicating if the executive is directing the simulation to Hold. |
| 106 | @param Holding if true, the executive has been directed to hold the sim from |
| 107 | advancing time. Some models may ignore this flag, such as the Input |
| 108 | model, which may need to be active to listen on a socket for the |
| 109 | "Resume" command to be given. |
| 110 | @return false if no error */ |
| 111 | bool Run(bool Holding) override; |
| 112 | |
| 113 | /** Adds a new input instance to the Input Manager. The definition of the |
| 114 | new input instance is read from a file. |
| 115 | @param fname the name of the file from which the ouput directives should |
| 116 | be read. |
| 117 | @return true if the execution succeeded. */ |
| 118 | bool SetDirectivesFile(const SGPath& fname); |
| 119 | |
| 120 | /// Enables the input generation for all input instances. |
| 121 | void Enable(void) { enabled = true; } |
| 122 | /// Disables the input generation for all input instances. |
| 123 | void Disable(void) { enabled = false; } |
| 124 | /** Toggles the input generation of each input instance. |
| 125 | @param idx ID of the input instance which input generation will be |
| 126 | toggled. |
| 127 | @result false if the instance does not exist otherwise returns the status |
| 128 | of the input generation (i.e. true if the input has been |
| 129 | enabled, false if the input has been disabled) */ |
| 130 | bool Toggle(int idx); |
| 131 | |
| 132 | /** Overwrites the name identifier under which the input will be logged. |
| 133 | This method is taken into account if it is called between Load() and |
| 134 | FGFDMExec::RunIC() otherwise it is ignored until the next call to |
| 135 | SetStartNewInput(). |
| 136 | @param idx ID of the instance which name identifier will be changed |
| 137 | @param name new name |
| 138 | @result false if the instance does not exists. */ |
| 139 | bool SetInputName(unsigned int idx, const std::string& name); |
| 140 | /** Get the name identifier to which the input will be directed. |
| 141 | @param idx ID of the input instance from which the name identifier must |
| 142 | be obtained |
| 143 | @result the name identifier.*/ |
| 144 | std::string GetInputName(unsigned int idx) const; |
| 145 | |
| 146 | private: |
| 147 | std::vector<FGInputType*> InputTypes; |
| 148 | bool enabled; |
| 149 | |
| 150 | void Debug(int from) override; |
| 151 | }; |
| 152 | } |
| 153 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 154 | #endif |