JSBSim Flight Dynamics Model 1.3.0 (09 Apr 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)
 Constructor.
 
 ~FGInputSocket () override
 Destructor.
 
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.
 
- Public Member Functions inherited from FGInputType
 FGInputType (FGFDMExec *fdmex)
 Constructor (implement the FGModel interface).
 
 ~FGInputType () override
 Destructor.
 
void Disable (void)
 Disables the input generation.
 
void Enable (void)
 Enables the input generation.
 
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.
 
bool Toggle (void)
 Toggles the input generation.
 
- 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 Attributes

bool BlockingInput
 
std::string data
 
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
 
- 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.
 
- 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)

Constructor.

Definition at line 56 of file FGInputSocket.cpp.

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

◆ ~FGInputSocket()

~FGInputSocket ( )
override

Destructor.

Definition at line 64 of file FGInputSocket.cpp.

65{
66 delete socket;
67}

Member Function Documentation

◆ 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 93 of file FGInputSocket.cpp.

94{
96 delete socket;
97 socket = new FGfdmSocket(SockPort, SockProtocol);
98
99 if (socket == 0) return false;
100 if (!socket->GetConnectStatus()) return false;
101
102 return true;
103 }
104
105 return false;
106}
bool InitModel(void) override
Init the input model according to its configitation.
bool GetConnectStatus(void)
Return the connection status of the socket.
+ 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 71 of file FGInputSocket.cpp.

72{
73 if (!FGInputType::Load(el))
74 return false;
75
76 SockPort = atoi(el->GetAttributeValue("port").c_str());
77
78 if (SockPort == 0) {
79 FGXMLLogging log(el, LogLevel::ERROR);
80 log << "No port assigned in input element\n";
81 return false;
82 }
83
84 string action = el->GetAttributeValue("action");
85 if (to_upper(action) == "BLOCKING_INPUT")
86 BlockingInput = true;
87
88 return true;
89}
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 110 of file FGInputSocket.cpp.

111{
112 if (!socket) return;
113 if (!socket->GetConnectStatus()) return;
114
115 if (BlockingInput)
116 socket->WaitUntilReadable(); // block until a transmission is received
117
118 string raw_data = socket->Receive(); // read data
119
120 if (!raw_data.empty()) {
121 size_t start = 0;
122
123 data += raw_data;
124
125 // parse lines
126 while (1) {
127 size_t string_start = data.find_first_not_of("\r\n", start);
128 if (string_start == string::npos) break;
129 size_t string_end = data.find_first_of("\r\n", string_start);
130 if (string_end == string::npos) break;
131 string line = data.substr(string_start, string_end-string_start);
132 if (line.empty()) break;
133
134 // now parse individual line
135 vector <string> tokens = split(line,' ');
136
137 string command, argument, str_value;
138 if (!tokens.empty()) {
139 command = to_lower(tokens[0]);
140 if (tokens.size() > 1) {
141 argument = trim(tokens[1]);
142 if (tokens.size() > 2) {
143 str_value = trim(tokens[2]);
144 }
145 }
146 }
147
148 if (command == "set") { // SET PROPERTY
149 SGPropertyNode* node = nullptr;
150
151 if (argument.empty()) {
152 socket->Reply("No property argument supplied.\r\n");
153 break;
154 }
155 try {
156 node = PropertyManager->GetNode(argument);
157 } catch(...) {
158 socket->Reply("Badly formed property query\r\n");
159 break;
160 }
161
162 if (!node) {
163 socket->Reply("Unknown property\r\n");
164 break;
165 } else if (!node->hasValue()) {
166 socket->Reply("Not a leaf property\r\n");
167 break;
168 } else {
169 try {
170 double value = atof_locale_c(str_value);
171 node->setDoubleValue(value);
172 } catch(InvalidNumber& e) {
173 string msg(e.what());
174 msg += "\r\n";
175 socket->Reply(msg);
176 break;
177 }
178 }
179 socket->Reply("set successful\r\n");
180
181 } else if (command == "get") { // GET PROPERTY
182 SGPropertyNode* node = nullptr;
183
184 if (argument.empty()) {
185 socket->Reply("No property argument supplied.\r\n");
186 break;
187 }
188 try {
189 node = PropertyManager->GetNode(argument);
190 } catch(...) {
191 socket->Reply("Badly formed property query\r\n");
192 break;
193 }
194
195 if (!node) {
196 socket->Reply("Unknown property\r\n");
197 break;
198 } else if (!node->hasValue()) {
199 if (Holding) { // if holding can query property list
200 string query = FDMExec->QueryPropertyCatalog(argument, "\r\n");
201 socket->Reply(query);
202 } else {
203 socket->Reply("Must be in HOLD to search properties\r\n");
204 }
205 } else {
206 ostringstream buf;
207 buf << argument << " = " << setw(12) << setprecision(6) << node->getDoubleValue() << '\r' << endl;
208 socket->Reply(buf.str());
209 }
210
211 } else if (command == "hold") { // PAUSE
212
213 FDMExec->Hold();
214 socket->Reply("Holding\r\n");
215
216 } else if (command == "resume") { // RESUME
217
218 FDMExec->Resume();
219 socket->Reply("Resuming\r\n");
220
221 } else if (command == "iterate") { // ITERATE
222
223 int argumentInt;
224 istringstream (argument) >> argumentInt;
225 if (argument.empty()) {
226 socket->Reply("No argument supplied for number of iterations.\r\n");
227 break;
228 }
229 if ( !(argumentInt > 0) ){
230 socket->Reply("Required argument must be a positive Integer.\r\n");
231 break;
232 }
233 FDMExec->EnableIncrementThenHold( argumentInt );
234 FDMExec->Resume();
235 socket->Reply("Iterations performed\r\n");
236
237 } else if (command == "quit") { // QUIT
238
239 // close the socket connection
240 socket->Send("Closing connection\r\n");
241 socket->Close();
242
243 } else if (command == "info") { // INFO
244
245 // get info about the sim run and/or aircraft, etc.
246 ostringstream info;
247 info << "JSBSim version: " << JSBSim_version << "\r\n";
248 info << "Config File version: " << needed_cfg_version << "\r\n";
249 info << "Aircraft simulated: " << FDMExec->GetAircraft()->GetAircraftName() << "\r\n";
250 info << "Simulation time: " << setw(8) << setprecision(3) << FDMExec->GetSimTime() << '\r' << endl;
251 socket->Reply(info.str());
252
253 } else if (command == "help") { // HELP
254
255 socket->Reply(
256 " JSBSim Server commands:\r\n\r\n"
257 " get {property name}\r\n"
258 " set {property name} {value}\r\n"
259 " hold\r\n"
260 " resume\r\n"
261 " iterate {value}\r\n"
262 " help\r\n"
263 " quit\r\n"
264 " info\r\n\r\n");
265
266 } else {
267 socket->Reply(string("Unknown command: ") + command + "\r\n");
268 }
269
270 start = string_end;
271 }
272
273 // Remove processed commands.
274 size_t last_crlf = data.find_last_of("\r\n");
275 if (last_crlf != string::npos) {
276 if (last_crlf < data.length()-1)
277 data = data.substr(last_crlf+1);
278 else
279 data.clear();
280 }
281 }
282
283}
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:491
void Resume(void)
Resumes execution from a "Hold".
Definition FGFDMExec.h:495
double GetSimTime(void) const
Returns the cumulative simulation time in seconds.
Definition FGFDMExec.h:550
void Hold(void)
Pauses execution by preventing time from incrementing.
Definition FGFDMExec.h:489
std::string Receive(void)
Receive data from the socket connection.
void Close(void)
Close the socket connection if the protocol is TCP.
void WaitUntilReadable(void)
Wait until the TCP socket is readable.
int Reply(const std::string &text)
Send a reply to the client ending by a prompt "JSBSim>".
void Send(void)
Send the internal buffer over the socket connection.
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:

Member Data Documentation

◆ BlockingInput

bool BlockingInput
protected

Definition at line 91 of file FGInputSocket.h.

◆ data

std::string data
protected

Definition at line 90 of file FGInputSocket.h.

◆ socket

FGfdmSocket* socket
protected

Definition at line 88 of file FGInputSocket.h.

◆ SockPort

unsigned int SockPort
protected

Definition at line 87 of file FGInputSocket.h.

◆ SockProtocol

FGfdmSocket::ProtocolType SockProtocol
protected

Definition at line 89 of file FGInputSocket.h.


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