]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/native_ctrls.cxx
Make a subtle change to tile loading/unloading policy in order to make the tile
[flightgear.git] / src / Network / native_ctrls.cxx
index bf759a2ef38ec2b0dfbe9bddf3e02d648dd542cd..4d2051a35caaf387312fb4bce5a2935fee71e6f9 100644 (file)
@@ -98,10 +98,14 @@ static void htond (double &x)
 
 
 // Populate the FGNetCtrls structure from the property tree.
-void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
+void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes,
+                       bool net_byte_order )
+{
     int i;
-    SGPropertyNode * node;
-    SGPropertyNode * tempnode;
+    SGPropertyNode *node;
+    SGPropertyNode *starter;
+    SGPropertyNode *fuelpump;
+    SGPropertyNode *tempnode;
 
     // fill in values
     node  = fgGetNode("/controls/flight", true);
@@ -111,16 +115,30 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
     net->elevator_trim = node->getDoubleValue( "elevator-trim" );
     net->rudder = node->getDoubleValue( "rudder" );
     net->flaps = node->getDoubleValue( "flaps" );
-    node = fgGetNode("/controls", true); 
     net->flaps_power
-            = node->getDoubleValue( "/systems/electrical/outputs/flaps",
-                                    1.0 ) >= 1.0;
+        = fgGetDouble( "/systems/electrical/outputs/flaps", 1.0 ) >= 1.0;
+    net->flap_motor_ok = node->getBoolValue( "flaps-serviceable" );
+
     net->num_engines = FGNetCtrls::FG_MAX_ENGINES;
     for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
+        // Controls
         node = fgGetNode("/controls/engines/engine", i );
-       net->throttle[i] = node->getDoubleValue( "throttle", 0.0 );
+        starter = fgGetNode("/systems/electrical/outputs/starter", i );
+        fuelpump = fgGetNode("/systems/electrical/outputs/fuel-pump", i );
+
+        tempnode = node->getChild("master-bat");
+        if ( tempnode != NULL ) {
+            net->master_bat[i] = tempnode->getBoolValue();
+        }
+        tempnode = node->getChild("master-alt");
+        if ( tempnode != NULL ) {
+            net->master_alt[i] = tempnode->getBoolValue();
+        }
+
+        net->throttle[i] = node->getDoubleValue( "throttle", 0.0 );
        net->mixture[i] = node->getDoubleValue( "mixture", 0.0 );
        net->prop_advance[i] = node->getDoubleValue( "propeller-pitch", 0.0 );
+       net->condition[i] = node->getDoubleValue( "condition", 0.0 );
        net->magnetos[i] = node->getIntValue( "magnetos", 0 );
        if ( i == 0 ) {
          // cout << "Magnetos -> " << node->getIntValue( "magnetos", 0 );
@@ -129,14 +147,32 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
          // cout << "Starter -> " << node->getIntValue( "starter", false )
          //      << endl;
        }
-        node = fgGetNode("/controls", true);
-       net->fuel_pump_power[i]
-            = node->getDoubleValue( "/systems/electrical/outputs/fuel-pump",
-                                    1.0 ) >= 1.0;
-
-       net->starter_power[i]
-            = node->getDoubleValue( "/systems/electrical/outputs/starter",
-                                    1.0 ) >= 1.0;
+
+        if ( fuelpump != NULL ) {
+            net->fuel_pump_power[i] = ( fuelpump->getDoubleValue() >= 1.0 );
+        } else {
+            net->fuel_pump_power[i] = 0.0;
+        }
+
+        if ( starter != NULL ) {
+            net->starter_power[i] = ( starter->getDoubleValue() >= 1.0 );
+        } else {
+            net->starter_power[i] = 0.0;
+        }
+
+       // Faults
+       SGPropertyNode *faults = node->getChild( "faults", 0, true );
+       net->engine_ok[i] = faults->getBoolValue( "serviceable", true );
+       net->mag_left_ok[i]
+         = faults->getBoolValue( "left-magneto-serviceable", true );
+       net->mag_right_ok[i]
+         = faults->getBoolValue( "right-magneto-serviceable", true);
+       net->spark_plugs_ok[i]
+         = faults->getBoolValue( "spark-plugs-serviceable", true );
+       net->oil_press_status[i]
+         = faults->getIntValue( "oil-pressure-status", 0 );
+       net->fuel_pump_ok[i]
+         = faults->getBoolValue( "fuel-pump-serviceable", true );
     }
     net->num_tanks = FGNetCtrls::FG_MAX_TANKS;
     for ( i = 0; i < FGNetCtrls::FG_MAX_TANKS; ++i ) {
@@ -148,31 +184,17 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
             net->fuel_selector[i] = false;
         }
     }
-    net->num_wheels = FGNetCtrls::FG_MAX_WHEELS;
-    tempnode = fgGetNode("/controls/gear", true);
-    for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
-        node = fgGetNode("/controls/gear/wheel", i);
-        if ( node->getChild("brake") != NULL ) {
-            if ( tempnode->getChild("parking-brake")->getDoubleValue() > 0.0 ) {
-                net->brake[i] = 1.0;
-           } else {
-                net->brake[i]
-                    = node->getChild("brake")->getDoubleValue();
-            }
-        } else {
-            net->brake[i] = 0.0;
-        }
-    }
+    node = fgGetNode("/controls/gear", true);
+    net->brake_left = node->getChild("brake-left")->getDoubleValue();
+    net->brake_right = node->getChild("brake-right")->getDoubleValue();
+    net->copilot_brake_left
+        = node->getChild("copilot-brake-left")->getDoubleValue();
+    net->copilot_brake_right
+        = node->getChild("copilot-brake-right")->getDoubleValue();
+    net->brake_parking = node->getChild("brake-parking")->getDoubleValue();
+
+    net->gear_handle = fgGetBool( "controls/gear/gear-down" );
 
-    node = fgGetNode("/controls/switches", true);
-    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();
@@ -180,7 +202,11 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
 
     net->wind_speed_kt = fgGetDouble("/environment/wind-speed-kt");
     net->wind_dir_deg = fgGetDouble("/environment/wind-from-heading-deg");
-    net->turbulence_norm = fgGetDouble("/environment/turbulence-norm");
+    net->turbulence_norm =
+        fgGetDouble("/environment/turbulence/magnitude-norm");
+
+    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.
@@ -189,16 +215,21 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
     // the user is switching views.
     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->speedup = fgGetInt("/sim/speed-up");
     net->freeze = 0;
-    if ( fgGetBool("/sim/freeze/master") ) {
-        net->freeze |= 0x01;
-    }
-    if ( fgGetBool("/sim/freeze/position") ) {
-        net->freeze |= 0x02;
-    }
-    if ( fgGetBool("/sim/freeze/fuel") ) {
-        net->freeze |= 0x04;
+    if ( honor_freezes ) {
+        if ( fgGetBool("/sim/freeze/master") ) {
+            net->freeze |= 0x01;
+        }
+        if ( fgGetBool("/sim/freeze/position") ) {
+            net->freeze |= 0x02;
+        }
+        if ( fgGetBool("/sim/freeze/fuel") ) {
+            net->freeze |= 0x04;
+        }
     }
 
     if ( net_byte_order ) {
@@ -210,32 +241,44 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
         htond(net->rudder);
         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]);
-            net->magnetos[i] = htonl(net->magnetos[i]);
-            net->starter_power[i] = htonl(net->starter_power[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);
-        for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
-            htond(net->brake[i]);
-        }
-        net->num_wheels = htonl(net->num_wheels);
+        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_bat = htonl(net->master_bat);
-        net->master_alt = htonl(net->master_alt);
         net->master_avionics = htonl(net->master_avionics);
         htond(net->wind_speed_kt);
         htond(net->wind_dir_deg);
         htond(net->turbulence_norm);
-        htond(net->hground);
+       htond(net->temp_c);
+        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);
     }
@@ -243,7 +286,9 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
 
 
 // Update the property tree from the FGNetCtrls structure.
-void FGNetCtrls2Props( FGNetCtrls *net, bool net_byte_order ) {
+void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes,
+                       bool net_byte_order )
+{
     int i;
 
     SGPropertyNode * node;
@@ -257,32 +302,44 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool net_byte_order ) {
         htond(net->rudder);
         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]);
         }
-        net->num_wheels = htonl(net->num_wheels);
-        for ( i = 0; i < net->num_wheels; ++i ) {
-            htond(net->brake[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_bat = htonl(net->master_bat);
-        net->master_alt = htonl(net->master_alt);
         net->master_avionics = htonl(net->master_avionics);
         htond(net->wind_speed_kt);
         htond(net->wind_dir_deg);
         htond(net->turbulence_norm);
+       htond(net->temp_c);
+        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);
     }
@@ -300,16 +357,31 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool net_byte_order ) {
     node->setDoubleValue( "elevator-trim", net->elevator_trim );
     node->setDoubleValue( "rudder", net->rudder );
     node->setDoubleValue( "flaps", net->flaps );
-
     fgSetBool( "/systems/electrical/outputs/flaps", net->flaps_power );
+    node->setBoolValue( "flaps-serviceable", net->flap_motor_ok );
 
     for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
+        // Controls
         node = fgGetNode("/controls/engines/engine", i);
         node->getChild( "throttle" )->setDoubleValue( net->throttle[i] );
         node->getChild( "mixture" )->setDoubleValue( net->mixture[i] );
         node->getChild( "propeller-pitch" )
             ->setDoubleValue( net->prop_advance[i] );
+        node->getChild( "condition" )
+            ->setDoubleValue( net->condition[i] );
         node->getChild( "magnetos" )->setDoubleValue( net->magnetos[i] );
+
+       // Faults
+       SGPropertyNode *faults = node->getNode( "faults", true );
+       faults->setBoolValue( "serviceable", net->engine_ok[i] );
+       faults->setBoolValue( "left-magneto-serviceable",
+                             net->mag_left_ok[i] );
+       faults->setBoolValue( "right-magneto-serviceable",
+                             net->mag_right_ok[i]);
+       faults->setBoolValue( "spark-plugs-serviceable",
+                             net->spark_plugs_ok[i] );
+       faults->setIntValue( "oil-pressure-status", net->oil_press_status[i] );
+       faults->setBoolValue( "fuel-pump-serviceable", net->fuel_pump_ok[i] );
     }
 
     fgSetBool( "/systems/electrical/outputs/fuel-pump",
@@ -322,9 +394,15 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool net_byte_order ) {
         node->getChild( "fuel_selector" )
             ->setBoolValue( net->fuel_selector[i] );
     }
-    for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
-        node = fgGetNode( "/controls/gear/wheel", i );
-        node->getChild( "brake" )->setDoubleValue( net->brake[i] );
+    node = fgGetNode( "/controls/gear" );
+    if ( node != NULL ) {
+        node->getChild( "brake-left" )->setDoubleValue( net->brake_left );
+        node->getChild( "brake-right" )->setDoubleValue( net->brake_right );
+        node->getChild( "copilot-brake-left" )
+            ->setDoubleValue( net->copilot_brake_left );
+        node->getChild( "copilot-brake-right" )
+            ->setDoubleValue( net->copilot_brake_right );
+        node->getChild( "brake-parking" )->setDoubleValue( net->brake_parking );
     }
 
     node = fgGetNode( "/controls/gear", true );
@@ -338,17 +416,26 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool net_byte_order ) {
     node = fgGetNode( "/environment", true );
     node->setDoubleValue( "wind-speed-kt", net->wind_speed_kt );
     node->setDoubleValue( "wind-from-heading-deg", net->wind_dir_deg );
-    node->setDoubleValue( "turbulence-norm", net->turbulence_norm );
+    node->setDoubleValue( "turbulence/magnitude-norm", net->turbulence_norm );
     node->setBoolValue( "magnetic-variation-deg", net->magvar );
 
+    node->setDoubleValue( "/environment/temperature-degc",
+                         net->temp_c );
+    node->setDoubleValue( "/environment/pressure-sea-level-inhg",
+                         net->press_inhg );
+
     // ground elevation ???
 
+    fgSetDouble("/hazards/icing/wing", net->icing);
+
     fgSetInt( "/sim/speed-up", net->speedup );
 
-    node = fgGetNode( "/sim/freeze", true );
-    node->setBoolValue( "master", net->freeze & 0x01 );
-    node->setBoolValue( "position", net->freeze & 0x02 );
-    node->setBoolValue( "fuel", net->freeze & 0x04 );
+    if ( honor_freezes ) {
+        node = fgGetNode( "/sim/freeze", true );
+        node->setBoolValue( "master", net->freeze & 0x01 );
+        node->setBoolValue( "position", net->freeze & 0x02 );
+        node->setBoolValue( "fuel", net->freeze & 0x04 );
+    }
 }
 
 
@@ -360,7 +447,7 @@ bool FGNativeCtrls::process() {
     if ( get_direction() == SG_IO_OUT ) {
        // cout << "size of cur_fdm_state = " << length << endl;
 
-       FGProps2NetCtrls( &net_ctrls );
+       FGProps2NetCtrls( &net_ctrls, true, true );
 
        if ( ! io->write( (char *)(& net_ctrls), length ) ) {
            SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
@@ -370,12 +457,12 @@ bool FGNativeCtrls::process() {
        if ( io->get_type() == sgFileType ) {
            if ( io->read( (char *)(& net_ctrls), length ) == length ) {
                SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
-               FGNetCtrls2Props( &net_ctrls );
+               FGNetCtrls2Props( &net_ctrls, true, true );
            }
        } else {
            while ( io->read( (char *)(& net_ctrls), length ) == length ) {
                SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
-               FGNetCtrls2Props( &net_ctrls );
+               FGNetCtrls2Props( &net_ctrls, true, true );
            }
        }
     }