]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/native_ctrls.cxx
Merge branch 'topics/mainloop' into next
[flightgear.git] / src / Network / native_ctrls.cxx
index d7c15b34c5605c924a2eb0bc916c4a1697188649..2ad871f834f28387b39baebd9cb1eea00661e054 100644 (file)
@@ -16,7 +16,7 @@
 //
 // 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.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #include <simgear/io/iochannel.hxx>
 #include <simgear/io/lowlevel.hxx> // endian tests
 
-#include <FDM/flight.hxx>
 #include <Main/fg_props.hxx>
 #include <Scenery/scenery.hxx> // ground elevation
 
 #include "native_ctrls.hxx"
 
 // FreeBSD works better with this included last ... (?)
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined( _MSC_VER )
 #  include <windows.h>
+#elif defined( __MINGW32__ )
+#  include <winsock2.h>
 #else
 #  include <netinet/in.h>      // htonl() ntohl()
 #endif
@@ -203,12 +204,7 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes,
     net->temp_c = fgGetDouble("/environment/temperature-degc");
     net->press_inhg = fgGetDouble("/environment/pressure-sea-level-inhg");
 
-    // 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.
-    net->hground = cur_fdm_state->get_ground_elev_ft() * SG_FEET_TO_METER;
+    net->hground = fgGetDouble("/position/ground-elev-m");
     net->magvar = fgGetDouble("/environment/magnetic-variation-deg");
 
     net->icing = fgGetBool("/hazards/icing/wing");
@@ -229,7 +225,7 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes,
 
     if ( net_byte_order ) {
         // convert to network byte order
-        net->version = htons(net->version);
+        net->version = htonl(net->version);
         htond(net->aileron);
         htond(net->elevator);
         htond(net->rudder);
@@ -237,17 +233,41 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes,
         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 < 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_tanks = htonl(net->num_tanks);
+        for ( i = 0; i < FGNetCtrls::FG_MAX_TANKS; ++i ) {
+            net->fuel_selector[i] = htonl(net->fuel_selector[i]);
         }
+
+        net->cross_feed = htonl(net->cross_feed);
         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);
@@ -255,6 +275,9 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes,
         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);
     }
 }
 
@@ -269,7 +292,7 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
 
     if ( net_byte_order ) {
         // convert from network byte order
-        net->version = htons(net->version);
+        net->version = htonl(net->version);
         htond(net->aileron);
         htond(net->elevator);
         htond(net->rudder);
@@ -277,17 +300,41 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
         htond(net->elevator_trim);
         htond(net->rudder_trim);
         htond(net->flaps);
-        for ( i = 0; i < net->num_engines; ++i ) {
+        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 < (int)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 < FGNetCtrls::FG_MAX_TANKS; ++i ) {
+            net->fuel_selector[i] = htonl(net->fuel_selector[i]);
+        }
+
+        net->cross_feed = htonl(net->cross_feed);
         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);
@@ -295,6 +342,9 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
         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 ) {
@@ -312,6 +362,10 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
     node->setDoubleValue( "elevator-trim", net->elevator_trim );
     node->setDoubleValue( "rudder-trim", net->rudder_trim );
     node->setDoubleValue( "flaps", net->flaps );
+    node->setDoubleValue( "speedbrake", net->speedbrake );  //JWW
+    // or
+    node->setDoubleValue( "spoilers", net->spoilers );  //JWW
+//    cout << "NET->Spoilers: " << net->spoilers << endl;
     fgSetBool( "/systems/electrical/outputs/flaps", net->flaps_power );
     node->setBoolValue( "flaps-serviceable", net->flap_motor_ok );
 
@@ -326,7 +380,8 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
             ->setDoubleValue( net->condition[i] );
         node->getChild( "magnetos" )->setDoubleValue( net->magnetos[i] );
         node->getChild( "starter" )->setDoubleValue( net->starter_power[i] );
-
+        node->getChild( "feed_tank" )->setIntValue( net->feed_tank_to[i] );
+        node->getChild( "reverser" )->setBoolValue( net->reverse[i] );
        // Faults
        SGPropertyNode *faults = node->getNode( "faults", true );
        faults->setBoolValue( "serviceable", net->engine_ok[i] );
@@ -347,6 +402,7 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
         node = fgGetNode( "/controls/fuel/tank", i );
         node->getChild( "fuel_selector" )
             ->setBoolValue( net->fuel_selector[i] );
+//        node->getChild( "to_tank" )->xfer_tank( i, net->xfer_to[i] );
     }
     node = fgGetNode( "/controls/gear" );
     if ( node != NULL ) {
@@ -361,6 +417,9 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
 
     node = fgGetNode( "/controls/gear", true );
     node->setBoolValue( "gear-down", net->gear_handle );
+//    node->setDoubleValue( "brake-parking", net->brake_parking );
+//    node->setDoubleValue( net->brake_left );
+//    node->setDoubleValue( net->brake_right );
 
     node = fgGetNode( "/controls/switches", true );
     node->setBoolValue( "master-bat", net->master_bat );
@@ -371,7 +430,7 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
     node->setDoubleValue( "wind-speed-kt", net->wind_speed_kt );
     node->setDoubleValue( "wind-from-heading-deg", net->wind_dir_deg );
     node->setDoubleValue( "turbulence/magnitude-norm", net->turbulence_norm );
-    node->setBoolValue( "magnetic-variation-deg", net->magvar );
+    node->setDoubleValue( "magnetic-variation-deg", net->magvar );
 
     node->setDoubleValue( "/environment/temperature-degc",
                          net->temp_c );
@@ -381,6 +440,11 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
     // ground elevation ???
 
     fgSetDouble("/hazards/icing/wing", net->icing);
+    
+    node = fgGetNode( "/radios", true );
+    node->setDoubleValue( "comm/frequencies/selected-mhz[0]", net->comm_1 );
+    node->setDoubleValue( "nav/frequencies/selected-mhz[0]", net->nav_1 );
+    node->setDoubleValue( "nav[1]/frequencies/selected-mhz[0]", net->nav_2 );
 
     fgSetInt( "/sim/speed-up", net->speedup );
 
@@ -399,7 +463,6 @@ bool FGNativeCtrls::process() {
     int length = sizeof(FGNetCtrls);
 
     if ( get_direction() == SG_IO_OUT ) {
-       // cout << "size of cur_fdm_state = " << length << endl;
 
        FGProps2NetCtrls( &net_ctrls, true, true );