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;
120 if (!
socket->GetConnectStatus())
return;
123 socket->WaitUntilReadable();
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) {
142 if (tokens.size() > 1) {
143 argument =
trim(tokens[1]);
144 if (tokens.size() > 2) {
145 str_value =
trim(tokens[2]);
152 if (argument.size() == 0) {
153 socket->Reply(
"No property argument supplied.\n");
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");
177 if (argument.size() == 0) {
178 socket->Reply(
"No property argument supplied.\n");
184 socket->Reply(
"Badly formed property query\n");
189 socket->Reply(
"Unknown property\n");
191 }
else if (!node->hasValue()) {
193 string query =
FDMExec->QueryPropertyCatalog(argument);
196 socket->Reply(
"Must be in HOLD to search properties\n");
200 buf << argument <<
" = " << setw(12) << setprecision(6) << node->getDoubleValue() << endl;
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");
226 FDMExec->EnableIncrementThenHold( argumentInt );
228 socket->Reply(
"Iterations performed\n");
230 }
else if (
command ==
"quit") {
233 socket->Reply(
"Closing connection\n");
236 }
else if (
command ==
"info") {
242 info <<
"Aircraft simulated: " <<
FDMExec->GetAircraft()->GetAircraftName() << 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"));
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
static const std::string JSBSim_version
static const std::string needed_cfg_version
FGPropertyManager * PropertyManager
Class wrapper for property handling.
Encapsulates an object that enables JSBSim to communicate via socket (input and/or output).
SGCommandMgr::command_t command
static double atof(const string &str)
static int atoi(const string &str)
std::string & to_upper(std::string &str)
std::vector< std::string > split(std::string str, char d)
std::string & to_lower(std::string &str)
std::string & trim(std::string &str)