46 #include "FGInputSocket.h" 47 #include "FGFDMExec.h" 48 #include "models/FGAircraft.h" 49 #include "input_output/FGXMLElement.h" 56 IDENT(IdHdr,ID_INPUTSOCKET);
85 cerr << endl <<
"No port assigned in input element" << endl;
100 if (socket == 0)
return false;
101 if (!socket->GetConnectStatus())
return false;
114 size_t start=0, string_start=0, string_end=0;
118 if (socket == 0)
return;
119 if (!socket->GetConnectStatus())
return;
121 data = socket->Receive();
123 if (data.size() > 0) {
126 string_start = data.find_first_not_of(
"\r\n", start);
127 if (string_start == string::npos)
break;
128 string_end = data.find_first_of(
"\r\n", string_start);
129 if (string_end == string::npos)
break;
130 line = data.substr(string_start, string_end-string_start);
131 if (line.size() == 0)
break;
134 vector <string> tokens = split(line,
' ');
136 string command=
"", argument=
"", str_value=
"";
137 if (tokens.size() > 0) {
138 command = to_lower(tokens[0]);
139 if (tokens.size() > 1) {
140 argument = trim(tokens[1]);
141 if (tokens.size() > 2) {
142 str_value = trim(tokens[2]);
147 if (command ==
"set") {
149 if (argument.size() == 0) {
150 socket->Reply(
"No property argument supplied.\n");
154 node = PropertyManager->GetNode(argument);
156 socket->Reply(
"Badly formed property query\n");
161 socket->Reply(
"Unknown property\n");
163 }
else if (!node->hasValue()) {
164 socket->Reply(
"Not a leaf property\n");
167 value = atof(str_value.c_str());
168 node->setDoubleValue(value);
172 }
else if (command ==
"get") {
174 if (argument.size() == 0) {
175 socket->Reply(
"No property argument supplied.\n");
179 node = PropertyManager->GetNode(argument);
181 socket->Reply(
"Badly formed property query\n");
186 socket->Reply(
"Unknown property\n");
188 }
else if (!node->hasValue()) {
191 socket->Reply(query);
193 socket->Reply(
"Must be in HOLD to search properties\n");
197 buf << argument <<
" = " << setw(12) << setprecision(6) << node->getDoubleValue() << endl;
198 socket->Reply(buf.str());
201 }
else if (command ==
"hold") {
206 }
else if (command ==
"resume") {
211 }
else if (command ==
"iterate") {
214 istringstream (argument) >> argumentInt;
215 if (argument.size() == 0) {
216 socket->Reply(
"No argument supplied for number of iterations.\n");
219 if ( !(argumentInt > 0) ){
220 socket->Reply(
"Required argument must be a positive Integer.\n");
227 }
else if (command ==
"quit") {
233 }
else if (command ==
"info") {
237 info <<
"JSBSim version: " << JSBSim_version << endl;
238 info <<
"Config File version: " << needed_cfg_version << endl;
240 info <<
"Simulation time: " << setw(8) << setprecision(3) << FDMExec->
GetSimTime() << endl;
241 socket->Reply(info.str());
243 }
else if (command ==
"help") {
246 " JSBSim Server commands:\n\n" 247 " get {property name}\n" 248 " set {property name} {value}\n" 257 socket->Reply(
string(
"Unknown command: ") + token +
string(
"\n"));
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Class wrapper for property handling.
const std::string & GetAircraftName(void) const
Gets the aircraft name.
void Hold(void)
Pauses execution by preventing time from incrementing.
FGAircraft * GetAircraft(void)
Returns the FGAircraft pointer.
void EnableIncrementThenHold(int Timesteps)
Turn on hold after increment.
std::string QueryPropertyCatalog(const std::string &check)
Retrieves property or properties matching the supplied string.
double GetSimTime(void) const
Returns the cumulative simulation time in seconds.
void Resume(void)
Resumes execution from a "Hold".
Encapsulates the JSBSim simulation executive.
Encapsulates an object that enables JSBSim to communicate via socket (input and/or output)...