2001-09-04 14:39:12 +00:00
|
|
|
// native_fdm.cxx -- FGFS "Native" flight dynamics protocal class
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started September 2001.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
2002-02-06 04:31:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-04 14:39:12 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
2002-02-04 22:54:02 +00:00
|
|
|
#include <simgear/io/lowlevel.hxx> // endian tests
|
2001-09-04 14:39:12 +00:00
|
|
|
#include <simgear/io/iochannel.hxx>
|
2002-03-16 00:18:38 +00:00
|
|
|
#include <simgear/timing/sg_time.hxx>
|
2001-09-04 14:39:12 +00:00
|
|
|
|
|
|
|
#include <FDM/flight.hxx>
|
2002-02-08 23:03:54 +00:00
|
|
|
#include <Time/tmp.hxx>
|
|
|
|
#include <Main/fg_props.hxx>
|
2002-02-04 22:54:02 +00:00
|
|
|
#include <Main/globals.hxx>
|
2003-07-31 01:44:40 +00:00
|
|
|
#include <Scenery/scenery.hxx>
|
2001-09-04 14:39:12 +00:00
|
|
|
|
|
|
|
#include "native_fdm.hxx"
|
|
|
|
|
2002-02-07 15:38:32 +00:00
|
|
|
// FreeBSD works better with this included last ... (?)
|
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
|
|
|
# include <windows.h>
|
|
|
|
#else
|
|
|
|
# include <netinet/in.h> // htonl() ntohl()
|
|
|
|
#endif
|
2001-09-04 14:39:12 +00:00
|
|
|
|
2002-02-04 22:54:02 +00:00
|
|
|
|
|
|
|
// The function htond is defined this way due to the way some
|
|
|
|
// processors and OSes treat floating point values. Some will raise
|
|
|
|
// an exception whenever a "bad" floating point value is loaded into a
|
|
|
|
// floating point register. Solaris is notorious for this, but then
|
|
|
|
// so is LynxOS on the PowerPC. By translating the data in place,
|
|
|
|
// there is no need to load a FP register with the "corruped" floating
|
|
|
|
// point value. By doing the BIG_ENDIAN test, I can optimize the
|
|
|
|
// routine for big-endian processors so it can be as efficient as
|
|
|
|
// possible
|
|
|
|
static void htond (double &x)
|
|
|
|
{
|
|
|
|
if ( sgIsLittleEndian() ) {
|
|
|
|
int *Double_Overlay;
|
|
|
|
int Holding_Buffer;
|
|
|
|
|
|
|
|
Double_Overlay = (int *) &x;
|
|
|
|
Holding_Buffer = Double_Overlay [0];
|
|
|
|
|
|
|
|
Double_Overlay [0] = htonl (Double_Overlay [1]);
|
|
|
|
Double_Overlay [1] = htonl (Holding_Buffer);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-10 18:55:41 +00:00
|
|
|
// Float version
|
|
|
|
static void htonf (float &x)
|
|
|
|
{
|
|
|
|
if ( sgIsLittleEndian() ) {
|
|
|
|
int *Float_Overlay;
|
|
|
|
int Holding_Buffer;
|
|
|
|
|
|
|
|
Float_Overlay = (int *) &x;
|
|
|
|
Holding_Buffer = Float_Overlay [0];
|
|
|
|
|
|
|
|
Float_Overlay [0] = htonl (Holding_Buffer);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-04 22:54:02 +00:00
|
|
|
|
2001-09-04 14:39:12 +00:00
|
|
|
FGNativeFDM::FGNativeFDM() {
|
|
|
|
}
|
|
|
|
|
|
|
|
FGNativeFDM::~FGNativeFDM() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// open hailing frequencies
|
|
|
|
bool FGNativeFDM::open() {
|
|
|
|
if ( is_enabled() ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
|
|
|
|
<< "is already in use, ignoring" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGIOChannel *io = get_io_channel();
|
|
|
|
|
|
|
|
if ( ! io->open( get_direction() ) ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_enabled( true );
|
|
|
|
|
2003-05-30 20:19:56 +00:00
|
|
|
// Is this really needed here ????
|
2001-09-04 14:39:12 +00:00
|
|
|
cur_fdm_state->_set_Sea_level_radius( SG_EQUATORIAL_RADIUS_FT );
|
2003-05-30 20:19:56 +00:00
|
|
|
|
2001-09-04 14:39:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
|
2003-01-12 22:11:55 +00:00
|
|
|
int i;
|
2002-02-08 23:03:54 +00:00
|
|
|
|
2003-01-12 22:11:55 +00:00
|
|
|
// Version sanity checking
|
2002-02-04 22:54:02 +00:00
|
|
|
net->version = FG_NET_FDM_VERSION;
|
2001-10-26 05:42:08 +00:00
|
|
|
|
2003-01-12 22:11:55 +00:00
|
|
|
// Aero parameters
|
2002-02-04 22:54:02 +00:00
|
|
|
net->longitude = cur_fdm_state->get_Longitude();
|
|
|
|
net->latitude = cur_fdm_state->get_Latitude();
|
|
|
|
net->altitude = cur_fdm_state->get_Altitude() * SG_FEET_TO_METER;
|
2003-07-22 20:05:38 +00:00
|
|
|
net->agl = cur_fdm_state->get_Altitude_AGL() * SG_FEET_TO_METER;
|
2002-02-04 22:54:02 +00:00
|
|
|
net->phi = cur_fdm_state->get_Phi();
|
|
|
|
net->theta = cur_fdm_state->get_Theta();
|
|
|
|
net->psi = cur_fdm_state->get_Psi();
|
2003-11-24 21:08:44 +00:00
|
|
|
net->alpha = cur_fdm_state->get_Alpha();
|
|
|
|
net->beta = cur_fdm_state->get_Beta();
|
2003-01-12 22:11:55 +00:00
|
|
|
net->phidot = cur_fdm_state->get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
|
|
|
|
net->thetadot = cur_fdm_state->get_Theta_dot_degps()
|
|
|
|
* SG_DEGREES_TO_RADIANS;
|
|
|
|
net->psidot = cur_fdm_state->get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
|
2001-10-26 05:42:08 +00:00
|
|
|
|
2002-02-04 22:54:02 +00:00
|
|
|
net->vcas = cur_fdm_state->get_V_calibrated_kts();
|
|
|
|
net->climb_rate = cur_fdm_state->get_Climb_Rate();
|
|
|
|
|
2003-01-12 22:11:55 +00:00
|
|
|
net->v_north = cur_fdm_state->get_V_north();
|
|
|
|
net->v_east = cur_fdm_state->get_V_east();
|
|
|
|
net->v_down = cur_fdm_state->get_V_down();
|
|
|
|
net->v_wind_body_north = cur_fdm_state->get_uBody();
|
|
|
|
net->v_wind_body_east = cur_fdm_state->get_vBody();
|
|
|
|
net->v_wind_body_down = cur_fdm_state->get_wBody();
|
|
|
|
|
|
|
|
net->A_X_pilot = cur_fdm_state->get_A_X_pilot();
|
|
|
|
net->A_Y_pilot = cur_fdm_state->get_A_Y_pilot();
|
|
|
|
net->A_Z_pilot = cur_fdm_state->get_A_Z_pilot();
|
|
|
|
|
2003-11-10 22:02:38 +00:00
|
|
|
net->stall_warning = fgGetDouble("/sim/alarms/stall-warning", 0.0);
|
|
|
|
net->slip_deg
|
|
|
|
= fgGetDouble("/instrumentation/slip-skid-ball/indicated-slip-skid");
|
|
|
|
|
2003-01-12 22:11:55 +00:00
|
|
|
// Engine parameters
|
|
|
|
net->num_engines = FGNetFDM::FG_MAX_ENGINES;
|
|
|
|
for ( i = 0; i < net->num_engines; ++i ) {
|
|
|
|
SGPropertyNode *node = fgGetNode("engines/engine", i, true);
|
|
|
|
if ( node->getBoolValue( "running" ) ) {
|
2004-04-02 01:54:38 +00:00
|
|
|
net->eng_state[i] = 2;
|
2003-01-12 22:11:55 +00:00
|
|
|
} else if ( node->getBoolValue( "cranking" ) ) {
|
2004-04-02 01:54:38 +00:00
|
|
|
net->eng_state[i] = 1;
|
2003-01-12 22:11:55 +00:00
|
|
|
} else {
|
2004-04-02 01:54:38 +00:00
|
|
|
net->eng_state[i] = 0;
|
2003-01-12 22:11:55 +00:00
|
|
|
}
|
|
|
|
net->rpm[i] = node->getDoubleValue( "rpm" );
|
|
|
|
net->fuel_flow[i] = node->getDoubleValue( "fuel-flow-gph" );
|
|
|
|
net->EGT[i] = node->getDoubleValue( "egt-degf" );
|
|
|
|
// cout << "egt = " << aero->EGT << endl;
|
|
|
|
net->oil_temp[i] = node->getDoubleValue( "oil-temperature-degf" );
|
|
|
|
net->oil_px[i] = node->getDoubleValue( "oil-pressure-psi" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Consumables
|
|
|
|
net->num_tanks = FGNetFDM::FG_MAX_TANKS;
|
|
|
|
for ( i = 0; i < net->num_tanks; ++i ) {
|
|
|
|
SGPropertyNode *node = fgGetNode("/consumables/fuel/tank", i, true);
|
|
|
|
net->fuel_quantity[i] = node->getDoubleValue("level-gal_us");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gear and flaps
|
|
|
|
net->num_wheels = FGNetFDM::FG_MAX_WHEELS;
|
|
|
|
for (i = 0; i < net->num_wheels; ++i ) {
|
|
|
|
SGPropertyNode *node = fgGetNode("/gear/gear", i, true);
|
|
|
|
net->wow[i] = node->getDoubleValue("wow");
|
2003-07-22 23:46:11 +00:00
|
|
|
net->gear_pos[i] = node->getDoubleValue("position-norm");
|
|
|
|
net->gear_steer[i] = node->getDoubleValue("steering-norm");
|
|
|
|
net->gear_compression[i] = node->getDoubleValue("compression-norm");
|
2003-01-12 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// the following really aren't used in this context
|
2002-02-04 22:54:02 +00:00
|
|
|
net->cur_time = globals->get_time_params()->get_cur_time();
|
|
|
|
net->warp = globals->get_warp();
|
2003-01-12 22:11:55 +00:00
|
|
|
net->visibility = fgGetDouble("/environment/visibility-m");
|
2002-02-04 22:54:02 +00:00
|
|
|
|
2003-07-10 18:55:41 +00:00
|
|
|
// Control surface positions
|
|
|
|
SGPropertyNode *node = fgGetNode("/surface-positions", true);
|
|
|
|
net->elevator = node->getDoubleValue( "elevator-pos-norm" );
|
2004-02-17 22:46:28 +00:00
|
|
|
net->elevator_trim_tab
|
|
|
|
= node->getDoubleValue( "elevator-trim-tab-pos-norm" );
|
2003-07-10 18:55:41 +00:00
|
|
|
net->flaps = node->getDoubleValue( "flap-pos-norm" );
|
|
|
|
net->left_aileron = node->getDoubleValue( "left-aileron-pos-norm" );
|
|
|
|
net->right_aileron = node->getDoubleValue( "right-aileron-pos-norm" );
|
|
|
|
net->rudder = node->getDoubleValue( "rudder-pos-norm" );
|
2003-11-24 01:47:52 +00:00
|
|
|
net->rudder = node->getDoubleValue( "nose-wheel-pos-norm" );
|
2003-07-10 18:55:41 +00:00
|
|
|
net->speedbrake = node->getDoubleValue( "speedbrake-pos-norm" );
|
|
|
|
net->spoilers = node->getDoubleValue( "spoilers-pos-norm" );
|
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
if ( net_byte_order ) {
|
|
|
|
// Convert the net buffer to network format
|
|
|
|
net->version = htonl(net->version);
|
|
|
|
|
|
|
|
htond(net->longitude);
|
|
|
|
htond(net->latitude);
|
|
|
|
htond(net->altitude);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->agl);
|
|
|
|
htonf(net->phi);
|
|
|
|
htonf(net->theta);
|
|
|
|
htonf(net->psi);
|
2003-11-24 21:08:44 +00:00
|
|
|
htonf(net->alpha);
|
|
|
|
htonf(net->beta);
|
2003-07-10 18:55:41 +00:00
|
|
|
|
|
|
|
htonf(net->phidot);
|
|
|
|
htonf(net->thetadot);
|
|
|
|
htonf(net->psidot);
|
|
|
|
htonf(net->vcas);
|
|
|
|
htonf(net->climb_rate);
|
|
|
|
htonf(net->v_north);
|
|
|
|
htonf(net->v_east);
|
|
|
|
htonf(net->v_down);
|
|
|
|
htonf(net->v_wind_body_north);
|
|
|
|
htonf(net->v_wind_body_east);
|
|
|
|
htonf(net->v_wind_body_down);
|
|
|
|
|
|
|
|
htonf(net->A_X_pilot);
|
|
|
|
htonf(net->A_Y_pilot);
|
|
|
|
htonf(net->A_Z_pilot);
|
2003-03-03 04:35:09 +00:00
|
|
|
|
2003-11-10 22:02:38 +00:00
|
|
|
htonf(net->stall_warning);
|
|
|
|
htonf(net->slip_deg);
|
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
for ( i = 0; i < net->num_engines; ++i ) {
|
2003-08-18 11:11:08 +00:00
|
|
|
net->eng_state[i] = htonl(net->eng_state[i]);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->rpm[i]);
|
|
|
|
htonf(net->fuel_flow[i]);
|
|
|
|
htonf(net->EGT[i]);
|
|
|
|
htonf(net->oil_temp[i]);
|
|
|
|
htonf(net->oil_px[i]);
|
2003-03-03 04:35:09 +00:00
|
|
|
}
|
|
|
|
net->num_engines = htonl(net->num_engines);
|
2003-01-12 22:11:55 +00:00
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
for ( i = 0; i < net->num_tanks; ++i ) {
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->fuel_quantity[i]);
|
2003-03-03 04:35:09 +00:00
|
|
|
}
|
|
|
|
net->num_tanks = htonl(net->num_tanks);
|
2003-01-12 22:11:55 +00:00
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
for ( i = 0; i < net->num_wheels; ++i ) {
|
2003-08-18 11:11:08 +00:00
|
|
|
net->wow[i] = htonl(net->wow[i]);
|
2003-07-23 03:19:08 +00:00
|
|
|
htonf(net->gear_pos[i]);
|
|
|
|
htonf(net->gear_steer[i]);
|
|
|
|
htonf(net->gear_compression[i]);
|
2003-03-03 04:35:09 +00:00
|
|
|
}
|
|
|
|
net->num_wheels = htonl(net->num_wheels);
|
2003-01-12 22:11:55 +00:00
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
net->cur_time = htonl( net->cur_time );
|
|
|
|
net->warp = htonl( net->warp );
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->visibility);
|
|
|
|
|
|
|
|
htonf(net->elevator);
|
2004-02-17 22:46:28 +00:00
|
|
|
htonf(net->elevator_trim_tab);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->flaps);
|
|
|
|
htonf(net->left_aileron);
|
|
|
|
htonf(net->right_aileron);
|
|
|
|
htonf(net->rudder);
|
2003-11-24 01:47:52 +00:00
|
|
|
htonf(net->nose_wheel);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->speedbrake);
|
|
|
|
htonf(net->spoilers);
|
2003-01-12 22:11:55 +00:00
|
|
|
}
|
2001-09-04 14:39:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
|
2003-01-12 22:11:55 +00:00
|
|
|
int i;
|
2002-02-04 22:54:02 +00:00
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
if ( net_byte_order ) {
|
|
|
|
// Convert to the net buffer from network format
|
|
|
|
net->version = ntohl(net->version);
|
|
|
|
|
|
|
|
htond(net->longitude);
|
|
|
|
htond(net->latitude);
|
|
|
|
htond(net->altitude);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->agl);
|
|
|
|
htonf(net->phi);
|
|
|
|
htonf(net->theta);
|
|
|
|
htonf(net->psi);
|
2003-11-24 21:08:44 +00:00
|
|
|
htonf(net->alpha);
|
|
|
|
htonf(net->beta);
|
2003-07-10 18:55:41 +00:00
|
|
|
|
|
|
|
htonf(net->phidot);
|
|
|
|
htonf(net->thetadot);
|
|
|
|
htonf(net->psidot);
|
|
|
|
htonf(net->vcas);
|
|
|
|
htonf(net->climb_rate);
|
|
|
|
htonf(net->v_north);
|
|
|
|
htonf(net->v_east);
|
|
|
|
htonf(net->v_down);
|
|
|
|
htonf(net->v_wind_body_north);
|
|
|
|
htonf(net->v_wind_body_east);
|
|
|
|
htonf(net->v_wind_body_down);
|
|
|
|
|
|
|
|
htonf(net->A_X_pilot);
|
|
|
|
htonf(net->A_Y_pilot);
|
|
|
|
htonf(net->A_Z_pilot);
|
2003-03-03 04:35:09 +00:00
|
|
|
|
2003-11-10 22:02:38 +00:00
|
|
|
htonf(net->stall_warning);
|
|
|
|
htonf(net->slip_deg);
|
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
net->num_engines = htonl(net->num_engines);
|
|
|
|
for ( i = 0; i < net->num_engines; ++i ) {
|
2003-08-18 11:11:08 +00:00
|
|
|
net->eng_state[i] = htonl(net->eng_state[i]);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->rpm[i]);
|
|
|
|
htonf(net->fuel_flow[i]);
|
|
|
|
htonf(net->EGT[i]);
|
|
|
|
htonf(net->oil_temp[i]);
|
|
|
|
htonf(net->oil_px[i]);
|
2003-03-03 04:35:09 +00:00
|
|
|
}
|
2003-01-12 22:11:55 +00:00
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
net->num_tanks = htonl(net->num_tanks);
|
|
|
|
for ( i = 0; i < net->num_tanks; ++i ) {
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->fuel_quantity[i]);
|
2003-03-03 04:35:09 +00:00
|
|
|
}
|
2003-01-12 22:11:55 +00:00
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
net->num_wheels = htonl(net->num_wheels);
|
2003-07-22 23:46:11 +00:00
|
|
|
for ( i = 0; i < net->num_wheels; ++i ) {
|
2003-08-18 11:11:08 +00:00
|
|
|
net->wow[i] = htonl(net->wow[i]);
|
2003-07-23 03:19:08 +00:00
|
|
|
htonf(net->gear_pos[i]);
|
|
|
|
htonf(net->gear_steer[i]);
|
|
|
|
htonf(net->gear_compression[i]);
|
2003-07-22 23:46:11 +00:00
|
|
|
}
|
2003-01-12 22:11:55 +00:00
|
|
|
|
2003-03-03 04:35:09 +00:00
|
|
|
net->cur_time = ntohl(net->cur_time);
|
|
|
|
net->warp = ntohl(net->warp);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->visibility);
|
|
|
|
|
|
|
|
htonf(net->elevator);
|
2004-02-17 22:46:28 +00:00
|
|
|
htonf(net->elevator_trim_tab);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->flaps);
|
|
|
|
htonf(net->left_aileron);
|
|
|
|
htonf(net->right_aileron);
|
|
|
|
htonf(net->rudder);
|
2003-11-24 01:47:52 +00:00
|
|
|
htonf(net->nose_wheel);
|
2003-07-10 18:55:41 +00:00
|
|
|
htonf(net->speedbrake);
|
|
|
|
htonf(net->spoilers);
|
2003-03-03 04:35:09 +00:00
|
|
|
}
|
2002-02-04 22:54:02 +00:00
|
|
|
|
|
|
|
if ( net->version == FG_NET_FDM_VERSION ) {
|
2002-02-08 23:03:54 +00:00
|
|
|
// cout << "pos = " << net->longitude << " " << net->latitude << endl;
|
2003-01-12 22:11:55 +00:00
|
|
|
// cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius()
|
|
|
|
// << endl;
|
2002-02-08 23:03:54 +00:00
|
|
|
cur_fdm_state->_updateGeodeticPosition( net->latitude,
|
|
|
|
net->longitude,
|
|
|
|
net->altitude
|
|
|
|
* SG_METER_TO_FEET );
|
2003-07-31 01:44:40 +00:00
|
|
|
if ( net->agl > -9000 ) {
|
|
|
|
cur_fdm_state->_set_Altitude_AGL( net->agl * SG_METER_TO_FEET );
|
|
|
|
} else {
|
|
|
|
double agl_m
|
|
|
|
= net->altitude - globals->get_scenery()->get_cur_elev();
|
|
|
|
cur_fdm_state->_set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
|
|
|
|
}
|
2002-02-08 23:03:54 +00:00
|
|
|
cur_fdm_state->_set_Euler_Angles( net->phi,
|
|
|
|
net->theta,
|
|
|
|
net->psi );
|
2003-11-24 21:08:44 +00:00
|
|
|
cur_fdm_state->_set_Alpha( net->alpha );
|
|
|
|
cur_fdm_state->_set_Beta( net->beta );
|
2003-01-12 22:11:55 +00:00
|
|
|
cur_fdm_state->_set_Euler_Rates( net->phidot,
|
|
|
|
net->thetadot,
|
|
|
|
net->psidot );
|
2002-02-08 23:03:54 +00:00
|
|
|
cur_fdm_state->_set_V_calibrated_kts( net->vcas );
|
|
|
|
cur_fdm_state->_set_Climb_Rate( net->climb_rate );
|
2003-01-12 22:11:55 +00:00
|
|
|
cur_fdm_state->_set_Velocities_Local( net->v_north,
|
|
|
|
net->v_east,
|
|
|
|
net->v_down );
|
|
|
|
cur_fdm_state->_set_Velocities_Wind_Body( net->v_wind_body_north,
|
|
|
|
net->v_wind_body_east,
|
|
|
|
net->v_wind_body_down );
|
|
|
|
|
|
|
|
cur_fdm_state->_set_Accels_Pilot_Body( net->A_X_pilot,
|
|
|
|
net->A_Y_pilot,
|
|
|
|
net->A_Z_pilot );
|
|
|
|
|
2003-11-10 22:02:38 +00:00
|
|
|
fgSetDouble( "/sim/alarms/stall-warning", net->stall_warning );
|
|
|
|
fgSetDouble( "/instrumentation/slip-skid-ball/indicated-slip-skid",
|
|
|
|
net->slip_deg );
|
|
|
|
fgSetBool( "/instrumentation/slip-skid-ball/override", true );
|
|
|
|
|
2003-01-12 22:11:55 +00:00
|
|
|
for ( i = 0; i < net->num_engines; ++i ) {
|
|
|
|
SGPropertyNode *node = fgGetNode( "engines/engine", i, true );
|
|
|
|
|
|
|
|
// node->setBoolValue("running", t->isRunning());
|
|
|
|
// node->setBoolValue("cranking", t->isCranking());
|
|
|
|
|
|
|
|
// cout << net->eng_state[i] << endl;
|
|
|
|
if ( net->eng_state[i] == 0 ) {
|
|
|
|
node->setBoolValue( "cranking", false );
|
|
|
|
node->setBoolValue( "running", false );
|
|
|
|
} else if ( net->eng_state[i] == 1 ) {
|
|
|
|
node->setBoolValue( "cranking", true );
|
|
|
|
node->setBoolValue( "running", false );
|
|
|
|
} else if ( net->eng_state[i] == 2 ) {
|
|
|
|
node->setBoolValue( "cranking", false );
|
|
|
|
node->setBoolValue( "running", true );
|
|
|
|
}
|
2002-02-04 22:54:02 +00:00
|
|
|
|
2003-01-12 22:11:55 +00:00
|
|
|
node->setDoubleValue( "rpm", net->rpm[i] );
|
|
|
|
node->setDoubleValue( "fuel-flow-gph", net->fuel_flow[i] );
|
|
|
|
node->setDoubleValue( "egt-degf", net->EGT[i] );
|
|
|
|
node->setDoubleValue( "oil-temperature-degf", net->oil_temp[i] );
|
|
|
|
node->setDoubleValue( "oil-pressure-psi", net->oil_px[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < net->num_tanks; ++i ) {
|
|
|
|
SGPropertyNode * node
|
|
|
|
= fgGetNode("/consumables/fuel/tank", i, true);
|
|
|
|
node->setDoubleValue("level-gal_us", net->fuel_quantity[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < net->num_wheels; ++i ) {
|
2003-07-22 23:46:11 +00:00
|
|
|
SGPropertyNode * node = fgGetNode("/gear/gear", i, true);
|
2003-01-12 22:11:55 +00:00
|
|
|
node->setDoubleValue("wow", net->wow[i] );
|
2003-07-22 23:46:11 +00:00
|
|
|
node->setDoubleValue("position-norm", net->gear_pos[i] );
|
|
|
|
node->setDoubleValue("steering-norm", net->gear_steer[i] );
|
|
|
|
node->setDoubleValue("compression-norm", net->gear_compression[i] );
|
2003-01-12 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* these are ignored for now ... */
|
|
|
|
/*
|
2002-02-13 17:43:01 +00:00
|
|
|
if ( net->cur_time ) {
|
2002-02-10 04:18:10 +00:00
|
|
|
fgSetLong("/sim/time/cur-time-override", net->cur_time);
|
|
|
|
}
|
|
|
|
|
2002-02-04 22:54:02 +00:00
|
|
|
globals->set_warp( net->warp );
|
2002-02-08 23:03:54 +00:00
|
|
|
last_warp = net->warp;
|
2003-01-12 22:11:55 +00:00
|
|
|
*/
|
2003-07-10 18:55:41 +00:00
|
|
|
|
|
|
|
SGPropertyNode *node = fgGetNode("/surface-positions", true);
|
|
|
|
node->setDoubleValue("elevator-pos-norm", net->elevator);
|
2004-02-17 22:46:28 +00:00
|
|
|
node->setDoubleValue("elevator-trim-tab-pos-norm",
|
|
|
|
net->elevator_trim_tab);
|
2003-07-10 18:55:41 +00:00
|
|
|
node->setDoubleValue("flap-pos-norm", net->flaps);
|
|
|
|
node->setDoubleValue("left-aileron-pos-norm", net->left_aileron);
|
|
|
|
node->setDoubleValue("right-aileron-pos-norm", net->right_aileron);
|
|
|
|
node->setDoubleValue("rudder-pos-norm", net->rudder);
|
2003-11-24 01:47:52 +00:00
|
|
|
node->setDoubleValue("nose-wheel-pos-norm", net->nose_wheel);
|
2003-07-10 18:55:41 +00:00
|
|
|
node->setDoubleValue("speedbrake-pos-norm", net->speedbrake);
|
|
|
|
node->setDoubleValue("spoilers-pos-norm", net->spoilers);
|
2001-09-04 14:39:12 +00:00
|
|
|
} else {
|
2003-01-12 23:28:21 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT,
|
|
|
|
"Error: version mismatch in FGNetFDM2Props()" );
|
2002-02-08 23:03:54 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT,
|
|
|
|
"\tread " << net->version << " need " << FG_NET_FDM_VERSION );
|
2001-09-04 14:39:12 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT,
|
2003-01-12 23:28:21 +00:00
|
|
|
"\tNeeds to upgrade net_fdm.hxx and recompile." );
|
2001-09-04 14:39:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// process work for this port
|
|
|
|
bool FGNativeFDM::process() {
|
|
|
|
SGIOChannel *io = get_io_channel();
|
|
|
|
int length = sizeof(buf);
|
|
|
|
|
|
|
|
if ( get_direction() == SG_IO_OUT ) {
|
|
|
|
// cout << "size of cur_fdm_state = " << length << endl;
|
2003-01-12 22:11:55 +00:00
|
|
|
FGProps2NetFDM( &buf );
|
2001-09-04 14:39:12 +00:00
|
|
|
if ( ! io->write( (char *)(& buf), length ) ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if ( get_direction() == SG_IO_IN ) {
|
|
|
|
if ( io->get_type() == sgFileType ) {
|
|
|
|
if ( io->read( (char *)(& buf), length ) == length ) {
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
|
2003-01-12 22:11:55 +00:00
|
|
|
FGNetFDM2Props( &buf );
|
2001-09-04 14:39:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-05-27 19:15:58 +00:00
|
|
|
int result;
|
|
|
|
result = io->read( (char *)(& buf), length );
|
2003-06-02 16:35:36 +00:00
|
|
|
while ( result == length ) {
|
2003-05-27 19:15:58 +00:00
|
|
|
if ( result == length ) {
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, " Success reading data." );
|
|
|
|
FGNetFDM2Props( &buf );
|
|
|
|
}
|
2003-06-02 16:35:36 +00:00
|
|
|
result = io->read( (char *)(& buf), length );
|
2001-09-04 14:39:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// close the channel
|
|
|
|
bool FGNativeFDM::close() {
|
|
|
|
SGIOChannel *io = get_io_channel();
|
|
|
|
|
|
|
|
set_enabled( false );
|
|
|
|
|
|
|
|
if ( ! io->close() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|