net_fdm.hxx.
}
-static void global2raw( FGRawCtrls *raw ) {
+static void global2net( FGNetCtrls *net ) {
int i;
// fill in values
SGPropertyNode * node = fgGetNode("/controls", true);
- raw->version = FG_RAW_CTRLS_VERSION;
- raw->aileron = node->getDoubleValue( "aileron" );
- raw->elevator = node->getDoubleValue( "elevator" );
- raw->elevator_trim = node->getDoubleValue( "elevator-trim" );
- raw->rudder = node->getDoubleValue( "rudder" );
- raw->flaps = node->getDoubleValue( "flaps" );
- raw->flaps_power
+ net->version = FG_NET_CTRLS_VERSION;
+ net->aileron = node->getDoubleValue( "aileron" );
+ net->elevator = node->getDoubleValue( "elevator" );
+ net->elevator_trim = node->getDoubleValue( "elevator-trim" );
+ net->rudder = node->getDoubleValue( "rudder" );
+ net->flaps = node->getDoubleValue( "flaps" );
+ net->flaps_power
= node->getDoubleValue( "/systems/electrical/outputs/flaps",
1.0 ) >= 1.0;
- raw->num_engines = FGRawCtrls::FG_MAX_ENGINES;
- for ( i = 0; i < FGRawCtrls::FG_MAX_ENGINES; ++i ) {
- raw->throttle[i] = node->getDoubleValue( "throttle", 0.0 );
- raw->mixture[i] = node->getDoubleValue( "mixture", 0.0 );
- raw->fuel_pump_power[i]
+ net->num_engines = FGNetCtrls::FG_MAX_ENGINES;
+ for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
+ net->throttle[i] = node->getDoubleValue( "throttle", 0.0 );
+ net->mixture[i] = node->getDoubleValue( "mixture", 0.0 );
+ net->fuel_pump_power[i]
= node->getDoubleValue( "/systems/electrical/outputs/fuel-pump",
1.0 ) >= 1.0;
- raw->prop_advance[i] = node->getDoubleValue( "propeller-pitch", 0.0 );
- raw->magnetos[i] = node->getIntValue( "magnetos", 0 );
+ net->prop_advance[i] = node->getDoubleValue( "propeller-pitch", 0.0 );
+ net->magnetos[i] = node->getIntValue( "magnetos", 0 );
if ( i == 0 ) {
// cout << "Magnetos -> " << node->getIntValue( "magnetos", 0 );
}
- raw->starter_power[i]
+ net->starter_power[i]
= node->getDoubleValue( "/systems/electrical/outputs/starter",
1.0 ) >= 1.0;
if ( i == 0 ) {
// << endl;
}
}
- raw->num_tanks = FGRawCtrls::FG_MAX_TANKS;
- for ( i = 0; i < FGRawCtrls::FG_MAX_TANKS; ++i ) {
+ net->num_tanks = FGNetCtrls::FG_MAX_TANKS;
+ for ( i = 0; i < FGNetCtrls::FG_MAX_TANKS; ++i ) {
if ( node->getChild("fuel-selector", i) != 0 ) {
- raw->fuel_selector[i]
+ net->fuel_selector[i]
= node->getChild("fuel-selector", i)->getDoubleValue();
} else {
- raw->fuel_selector[i] = false;
+ net->fuel_selector[i] = false;
}
}
- raw->num_wheels = FGRawCtrls::FG_MAX_WHEELS;
- for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) {
+ net->num_wheels = FGNetCtrls::FG_MAX_WHEELS;
+ for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
if ( node->getChild("brakes", i) != 0 ) {
- raw->brake[i]
+ net->brake[i]
= node->getChild("brakes", i)->getDoubleValue();
} else {
- raw->brake[i] = 0.0;
+ net->brake[i] = 0.0;
}
}
node = fgGetNode("/controls/switches", true);
- raw->master_bat = node->getChild("master-bat")->getBoolValue();
- raw->master_alt = node->getChild("master-alt")->getBoolValue();
- raw->master_avionics = node->getChild("master-avionics")->getBoolValue();
+ net->master_bat = node->getChild("master-bat")->getBoolValue();
+ net->master_alt = node->getChild("master-alt")->getBoolValue();
+ net->master_avionics = node->getChild("master-avionics")->getBoolValue();
// cur_fdm_state->get_ground_elev_ft() is what we want ... this
// reports the altitude of the aircraft.
// "/environment/ground-elevation-m" reports the ground elevation
// of the current view point which could change substantially if
// the user is switching views.
- raw->hground = cur_fdm_state->get_ground_elev_ft() * SG_FEET_TO_METER;
- raw->magvar = fgGetDouble("/environment/magnetic-variation-deg");
- raw->speedup = fgGetInt("/sim/speed-up");
+ net->hground = cur_fdm_state->get_ground_elev_ft() * SG_FEET_TO_METER;
+ net->magvar = fgGetDouble("/environment/magnetic-variation-deg");
+ net->speedup = fgGetInt("/sim/speed-up");
// convert to network byte order
- raw->version = htonl(raw->version);
- htond(raw->aileron);
- htond(raw->elevator);
- htond(raw->elevator_trim);
- htond(raw->rudder);
- htond(raw->flaps);
- raw->flaps_power = htonl(raw->flaps_power);
- for ( i = 0; i < FGRawCtrls::FG_MAX_ENGINES; ++i ) {
- htond(raw->throttle[i]);
- htond(raw->mixture[i]);
- raw->fuel_pump_power[i] = htonl(raw->fuel_pump_power[i]);
- htond(raw->prop_advance[i]);
- raw->magnetos[i] = htonl(raw->magnetos[i]);
- raw->starter_power[i] = htonl(raw->starter_power[i]);
+ net->version = htonl(net->version);
+ htond(net->aileron);
+ htond(net->elevator);
+ htond(net->elevator_trim);
+ htond(net->rudder);
+ htond(net->flaps);
+ net->flaps_power = htonl(net->flaps_power);
+ for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
+ htond(net->throttle[i]);
+ htond(net->mixture[i]);
+ net->fuel_pump_power[i] = htonl(net->fuel_pump_power[i]);
+ htond(net->prop_advance[i]);
+ net->magnetos[i] = htonl(net->magnetos[i]);
+ net->starter_power[i] = htonl(net->starter_power[i]);
}
- raw->num_engines = htonl(raw->num_engines);
- for ( i = 0; i < FGRawCtrls::FG_MAX_TANKS; ++i ) {
- raw->fuel_selector[i] = htonl(raw->fuel_selector[i]);
+ net->num_engines = htonl(net->num_engines);
+ for ( i = 0; i < FGNetCtrls::FG_MAX_TANKS; ++i ) {
+ net->fuel_selector[i] = htonl(net->fuel_selector[i]);
}
- raw->num_tanks = htonl(raw->num_tanks);
- for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) {
- htond(raw->brake[i]);
+ net->num_tanks = htonl(net->num_tanks);
+ for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
+ htond(net->brake[i]);
}
- raw->num_wheels = htonl(raw->num_wheels);
- raw->gear_handle = htonl(raw->gear_handle);
- raw->master_bat = htonl(raw->master_bat);
- raw->master_alt = htonl(raw->master_alt);
- raw->master_avionics = htonl(raw->master_avionics);
- htond(raw->hground);
- htond(raw->magvar);
- raw->speedup = htonl(raw->speedup);
+ net->num_wheels = htonl(net->num_wheels);
+ net->gear_handle = htonl(net->gear_handle);
+ net->master_bat = htonl(net->master_bat);
+ net->master_alt = htonl(net->master_alt);
+ net->master_avionics = htonl(net->master_avionics);
+ htond(net->hground);
+ htond(net->magvar);
+ net->speedup = htonl(net->speedup);
}
// Send control positions to remote fdm
length = sizeof(ctrls);
- global2raw( &ctrls );
+ global2net( &ctrls );
if ( data_client.send( (char *)(& ctrls), length, 0 ) != length ) {
SG_LOG( SG_IO, SG_DEBUG, "Error writing data." );
} else {
#include <plib/netBuffer.h>
#include <plib/netSocket.h>
-#include <Network/raw_ctrls.hxx>
+#include <Network/net_ctrls.hxx>
#include <Network/net_fdm.hxx>
#include <FDM/flight.hxx>
bool valid;
- FGRawCtrls ctrls;
+ FGNetCtrls ctrls;
FGNetFDM fdm;
public:
native.cxx native.hxx \
native_ctrls.cxx native_ctrls.hxx \
native_fdm.cxx native_fdm.hxx \
- net_fdm.hxx \
+ net_ctrls.hxx net_fdm.hxx \
nmea.cxx nmea.hxx \
opengc.cxx opengc.hxx opengc_data.hxx \
props.cxx props.hxx \
pve.cxx pve.hxx \
- raw_ctrls.hxx \
ray.cxx ray.hxx \
rul.cxx rul.hxx
}
-static void global2raw( const FGControls *global, FGRawCtrls *raw ) {
+static void global2net( const FGControls *global, FGNetCtrls *net ) {
int i;
- raw->version = FG_RAW_CTRLS_VERSION;
- raw->aileron = globals->get_controls()->get_aileron();
- raw->elevator = globals->get_controls()->get_elevator();
- raw->elevator_trim = globals->get_controls()->get_elevator_trim();
- raw->rudder = globals->get_controls()->get_rudder();
- raw->flaps = globals->get_controls()->get_flaps();
- for ( i = 0; i < FGRawCtrls::FG_MAX_ENGINES; ++i ) {
- raw->throttle[i] = globals->get_controls()->get_throttle(i);
- raw->mixture[i] = globals->get_controls()->get_mixture(i);
- raw->prop_advance[i] = globals->get_controls()->get_prop_advance(i);
+ net->version = FG_NET_CTRLS_VERSION;
+ net->aileron = globals->get_controls()->get_aileron();
+ net->elevator = globals->get_controls()->get_elevator();
+ net->elevator_trim = globals->get_controls()->get_elevator_trim();
+ net->rudder = globals->get_controls()->get_rudder();
+ net->flaps = globals->get_controls()->get_flaps();
+ for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
+ net->throttle[i] = globals->get_controls()->get_throttle(i);
+ net->mixture[i] = globals->get_controls()->get_mixture(i);
+ net->prop_advance[i] = globals->get_controls()->get_prop_advance(i);
}
- for ( i = 0; i < FGRawCtrls::FG_MAX_TANKS; ++i ) {
- raw->fuel_selector[i] = globals->get_controls()->get_fuel_selector(i);
+ for ( i = 0; i < FGNetCtrls::FG_MAX_TANKS; ++i ) {
+ net->fuel_selector[i] = globals->get_controls()->get_fuel_selector(i);
}
- for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) {
- raw->brake[i] = globals->get_controls()->get_brake(i);
+ for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
+ net->brake[i] = globals->get_controls()->get_brake(i);
}
- raw->hground = globals->get_scenery()->get_cur_elev();
+ net->hground = globals->get_scenery()->get_cur_elev();
}
-static void raw2global( const FGRawCtrls *raw, FGControls *global ) {
+static void net2global( const FGNetCtrls *net, FGControls *global ) {
int i;
- if ( raw->version == FG_RAW_CTRLS_VERSION ) {
- globals->get_controls()->set_aileron( raw->aileron );
- globals->get_controls()->set_elevator( raw->elevator );
- globals->get_controls()->set_elevator_trim( raw->elevator_trim );
- globals->get_controls()->set_rudder( raw->rudder );
- globals->get_controls()->set_flaps( raw->flaps );
- for ( i = 0; i < FGRawCtrls::FG_MAX_ENGINES; ++i ) {
- globals->get_controls()->set_throttle( i, raw->throttle[i] );
- globals->get_controls()->set_mixture( i, raw->mixture[i] );
- globals->get_controls()->set_prop_advance( i, raw->prop_advance[i]);
+ if ( net->version == FG_NET_CTRLS_VERSION ) {
+ globals->get_controls()->set_aileron( net->aileron );
+ globals->get_controls()->set_elevator( net->elevator );
+ globals->get_controls()->set_elevator_trim( net->elevator_trim );
+ globals->get_controls()->set_rudder( net->rudder );
+ globals->get_controls()->set_flaps( net->flaps );
+ for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
+ globals->get_controls()->set_throttle( i, net->throttle[i] );
+ globals->get_controls()->set_mixture( i, net->mixture[i] );
+ globals->get_controls()->set_prop_advance( i, net->prop_advance[i]);
}
- for ( i = 0; i < FGRawCtrls::FG_MAX_TANKS; ++i ) {
- globals->get_controls()->set_fuel_selector( i, raw->fuel_selector[i] );
+ for ( i = 0; i < FGNetCtrls::FG_MAX_TANKS; ++i ) {
+ globals->get_controls()->set_fuel_selector( i, net->fuel_selector[i] );
}
- for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) {
- globals->get_controls()->set_brake( i, raw->brake[i] );
+ for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
+ globals->get_controls()->set_brake( i, net->brake[i] );
}
- globals->get_controls()->set_gear_down( raw->gear_handle );
- globals->get_scenery()->set_cur_elev( raw->hground );
+ globals->get_controls()->set_gear_down( net->gear_handle );
+ globals->get_scenery()->set_cur_elev( net->hground );
} else {
- SG_LOG( SG_IO, SG_ALERT, "Error: version mismatch in raw2global()" );
+ SG_LOG( SG_IO, SG_ALERT, "Error: version mismatch in net2global()" );
SG_LOG( SG_IO, SG_ALERT,
- "\tsomeone needs to upgrade raw_ctrls.hxx and recompile." );
+ "\tsomeone needs to upgrade net_ctrls.hxx and recompile." );
}
}
// process work for this port
bool FGNativeCtrls::process() {
SGIOChannel *io = get_io_channel();
- int length = sizeof(FGRawCtrls);
+ int length = sizeof(FGNetCtrls);
if ( get_direction() == SG_IO_OUT ) {
// cout << "size of cur_fdm_state = " << length << endl;
- global2raw( globals->get_controls(), &raw_ctrls );
+ global2net( globals->get_controls(), &net_ctrls );
- if ( ! io->write( (char *)(& raw_ctrls), length ) ) {
+ if ( ! io->write( (char *)(& net_ctrls), 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 *)(& raw_ctrls), length ) == length ) {
+ if ( io->read( (char *)(& net_ctrls), length ) == length ) {
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
- raw2global( &raw_ctrls, globals->get_controls() );
+ net2global( &net_ctrls, globals->get_controls() );
}
} else {
- while ( io->read( (char *)(& raw_ctrls), length ) == length ) {
+ while ( io->read( (char *)(& net_ctrls), length ) == length ) {
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
- raw2global( &raw_ctrls, globals->get_controls() );
+ net2global( &net_ctrls, globals->get_controls() );
}
}
}
#include <Controls/controls.hxx>
#include "protocol.hxx"
-#include "raw_ctrls.hxx"
+#include "net_ctrls.hxx"
SG_USING_STD(string);
class FGNativeCtrls : public FGProtocol {
- FGRawCtrls raw_ctrls;
+ FGNetCtrls net_ctrls;
FGControls ctrls;
int length;
--- /dev/null
+// net_ctrls.hxx -- defines a common net I/O interface to the flight
+// sim controls
+//
+// Written by Curtis Olson, started July 2001.
+//
+// Copyright (C) 2001 Curtis L. Olson - curt@flightgear.com
+//
+// 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$
+
+
+#ifndef _NET_CTRLS_HXX
+#define _NET_CTRLS_HXX
+
+
+#ifndef __cplusplus
+# error This library requires C++
+#endif
+
+const int FG_NET_CTRLS_VERSION = 11;
+
+
+// Define a structure containing the control parameters
+
+class FGNetCtrls {
+
+public:
+
+ int version; // increment when data values change
+
+ enum {
+ FG_MAX_ENGINES = 4,
+ FG_MAX_WHEELS = 3,
+ FG_MAX_TANKS = 4
+ };
+
+ // Aero controls
+ double aileron; // -1 ... 1
+ double elevator; // -1 ... 1
+ double elevator_trim; // -1 ... 1
+ double rudder; // -1 ... 1
+ double flaps; // 0 ... 1
+ bool flaps_power; // true = power available
+
+ // Engine controls
+ int num_engines; // number of valid engines
+ int magnetos[FG_MAX_ENGINES];
+ bool starter_power[FG_MAX_ENGINES]; // true = starter power
+ double throttle[FG_MAX_ENGINES]; // 0 ... 1
+ double mixture[FG_MAX_ENGINES]; // 0 ... 1
+ bool fuel_pump_power[FG_MAX_ENGINES];// true = on
+ double prop_advance[FG_MAX_ENGINES]; // 0 ... 1
+
+ // Fuel management
+ int num_tanks; // number of valid tanks
+ bool fuel_selector[FG_MAX_TANKS]; // false = off, true = on
+
+ // Brake controls
+ int num_wheels; // number of valid wheels
+ double brake[FG_MAX_WHEELS]; // 0 ... 1
+
+ // Landing Gear
+ bool gear_handle; // true=gear handle down; false= gear handle up
+
+ // Switches
+ bool master_bat;
+ bool master_alt;
+ bool master_avionics;
+
+ // Other values of use to a remote FDM
+ double hground; // ground elevation (meters)
+ double magvar; // local magnetic variation in degrees.
+ int speedup; // integer speedup multiplier
+};
+
+
+#endif // _NET_CTRLS_HXX
+
+
+++ /dev/null
-// raw_ctrls.hxx -- defines a common raw I/O interface to the flight
-// sim controls
-//
-// Written by Curtis Olson, started July 2001.
-//
-// Copyright (C) 2001 Curtis L. Olson - curt@flightgear.com
-//
-// 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$
-
-
-#ifndef _RAW_CTRLS_HXX
-#define _RAW_CTRLS_HXX
-
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-const int FG_RAW_CTRLS_VERSION = 11;
-
-
-// Define a structure containing the control parameters
-
-class FGRawCtrls {
-
-public:
-
- int version; // increment when data values change
-
- enum {
- FG_MAX_ENGINES = 4,
- FG_MAX_WHEELS = 3,
- FG_MAX_TANKS = 4
- };
-
- // Aero controls
- double aileron; // -1 ... 1
- double elevator; // -1 ... 1
- double elevator_trim; // -1 ... 1
- double rudder; // -1 ... 1
- double flaps; // 0 ... 1
- bool flaps_power; // true = power available
-
- // Engine controls
- int num_engines; // number of valid engines
- int magnetos[FG_MAX_ENGINES];
- bool starter_power[FG_MAX_ENGINES]; // true = starter power
- double throttle[FG_MAX_ENGINES]; // 0 ... 1
- double mixture[FG_MAX_ENGINES]; // 0 ... 1
- bool fuel_pump_power[FG_MAX_ENGINES];// true = on
- double prop_advance[FG_MAX_ENGINES]; // 0 ... 1
-
- // Fuel management
- int num_tanks; // number of valid tanks
- bool fuel_selector[FG_MAX_TANKS]; // false = off, true = on
-
- // Brake controls
- int num_wheels; // number of valid wheels
- double brake[FG_MAX_WHEELS]; // 0 ... 1
-
- // Landing Gear
- bool gear_handle; // true=gear handle down; false= gear handle up
-
- // Switches
- bool master_bat;
- bool master_alt;
- bool master_avionics;
-
- // Other values of use to a remote FDM
- double hground; // ground elevation (meters)
- double magvar; // local magnetic variation in degrees.
- int speedup; // integer speedup multiplier
-};
-
-
-#endif // _RAW_CTRLS_HXX
-
-