tempnode = fgGetNode("/controls/gear", true);
for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
node = fgGetNode("/controls/gear/wheel", i);
- if ( node->getChild("brake") != 0 ) {
+ if ( node->getChild("brake") != NULL ) {
if ( tempnode->getChild("parking-brake")->getDoubleValue() > 0.0 ) {
net->brake[i] = 1.0;
} else {
}
node = fgGetNode("/controls/switches", true);
- net->master_bat = node->getChild("master-bat")->getBoolValue();
- net->master_alt = node->getChild("master-alt")->getBoolValue();
- net->master_avionics = node->getChild("master-avionics")->getBoolValue();
+ tempnode = node->getChild("master-bat");
+ if ( tempnode != NULL ) {
+ net->master_bat = tempnode->getBoolValue();
+ }
+ tempnode = node->getChild("master-alt");
+ if ( tempnode != NULL ) {
+ net->master_alt = tempnode->getBoolValue();
+ }
+ tempnode = node->getChild("master-avionics");
+ if ( tempnode != NULL ) {
+ net->master_avionics = tempnode->getBoolValue();
+ }
net->wind_speed_kt = fgGetDouble("/environment/wind-speed-kt");
net->wind_dir_deg = fgGetDouble("/environment/wind-from-heading-deg");
}
}
+// 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;
+ }
+}
+
FGNativeFDM::FGNativeFDM() {
}
net->wow[i] = node->getDoubleValue("wow");
}
- // cout << "Flap deflection = " << aero->dflap << endl;
- net->flap_deflection = fgGetDouble("/surface-positions/flap-pos-norm" );
-
// the following really aren't used in this context
net->cur_time = globals->get_time_params()->get_cur_time();
net->warp = globals->get_warp();
net->visibility = fgGetDouble("/environment/visibility-m");
+ // Control surface positions
+ SGPropertyNode *node = fgGetNode("/surface-positions", true);
+ net->elevator = node->getDoubleValue( "elevator-pos-norm" );
+ 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" );
+ net->speedbrake = node->getDoubleValue( "speedbrake-pos-norm" );
+ net->spoilers = node->getDoubleValue( "spoilers-pos-norm" );
+
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);
- htond(net->phi);
- htond(net->theta);
- htond(net->psi);
-
- htond(net->phidot);
- htond(net->thetadot);
- htond(net->psidot);
- htond(net->vcas);
- htond(net->climb_rate);
- htond(net->v_north);
- htond(net->v_east);
- htond(net->v_down);
- htond(net->v_wind_body_north);
- htond(net->v_wind_body_east);
- htond(net->v_wind_body_down);
- htond(net->stall_warning);
-
- htond(net->A_X_pilot);
- htond(net->A_Y_pilot);
- htond(net->A_Z_pilot);
+ htonf(net->agl);
+ htonf(net->phi);
+ htonf(net->theta);
+ htonf(net->psi);
+
+ 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->stall_warning);
+
+ htonf(net->A_X_pilot);
+ htonf(net->A_Y_pilot);
+ htonf(net->A_Z_pilot);
for ( i = 0; i < net->num_engines; ++i ) {
htonl(net->eng_state[i]);
- htond(net->rpm[i]);
- htond(net->fuel_flow[i]);
- htond(net->EGT[i]);
- htond(net->oil_temp[i]);
- htond(net->oil_px[i]);
+ htonf(net->rpm[i]);
+ htonf(net->fuel_flow[i]);
+ htonf(net->EGT[i]);
+ htonf(net->oil_temp[i]);
+ htonf(net->oil_px[i]);
}
net->num_engines = htonl(net->num_engines);
for ( i = 0; i < net->num_tanks; ++i ) {
- htond(net->fuel_quantity[i]);
+ htonf(net->fuel_quantity[i]);
}
net->num_tanks = htonl(net->num_tanks);
net->wow[i] = htonl(net->wow[i]);
}
net->num_wheels = htonl(net->num_wheels);
- htond(net->flap_deflection);
net->cur_time = htonl( net->cur_time );
net->warp = htonl( net->warp );
- htond(net->visibility);
+ htonf(net->visibility);
+
+ htonf(net->elevator);
+ htonf(net->flaps);
+ htonf(net->left_aileron);
+ htonf(net->right_aileron);
+ htonf(net->rudder);
+ htonf(net->speedbrake);
+ htonf(net->spoilers);
}
}
htond(net->longitude);
htond(net->latitude);
htond(net->altitude);
- htond(net->phi);
- htond(net->theta);
- htond(net->psi);
-
- htond(net->phidot);
- htond(net->thetadot);
- htond(net->psidot);
- htond(net->vcas);
- htond(net->climb_rate);
- htond(net->v_north);
- htond(net->v_east);
- htond(net->v_down);
- htond(net->v_wind_body_north);
- htond(net->v_wind_body_east);
- htond(net->v_wind_body_down);
- htond(net->stall_warning);
-
- htond(net->A_X_pilot);
- htond(net->A_Y_pilot);
- htond(net->A_Z_pilot);
+ htonf(net->agl);
+ htonf(net->phi);
+ htonf(net->theta);
+ htonf(net->psi);
+
+ 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->stall_warning);
+
+ htonf(net->A_X_pilot);
+ htonf(net->A_Y_pilot);
+ htonf(net->A_Z_pilot);
net->num_engines = htonl(net->num_engines);
for ( i = 0; i < net->num_engines; ++i ) {
htonl(net->eng_state[i]);
- htond(net->rpm[i]);
- htond(net->fuel_flow[i]);
- htond(net->EGT[i]);
- htond(net->oil_temp[i]);
- htond(net->oil_px[i]);
+ htonf(net->rpm[i]);
+ htonf(net->fuel_flow[i]);
+ htonf(net->EGT[i]);
+ htonf(net->oil_temp[i]);
+ htonf(net->oil_px[i]);
}
net->num_tanks = htonl(net->num_tanks);
for ( i = 0; i < net->num_tanks; ++i ) {
- htond(net->fuel_quantity[i]);
+ htonf(net->fuel_quantity[i]);
}
net->num_wheels = htonl(net->num_wheels);
// I don't need to convert the Wow flags, since they are one
// byte in size
- htond(net->flap_deflection);
net->cur_time = ntohl(net->cur_time);
net->warp = ntohl(net->warp);
- htond(net->visibility);
+ htonf(net->visibility);
+
+ htonf(net->elevator);
+ htonf(net->flaps);
+ htonf(net->left_aileron);
+ htonf(net->right_aileron);
+ htonf(net->rudder);
+ htonf(net->speedbrake);
+ htonf(net->spoilers);
}
if ( net->version == FG_NET_FDM_VERSION ) {
node->setDoubleValue("wow", net->wow[i] );
}
- fgSetDouble("/surface-positions/flap-pos-norm", net->flap_deflection);
- SGPropertyNode * node = fgGetNode("/controls", true);
- fgSetDouble("/surface-positions/elevator-pos-norm",
- node->getDoubleValue( "elevator" ));
- fgSetDouble("/surface-positions/rudder-pos-norm",
- node->getDoubleValue( "rudder" ));
- fgSetDouble("/surface-positions/left-aileron-pos-norm",
- node->getDoubleValue( "aileron" ));
- fgSetDouble("/surface-positions/right-aileron-pos-norm",
- -node->getDoubleValue( "aileron" ));
-
/* these are ignored for now ... */
/*
if ( net->cur_time ) {
globals->set_warp( net->warp );
last_warp = net->warp;
*/
+
+ SGPropertyNode *node = fgGetNode("/surface-positions", true);
+ node->setDoubleValue("elevator-pos-norm", net->elevator);
+ 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);
+ node->setDoubleValue("speedbrake-pos-norm", net->speedbrake);
+ node->setDoubleValue("spoilers-pos-norm", net->spoilers);
} else {
SG_LOG( SG_IO, SG_ALERT,
"Error: version mismatch in FGNetFDM2Props()" );
#include <time.h> // time_t
-const int FG_NET_FDM_VERSION = 11;
+const int FG_NET_FDM_VERSION = 12;
// Define a structure containing the top level flight dynamics model
double longitude; // geodetic (radians)
double latitude; // geodetic (radians)
double altitude; // above sea level (meters)
- double agl; // above ground level (meters)
- double phi; // roll (radians)
- double theta; // pitch (radians)
- double psi; // yaw or true heading (radians)
+ float agl; // above ground level (meters)
+ float phi; // roll (radians)
+ float theta; // pitch (radians)
+ float psi; // yaw or true heading (radians)
// Velocities
- double phidot; // roll rate (radians/sec)
- double thetadot; // pitch rate (radians/sec)
- double psidot; // yaw rate (radians/sec)
- double vcas; // calibrated airspeed
- double climb_rate; // feet per second
- double v_north; // north velocity in local/body frame, fps
- double v_east; // east velocity in local/body frame, fps
- double v_down; // down/vertical velocity in local/body frame, fps
- double v_wind_body_north; // north velocity in local/body frame
+ float phidot; // roll rate (radians/sec)
+ float thetadot; // pitch rate (radians/sec)
+ float psidot; // yaw rate (radians/sec)
+ float vcas; // calibrated airspeed
+ float climb_rate; // feet per second
+ float v_north; // north velocity in local/body frame, fps
+ float v_east; // east velocity in local/body frame, fps
+ float v_down; // down/vertical velocity in local/body frame, fps
+ float v_wind_body_north; // north velocity in local/body frame
// relative to local airmass, fps
- double v_wind_body_east; // east velocity in local/body frame
+ float v_wind_body_east; // east velocity in local/body frame
// relative to local airmass, fps
- double v_wind_body_down; // down/vertical velocity in local/body
+ float v_wind_body_down; // down/vertical velocity in local/body
// frame relative to local airmass, fps
// Stall
- double stall_warning; // 0.0 - 1.0 indicating the amount of stall
+ float stall_warning; // 0.0 - 1.0 indicating the amount of stall
// Accelerations
- double A_X_pilot; // X accel in body frame ft/sec^2
- double A_Y_pilot; // Y accel in body frame ft/sec^2
- double A_Z_pilot; // Z accel in body frame ft/sec^2
+ float A_X_pilot; // X accel in body frame ft/sec^2
+ float A_Y_pilot; // Y accel in body frame ft/sec^2
+ float A_Z_pilot; // Z accel in body frame ft/sec^2
// Pressure
// Engine status
int num_engines; // Number of valid engines
int eng_state[FG_MAX_ENGINES]; // Engine state (off, cranking, running)
- double rpm[FG_MAX_ENGINES]; // Engine RPM rev/min
- double fuel_flow[FG_MAX_ENGINES]; // Fuel flow gallons/hr
- double EGT[FG_MAX_ENGINES]; // Exhuast gas temp deg F
- double oil_temp[FG_MAX_ENGINES]; // Oil temp deg F
- double oil_px[FG_MAX_ENGINES]; // Oil pressure psi
+ float rpm[FG_MAX_ENGINES]; // Engine RPM rev/min
+ float fuel_flow[FG_MAX_ENGINES]; // Fuel flow gallons/hr
+ float EGT[FG_MAX_ENGINES]; // Exhuast gas temp deg F
+ float oil_temp[FG_MAX_ENGINES]; // Oil temp deg F
+ float oil_px[FG_MAX_ENGINES]; // Oil pressure psi
// Consumables
int num_tanks; // Max number of fuel tanks
- double fuel_quantity[FG_MAX_TANKS];
+ float fuel_quantity[FG_MAX_TANKS];
- // Gear and flaps status
+ // Gear status
int num_wheels;
bool wow[FG_MAX_WHEELS];
- double flap_deflection; // normalized from 0 = up to 1 = full deflection
// Environment
time_t cur_time; // current unix time
long int warp; // offset in seconds to unix time
- double visibility; // visibility in meters (for env. effects)
+ float visibility; // visibility in meters (for env. effects)
+
+ // Control surface positions (normalized values)
+ float elevator;
+ float flaps;
+ float left_aileron;
+ float right_aileron;
+ float rudder;
+ float speedbrake;
+ float spoilers;
};