46 #include "FGInputSocket.h"
47 #include "FGFDMExec.h"
48 #include "models/FGAircraft.h"
49 #include "input_output/FGXMLElement.h"
82 cerr << endl <<
"No port assigned in input element" << endl;
87 if (to_upper(action) ==
"BLOCKING_INPUT")
101 if (socket == 0)
return false;
102 if (!socket->GetConnectStatus())
return false;
115 size_t start=0, string_start=0, string_end=0;
119 if (socket == 0)
return;
120 if (!socket->GetConnectStatus())
return;
123 socket->WaitUntilReadable();
124 data = socket->Receive();
126 if (data.size() > 0) {
129 string_start = data.find_first_not_of(
"\r\n", start);
130 if (string_start == string::npos)
break;
131 string_end = data.find_first_of(
"\r\n", string_start);
132 if (string_end == string::npos)
break;
133 line = data.substr(string_start, string_end-string_start);
134 if (line.size() == 0)
break;
137 vector <string> tokens = split(line,
' ');
139 string command=
"", argument=
"", str_value=
"";
140 if (tokens.size() > 0) {
141 command = to_lower(tokens[0]);
142 if (tokens.size() > 1) {
143 argument = trim(tokens[1]);
144 if (tokens.size() > 2) {
145 str_value = trim(tokens[2]);
150 if (command ==
"set") {
152 if (argument.size() == 0) {
153 socket->Reply(
"No property argument supplied.\n");
157 node = PropertyManager->GetNode(argument);
159 socket->Reply(
"Badly formed property query\n");
164 socket->Reply(
"Unknown property\n");
166 }
else if (!node->hasValue()) {
167 socket->Reply(
"Not a leaf property\n");
170 value = atof(str_value.c_str());
171 node->setDoubleValue(value);
173 socket->Reply(
"set successful\n");
175 }
else if (command ==
"get") {
177 if (argument.size() == 0) {
178 socket->Reply(
"No property argument supplied.\n");
182 node = PropertyManager->GetNode(argument);
184 socket->Reply(
"Badly formed property query\n");
189 socket->Reply(
"Unknown property\n");
191 }
else if (!node->hasValue()) {
194 socket->Reply(query);
196 socket->Reply(
"Must be in HOLD to search properties\n");
200 buf << argument <<
" = " << setw(12) << setprecision(6) << node->getDoubleValue() << endl;
201 socket->Reply(buf.str());
204 }
else if (command ==
"hold") {
207 socket->Reply(
"Holding\n");
209 }
else if (command ==
"resume") {
212 socket->Reply(
"Resuming\n");
214 }
else if (command ==
"iterate") {
217 istringstream (argument) >> argumentInt;
218 if (argument.size() == 0) {
219 socket->Reply(
"No argument supplied for number of iterations.\n");
222 if ( !(argumentInt > 0) ){
223 socket->Reply(
"Required argument must be a positive Integer.\n");
228 socket->Reply(
"Iterations performed\n");
230 }
else if (command ==
"quit") {
233 socket->Reply(
"Closing connection\n");
236 }
else if (command ==
"info") {
240 info <<
"JSBSim version: " << JSBSim_version << endl;
241 info <<
"Config File version: " << needed_cfg_version << endl;
243 info <<
"Simulation time: " << setw(8) << setprecision(3) << FDMExec->
GetSimTime() << endl;
244 socket->Reply(info.str());
246 }
else if (command ==
"help") {
249 " JSBSim Server commands:\n\n"
250 " get {property name}\n"
251 " set {property name} {value}\n"
260 socket->Reply(
string(
"Unknown command: ") + token +
string(
"\n"));