X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2Fmodels%2FFGInput.cpp;h=c1ff0b8f21084aa9a9f95755436a1e51b51ff1fb;hb=a302cdc1cbb3c147e7c862b484cdd5d86f30a29c;hp=d7e2a2a517a0e1d175a52932115da2f6365d20e2;hpb=cb435814c1293b5ada428612a3e6bb8f2180f21b;p=flightgear.git diff --git a/src/FDM/JSBSim/models/FGInput.cpp b/src/FDM/JSBSim/models/FGInput.cpp index d7e2a2a51..c1ff0b8f2 100755 --- a/src/FDM/JSBSim/models/FGInput.cpp +++ b/src/FDM/JSBSim/models/FGInput.cpp @@ -6,7 +6,7 @@ Purpose: Manage output of sim parameters to file or stdout Called by: FGSimExec - ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- + ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -39,15 +39,21 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGInput.h" -#include "FGState.h" +#include "FGAircraft.h" #include "FGFDMExec.h" -#include +#include "input_output/FGfdmSocket.h" +#include "input_output/FGXMLElement.h" + +#include #include +#include + +using namespace std; namespace JSBSim { -static const char *IdSrc = "$Id$"; +static const char *IdSrc = "$Id: FGInput.cpp,v 1.21 2011/05/20 03:18:36 jberndt Exp $"; static const char *IdHdr = ID_INPUT; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -77,8 +83,6 @@ FGInput::~FGInput() bool FGInput::InitModel(void) { - if (!FGModel::InitModel()) return false; - return true; } @@ -87,20 +91,20 @@ bool FGInput::InitModel(void) // This function handles accepting input commands from the socket interface. // -bool FGInput::Run(void) +bool FGInput::Run(bool Holding) { - string line, token, info_string; - int start=0, string_start=0, string_end=0; - int token_start=0, token_end=0; - char buf[100]; + string line, token; + size_t start=0, string_start=0, string_end=0; double value=0; FGPropertyManager* node=0; - if (FGModel::Run()) return true; // fast exit if nothing to do + if (FGModel::Run(Holding)) return true; // fast exit if nothing to do if (port == 0) return false; // Do nothing here if port not defined // return false if no error // This model DOES execute if "Exec->Holding" + RunPreFunctions(); + data = socket->Receive(); // get socket transmission if present if (data.size() > 0) { @@ -151,15 +155,16 @@ bool FGInput::Run(void) break; } if (node == 0) { - if (FDMExec->Holding()) { // if holding can query property list + if (Holding) { // if holding can query property list string query = FDMExec->QueryPropertyCatalog(argument); socket->Reply(query); } else { socket->Reply("Must be in HOLD to search properties\n"); } } else if (node > 0) { - sprintf(buf, "%s = %12.6f\n", argument.c_str(), node->getDoubleValue()); - socket->Reply(buf); + ostringstream buf; + buf << argument << " = " << setw(12) << setprecision(6) << node->getDoubleValue() << endl; + socket->Reply(buf.str()); } } else if (command == "hold") { // PAUSE @@ -181,12 +186,12 @@ bool FGInput::Run(void) } else if (command == "info") { // INFO // get info about the sim run and/or aircraft, etc. - sprintf(buf, "%8.3f\0", State->Getsim_time()); - info_string = "JSBSim version: " + JSBSim_version + "\n"; - info_string += "Config File version: " + needed_cfg_version + "\n"; - info_string += "Aircraft simulated: " + Aircraft->GetAircraftName() + "\n"; - info_string += "Simulation time: " + string(buf) + "\n"; - socket->Reply(info_string); + ostringstream info; + info << "JSBSim version: " << JSBSim_version << endl; + info << "Config File version: " << needed_cfg_version << endl; + info << "Aircraft simulated: " << FDMExec->GetAircraft()->GetAircraftName() << endl; + info << "Simulation time: " << setw(8) << setprecision(3) << FDMExec->GetSimTime() << endl; + socket->Reply(info.str()); } else if (command == "help") { // HELP @@ -208,6 +213,8 @@ bool FGInput::Run(void) } } + RunPostFunctions(); + return false; }