]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/navcom.cxx
Begin interfacing the navcom's to the electrical model.
[flightgear.git] / src / Cockpit / navcom.cxx
index 836362a8267032e13ee5eba6a457030f895b8917..75aa78f9f2fc9e81f558c9b6d02134a4ee5497a5 100644 (file)
@@ -32,7 +32,6 @@
 
 #include <Aircraft/aircraft.hxx>
 #include <Navaids/ilslist.hxx>
-#include <Navaids/mkrbeacons.hxx>
 #include <Navaids/navlist.hxx>
 #include <Time/FGEventMgr.hxx>
 
 SG_USING_STD(string);
 
 
-/**
- * Boy, this is ugly!  Make the VOR range vary by altitude difference.
- */
-static double kludgeRange ( double stationElev, double aircraftElev,
-                           double nominalRange)
-{
-    // Assume that the nominal range (usually 50nm) applies at a 5,000
-    // ft difference.  Just a wild guess!
-    double factor = ((aircraftElev*SG_METER_TO_FEET) - stationElev) / 5000.0;
-    double range = fabs(nominalRange * factor);
-
-    // Clamp the range to keep it sane; for now, never less than 25%
-    // or more than 500% of nominal range.
-    if (range < nominalRange/4.0) {
-        range = nominalRange/4.0;
-    } else if (range > nominalRange*5.0) {
-        range = nominalRange*5.0;
-    }
-
-    return range;
-}
-
-
 // Constructor
 FGNavCom::FGNavCom() :
     lon_node(fgGetNode("/position/longitude-deg", true)),
@@ -113,7 +89,6 @@ void
 FGNavCom::init ()
 {
     morse.init();
-    beacon.init();
 
     search();
 
@@ -125,6 +100,13 @@ FGNavCom::bind ()
 {
     char propname[256];
 
+    // we know index is valid now so lets bind to the bus property
+    // here.
+    sprintf( propname, "/systems/electrical/outputs/navcomm[%d]", index );
+    // default to true in case no electrical system defined.
+    fgSetDouble( propname, 60.0 );
+    bus_power = fgGetNode( propname, true );
+
                                // User inputs
     sprintf( propname, "/radios/comm[%d]/inputs/power-btn", index );
     fgTie( propname, this,
@@ -306,7 +288,7 @@ FGNavCom::update(double dt)
     // Nav.
     ////////////////////////////////////////////////////////////////////////
 
-    if ( nav_valid && power_btn ) {
+    if ( nav_valid && power_btn && (bus_power->getDoubleValue() > 1.0) ) {
        station = Point3D( nav_x, nav_y, nav_z );
        nav_loc_dist = aircraft.distance3D( station );
 
@@ -361,7 +343,9 @@ FGNavCom::update(double dt)
     if ( nav_valid && nav_inrange ) {
        // play station ident via audio system if on + ident,
        // otherwise turn it off
-       if ( power_btn && nav_ident_btn ) {
+       if ( power_btn && (bus_power->getDoubleValue() > 1.0)
+             && nav_ident_btn )
+        {
            FGSimpleSound *sound;
            sound = globals->get_soundmgr()->find( nav_fx_name );
             if ( sound != NULL ) {
@@ -377,17 +361,18 @@ FGNavCom::update(double dt)
                 SG_LOG( SG_COCKPIT, SG_ALERT,
                         "Can't find nav-dme-ident sound" );
             }
-            cout << "nav_last_time = " << nav_last_time << " ";
-            cout << "cur_time = " << globals->get_time_params()->get_cur_time();
+            // cout << "nav_last_time = " << nav_last_time << " ";
+            // cout << "cur_time = "
+            //      << globals->get_time_params()->get_cur_time();
            if ( nav_last_time <
                 globals->get_time_params()->get_cur_time() - 30 ) {
                nav_last_time = globals->get_time_params()->get_cur_time();
                nav_play_count = 0;
            }
-            cout << " nav_play_count = " << nav_play_count << endl;
-            cout << "playing = "
-                 << globals->get_soundmgr()->is_playing(nav_fx_name)
-                 << endl;
+            // cout << " nav_play_count = " << nav_play_count << endl;
+            // cout << "playing = "
+            //      << globals->get_soundmgr()->is_playing(nav_fx_name)
+            //      << endl;
            if ( nav_play_count < 4 ) {
                // play VOR ident
                if ( !globals->get_soundmgr()->is_playing(nav_fx_name) ) {
@@ -476,11 +461,11 @@ void FGNavCom::search()
            nav_play_count = offset / 4;
            nav_last_time = globals->get_time_params()->get_cur_time() -
                offset;
-           cout << "offset = " << offset << " play_count = "
-                << nav_play_count
-                << " nav_last_time = " << nav_last_time
-                << " current time = "
-                << globals->get_time_params()->get_cur_time() << endl;
+           // cout << "offset = " << offset << " play_count = "
+           //      << nav_play_count
+           //      << " nav_last_time = " << nav_last_time
+           //      << " current time = "
+           //      << globals->get_time_params()->get_cur_time() << endl;
 #endif
 
            // cout << "Found an ils station in range" << endl;
@@ -516,7 +501,7 @@ void FGNavCom::search()
            sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY );
            sound->set_volume( 0.3 );
            if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) {
-                cout << "Added nav-vor-ident sound" << endl;
+                // cout << "Added nav-vor-ident sound" << endl;
             } else {
                 cout << "Failed to add v1-vor-ident sound" << endl;
             }
@@ -532,10 +517,10 @@ void FGNavCom::search()
            nav_play_count = offset / 4;
            nav_last_time = globals->get_time_params()->get_cur_time() -
                offset;
-           cout << "offset = " << offset << " play_count = "
-                << nav_play_count << " nav_last_time = "
-                << nav_last_time << " current time = "
-                << globals->get_time_params()->get_cur_time() << endl;
+           // cout << "offset = " << offset << " play_count = "
+           //      << nav_play_count << " nav_last_time = "
+           //      << nav_last_time << " current time = "
+           //      << globals->get_time_params()->get_cur_time() << endl;
 #endif
 
            // cout << "Found a vor station in range" << endl;