JSBSim Flight Dynamics Model 1.3.1 (17 May 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGInputSocket Class Reference

Detailed Description

Implements the input from a socket.

This class inputs data from a telnet session. This is a leaf class.

Definition at line 62 of file FGInputSocket.h.

#include <FGInputSocket.h>

+ Inheritance diagram for FGInputSocket:
+ Collaboration diagram for FGInputSocket:

Public Member Functions

 FGInputSocket (FGFDMExec *fdmex, bool isEnabled)
 Constructor.
 
void Disable () override
 Disables the input generation.
 
void Enable () override
 Methods to enable, disable and toggle the input.
 
bool InitModel (void) override
 Initializes the instance.
 
bool Load (Element *el) override
 Init the input directives from an XML file.
 
void Read (bool Holding) override
 Generates the input.
 
bool Toggle () override
 Toggles the input generation.
 
- Public Member Functions inherited from FGInputType
 FGInputType (FGFDMExec *fdmex, bool isEnabled=true)
 Constructor (implement the FGModel interface).
 
 ~FGInputType () override
 Destructor.
 
virtual const std::string & GetInputName (void) const
 Get the name identifier to which the input will be directed.
 
bool InitModel (void) override
 Init the input model according to its configitation.
 
bool Load (Element *el) override
 Init the input directives from an XML file (implement the FGModel interface).
 
bool Run (bool Holding) override
 Executes the input directives (implement the FGModel interface).
 
void SetIdx (unsigned int idx)
 Set the idx for this input instance.
 
virtual void SetInputName (const std::string &name)
 Overwrites the name identifier under which the input will be read.
 
- Public Member Functions inherited from FGModel
 FGModel (FGFDMExec *)
 Constructor.
 
 ~FGModel () override
 Destructor.
 
virtual SGPath FindFullPathName (const SGPath &path) const
 
FGFDMExecGetExec (void) const
 
const std::string & GetName (void) const
 
unsigned int GetRate (void) const
 Get the output rate for the model in frames.
 
bool InitModel (void) override
 
void SetPropertyManager (std::shared_ptr< FGPropertyManager > fgpm)
 
void SetRate (unsigned int tt)
 Set the ouput rate for the model in frames.
 
- Public Member Functions inherited from FGModelFunctions
std::string GetFunctionStrings (const std::string &delimeter) const
 Gets the strings for the current set of functions.
 
std::string GetFunctionValues (const std::string &delimeter) const
 Gets the function values.
 
std::shared_ptr< FGFunctionGetPreFunction (const std::string &name)
 Get one of the "pre" function.
 
bool Load (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void PostLoad (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void PreLoad (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void RunPostFunctions (void)
 
void RunPreFunctions (void)
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 

Protected Member Functions

bool CreateSocket ()
 
- Protected Member Functions inherited from FGInputType
void Debug (int from) override
 
- Protected Member Functions inherited from FGModel
bool Upload (Element *el, bool preLoad)
 Uploads this model in memory.
 

Protected Attributes

bool BlockingInput
 
std::string data
 
std::unique_ptr< FGfdmSocketsocket
 
unsigned int SockPort
 
FGfdmSocket::ProtocolType SockProtocol
 
- Protected Attributes inherited from FGInputType
bool enabled
 
unsigned int InputIdx
 
- Protected Attributes inherited from FGModel
unsigned int exe_ctr
 
FGFDMExecFDMExec
 
std::string Name
 
std::shared_ptr< FGPropertyManager > PropertyManager
 
unsigned int rate
 
- Protected Attributes inherited from FGModelFunctions
FGPropertyReader LocalProperties
 
std::vector< std::shared_ptr< FGFunction > > PostFunctions
 
std::vector< std::shared_ptr< FGFunction > > PreFunctions
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1 , eM , eN }
 Moments L, M, N. More...
 
enum  { eP = 1 , eQ , eR }
 Rates P, Q, R. More...
 
enum  { eU = 1 , eV , eW }
 Velocities U, V, W. More...
 
enum  { eX = 1 , eY , eZ }
 Positions X, Y, Z. More...
 
enum  { ePhi = 1 , eTht , ePsi }
 Euler angles Phi, Theta, Psi. More...
 
enum  { eDrag = 1 , eSide , eLift }
 Stability axis forces, Drag, Side force, Lift. More...
 
enum  { eRoll = 1 , ePitch , eYaw }
 Local frame orientation Roll, Pitch, Yaw. More...
 
enum  { eNorth = 1 , eEast , eDown }
 Local frame position North, East, Down. More...
 
enum  { eLat = 1 , eLong , eRad }
 Locations Radius, Latitude, Longitude. More...
 
enum  {
  inNone = 0 , inDegrees , inRadians , inMeters ,
  inFeet
}
 Conversion specifiers. More...
 
- Static Public Member Functions inherited from FGJSBBase
static const std::string & GetVersion (void)
 Returns the version number of JSBSim.
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit.
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine.
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius.
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine.
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin.
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius.
 
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit.
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin.
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius.
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison.
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static constexpr double sign (double num)
 
- Static Public Attributes inherited from FGJSBBase
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
static short debug_lvl = 1
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double degtorad = M_PI / 180.
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double fttom = 0.3048
 
static constexpr double ktstofps = 1852./(3600*fttom)
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inhgtopa = 3386.38
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff.
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static const std::string needed_cfg_version = "2.0"
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 

Constructor & Destructor Documentation

◆ FGInputSocket()

FGInputSocket ( FGFDMExec fdmex,
bool  isEnabled 
)

Constructor.

Definition at line 56 of file FGInputSocket.cpp.

56 :
57 FGInputType(fdmex, isEnabled), SockProtocol(FGfdmSocket::ptTCP),
58 BlockingInput(false)
59{
60}
FGInputType(FGFDMExec *fdmex, bool isEnabled=true)
Constructor (implement the FGModel interface).

Member Function Documentation

◆ CreateSocket()

bool CreateSocket ( )
protected

Definition at line 99 of file FGInputSocket.cpp.

100{
101 socket = std::make_unique<FGfdmSocket>(SockPort, SockProtocol);
102
103 if (!socket) return false;
104 if (!socket->GetConnectStatus()) return false;
105
106 return true;
107}

◆ Disable()

void Disable ( void  )
overridevirtual

Disables the input generation.

Reimplemented from FGInputType.

Definition at line 120 of file FGInputSocket.cpp.

121{
123 socket.reset();
124}
virtual void Disable(void)
Disables the input generation.
+ Here is the call graph for this function:

◆ Enable()

void Enable ( void  )
overridevirtual

Methods to enable, disable and toggle the input.

Reimplemented from FGInputType.

Definition at line 111 of file FGInputSocket.cpp.

112{
113 if (enabled) return; // already enabled
115 CreateSocket();
116}
virtual void Enable(void)
Enables the input generation.
+ Here is the call graph for this function:

◆ InitModel()

bool InitModel ( void  )
overridevirtual

Initializes the instance.

This method basically opens the socket to which inputs will be directed.

Returns
true if the execution succeeded.

Reimplemented from FGModelFunctions.

Definition at line 86 of file FGInputSocket.cpp.

87{
89 return false;
90
91 if (enabled)
92 return CreateSocket();
93
94 return true;
95}
bool InitModel(void) override
Init the input model according to its configitation.
+ Here is the call graph for this function:

◆ Load()

bool Load ( Element el)
overridevirtual

Init the input directives from an XML file.

Parameters
elementXML Element that is pointing to the input directives

Reimplemented from FGModel.

Reimplemented in FGUDPInputSocket.

Definition at line 64 of file FGInputSocket.cpp.

65{
66 if (!FGInputType::Load(el))
67 return false;
68
69 SockPort = atoi(el->GetAttributeValue("port").c_str());
70
71 if (SockPort == 0) {
72 FGXMLLogging log(el, LogLevel::ERROR);
73 log << "No port assigned in input element\n";
74 return false;
75 }
76
77 string action = el->GetAttributeValue("action");
78 if (to_upper(action) == "BLOCKING_INPUT")
79 BlockingInput = true;
80
81 return true;
82}
bool Load(Element *el) override
Init the input directives from an XML file (implement the FGModel interface).
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Read()

void Read ( bool  Holding)
overridevirtual

Generates the input.

Implements FGInputType.

Reimplemented in FGUDPInputSocket.

Definition at line 141 of file FGInputSocket.cpp.

142{
143 if (!socket) return;
144 if (!socket->GetConnectStatus()) return;
145
146 if (BlockingInput)
147 socket->WaitUntilReadable(); // block until a transmission is received
148
149 string raw_data = socket->Receive(); // read data
150
151 if (!raw_data.empty()) {
152 size_t start = 0;
153
154 data += raw_data;
155
156 // parse lines
157 while (1) {
158 size_t string_start = data.find_first_not_of("\r\n", start);
159 if (string_start == string::npos) break;
160 size_t string_end = data.find_first_of("\r\n", string_start);
161 if (string_end == string::npos) break;
162 string line = data.substr(string_start, string_end-string_start);
163 if (line.empty()) break;
164
165 // now parse individual line
166 vector <string> tokens = split(line,' ');
167
168 string command, argument, str_value;
169 if (!tokens.empty()) {
170 command = to_lower(tokens[0]);
171 if (tokens.size() > 1) {
172 argument = trim(tokens[1]);
173 if (tokens.size() > 2) {
174 str_value = trim(tokens[2]);
175 }
176 }
177 }
178
179 if (command == "set") { // SET PROPERTY
180 SGPropertyNode* node = nullptr;
181
182 if (argument.empty()) {
183 socket->Reply("No property argument supplied.\r\n");
184 break;
185 }
186 try {
187 node = PropertyManager->GetNode(argument);
188 } catch(...) {
189 socket->Reply("Badly formed property query\r\n");
190 break;
191 }
192
193 if (!node) {
194 socket->Reply("Unknown property\r\n");
195 break;
196 } else if (!node->hasValue()) {
197 socket->Reply("Not a leaf property\r\n");
198 break;
199 } else {
200 try {
201 double value = atof_locale_c(str_value);
202 node->setDoubleValue(value);
203 } catch(InvalidNumber& e) {
204 string msg(e.what());
205 msg += "\r\n";
206 socket->Reply(msg);
207 break;
208 }
209 }
210 socket->Reply("set successful\r\n");
211
212 } else if (command == "get") { // GET PROPERTY
213 SGPropertyNode* node = nullptr;
214
215 if (argument.empty()) {
216 socket->Reply("No property argument supplied.\r\n");
217 break;
218 }
219 try {
220 node = PropertyManager->GetNode(argument);
221 } catch(...) {
222 socket->Reply("Badly formed property query\r\n");
223 break;
224 }
225
226 if (!node) {
227 socket->Reply("Unknown property\r\n");
228 break;
229 } else if (!node->hasValue()) {
230 if (Holding) { // if holding can query property list
231 string query = FDMExec->QueryPropertyCatalog(argument, "\r\n");
232 socket->Reply(query);
233 } else {
234 socket->Reply("Must be in HOLD to search properties\r\n");
235 }
236 } else {
237 ostringstream buf;
238 buf << argument << " = " << setw(12) << setprecision(6) << node->getDoubleValue() << '\r' << endl;
239 socket->Reply(buf.str());
240 }
241
242 } else if (command == "hold") { // PAUSE
243
244 FDMExec->Hold();
245 socket->Reply("Holding\r\n");
246
247 } else if (command == "resume") { // RESUME
248
249 FDMExec->Resume();
250 socket->Reply("Resuming\r\n");
251
252 } else if (command == "iterate") { // ITERATE
253
254 int argumentInt;
255 istringstream (argument) >> argumentInt;
256 if (argument.empty()) {
257 socket->Reply("No argument supplied for number of iterations.\r\n");
258 break;
259 }
260 if ( !(argumentInt > 0) ){
261 socket->Reply("Required argument must be a positive Integer.\r\n");
262 break;
263 }
264 FDMExec->EnableIncrementThenHold( argumentInt );
265 FDMExec->Resume();
266 socket->Reply("Iterations performed\r\n");
267
268 } else if (command == "quit") { // QUIT
269
270 // close the socket connection
271 socket->Send("Closing connection\r\n");
272 socket->Close();
273
274 } else if (command == "info") { // INFO
275
276 // get info about the sim run and/or aircraft, etc.
277 ostringstream info;
278 info << "JSBSim version: " << JSBSim_version << "\r\n";
279 info << "Config File version: " << needed_cfg_version << "\r\n";
280 info << "Aircraft simulated: " << FDMExec->GetAircraft()->GetAircraftName() << "\r\n";
281 info << "Simulation time: " << setw(8) << setprecision(3) << FDMExec->GetSimTime() << '\r' << endl;
282 socket->Reply(info.str());
283
284 } else if (command == "help") { // HELP
285
286 socket->Reply(
287 " JSBSim Server commands:\r\n\r\n"
288 " get {property name}\r\n"
289 " set {property name} {value}\r\n"
290 " hold\r\n"
291 " resume\r\n"
292 " iterate {value}\r\n"
293 " help\r\n"
294 " quit\r\n"
295 " info\r\n\r\n");
296
297 } else {
298 socket->Reply(string("Unknown command: ") + command + "\r\n");
299 }
300
301 start = string_end;
302 }
303
304 // Remove processed commands.
305 size_t last_crlf = data.find_last_of("\r\n");
306 if (last_crlf != string::npos) {
307 if (last_crlf < data.length()-1)
308 data = data.substr(last_crlf+1);
309 else
310 data.clear();
311 }
312 }
313
314}
std::shared_ptr< FGAircraft > GetAircraft(void) const
Returns the FGAircraft pointer.
std::string QueryPropertyCatalog(const std::string &check, const std::string &end_of_line="\n")
Retrieves property or properties matching the supplied string.
void EnableIncrementThenHold(int Timesteps)
Turn on hold after increment.
Definition FGFDMExec.h:495
void Resume(void)
Resumes execution from a "Hold".
Definition FGFDMExec.h:499
double GetSimTime(void) const
Returns the cumulative simulation time in seconds.
Definition FGFDMExec.h:554
void Hold(void)
Pauses execution by preventing time from incrementing.
Definition FGFDMExec.h:493
A node in a property tree.
Definition props.hxx:747
double getDoubleValue() const
Get a double value for this node.
bool setDoubleValue(double value)
Set a double value for this node.
bool hasValue() const
Test whether this node contains a primitive leaf value.
Definition props.hxx:810
+ Here is the call graph for this function:

◆ Toggle()

bool Toggle ( void  )
overridevirtual

Toggles the input generation.

Returns
the input generation status i.e. true if the input has been enabled, false if the input has been disabled.

Reimplemented from FGInputType.

Definition at line 128 of file FGInputSocket.cpp.

129{
130 bool enabled_status = FGInputType::Toggle();
131 if (enabled_status)
132 CreateSocket();
133 else
134 socket.reset();
135
136 return enabled_status;
137}
virtual bool Toggle(void)
Toggles the input generation.
+ Here is the call graph for this function:

Member Data Documentation

◆ BlockingInput

bool BlockingInput
protected

Definition at line 95 of file FGInputSocket.h.

◆ data

std::string data
protected

Definition at line 94 of file FGInputSocket.h.

◆ socket

std::unique_ptr<FGfdmSocket> socket
protected

Definition at line 92 of file FGInputSocket.h.

◆ SockPort

unsigned int SockPort
protected

Definition at line 91 of file FGInputSocket.h.

◆ SockProtocol

FGfdmSocket::ProtocolType SockProtocol
protected

Definition at line 93 of file FGInputSocket.h.


The documentation for this class was generated from the following files: