44 #include "FGUDPInputSocket.h" 45 #include "FGFDMExec.h" 46 #include "input_output/FGXMLElement.h" 53 IDENT(IdHdr,ID_UDPINPUTSOCKET);
59 FGUDPInputSocket::FGUDPInputSocket(
FGFDMExec* fdmex) :
87 cerr << endl <<
"No port assigned in input element" << endl;
93 while (property_element) {
94 string property_str = property_element->
GetDataLine();
97 cerr <<
fgred <<
highint << endl <<
" No property by the name " 98 << property_str <<
" can be found." <<
reset << endl;
100 InputProperties.push_back(node);
114 socket =
new FGfdmSocket(SockPort, FGfdmSocket::ptUDP, FGfdmSocket::dIN);
116 if (socket == 0)
return false;
117 cout <<
"UDP input socket established on port " << SockPort << endl;
129 if (socket == 0)
return;
131 data = socket->Receive();
133 if (data.size() > 0) {
135 vector<string> tokens;
136 stringstream ss(data);
138 while (getline(ss, temp,
',')) {
139 tokens.push_back(temp);
142 vector<double> values;
144 for (
unsigned int i=0; i<tokens.size(); i++) {
145 values.push_back( atof(tokens[i].c_str()) );
148 if (values[0] < oldTimeStamp) {
151 oldTimeStamp = values[0];
155 if ((values.size() - 1) != InputProperties.size()) {
156 cerr << endl <<
"Mismatch between UDP input property and value counts." << endl;
160 for (
unsigned int i=1; i<values.size(); i++) {
161 InputProperties[i-1]->setDoubleValue(values[i]);
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Class wrapper for property handling.
static char reset[5]
resets text properties
Element * FindElement(const std::string &el="")
Searches for a specified element.
static char fgred[6]
red text
void SetRate(unsigned int tt)
Set the ouput rate for the model in frames.
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
static char highint[5]
highlights text
double GetDeltaT(void) const
Returns the simulation delta T.
Encapsulates the JSBSim simulation executive.
Encapsulates an object that enables JSBSim to communicate via socket (input and/or output)...