Loading [MathJax]/extensions/tex2jax.js
JSBSim Flight Dynamics Model 1.2.2 (22 Mar 2025)
An Open Source Flight Dynamics and Control Software Library in C++
All Classes Functions Variables Enumerations Enumerator Friends Pages
FGUDPInputSocket Class Reference

Detailed Description

Implements a UDP input socket.

Definition at line 60 of file FGUDPInputSocket.h.

#include <FGUDPInputSocket.h>

+ Inheritance diagram for FGUDPInputSocket:
+ Collaboration diagram for FGUDPInputSocket:

Public Member Functions

 FGUDPInputSocket (FGFDMExec *fdmex)
 Constructor.
 
bool Load (Element *el) override
 Reads the property names from an XML file.
 
void Read (bool Holding) override
 Reads the socket and updates properties accordingly.
 
- Public Member Functions inherited from FGInputSocket
 FGInputSocket (FGFDMExec *fdmex)
 Constructor.
 
 ~FGInputSocket () override
 Destructor.
 
bool InitModel (void) override
 Initializes the instance.
 
- 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 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 std::string & GetName (void)
 
unsigned int GetRate (void)
 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

std::vector< FGPropertyNode_ptr > InputProperties
 
double oldTimeStamp
 
int rate
 
- Protected Attributes inherited from FGInputSocket
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< FGPropertyManagerPropertyManager
 
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

◆ FGUDPInputSocket()

Constructor.

Definition at line 57 of file FGUDPInputSocket.cpp.

57 :
58 FGInputSocket(fdmex), rate(20), oldTimeStamp(0.0)
59{
60 SockPort = 5139;
61 SockProtocol = FGfdmSocket::ptUDP;
62}
FGInputSocket(FGFDMExec *fdmex)
Constructor.

Member Function Documentation

◆ Load()

bool Load ( Element el)
overridevirtual

Reads the property names from an XML file.

Parameters
elementThe root XML Element of the input file.

Reimplemented from FGInputSocket.

Definition at line 66 of file FGUDPInputSocket.cpp.

67{
68 if (!FGInputSocket::Load(el))
69 return false;
70
71 rate = atoi(el->GetAttributeValue("rate").c_str());
72 SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rate));
73
74 Element *property_element = el->FindElement("property");
75
76 while (property_element) {
77 string property_str = property_element->GetDataLine();
78 FGPropertyNode* node = PropertyManager->GetNode(property_str);
79 if (!node) {
80 cerr << fgred << highint << endl << " No property by the name "
81 << property_str << " can be found." << reset << endl;
82 } else {
83 InputProperties.push_back(node);
84 }
85 property_element = el->FindNextElement("property");
86 }
87
88 return true;
89}
double GetDeltaT(void) const
Returns the simulation delta T.
Definition FGFDMExec.h:552
bool Load(Element *el) override
Init the input directives from an XML file.
static char fgred[6]
red text
Definition FGJSBBase.h:166
static char reset[5]
resets text properties
Definition FGJSBBase.h:156
static char highint[5]
highlights text
Definition FGJSBBase.h:150
void SetRate(unsigned int tt)
Set the ouput rate for the model in frames.
Definition FGModel.h:91
+ Here is the call graph for this function:

◆ Read()

void Read ( bool  Holding)
overridevirtual

Reads the socket and updates properties accordingly.

Reimplemented from FGInputSocket.

Definition at line 93 of file FGUDPInputSocket.cpp.

94{
95 if (socket == 0) return;
96
97 data = socket->Receive();
98
99 if (!data.empty()) {
100
101 vector<string> tokens;
102 stringstream ss(data);
103 string temp;
104 while (getline(ss, temp, ',')) {
105 tokens.push_back(temp);
106 }
107
108 vector<double> values;
109
110 try {
111 for (string& token : tokens)
112 values.push_back(atof_locale_c(token));
113 } catch(InvalidNumber& e) {
114 cerr << e.what() << endl;
115 return;
116 }
117
118 if (values[0] < oldTimeStamp) {
119 return;
120 } else {
121 oldTimeStamp = values[0];
122 }
123
124 // the zeroeth value is the time stamp
125 if ((values.size() - 1) != InputProperties.size()) {
126 cerr << endl << "Mismatch between UDP input property and value counts." << endl;
127 return;
128 }
129
130 for (unsigned int i=1; i<values.size(); i++) {
131 InputProperties[i-1]->setDoubleValue(values[i]);
132 }
133 }
134}
std::string Receive(void)
Receive data from the socket connection.
+ Here is the call graph for this function:

Member Data Documentation

◆ InputProperties

std::vector<FGPropertyNode_ptr> InputProperties
protected

Definition at line 78 of file FGUDPInputSocket.h.

◆ oldTimeStamp

double oldTimeStamp
protected

Definition at line 77 of file FGUDPInputSocket.h.

◆ rate

int rate
protected

Definition at line 76 of file FGUDPInputSocket.h.


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