1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Manage output of sim parameters to file or stdout
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This is the place where you create output routines to dump data for perusal
34 --------------------------------------------------------------------------------
36 11/09/07 HDW Added FlightGear Socket Interface
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGFDMExec.h"
45 #include "FGAtmosphere.h"
47 #include "FGAerodynamics.h"
48 #include "FGGroundReactions.h"
49 #include "FGAircraft.h"
50 #include "FGMassBalance.h"
51 #include "FGPropagate.h"
52 #include "FGAuxiliary.h"
53 #include "FGInertial.h"
54 #include "FGPropulsion.h" //access to FGEngine, FGTank
55 #include "models/propulsion/FGPiston.h"
60 #include "input_output/net_fdm.hxx"
62 #if defined(WIN32) && !defined(__CYGWIN__)
65 # include <netinet/in.h> // htonl() ntohl()
68 static const int endianTest = 1;
69 #define isLittleEndian (*((char *) &endianTest ) != 0)
73 static const char *IdSrc = "$Id$";
74 static const char *IdHdr = ID_OUTPUT;
76 // (stolen from FGFS native_fdm.cxx)
77 // The function htond is defined this way due to the way some
78 // processors and OSes treat floating point values. Some will raise
79 // an exception whenever a "bad" floating point value is loaded into a
80 // floating point register. Solaris is notorious for this, but then
81 // so is LynxOS on the PowerPC. By translating the data in place,
82 // there is no need to load a FP register with the "corruped" floating
83 // point value. By doing the BIG_ENDIAN test, I can optimize the
84 // routine for big-endian processors so it can be as efficient as
86 static void htond (double &x)
88 if ( isLittleEndian ) {
92 Double_Overlay = (int *) &x;
93 Holding_Buffer = Double_Overlay [0];
95 Double_Overlay [0] = htonl (Double_Overlay [1]);
96 Double_Overlay [1] = htonl (Holding_Buffer);
103 static void htonf (float &x)
105 if ( isLittleEndian ) {
109 Float_Overlay = (int *) &x;
110 Holding_Buffer = Float_Overlay [0];
112 Float_Overlay [0] = htonl (Holding_Buffer);
119 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
123 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
126 sFirstPass = dFirstPass = true;
128 flightGearSocket = 0;
135 output_file_name = "";
137 memset(&fgSockBuf, 0x00, sizeof(fgSockBuf));
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 FGOutput::~FGOutput()
147 delete flightGearSocket;
148 OutputProperties.clear();
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 bool FGOutput::InitModel(void)
156 if (!FGModel::InitModel()) return false;
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 bool FGOutput::Run(void)
165 if (FGModel::Run()) return true;
167 if (enabled && !State->IntegrationSuspended()&& !FDMExec->Holding()) {
168 if (Type == otSocket) {
170 } else if (Type == otFlightGear) {
171 FlightGearSocketOutput();
172 } else if (Type == otCSV || Type == otTab) {
173 DelimitedOutput(Filename);
174 } else if (Type == otTerminal) {
176 } else if (Type == otNone) {
179 // Not a valid type of output
185 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 void FGOutput::SetType(string type)
192 } else if (type == "TABULAR") {
195 } else if (type == "SOCKET") {
197 } else if (type == "FLIGHTGEAR") {
199 } else if (type == "TERMINAL") {
201 } else if (type != string("NONE")) {
203 cerr << "Unknown type of output specified in config file" << endl;
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 void FGOutput::DelimitedOutput(string fname)
214 if (fname == "COUT" || fname == "cout") {
215 buffer = cout.rdbuf();
217 datafile.open(fname.c_str());
218 buffer = datafile.rdbuf();
221 ostream outstream(buffer);
223 outstream.precision(10);
227 if (SubSystems & ssSimulation) {
230 if (SubSystems & ssAerosurfaces) {
231 outstream << delimeter;
232 outstream << "Aileron Command (norm)" + delimeter;
233 outstream << "Elevator Command (norm)" + delimeter;
234 outstream << "Rudder Command (norm)" + delimeter;
235 outstream << "Flap Command (norm)" + delimeter;
236 outstream << "Left Aileron Position (deg)" + delimeter;
237 outstream << "Right Aileron Position (deg)" + delimeter;
238 outstream << "Elevator Position (deg)" + delimeter;
239 outstream << "Rudder Position (deg)" + delimeter;
240 outstream << "Flap Position (deg)";
242 if (SubSystems & ssRates) {
243 outstream << delimeter;
244 outstream << "P (deg/s)" + delimeter + "Q (deg/s)" + delimeter + "R (deg/s)" + delimeter;
245 outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)";
247 if (SubSystems & ssVelocities) {
248 outstream << delimeter;
249 outstream << "q bar (psf)" + delimeter;
250 outstream << "Reynolds Number" + delimeter;
251 outstream << "V_{Total} (ft/s)" + delimeter;
252 outstream << "V_{Inertial} (ft/s)" + delimeter;
253 outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
254 outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
255 outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
257 if (SubSystems & ssForces) {
258 outstream << delimeter;
259 outstream << "F_{Drag} (lbs)" + delimeter + "F_{Side} (lbs)" + delimeter + "F_{Lift} (lbs)" + delimeter;
260 outstream << "L/D" + delimeter;
261 outstream << "F_X (lbs)" + delimeter + "F_Y (lbs)" + delimeter + "F_Z (lbs)";
263 if (SubSystems & ssMoments) {
264 outstream << delimeter;
265 outstream << "L (ft-lbs)" + delimeter + "M (ft-lbs)" + delimeter + "N (ft-lbs)";
267 if (SubSystems & ssAtmosphere) {
268 outstream << delimeter;
269 outstream << "Rho (slugs/ft^3)" + delimeter;
270 outstream << "Absolute Viscosity" + delimeter;
271 outstream << "Kinematic Viscosity" + delimeter;
272 outstream << "Temperature (R)" + delimeter;
273 outstream << "P_{SL} (psf)" + delimeter;
274 outstream << "P_{Ambient} (psf)" + delimeter;
275 outstream << "Turbulence Magnitude (ft/sec)" + delimeter;
276 outstream << "Turbulence X Direction (rad)" + delimeter + "Turbulence Y Direction (rad)" + delimeter + "Turbulence Z Direction (rad)" + delimeter;
277 outstream << "Wind V_{North} (ft/s)" + delimeter + "Wind V_{East} (ft/s)" + delimeter + "Wind V_{Down} (ft/s)";
279 if (SubSystems & ssMassProps) {
280 outstream << delimeter;
281 outstream << "I_{xx}" + delimeter;
282 outstream << "I_{xy}" + delimeter;
283 outstream << "I_{xz}" + delimeter;
284 outstream << "I_{yx}" + delimeter;
285 outstream << "I_{yy}" + delimeter;
286 outstream << "I_{yz}" + delimeter;
287 outstream << "I_{zx}" + delimeter;
288 outstream << "I_{zy}" + delimeter;
289 outstream << "I_{zz}" + delimeter;
290 outstream << "Mass" + delimeter;
291 outstream << "X_{cg}" + delimeter + "Y_{cg}" + delimeter + "Z_{cg}";
293 if (SubSystems & ssPropagate) {
294 outstream << delimeter;
295 outstream << "Altitude (ft)" + delimeter;
296 outstream << "Phi (deg)" + delimeter + "Theta (deg)" + delimeter + "Psi (deg)" + delimeter;
297 outstream << "Alpha (deg)" + delimeter;
298 outstream << "Beta (deg)" + delimeter;
299 outstream << "Latitude (deg)" + delimeter;
300 outstream << "Longitude (deg)" + delimeter;
301 outstream << "ECEF X (ft)" + delimeter + "ECEF Y (ft)" + delimeter + "ECEF Z (ft)" + delimeter;
302 outstream << "EPA (deg)" + delimeter;
303 outstream << "Distance AGL (ft)" + delimeter;
304 outstream << "Runway Radius (ft)";
306 if (SubSystems & ssCoefficients) {
307 scratch = Aerodynamics->GetCoefficientStrings(delimeter);
308 if (scratch.length() != 0) outstream << delimeter << scratch;
310 if (SubSystems & ssFCS) {
311 scratch = FCS->GetComponentStrings(delimeter);
312 if (scratch.length() != 0) outstream << delimeter << scratch;
314 if (SubSystems & ssGroundReactions) {
315 outstream << delimeter;
316 outstream << GroundReactions->GetGroundReactionStrings(delimeter);
318 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
319 outstream << delimeter;
320 outstream << Propulsion->GetPropulsionStrings(delimeter);
322 if (OutputProperties.size() > 0) {
323 for (unsigned int i=0;i<OutputProperties.size();i++) {
324 outstream << delimeter << OutputProperties[i]->GetPrintableName();
332 outstream << State->Getsim_time();
333 if (SubSystems & ssSimulation) {
335 if (SubSystems & ssAerosurfaces) {
336 outstream << delimeter;
337 outstream << FCS->GetDaCmd() << delimeter;
338 outstream << FCS->GetDeCmd() << delimeter;
339 outstream << FCS->GetDrCmd() << delimeter;
340 outstream << FCS->GetDfCmd() << delimeter;
341 outstream << FCS->GetDaLPos(ofDeg) << delimeter;
342 outstream << FCS->GetDaRPos(ofDeg) << delimeter;
343 outstream << FCS->GetDePos(ofDeg) << delimeter;
344 outstream << FCS->GetDrPos(ofDeg) << delimeter;
345 outstream << FCS->GetDfPos(ofDeg);
347 if (SubSystems & ssRates) {
348 outstream << delimeter;
349 outstream << (radtodeg*Propagate->GetPQR()).Dump(delimeter) << delimeter;
350 outstream << (radtodeg*Propagate->GetPQRdot()).Dump(delimeter);
352 if (SubSystems & ssVelocities) {
353 outstream << delimeter;
354 outstream << Auxiliary->Getqbar() << delimeter;
355 outstream << Auxiliary->GetReynoldsNumber() << delimeter;
356 outstream << setprecision(12) << Auxiliary->GetVt() << delimeter;
357 outstream << Propagate->GetInertialVelocityMagnitude() << delimeter;
358 outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
359 outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
360 outstream << Propagate->GetVel().Dump(delimeter);
362 if (SubSystems & ssForces) {
363 outstream << delimeter;
364 outstream << Aerodynamics->GetvFw() << delimeter;
365 outstream << Aerodynamics->GetLoD() << delimeter;
366 outstream << Aircraft->GetForces().Dump(delimeter);
368 if (SubSystems & ssMoments) {
369 outstream << delimeter;
370 outstream << Aircraft->GetMoments().Dump(delimeter);
372 if (SubSystems & ssAtmosphere) {
373 outstream << delimeter;
374 outstream << Atmosphere->GetDensity() << delimeter;
375 outstream << Atmosphere->GetAbsoluteViscosity() << delimeter;
376 outstream << Atmosphere->GetKinematicViscosity() << delimeter;
377 outstream << Atmosphere->GetTemperature() << delimeter;
378 outstream << Atmosphere->GetPressureSL() << delimeter;
379 outstream << Atmosphere->GetPressure() << delimeter;
380 outstream << Atmosphere->GetTurbMagnitude() << delimeter;
381 outstream << Atmosphere->GetTurbDirection().Dump(delimeter) << delimeter;
382 outstream << Atmosphere->GetTotalWindNED().Dump(delimeter);
384 if (SubSystems & ssMassProps) {
385 outstream << delimeter;
386 outstream << MassBalance->GetJ() << delimeter;
387 outstream << MassBalance->GetMass() << delimeter;
388 outstream << MassBalance->GetXYZcg();
390 if (SubSystems & ssPropagate) {
391 outstream << delimeter;
392 outstream << Propagate->Geth() << delimeter;
393 outstream << (radtodeg*Propagate->GetEuler()).Dump(delimeter) << delimeter;
394 outstream << Auxiliary->Getalpha(inDegrees) << delimeter;
395 outstream << Auxiliary->Getbeta(inDegrees) << delimeter;
396 outstream << Propagate->GetLocation().GetLatitudeDeg() << delimeter;
397 outstream << Propagate->GetLocation().GetLongitudeDeg() << delimeter;
398 outstream << ((FGColumnVector3)Propagate->GetLocation()).Dump(delimeter) << delimeter;
399 outstream << Inertial->GetEarthPositionAngleDeg() << delimeter;
400 outstream << Propagate->GetDistanceAGL() << delimeter;
401 outstream << Propagate->GetRunwayRadius();
403 if (SubSystems & ssCoefficients) {
404 scratch = Aerodynamics->GetCoefficientValues(delimeter);
405 if (scratch.length() != 0) outstream << delimeter << scratch;
407 if (SubSystems & ssFCS) {
408 scratch = FCS->GetComponentValues(delimeter);
409 if (scratch.length() != 0) outstream << delimeter << scratch;
411 if (SubSystems & ssGroundReactions) {
412 outstream << delimeter;
413 outstream << GroundReactions->GetGroundReactionValues(delimeter);
415 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
416 outstream << delimeter;
417 outstream << Propulsion->GetPropulsionValues(delimeter);
420 for (unsigned int i=0;i<OutputProperties.size();i++) {
421 outstream << delimeter << OutputProperties[i]->getDoubleValue();
428 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 void FGOutput::SocketDataFill(FGNetFDM* net)
435 net->version = FG_NET_FDM_VERSION;
438 net->longitude = Propagate->GetLocation().GetLongitude(); // geodetic (radians)
439 net->latitude = Propagate->GetLocation().GetLatitude(); // geodetic (radians)
440 net->altitude = Propagate->Geth()*0.3048; // altitude, above sea level (meters)
441 net->agl = (float)(Propagate->GetDistanceAGL()*0.3048); // altitude, above ground level (meters)
443 net->phi = (float)(Propagate->GetEuler(ePhi)); // roll (radians)
444 net->theta = (float)(Propagate->GetEuler(eTht)); // pitch (radians)
445 net->psi = (float)(Propagate->GetEuler(ePsi)); // yaw or true heading (radians)
447 net->alpha = (float)(Auxiliary->Getalpha()); // angle of attack (radians)
448 net->beta = (float)(Auxiliary->Getbeta()); // side slip angle (radians)
451 net->phidot = (float)(Auxiliary->GetEulerRates(ePhi)); // roll rate (radians/sec)
452 net->thetadot = (float)(Auxiliary->GetEulerRates(eTht)); // pitch rate (radians/sec)
453 net->psidot = (float)(Auxiliary->GetEulerRates(ePsi)); // yaw rate (radians/sec)
454 net->vcas = (float)(Auxiliary->GetVcalibratedFPS()); // VCAS, ft/sec
455 net->climb_rate = (float)(Propagate->Gethdot()); // altitude rate, ft/sec
456 net->v_north = (float)(Propagate->GetVel(eNorth)); // north vel in NED frame, fps
457 net->v_east = (float)(Propagate->GetVel(eEast)); // east vel in NED frame, fps
458 net->v_down = (float)(Propagate->GetVel(eDown)); // down vel in NED frame, fps
459 //---ADD METHOD TO CALCULATE THESE TERMS---
460 net->v_wind_body_north = (float)(Propagate->GetVel(eNorth)); // north vel in NED relative to airmass, fps
461 net->v_wind_body_east = (float)(Propagate->GetVel(eEast)); // east vel in NED relative to airmass, fps
462 net->v_wind_body_down = (float)(Propagate->GetVel(eDown)); // down vel in NED relative to airmass, fps
465 net->A_X_pilot = (float)(Auxiliary->GetPilotAccel(1)); // X body accel, ft/s/s
466 net->A_Y_pilot = (float)(Auxiliary->GetPilotAccel(2)); // Y body accel, ft/s/s
467 net->A_Z_pilot = (float)(Auxiliary->GetPilotAccel(3)); // Z body accel, ft/s/s
470 net->stall_warning = 0.0; // 0.0 - 1.0 indicating the amount of stall
471 net->slip_deg = (float)(Auxiliary->Getbeta(inDegrees)); // slip ball deflection, deg
474 net->num_engines = Propulsion->GetNumEngines(); // Number of valid engines
476 for (i=0; i<net->num_engines; i++) {
477 if (Propulsion->GetEngine(i)->GetRunning())
478 net->eng_state[i] = 2; // Engine state running
479 else if (Propulsion->GetEngine(i)->GetCranking())
480 net->eng_state[i] = 1; // Engine state cranking
482 net->eng_state[i] = 0; // Engine state off
484 switch (Propulsion->GetEngine(i)->GetType()) {
485 case (FGEngine::etRocket):
487 case (FGEngine::etPiston):
488 net->rpm[i] = (float)(((FGPiston *)Propulsion->GetEngine(i))->getRPM());
489 net->fuel_flow[i] = (float)(((FGPiston *)Propulsion->GetEngine(i))->getFuelFlow_gph());
490 net->fuel_px[i] = 0; // Fuel pressure, psi (N/A in current model)
491 net->egt[i] = (float)(((FGPiston *)Propulsion->GetEngine(i))->GetEGT());
492 net->cht[i] = (float)(((FGPiston *)Propulsion->GetEngine(i))->getCylinderHeadTemp_degF());
493 net->mp_osi[i] = (float)(((FGPiston *)Propulsion->GetEngine(i))->getManifoldPressure_inHg());
494 net->oil_temp[i] = (float)(((FGPiston *)Propulsion->GetEngine(i))->getOilTemp_degF());
495 net->oil_px[i] = (float)(((FGPiston *)Propulsion->GetEngine(i))->getOilPressure_psi());
496 net->tit[i] = 0; // Turbine Inlet Temperature (N/A for piston)
498 case (FGEngine::etTurbine):
500 case (FGEngine::etTurboprop):
502 case (FGEngine::etElectric):
504 case (FGEngine::etUnknown):
511 net->num_tanks = Propulsion->GetNumTanks(); // Max number of fuel tanks
513 for (i=0; i<net->num_tanks; i++) {
514 net->fuel_quantity[i] = (float)(((FGTank *)Propulsion->GetTank(i))->GetContents());
519 net->num_wheels = GroundReactions->GetNumGearUnits();
521 for (i=0; i<net->num_wheels; i++) {
522 net->wow[i] = GroundReactions->GetGearUnit(i)->GetWOW();
523 if (GroundReactions->GetGearUnit(i)->GetGearUnitDown())
524 net->gear_pos[i] = 1; //gear down, using FCS convention
526 net->gear_pos[i] = 0; //gear up, using FCS convention
527 net->gear_steer[i] = (float)(GroundReactions->GetGearUnit(i)->GetSteerNorm());
528 net->gear_compression[i] = (float)(GroundReactions->GetGearUnit(i)->GetCompLen());
533 net->cur_time = (long int)1234567890; // Friday, Feb 13, 2009, 23:31:30 UTC (not processed by FGFS anyway)
534 net->warp = 0; // offset in seconds to unix time
535 net->visibility = 25000.0; // visibility in meters (for env. effects)
538 // Control surface positions (normalized values)
539 net->elevator = (float)(FCS->GetDePos(ofNorm)); // Norm Elevator Pos, --
540 net->elevator_trim_tab = (float)(FCS->GetPitchTrimCmd()); // Norm Elev Trim Tab Pos, --
541 net->left_flap = (float)(FCS->GetDfPos(ofNorm)); // Norm Flap Pos, --
542 net->right_flap = (float)(FCS->GetDfPos(ofNorm)); // Norm Flap Pos, --
543 net->left_aileron = (float)(FCS->GetDaLPos(ofNorm)); // Norm L Aileron Pos, --
544 net->right_aileron = (float)(FCS->GetDaRPos(ofNorm)); // Norm R Aileron Pos, --
545 net->rudder = (float)(FCS->GetDrPos(ofNorm)); // Norm Rudder Pos, --
546 net->nose_wheel = (float)(FCS->GetDrPos(ofNorm)); // *** FIX *** Using Rudder Pos for NWS, --
547 net->speedbrake = (float)(FCS->GetDsbPos(ofNorm)); // Norm Speedbrake Pos, --
548 net->spoilers = (float)(FCS->GetDspPos(ofNorm)); // Norm Spoiler Pos, --
551 // Convert the net buffer to network format
552 if ( isLittleEndian ) {
553 net->version = htonl(net->version);
555 htond(net->longitude);
556 htond(net->latitude);
557 htond(net->altitude);
566 htonf(net->thetadot);
569 htonf(net->climb_rate);
573 htonf(net->v_wind_body_north);
574 htonf(net->v_wind_body_east);
575 htonf(net->v_wind_body_down);
577 htonf(net->A_X_pilot);
578 htonf(net->A_Y_pilot);
579 htonf(net->A_Z_pilot);
581 htonf(net->stall_warning);
582 htonf(net->slip_deg);
584 for (i=0; i<net->num_engines; ++i ) {
585 net->eng_state[i] = htonl(net->eng_state[i]);
587 htonf(net->fuel_flow[i]);
588 htonf(net->fuel_px[i]);
591 htonf(net->mp_osi[i]);
593 htonf(net->oil_temp[i]);
594 htonf(net->oil_px[i]);
596 net->num_engines = htonl(net->num_engines);
598 for (i=0; i<net->num_tanks; ++i ) {
599 htonf(net->fuel_quantity[i]);
601 net->num_tanks = htonl(net->num_tanks);
603 for (i=0; i<net->num_wheels; ++i ) {
604 net->wow[i] = htonl(net->wow[i]);
605 htonf(net->gear_pos[i]);
606 htonf(net->gear_steer[i]);
607 htonf(net->gear_compression[i]);
609 net->num_wheels = htonl(net->num_wheels);
611 net->cur_time = htonl( net->cur_time );
612 net->warp = htonl( net->warp );
613 htonf(net->visibility);
615 htonf(net->elevator);
616 htonf(net->elevator_trim_tab);
617 htonf(net->left_flap);
618 htonf(net->right_flap);
619 htonf(net->left_aileron);
620 htonf(net->right_aileron);
622 htonf(net->nose_wheel);
623 htonf(net->speedbrake);
624 htonf(net->spoilers);
628 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 void FGOutput::FlightGearSocketOutput(void)
632 int length = sizeof(fgSockBuf);
635 if (flightGearSocket == NULL) return;
636 if (!flightGearSocket->GetConnectStatus()) return;
638 SocketDataFill(&fgSockBuf);
639 flightGearSocket->Send((char *)&fgSockBuf, length);
642 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
644 void FGOutput::SocketOutput(void)
646 string asciiData, scratch;
648 if (socket == NULL) return;
649 if (!socket->GetConnectStatus()) return;
653 socket->Clear("<LABELS>");
654 socket->Append("Time");
656 if (SubSystems & ssAerosurfaces) {
657 socket->Append("Aileron Command");
658 socket->Append("Elevator Command");
659 socket->Append("Rudder Command");
660 socket->Append("Flap Command");
661 socket->Append("Left Aileron Position");
662 socket->Append("Right Aileron Position");
663 socket->Append("Elevator Position");
664 socket->Append("Rudder Position");
665 socket->Append("Flap Position");
668 if (SubSystems & ssRates) {
672 socket->Append("PDot");
673 socket->Append("QDot");
674 socket->Append("RDot");
677 if (SubSystems & ssVelocities) {
678 socket->Append("QBar");
679 socket->Append("Vtotal");
680 socket->Append("UBody");
681 socket->Append("VBody");
682 socket->Append("WBody");
683 socket->Append("UAero");
684 socket->Append("VAero");
685 socket->Append("WAero");
686 socket->Append("Vn");
687 socket->Append("Ve");
688 socket->Append("Vd");
690 if (SubSystems & ssForces) {
691 socket->Append("F_Drag");
692 socket->Append("F_Side");
693 socket->Append("F_Lift");
694 socket->Append("LoD");
695 socket->Append("Fx");
696 socket->Append("Fy");
697 socket->Append("Fz");
699 if (SubSystems & ssMoments) {
704 if (SubSystems & ssAtmosphere) {
705 socket->Append("Rho");
706 socket->Append("SL pressure");
707 socket->Append("Ambient pressure");
708 socket->Append("Turbulence Magnitude");
709 socket->Append("Turbulence Direction X");
710 socket->Append("Turbulence Direction Y");
711 socket->Append("Turbulence Direction Z");
712 socket->Append("NWind");
713 socket->Append("EWind");
714 socket->Append("DWind");
716 if (SubSystems & ssMassProps) {
717 socket->Append("Ixx");
718 socket->Append("Ixy");
719 socket->Append("Ixz");
720 socket->Append("Iyx");
721 socket->Append("Iyy");
722 socket->Append("Iyz");
723 socket->Append("Izx");
724 socket->Append("Izy");
725 socket->Append("Izz");
726 socket->Append("Mass");
727 socket->Append("Xcg");
728 socket->Append("Ycg");
729 socket->Append("Zcg");
731 if (SubSystems & ssPropagate) {
732 socket->Append("Altitude");
733 socket->Append("Phi (deg)");
734 socket->Append("Tht (deg)");
735 socket->Append("Psi (deg)");
736 socket->Append("Alpha (deg)");
737 socket->Append("Beta (deg)");
738 socket->Append("Latitude (deg)");
739 socket->Append("Longitude (deg)");
741 if (SubSystems & ssCoefficients) {
742 scratch = Aerodynamics->GetCoefficientStrings(",");
743 if (scratch.length() != 0) socket->Append(scratch);
745 if (SubSystems & ssFCS) {
746 scratch = FCS->GetComponentStrings(",");
747 if (scratch.length() != 0) socket->Append(scratch);
749 if (SubSystems & ssGroundReactions) {
750 socket->Append(GroundReactions->GetGroundReactionStrings(","));
752 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
753 socket->Append(Propulsion->GetPropulsionStrings(","));
755 if (OutputProperties.size() > 0) {
756 for (unsigned int i=0;i<OutputProperties.size();i++) {
757 socket->Append(OutputProperties[i]->GetPrintableName());
766 socket->Append(State->Getsim_time());
768 if (SubSystems & ssAerosurfaces) {
769 socket->Append(FCS->GetDaCmd());
770 socket->Append(FCS->GetDeCmd());
771 socket->Append(FCS->GetDrCmd());
772 socket->Append(FCS->GetDfCmd());
773 socket->Append(FCS->GetDaLPos());
774 socket->Append(FCS->GetDaRPos());
775 socket->Append(FCS->GetDePos());
776 socket->Append(FCS->GetDrPos());
777 socket->Append(FCS->GetDfPos());
779 if (SubSystems & ssRates) {
780 socket->Append(radtodeg*Propagate->GetPQR(eP));
781 socket->Append(radtodeg*Propagate->GetPQR(eQ));
782 socket->Append(radtodeg*Propagate->GetPQR(eR));
783 socket->Append(radtodeg*Propagate->GetPQRdot(eP));
784 socket->Append(radtodeg*Propagate->GetPQRdot(eQ));
785 socket->Append(radtodeg*Propagate->GetPQRdot(eR));
787 if (SubSystems & ssVelocities) {
788 socket->Append(Auxiliary->Getqbar());
789 socket->Append(Auxiliary->GetVt());
790 socket->Append(Propagate->GetUVW(eU));
791 socket->Append(Propagate->GetUVW(eV));
792 socket->Append(Propagate->GetUVW(eW));
793 socket->Append(Auxiliary->GetAeroUVW(eU));
794 socket->Append(Auxiliary->GetAeroUVW(eV));
795 socket->Append(Auxiliary->GetAeroUVW(eW));
796 socket->Append(Propagate->GetVel(eNorth));
797 socket->Append(Propagate->GetVel(eEast));
798 socket->Append(Propagate->GetVel(eDown));
800 if (SubSystems & ssForces) {
801 socket->Append(Aerodynamics->GetvFw()(eDrag));
802 socket->Append(Aerodynamics->GetvFw()(eSide));
803 socket->Append(Aerodynamics->GetvFw()(eLift));
804 socket->Append(Aerodynamics->GetLoD());
805 socket->Append(Aircraft->GetForces(eX));
806 socket->Append(Aircraft->GetForces(eY));
807 socket->Append(Aircraft->GetForces(eZ));
809 if (SubSystems & ssMoments) {
810 socket->Append(Aircraft->GetMoments(eL));
811 socket->Append(Aircraft->GetMoments(eM));
812 socket->Append(Aircraft->GetMoments(eN));
814 if (SubSystems & ssAtmosphere) {
815 socket->Append(Atmosphere->GetDensity());
816 socket->Append(Atmosphere->GetPressureSL());
817 socket->Append(Atmosphere->GetPressure());
818 socket->Append(Atmosphere->GetTurbMagnitude());
819 socket->Append(Atmosphere->GetTurbDirection().Dump(","));
820 socket->Append(Atmosphere->GetTotalWindNED().Dump(","));
822 if (SubSystems & ssMassProps) {
823 socket->Append(MassBalance->GetJ()(1,1));
824 socket->Append(MassBalance->GetJ()(1,2));
825 socket->Append(MassBalance->GetJ()(1,3));
826 socket->Append(MassBalance->GetJ()(2,1));
827 socket->Append(MassBalance->GetJ()(2,2));
828 socket->Append(MassBalance->GetJ()(2,3));
829 socket->Append(MassBalance->GetJ()(3,1));
830 socket->Append(MassBalance->GetJ()(3,2));
831 socket->Append(MassBalance->GetJ()(3,3));
832 socket->Append(MassBalance->GetMass());
833 socket->Append(MassBalance->GetXYZcg()(eX));
834 socket->Append(MassBalance->GetXYZcg()(eY));
835 socket->Append(MassBalance->GetXYZcg()(eZ));
837 if (SubSystems & ssPropagate) {
838 socket->Append(Propagate->Geth());
839 socket->Append(radtodeg*Propagate->GetEuler(ePhi));
840 socket->Append(radtodeg*Propagate->GetEuler(eTht));
841 socket->Append(radtodeg*Propagate->GetEuler(ePsi));
842 socket->Append(Auxiliary->Getalpha(inDegrees));
843 socket->Append(Auxiliary->Getbeta(inDegrees));
844 socket->Append(Propagate->GetLocation().GetLatitudeDeg());
845 socket->Append(Propagate->GetLocation().GetLongitudeDeg());
847 if (SubSystems & ssCoefficients) {
848 scratch = Aerodynamics->GetCoefficientValues(",");
849 if (scratch.length() != 0) socket->Append(scratch);
851 if (SubSystems & ssFCS) {
852 scratch = FCS->GetComponentValues(",");
853 if (scratch.length() != 0) socket->Append(scratch);
855 if (SubSystems & ssGroundReactions) {
856 socket->Append(GroundReactions->GetGroundReactionValues(","));
858 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
859 socket->Append(Propulsion->GetPropulsionValues(","));
862 for (unsigned int i=0;i<OutputProperties.size();i++) {
863 socket->Append(OutputProperties[i]->getDoubleValue());
869 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
871 void FGOutput::SocketStatusOutput(string out_str)
875 if (socket == NULL) return;
878 asciiData = string("<STATUS>") + out_str;
879 socket->Append(asciiData.c_str());
883 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
885 bool FGOutput::Load(Element* element)
887 string type="", parameter="";
889 string protocol="tcp";
893 Element *property_element;
895 string separator = "/";
897 if (!DirectivesFile.empty()) { // A directives filename from the command line overrides
898 output_file_name = DirectivesFile; // one found in the config file.
899 document = LoadXMLDocument(output_file_name);
900 } else if (!element->GetAttributeValue("file").empty()) {
901 output_file_name = element->GetAttributeValue("file");
902 document = LoadXMLDocument(output_file_name);
907 name = document->GetAttributeValue("name");
908 type = document->GetAttributeValue("type");
910 if (!document->GetAttributeValue("port").empty() && type == string("SOCKET")) {
911 port = atoi(document->GetAttributeValue("port").c_str());
912 socket = new FGfdmSocket(name, port);
913 } else if (!document->GetAttributeValue("port").empty() && type == string("FLIGHTGEAR")) {
914 port = atoi(document->GetAttributeValue("port").c_str());
915 if (!document->GetAttributeValue("protocol").empty())
916 protocol = document->GetAttributeValue("protocol");
917 if (protocol == "udp")
918 flightGearSocket = new FGfdmSocket(name, port, FGfdmSocket::ptUDP); // create udp socket
920 flightGearSocket = new FGfdmSocket(name, port, FGfdmSocket::ptTCP); // create tcp socket (default)
924 if (!document->GetAttributeValue("rate").empty()) {
925 OutRate = (int)document->GetAttributeValueAsNumber("rate");
930 if (document->FindElementValue("simulation") == string("ON"))
931 SubSystems += ssSimulation;
932 if (document->FindElementValue("aerosurfaces") == string("ON"))
933 SubSystems += ssAerosurfaces;
934 if (document->FindElementValue("rates") == string("ON"))
935 SubSystems += ssRates;
936 if (document->FindElementValue("velocities") == string("ON"))
937 SubSystems += ssVelocities;
938 if (document->FindElementValue("forces") == string("ON"))
939 SubSystems += ssForces;
940 if (document->FindElementValue("moments") == string("ON"))
941 SubSystems += ssMoments;
942 if (document->FindElementValue("atmosphere") == string("ON"))
943 SubSystems += ssAtmosphere;
944 if (document->FindElementValue("massprops") == string("ON"))
945 SubSystems += ssMassProps;
946 if (document->FindElementValue("position") == string("ON"))
947 SubSystems += ssPropagate;
948 if (document->FindElementValue("coefficients") == string("ON"))
949 SubSystems += ssCoefficients;
950 if (document->FindElementValue("ground_reactions") == string("ON"))
951 SubSystems += ssGroundReactions;
952 if (document->FindElementValue("fcs") == string("ON"))
954 if (document->FindElementValue("propulsion") == string("ON"))
955 SubSystems += ssPropulsion;
956 property_element = document->FindElement("property");
957 while (property_element) {
958 string property_str = property_element->GetDataLine();
959 FGPropertyManager* node = PropertyManager->GetNode(property_str);
961 cerr << fgred << highint << endl << " No property by the name "
962 << property_str << " has been defined. This property will " << endl
963 << " not be logged. You should check your configuration file."
966 OutputProperties.push_back(node);
968 property_element = document->FindNextElement("property");
971 OutRate = OutRate>1000?1000:(OutRate<0?0:OutRate);
972 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
979 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
980 // The bitmasked value choices are as follows:
981 // unset: In this case (the default) JSBSim would only print
982 // out the normally expected messages, essentially echoing
983 // the config files as they are read. If the environment
984 // variable is not set, debug_lvl is set to 1 internally
985 // 0: This requests JSBSim not to output any messages
987 // 1: This value explicity requests the normal JSBSim
989 // 2: This value asks for a message to be printed out when
990 // a class is instantiated
991 // 4: When this value is set, a message is displayed when a
992 // FGModel object executes its Run() method
993 // 8: When this value is set, various runtime state variables
994 // are printed out periodically
995 // 16: When set various parameters are sanity checked and
996 // a message is printed out when they go out of bounds
998 void FGOutput::Debug(int from)
1002 if (debug_lvl <= 0) return;
1004 if (debug_lvl & 1) { // Standard console startup message output
1005 if (from == 0) { // Constructor
1009 if (output_file_name.empty())
1010 cout << " " << "Output parameters read inline" << endl;
1012 cout << " Output parameters read from file: " << output_file_name << endl;
1014 if (Filename == "cout" || Filename == "COUT") {
1015 scratch = " Log output goes to screen console";
1016 } else if (!Filename.empty()) {
1017 scratch = " Log output goes to file: " + Filename;
1021 cout << scratch << " in CSV format output at rate " << 1/(State->Getdt()*rate) << " Hz" << endl;
1024 cout << " No log output" << endl;
1028 if (SubSystems & ssSimulation) cout << " Simulation parameters logged" << endl;
1029 if (SubSystems & ssAerosurfaces) cout << " Aerosurface parameters logged" << endl;
1030 if (SubSystems & ssRates) cout << " Rate parameters logged" << endl;
1031 if (SubSystems & ssVelocities) cout << " Velocity parameters logged" << endl;
1032 if (SubSystems & ssForces) cout << " Force parameters logged" << endl;
1033 if (SubSystems & ssMoments) cout << " Moments parameters logged" << endl;
1034 if (SubSystems & ssAtmosphere) cout << " Atmosphere parameters logged" << endl;
1035 if (SubSystems & ssMassProps) cout << " Mass parameters logged" << endl;
1036 if (SubSystems & ssCoefficients) cout << " Coefficient parameters logged" << endl;
1037 if (SubSystems & ssPropagate) cout << " Propagate parameters logged" << endl;
1038 if (SubSystems & ssGroundReactions) cout << " Ground parameters logged" << endl;
1039 if (SubSystems & ssFCS) cout << " FCS parameters logged" << endl;
1040 if (SubSystems & ssPropulsion) cout << " Propulsion parameters logged" << endl;
1041 if (OutputProperties.size() > 0) cout << " Properties logged:" << endl;
1042 for (unsigned int i=0;i<OutputProperties.size();i++) {
1043 cout << " - " << OutputProperties[i]->GetName() << endl;
1047 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1048 if (from == 0) cout << "Instantiated: FGOutput" << endl;
1049 if (from == 1) cout << "Destroyed: FGOutput" << endl;
1051 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1053 if (debug_lvl & 8 ) { // Runtime state variables
1055 if (debug_lvl & 16) { // Sanity checking
1057 if (debug_lvl & 64) {
1058 if (from == 0) { // Constructor
1059 cout << IdSrc << endl;
1060 cout << IdHdr << endl;