%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGOutput.h"
-#include "FGState.h"
#include "FGFDMExec.h"
#include "FGAtmosphere.h"
#include "FGFCS.h"
#include "FGPropagate.h"
#include "FGAuxiliary.h"
#include "FGInertial.h"
-#include "FGPropulsion.h" //access to FGEngine, FGTank
+#include "FGPropulsion.h"
+#include "models/propulsion/FGEngine.h"
+#include "models/propulsion/FGTank.h"
#include "models/propulsion/FGPiston.h"
-#include <fstream>
+#include <sstream>
#include <iomanip>
#include <cstring>
-
-#include "input_output/net_fdm.hxx"
+#include <cstdlib>
#if defined(WIN32) && !defined(__CYGWIN__)
# include <windows.h>
static const int endianTest = 1;
#define isLittleEndian (*((char *) &endianTest ) != 0)
+using namespace std;
+
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGOutput.cpp,v 1.50 2010/11/18 12:38:06 jberndt Exp $";
static const char *IdHdr = ID_OUTPUT;
// (stolen from FGFS native_fdm.cxx)
Name = "FGOutput";
sFirstPass = dFirstPass = true;
socket = 0;
- flightGearSocket = 0;
runID_postfix = 0;
Type = otNone;
SubSystems = 0;
FGOutput::~FGOutput()
{
delete socket;
- delete flightGearSocket;
OutputProperties.clear();
Debug(1);
}
bool FGOutput::InitModel(void)
{
- char fname[1000] = "";
-
if (!FGModel::InitModel()) return false;
if (Filename.size() > 0 && StartNewFile) {
- int idx = BaseFilename.find_last_of(".");
- int len = BaseFilename.length();
- string extension = "";
- if (idx != string::npos) {
- extension = BaseFilename.substr(idx, len-idx);
- len -= extension.length();
+ ostringstream buf;
+ string::size_type dot = BaseFilename.find_last_of('.');
+ if (dot != string::npos) {
+ buf << BaseFilename.substr(0, dot) << '_' << runID_postfix++ << BaseFilename.substr(dot);
+ } else {
+ buf << BaseFilename << '_' << runID_postfix++;
}
- sprintf(fname, "%s_%d%s", BaseFilename.substr(0,len).c_str(), runID_postfix++, extension.c_str());
- Filename = string(fname);
+ Filename = buf.str();
datafile.close();
StartNewFile = false;
dFirstPass = true;
{
if (FGModel::Run()) return true;
- if (enabled && !State->IntegrationSuspended()&& !FDMExec->Holding()) {
+ if (enabled && !FDMExec->IntegrationSuspended()&& !FDMExec->Holding()) {
+ RunPreFunctions();
if (Type == otSocket) {
SocketOutput();
} else if (Type == otFlightGear) {
} else {
// Not a valid type of output
}
+ RunPostFunctions();
}
return false;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGOutput::SetType(string type)
+void FGOutput::SetType(const string& type)
{
if (type == "CSV") {
Type = otCSV;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGOutput::DelimitedOutput(string fname)
+void FGOutput::SetProtocol(const string& protocol)
+{
+ if (protocol == "UDP") Protocol = FGfdmSocket::ptUDP;
+ else if (protocol == "TCP") Protocol = FGfdmSocket::ptTCP;
+ else Protocol = FGfdmSocket::ptTCP; // Default to TCP
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGOutput::DelimitedOutput(const string& fname)
{
+ const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+ const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+ const FGAircraft* Aircraft = FDMExec->GetAircraft();
+ const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
+ const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+ const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+ const FGPropagate* Propagate = FDMExec->GetPropagate();
+ const FGFCS* FCS = FDMExec->GetFCS();
+ const FGInertial* Inertial = FDMExec->GetInertial();
+ const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
+ const FGExternalReactions* ExternalReactions = FDMExec->GetExternalReactions();
+ const FGBuoyantForces* BuoyantForces = FDMExec->GetBuoyantForces();
+
streambuf* buffer;
string scratch = "";
if (SubSystems & ssRates) {
outstream << delimeter;
outstream << "P (deg/s)" + delimeter + "Q (deg/s)" + delimeter + "R (deg/s)" + delimeter;
- outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)";
+ outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)" + delimeter;
+ outstream << "P_{inertial} (deg/s)" + delimeter + "Q_{inertial} (deg/s)" + delimeter + "R_{inertial} (deg/s)";
}
if (SubSystems & ssVelocities) {
outstream << delimeter;
outstream << "V_{Inertial} (ft/s)" + delimeter;
outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
+ outstream << "V_{X_{inertial}} (ft/s)" + delimeter + "V_{Y_{inertial}} (ft/s)" + delimeter + "V_{Z_{inertial}} (ft/s)" + delimeter;
outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
}
if (SubSystems & ssForces) {
outstream << "Beta (deg)" + delimeter;
outstream << "Latitude (deg)" + delimeter;
outstream << "Longitude (deg)" + delimeter;
- outstream << "ECEF X (ft)" + delimeter + "ECEF Y (ft)" + delimeter + "ECEF Z (ft)" + delimeter;
- outstream << "EPA (deg)" + delimeter;
+ outstream << "X_{ECI} (ft)" + delimeter + "Y_{ECI} (ft)" + delimeter + "Z_{ECI} (ft)" + delimeter;
+ outstream << "X_{ECEF} (ft)" + delimeter + "Y_{ECEF} (ft)" + delimeter + "Z_{ECEF} (ft)" + delimeter;
+ outstream << "Earth Position Angle (deg)" + delimeter;
outstream << "Distance AGL (ft)" + delimeter;
outstream << "Terrain Elevation (ft)";
}
dFirstPass = false;
}
- outstream << State->Getsim_time();
+ outstream << FDMExec->GetSimTime();
if (SubSystems & ssSimulation) {
}
if (SubSystems & ssAerosurfaces) {
if (SubSystems & ssRates) {
outstream << delimeter;
outstream << (radtodeg*Propagate->GetPQR()).Dump(delimeter) << delimeter;
- outstream << (radtodeg*Propagate->GetPQRdot()).Dump(delimeter);
+ outstream << (radtodeg*Propagate->GetPQRdot()).Dump(delimeter) << delimeter;
+ outstream << (radtodeg*Propagate->GetPQRi()).Dump(delimeter);
}
if (SubSystems & ssVelocities) {
outstream << delimeter;
outstream << Propagate->GetInertialVelocityMagnitude() << delimeter;
outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
+ outstream << Propagate->GetInertialVelocity().Dump(delimeter) << delimeter;
outstream << Propagate->GetVel().Dump(delimeter);
outstream.precision(10);
}
if (SubSystems & ssForces) {
outstream << delimeter;
- outstream << Aerodynamics->GetvFw() << delimeter;
+ outstream << Aerodynamics->GetvFw().Dump(delimeter) << delimeter;
outstream << Aerodynamics->GetLoD() << delimeter;
- outstream << Aerodynamics->GetForces() << delimeter;
- outstream << Propulsion->GetForces() << delimeter;
- outstream << GroundReactions->GetForces() << delimeter;
- outstream << ExternalReactions->GetForces() << delimeter;
- outstream << BuoyantForces->GetForces() << delimeter;
+ outstream << Aerodynamics->GetForces().Dump(delimeter) << delimeter;
+ outstream << Propulsion->GetForces().Dump(delimeter) << delimeter;
+ outstream << GroundReactions->GetForces().Dump(delimeter) << delimeter;
+ outstream << ExternalReactions->GetForces().Dump(delimeter) << delimeter;
+ outstream << BuoyantForces->GetForces().Dump(delimeter) << delimeter;
outstream << Aircraft->GetForces().Dump(delimeter);
}
if (SubSystems & ssMoments) {
outstream << delimeter;
- outstream << Aerodynamics->GetMoments() << delimeter;
- outstream << Propulsion->GetMoments() << delimeter;
- outstream << GroundReactions->GetMoments() << delimeter;
- outstream << ExternalReactions->GetMoments() << delimeter;
- outstream << BuoyantForces->GetMoments() << delimeter;
+ outstream << Aerodynamics->GetMoments().Dump(delimeter) << delimeter;
+ outstream << Propulsion->GetMoments().Dump(delimeter) << delimeter;
+ outstream << GroundReactions->GetMoments().Dump(delimeter) << delimeter;
+ outstream << ExternalReactions->GetMoments().Dump(delimeter) << delimeter;
+ outstream << BuoyantForces->GetMoments().Dump(delimeter) << delimeter;
outstream << Aircraft->GetMoments().Dump(delimeter);
}
if (SubSystems & ssAtmosphere) {
}
if (SubSystems & ssMassProps) {
outstream << delimeter;
- outstream << MassBalance->GetJ() << delimeter;
+ outstream << MassBalance->GetJ().Dump(delimeter) << delimeter;
outstream << MassBalance->GetMass() << delimeter;
- outstream << MassBalance->GetXYZcg();
+ outstream << MassBalance->GetXYZcg().Dump(delimeter);
}
if (SubSystems & ssPropagate) {
outstream.precision(14);
outstream << Propagate->GetLocation().GetLatitudeDeg() << delimeter;
outstream << Propagate->GetLocation().GetLongitudeDeg() << delimeter;
outstream.precision(18);
+ outstream << ((FGColumnVector3)Propagate->GetInertialPosition()).Dump(delimeter) << delimeter;
outstream << ((FGColumnVector3)Propagate->GetLocation()).Dump(delimeter) << delimeter;
outstream.precision(14);
outstream << Inertial->GetEarthPositionAngleDeg() << delimeter;
void FGOutput::SocketDataFill(FGNetFDM* net)
{
+ const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+ const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+ const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+ const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+ const FGPropagate* Propagate = FDMExec->GetPropagate();
+ const FGFCS* FCS = FDMExec->GetFCS();
+ const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
unsigned int i;
// Version
}
}
-
// Consumables
net->num_tanks = Propulsion->GetNumTanks(); // Max number of fuel tanks
net->fuel_quantity[i] = (float)(((FGTank *)Propulsion->GetTank(i))->GetContents());
}
-
// Gear status
net->num_wheels = GroundReactions->GetNumGearUnits();
net->gear_compression[i] = (float)(GroundReactions->GetGearUnit(i)->GetCompLen());
}
-
// Environment
- net->cur_time = (long int)1234567890; // Friday, Feb 13, 2009, 23:31:30 UTC (not processed by FGFS anyway)
+ net->cur_time = (long int)1234567890; // Friday, Feb 13, 2009, 23:31:30 UTC (not processed by FGFS anyway)
net->warp = 0; // offset in seconds to unix time
net->visibility = 25000.0; // visibility in meters (for env. effects)
-
// Control surface positions (normalized values)
net->elevator = (float)(FCS->GetDePos(ofNorm)); // Norm Elevator Pos, --
net->elevator_trim_tab = (float)(FCS->GetPitchTrimCmd()); // Norm Elev Trim Tab Pos, --
net->speedbrake = (float)(FCS->GetDsbPos(ofNorm)); // Norm Speedbrake Pos, --
net->spoilers = (float)(FCS->GetDspPos(ofNorm)); // Norm Spoiler Pos, --
-
// Convert the net buffer to network format
if ( isLittleEndian ) {
net->version = htonl(net->version);
{
int length = sizeof(fgSockBuf);
-
- if (flightGearSocket == NULL) return;
- if (!flightGearSocket->GetConnectStatus()) return;
+ if (socket == NULL) return;
+ if (!socket->GetConnectStatus()) return;
SocketDataFill(&fgSockBuf);
- flightGearSocket->Send((char *)&fgSockBuf, length);
+ socket->Send((char *)&fgSockBuf, length);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGOutput::SocketOutput(void)
{
+ const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics();
+ const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary();
+ const FGPropulsion* Propulsion = FDMExec->GetPropulsion();
+ const FGMassBalance* MassBalance = FDMExec->GetMassBalance();
+ const FGPropagate* Propagate = FDMExec->GetPropagate();
+ const FGFCS* FCS = FDMExec->GetFCS();
+ const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere();
+ const FGAircraft* Aircraft = FDMExec->GetAircraft();
+ const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions();
+
string asciiData, scratch;
if (socket == NULL) return;
}
socket->Clear();
- socket->Append(State->Getsim_time());
+ socket->Append(FDMExec->GetSimTime());
if (SubSystems & ssAerosurfaces) {
socket->Append(FCS->GetDaCmd());
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGOutput::SocketStatusOutput(string out_str)
+void FGOutput::SocketStatusOutput(const string& out_str)
{
string asciiData;
bool FGOutput::Load(Element* element)
{
- string type="", parameter="";
+ string parameter="";
string name="";
- string protocol="tcp";
int OutRate = 0;
- string property;
unsigned int port;
Element *property_element;
output_file_name = DirectivesFile; // one found in the config file.
document = LoadXMLDocument(output_file_name);
} else if (!element->GetAttributeValue("file").empty()) {
- output_file_name = element->GetAttributeValue("file");
+ output_file_name = FDMExec->GetRootDir() + element->GetAttributeValue("file");
document = LoadXMLDocument(output_file_name);
} else {
document = element;
}
- name = document->GetAttributeValue("name");
- type = document->GetAttributeValue("type");
- SetType(type);
- if (!document->GetAttributeValue("port").empty() && type == string("SOCKET")) {
- port = atoi(document->GetAttributeValue("port").c_str());
- socket = new FGfdmSocket(name, port);
- } else if (!document->GetAttributeValue("port").empty() && type == string("FLIGHTGEAR")) {
- port = atoi(document->GetAttributeValue("port").c_str());
- if (!document->GetAttributeValue("protocol").empty())
- protocol = document->GetAttributeValue("protocol");
- if (protocol == "udp")
- flightGearSocket = new FGfdmSocket(name, port, FGfdmSocket::ptUDP); // create udp socket
- else
- flightGearSocket = new FGfdmSocket(name, port, FGfdmSocket::ptTCP); // create tcp socket (default)
+ if (!document) return false;
+
+ name = FDMExec->GetRootDir() + document->GetAttributeValue("name");
+ SetType(document->GetAttributeValue("type"));
+ Port = document->GetAttributeValue("port");
+ if (!Port.empty() && (Type == otSocket || Type == otFlightGear)) {
+ port = atoi(Port.c_str());
+ SetProtocol(document->GetAttributeValue("protocol"));
+ socket = new FGfdmSocket(name, port, Protocol);
} else {
BaseFilename = Filename = name;
}
{
rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
if (rtHz > 0) {
- rate = (int)(0.5 + 1.0/(State->Getdt()*rtHz));
+ rate = (int)(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
Enable();
} else {
rate = 1;
}
switch (Type) {
case otCSV:
- cout << scratch << " in CSV format output at rate " << 1/(State->Getdt()*rate) << " Hz" << endl;
+ cout << scratch << " in CSV format output at rate " << 1/(FDMExec->GetDeltaT()*rate) << " Hz" << endl;
break;
case otNone:
+ default:
cout << " No log output" << endl;
break;
}