FGNetFDM, and FGNetGUI structures more cross platform/architecture portable.
if ( fuelpump != NULL ) {
net->fuel_pump_power[i] = ( fuelpump->getDoubleValue() >= 1.0 );
} else {
- net->fuel_pump_power[i] = 0.0;
+ net->fuel_pump_power[i] = 0;
}
// Faults
net->hground = cur_fdm_state->get_ground_elev_ft() * SG_FEET_TO_METER;
net->magvar = fgGetDouble("/environment/magnetic-variation-deg");
- net->icing = fgGetDouble("/hazards/icing/wing");
+ net->icing = fgGetBool("/hazards/icing/wing");
net->speedup = fgGetInt("/sim/speed-up");
net->freeze = 0;
if ( net_byte_order ) {
// convert to network byte order
- net->version = htonl(net->version);
+ net->version = htons(net->version);
htond(net->aileron);
htond(net->elevator);
htond(net->rudder);
htond(net->elevator_trim);
htond(net->rudder_trim);
htond(net->flaps);
- net->flaps_power = htonl(net->flaps_power);
- net->flap_motor_ok = htonl(net->flap_motor_ok);
for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
- net->master_bat[i] = htonl(net->master_bat[i]);
- net->master_alt[i] = htonl(net->master_alt[i]);
- net->magnetos[i] = htonl(net->magnetos[i]);
- net->starter_power[i] = htonl(net->starter_power[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]);
htond(net->condition[i]);
- net->engine_ok[i] = htonl(net->engine_ok[i]);
- net->mag_left_ok[i] = htonl(net->mag_left_ok[i]);
- net->mag_right_ok[i] = htonl(net->mag_right_ok[i]);
- net->spark_plugs_ok[i] = htonl(net->spark_plugs_ok[i]);
- net->oil_press_status[i] = htonl(net->oil_press_status[i]);
- net->fuel_pump_ok[i] = htonl(net->fuel_pump_ok[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]);
- }
- net->num_tanks = htonl(net->num_tanks);
htond(net->brake_left);
htond(net->brake_right);
htond(net->copilot_brake_left);
htond(net->copilot_brake_right);
htond(net->brake_parking);
- net->gear_handle = htonl(net->gear_handle);
- net->master_avionics = htonl(net->master_avionics);
htond(net->wind_speed_kt);
htond(net->wind_dir_deg);
htond(net->turbulence_norm);
htond(net->press_inhg);
htond(net->hground);
htond(net->magvar);
- net->icing = htonl(net->icing);
- net->speedup = htonl(net->speedup);
- net->freeze = htonl(net->freeze);
}
}
if ( net_byte_order ) {
// convert from network byte order
- net->version = htonl(net->version);
+ net->version = htons(net->version);
htond(net->aileron);
htond(net->elevator);
htond(net->rudder);
htond(net->elevator_trim);
htond(net->rudder_trim);
htond(net->flaps);
- net->flaps_power = htonl(net->flaps_power);
- net->flap_motor_ok = htonl(net->flap_motor_ok);
- net->num_engines = htonl(net->num_engines);
for ( i = 0; i < net->num_engines; ++i ) {
- net->master_bat[i] = htonl(net->master_bat[i]);
- net->master_alt[i] = htonl(net->master_alt[i]);
- net->magnetos[i] = htonl(net->magnetos[i]);
- net->starter_power[i] = htonl(net->starter_power[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]);
htond(net->condition[i]);
- net->engine_ok[i] = htonl(net->engine_ok[i]);
- net->mag_left_ok[i] = htonl(net->mag_left_ok[i]);
- net->mag_right_ok[i] = htonl(net->mag_right_ok[i]);
- net->spark_plugs_ok[i] = htonl(net->spark_plugs_ok[i]);
- net->oil_press_status[i] = htonl(net->oil_press_status[i]);
- net->fuel_pump_ok[i] = htonl(net->fuel_pump_ok[i]);
- }
- net->num_tanks = htonl(net->num_tanks);
- for ( i = 0; i < net->num_tanks; ++i ) {
- net->fuel_selector[i] = htonl(net->fuel_selector[i]);
}
htond(net->brake_left);
htond(net->brake_right);
htond(net->copilot_brake_left);
htond(net->copilot_brake_right);
htond(net->brake_parking);
- net->gear_handle = htonl(net->gear_handle);
- net->master_avionics = htonl(net->master_avionics);
htond(net->wind_speed_kt);
htond(net->wind_dir_deg);
htond(net->turbulence_norm);
htond(net->press_inhg);
htond(net->hground);
htond(net->magvar);
- net->icing = htonl(net->icing);
- net->speedup = htonl(net->speedup);
- net->freeze = htonl(net->freeze);
}
if ( net->version != FG_NET_CTRLS_VERSION ) {
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");
+ net->wow[i] = node->getIntValue("wow");
net->gear_pos[i] = node->getDoubleValue("position-norm");
net->gear_steer[i] = node->getDoubleValue("steering-norm");
net->gear_compression[i] = node->getDoubleValue("compression-norm");
if ( net_byte_order ) {
// Convert the net buffer to network format
- net->version = htonl(net->version);
+ net->version = htons(net->version);
htond(net->longitude);
htond(net->latitude);
htonf(net->slip_deg);
for ( i = 0; i < net->num_engines; ++i ) {
- net->eng_state[i] = htonl(net->eng_state[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 ) {
htonf(net->fuel_quantity[i]);
}
- net->num_tanks = htonl(net->num_tanks);
for ( i = 0; i < net->num_wheels; ++i ) {
- net->wow[i] = htonl(net->wow[i]);
htonf(net->gear_pos[i]);
htonf(net->gear_steer[i]);
htonf(net->gear_compression[i]);
}
- net->num_wheels = htonl(net->num_wheels);
net->cur_time = htonl( net->cur_time );
net->warp = htonl( net->warp );
if ( net_byte_order ) {
// Convert to the net buffer from network format
- net->version = ntohl(net->version);
+ net->version = ntohs(net->version);
htond(net->longitude);
htond(net->latitude);
htonf(net->stall_warning);
htonf(net->slip_deg);
- net->num_engines = htonl(net->num_engines);
for ( i = 0; i < net->num_engines; ++i ) {
- net->eng_state[i] = htonl(net->eng_state[i]);
htonf(net->rpm[i]);
htonf(net->fuel_flow[i]);
htonf(net->egt[i]);
htonf(net->oil_px[i]);
}
- net->num_tanks = htonl(net->num_tanks);
for ( i = 0; i < net->num_tanks; ++i ) {
htonf(net->fuel_quantity[i]);
}
- net->num_wheels = htonl(net->num_wheels);
for ( i = 0; i < net->num_wheels; ++i ) {
- net->wow[i] = htonl(net->wow[i]);
htonf(net->gear_pos[i]);
htonf(net->gear_steer[i]);
htonf(net->gear_compression[i]);
}
- net->cur_time = ntohl(net->cur_time);
+ net->cur_time = htonl(net->cur_time);
net->warp = ntohl(net->warp);
htonf(net->visibility);
#if defined( FG_USE_NETWORK_BYTE_ORDER )
// Convert the net buffer to network format
- net->version = htonl(net->version);
+ net->version = htons(net->version);
htond(net->longitude);
htond(net->latitude);
for ( i = 0; i < net->num_tanks; ++i ) {
htonf(net->fuel_quantity[i]);
}
- net->num_tanks = htonl(net->num_tanks);
net->cur_time = htonl( net->cur_time );
net->warp = htonl( net->warp );
htonf(net->tuned_freq);
htonf(net->nav_radial);
- net->in_range = htonl(net->in_range);
htonf(net->dist_nm);
htonf(net->course_deviation_deg);
htonf(net->gs_deviation_deg);
#if defined( FG_USE_NETWORK_BYTE_ORDER )
// Convert to the net buffer from network format
- net->version = ntohl(net->version);
+ net->version = ntohs(net->version);
htond(net->longitude);
htond(net->latitude);
htonf(net->vcas);
htonf(net->climb_rate);
- net->num_tanks = htonl(net->num_tanks);
for ( i = 0; i < net->num_tanks; ++i ) {
htonf(net->fuel_quantity[i]);
}
net->ground_elev = htonl( net->ground_elev );
htonf(net->tuned_freq);
- net->in_range = htonl(net->in_range);
htonf(net->dist_nm);
htonf(net->course_deviation_deg);
htonf(net->gs_deviation_deg);
#define _NET_CTRLS_HXX
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-const int FG_NET_CTRLS_VERSION = 24;
+// NOTE: this file defines an external interface structure. Due to
+// variability between platforms and architectures, we only used fixed
+// length types here. Specifically, integer types can vary in length.
+// I am not aware of any platforms that don't use 4 bytes for float
+// and 8 bytes for double.
+
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#elif defined( _MSC_VER ) || defined(__MINGW32__)
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+typedef signed __int64 int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned __int64 uint64_t;
+#else
+# error "Port me! Platforms that don't have <stdint.h> need to define int8_t, et. al."
+#endif
+
+const uint16_t FG_NET_CTRLS_VERSION = 25;
// Define a structure containing the control parameters
public:
- int version; // increment when data values change
-
enum {
FG_MAX_ENGINES = 4,
FG_MAX_WHEELS = 16,
FG_MAX_TANKS = 6
};
+ uint16_t version; // increment when data values change
+
// Aero controls
double aileron; // -1 ... 1
double elevator; // -1 ... 1
double flaps; // 0 ... 1
// Aero control faults
- bool flaps_power; // true = power available
- bool flap_motor_ok;
+ uint8_t flaps_power; // true = power available
+ uint8_t flap_motor_ok;
// Engine controls
- int num_engines; // number of valid engines
- bool master_bat[FG_MAX_ENGINES];
- bool master_alt[FG_MAX_ENGINES];
- int magnetos[FG_MAX_ENGINES];
- bool starter_power[FG_MAX_ENGINES]; // true = starter power
+ uint8_t num_engines; // number of valid engines
+ uint8_t master_bat[FG_MAX_ENGINES];
+ uint8_t master_alt[FG_MAX_ENGINES];
+ uint8_t magnetos[FG_MAX_ENGINES];
+ uint8_t starter_power[FG_MAX_ENGINES];// true = starter power
double throttle[FG_MAX_ENGINES]; // 0 ... 1
double mixture[FG_MAX_ENGINES]; // 0 ... 1
double condition[FG_MAX_ENGINES]; // 0 ... 1
- bool fuel_pump_power[FG_MAX_ENGINES];// true = on
+ uint8_t fuel_pump_power[FG_MAX_ENGINES];// true = on
double prop_advance[FG_MAX_ENGINES]; // 0 ... 1
// Engine faults
- bool engine_ok[FG_MAX_ENGINES];
- bool mag_left_ok[FG_MAX_ENGINES];
- bool mag_right_ok[FG_MAX_ENGINES];
- bool spark_plugs_ok[FG_MAX_ENGINES]; // false = fouled plugs
- int oil_press_status[FG_MAX_ENGINES]; // 0 = normal, 1 = low, 2 = full fail
- bool fuel_pump_ok[FG_MAX_ENGINES];
+ uint8_t engine_ok[FG_MAX_ENGINES];
+ uint8_t mag_left_ok[FG_MAX_ENGINES];
+ uint8_t mag_right_ok[FG_MAX_ENGINES];
+ uint8_t spark_plugs_ok[FG_MAX_ENGINES]; // false = fouled plugs
+ uint8_t oil_press_status[FG_MAX_ENGINES];// 0 = normal, 1 = low, 2 = full fail
+ uint8_t fuel_pump_ok[FG_MAX_ENGINES];
// Fuel management
- int num_tanks; // number of valid tanks
- bool fuel_selector[FG_MAX_TANKS]; // false = off, true = on
+ uint8_t num_tanks; // number of valid tanks
+ uint8_t fuel_selector[FG_MAX_TANKS]; // false = off, true = on
+ uint8_t cross_feed; // false = off, true = on
// Brake controls
double brake_left;
double brake_parking;
// Landing Gear
- bool gear_handle; // true=gear handle down; false= gear handle up
+ uint8_t gear_handle; // true=gear handle down; false= gear handle up
// Switches
- bool master_avionics;
+ uint8_t master_avionics;
// wind and turbulance
double wind_speed_kt;
double magvar; // local magnetic variation in degs.
// hazards
- bool icing; // icing status could me much
+ uint8_t icing; // icing status could me much
// more complex but I'm
// starting simple here.
// simulation control
- int speedup; // integer speedup multiplier
- int freeze; // 0=normal
+ uint8_t speedup; // integer speedup multiplier
+ uint8_t freeze; // 0=normal
// 0x01=master
// 0x02=position
// 0x04=fuel
#define _NET_FDM_HXX
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
#include <time.h> // time_t
-const int FG_NET_FDM_VERSION = 20;
+// NOTE: this file defines an external interface structure. Due to
+// variability between platforms and architectures, we only used fixed
+// length types here. Specifically, integer types can vary in length.
+// I am not aware of any platforms that don't use 4 bytes for float
+// and 8 bytes for double.
+
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#elif defined( _MSC_VER ) || defined(__MINGW32__)
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+typedef signed __int64 int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned __int64 uint64_t;
+#else
+# error "Port me! Platforms that don't have <stdint.h> need to define int8_t, et. al."
+#endif
+
+const uint16_t FG_NET_FDM_VERSION = 21;
// Define a structure containing the top level flight dynamics model
public:
- int version; // increment when data values change
- int pad; // keep doubles 64-bit aligned for some
- // hardware platforms, such as the Sun
- // SPARC, which don't like misaligned
- // data
-
enum {
FG_MAX_ENGINES = 4,
FG_MAX_WHEELS = 3,
FG_MAX_TANKS = 4
};
+ uint16_t version; // increment when data values change
+
// Positions
double longitude; // geodetic (radians)
double latitude; // geodetic (radians)
// Pressure
// Engine status
- int num_engines; // Number of valid engines
- int eng_state[FG_MAX_ENGINES]; // Engine state (off, cranking, running)
+ uint8_t num_engines; // Number of valid engines
+ uint8_t eng_state[FG_MAX_ENGINES];// Engine state (off, cranking, running)
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_px[FG_MAX_ENGINES]; // Oil pressure psi
// Consumables
- int num_tanks; // Max number of fuel tanks
+ uint8_t num_tanks; // Max number of fuel tanks
float fuel_quantity[FG_MAX_TANKS];
// Gear status
- int num_wheels;
- bool wow[FG_MAX_WHEELS];
+ uint8_t num_wheels;
+ uint8_t wow[FG_MAX_WHEELS];
float gear_pos[FG_MAX_WHEELS];
float gear_steer[FG_MAX_WHEELS];
float gear_compression[FG_MAX_WHEELS];
// Environment
- time_t cur_time; // current unix time
- long int warp; // offset in seconds to unix time
- float visibility; // visibility in meters (for env. effects)
+ uint32_t cur_time; // current unix time
+ // FIXME: make this uint64_t before 2038
+ uint32_t warp; // offset in seconds to unix time
+ float visibility; // visibility in meters (for env. effects)
// Control surface positions (normalized values)
float elevator;
#define _NET_GUI_HXX
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-
-const int FG_NET_GUI_VERSION = 5;
+// NOTE: this file defines an external interface structure. Due to
+// variability between platforms and architectures, we only used fixed
+// length types here. Specifically, integer types can vary in length.
+// I am not aware of any platforms that don't use 4 bytes for float
+// and 8 bytes for double.
+
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#elif defined( _MSC_VER ) || defined(__MINGW32__)
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+typedef signed __int64 int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned __int64 uint64_t;
+#else
+# error "Port me! Platforms that don't have <stdint.h> need to define int8_t, et. al."
+#endif
+
+const uint16_t FG_NET_GUI_VERSION = 6;
// Define a structure containing the top level flight dynamics model
FG_MAX_TANKS = 4
};
- int version; // increment when data values change
- int pad; // keep doubles 64-bit aligned for some
- // hardware platforms, such as the Sun
- // SPARC, which don't like misaligned
- // data
+ uint16_t version; // increment when data values change
// Positions
double longitude; // geodetic (radians)
float climb_rate; // feet per second
// Consumables
- int num_tanks; // Max number of fuel tanks
+ uint8_t num_tanks; // Max number of fuel tanks
float fuel_quantity[FG_MAX_TANKS];
// Environment
- time_t cur_time; // current unix time
- long int warp; // offset in seconds to unix time
+ uint32_t cur_time; // current unix time
+ // FIXME: make this uint64_t before 2038
+ uint32_t warp; // offset in seconds to unix time
float ground_elev; // ground elev (meters)
// Approach
float tuned_freq; // currently tuned frequency
float nav_radial; // target nav radial
- int in_range; // tuned navaid is in range?
+ uint8_t in_range; // tuned navaid is in range?
float dist_nm; // distance to tuned navaid in nautical miles
float course_deviation_deg; // degrees off target course
float gs_deviation_deg; // degrees off target glide slope
// Gear status
for ( i = 0; i < fdm1.num_wheels; ++i ) {
- result.fdm.wow[i] = weight( fdm1.wow[i], fdm2.wow[i], ratio );
+ result.fdm.wow[i] = (int)(weight( fdm1.wow[i], fdm2.wow[i], ratio ));
result.fdm.gear_pos[i]
= weight( fdm1.gear_pos[i], fdm2.gear_pos[i], ratio );
result.fdm.gear_steer[i]