]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/radiostack.cxx
Commented out a cout statement.
[flightgear.git] / src / Cockpit / radiostack.cxx
index c2a759c9b11c4bbaeb74d198b79df66bd244f7cd..fd9dd25ff067bc8b56c687052d67d39c7d5d5367 100644 (file)
@@ -34,7 +34,7 @@
 #include <Navaids/ilslist.hxx>
 #include <Navaids/mkrbeacons.hxx>
 #include <Navaids/navlist.hxx>
-#include <Time/event.hxx>
+#include <Time/FGEventMgr.hxx>
 
 #include "radiostack.hxx"
 
@@ -43,10 +43,8 @@ SG_USING_STD(string);
 
 static int nav1_play_count = 0;
 static int nav2_play_count = 0;
-static int adf_play_count = 0;
 static time_t nav1_last_time = 0;
 static time_t nav2_last_time = 0;
-static time_t adf_last_time = 0;
 
 
 FGRadioStack *current_radiostack;
@@ -77,11 +75,6 @@ static double kludgeRange ( double stationElev, double aircraftElev,
 }
 
 
-// periodic radio station search wrapper
-static void fgRadioSearch( void ) {
-    current_radiostack->search();
-}
-
 // Constructor
 FGRadioStack::FGRadioStack() :
     lon_node(fgGetNode("/position/longitude-deg", true)),
@@ -90,14 +83,18 @@ FGRadioStack::FGRadioStack() :
     need_update(true),
     comm1_freq(0.0),
     comm1_alt_freq(0.0),
+    comm1_vol_btn(0.0),
     comm2_freq(0.0),
     comm2_alt_freq(0.0),
+    comm2_vol_btn(0.0),
     nav1_freq(0.0),
     nav1_alt_freq(0.0),
     nav1_radial(0.0),
+    nav1_vol_btn(0.0),
     nav2_freq(0.0),
     nav2_alt_freq(0.0),
     nav2_radial(0.0),
+    nav2_vol_btn(0.0),
     dme_freq(0.0),
     dme_dist(0.0),
     dme_prev_dist(0.0),
@@ -105,9 +102,7 @@ FGRadioStack::FGRadioStack() :
     dme_ete(0.0),
     outer_blink(false),
     middle_blink(false),
-    inner_blink(false),
-    adf_freq(0.0),
-    adf_alt_freq(0.0)
+    inner_blink(false)
 {
     SGPath path( globals->get_fg_root() );
     SGPath term = path;
@@ -127,6 +122,7 @@ FGRadioStack::FGRadioStack() :
 // Destructor
 FGRadioStack::~FGRadioStack() 
 {
+    adf.unbind();
     unbind();                  // FIXME: should be called externally
 
     delete term_tbl;
@@ -138,16 +134,22 @@ FGRadioStack::~FGRadioStack()
 void
 FGRadioStack::init ()
 {
+    adf.init();
+
     morse.init();
     beacon.init();
     blink.stamp();
 
     search();
-    update(1);                 // FIXME: use dt
+    adf.search();
+
+    update(0);                 // FIXME: use dt
+    adf.update(0);
 
     // Search radio database once per second
-    global_events.Register( "fgRadioSearch()", fgRadioSearch,
-                           fgEVENT::FG_EVENT_READY, 1000);
+    global_events.Register( "fgRadioSearch()",
+                           current_radiostack, &FGRadioStack::search,
+                           1000 );
 }
 
 void
@@ -255,31 +257,14 @@ FGRadioStack::bind ()
     fgTie("/radios/dme/speed-kt", this, &FGRadioStack::get_dme_spd);
     fgTie("/radios/dme/ete-min", this, &FGRadioStack::get_dme_ete);
 
-                               // User inputs
-    fgTie("/radios/adf/frequencies/selected-khz", this,
-         &FGRadioStack::get_adf_freq, &FGRadioStack::set_adf_freq);
-    fgSetArchivable("/radios/adf/frequencies/selected-khz");
-    fgTie("/radios/adf/frequencies/standby-khz", this,
-         &FGRadioStack::get_adf_alt_freq, &FGRadioStack::set_adf_alt_freq);
-    fgSetArchivable("/radios/adf/frequencies/standby-khz");
-    fgTie("/radios/adf/rotation-deg", this,
-         &FGRadioStack::get_adf_rotation, &FGRadioStack::set_adf_rotation);
-    fgSetArchivable("/radios/adf/rotation-deg");
-    fgTie("/radios/adf/volume", this,
-         &FGRadioStack::get_adf_vol_btn,
-         &FGRadioStack::set_adf_vol_btn);
-    fgSetArchivable("/radios/adf/volume");
-    fgTie("/radios/adf/ident", this,
-         &FGRadioStack::get_adf_ident_btn,
-         &FGRadioStack::set_adf_ident_btn);
-    fgSetArchivable("/radios/adf/ident");
-
     fgTie("/radios/marker-beacon/inner", this,
          &FGRadioStack::get_inner_blink);
     fgTie("/radios/marker-beacon/middle", this,
          &FGRadioStack::get_middle_blink);
     fgTie("/radios/marker-beacon/outer", this,
          &FGRadioStack::get_outer_blink);
+
+    adf.bind();
 }
 
 void
@@ -327,15 +312,11 @@ FGRadioStack::unbind ()
     fgUntie("/radios/dme/speed-kt");
     fgUntie("/radios/dme/ete-min");
 
-    fgUntie("/radios/adf/frequencies/selected-khz");
-    fgUntie("/radios/adf/frequencies/standby-khz");
-    fgUntie("/radios/adf/rotation-deg");
-    fgUntie("/radios/adf/on");
-    fgUntie("/radios/adf/ident");
-
     fgUntie("/radios/marker-beacon/inner");
     fgUntie("/radios/marker-beacon/middle");
     fgUntie("/radios/marker-beacon/outer");
+
+    adf.unbind();
 }
 
 
@@ -403,7 +384,7 @@ double FGRadioStack::adjustILSRange( double stationElev, double aircraftElev,
 
 // Update the various nav values based on position and valid tuned in navs
 void 
-FGRadioStack::update(int dt) 
+FGRadioStack::update(double dt) 
 {
     double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
     double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
@@ -477,20 +458,36 @@ FGRadioStack::update(int dt)
        if ( nav1_vol_btn > 0.1 && nav1_ident_btn ) {
            FGSimpleSound *sound;
            sound = globals->get_soundmgr()->find( "nav1-vor-ident" );
-           sound->set_volume( nav1_vol_btn * 0.3 );
+            if ( sound != NULL ) {
+                sound->set_volume( nav1_vol_btn );
+            } else {
+                SG_LOG( SG_COCKPIT, SG_ALERT,
+                        "Can't find nav1-vor-ident sound" );
+            }
            sound = globals->get_soundmgr()->find( "nav1-dme-ident" );
-           sound->set_volume( nav1_vol_btn * 0.3 );
+            if ( sound != NULL ) {
+                sound->set_volume( nav1_vol_btn );
+            } else {
+                SG_LOG( SG_COCKPIT, SG_ALERT,
+                        "Can't find nav1-dme-ident sound" );
+            }
+            // cout << "nav1_last_time = " << nav1_last_time << " ";
+            // cout << "cur_time = " << globals->get_time_params()->get_cur_time();
            if ( nav1_last_time <
                 globals->get_time_params()->get_cur_time() - 30 ) {
                nav1_last_time = globals->get_time_params()->get_cur_time();
                nav1_play_count = 0;
            }
+            // cout << " nav1_play_count = " << nav1_play_count << endl;
+            // cout << "playing = "
+            //      << globals->get_soundmgr()->is_playing("nav1-vor-ident")
+            //      << endl;
            if ( nav1_play_count < 4 ) {
                // play VOR ident
                if ( !globals->get_soundmgr()->is_playing("nav1-vor-ident") ) {
                    globals->get_soundmgr()->play_once( "nav1-vor-ident" );
                    ++nav1_play_count;
-               }
+                }
            } else if ( nav1_play_count < 5 && nav1_has_dme ) {
                // play DME ident
                if ( !globals->get_soundmgr()->is_playing("nav1-vor-ident") &&
@@ -568,10 +565,20 @@ FGRadioStack::update(int dt)
        if ( nav2_vol_btn > 0.1 && nav2_ident_btn ) {
            FGSimpleSound *sound;
            sound = globals->get_soundmgr()->find( "nav2-vor-ident" );
-           sound->set_volume( nav2_vol_btn * 0.3 );
+            if ( sound != NULL ) {
+                sound->set_volume( nav2_vol_btn );
+            } else {
+                SG_LOG( SG_COCKPIT, SG_ALERT,
+                        "Can't find nav2-vor-ident sound" );
+            }
            sound = globals->get_soundmgr()->find( "nav2-dme-ident" );
-           sound->set_volume( nav2_vol_btn * 0.3 );
-           if ( nav2_last_time <
+            if ( sound != NULL ) {
+                sound->set_volume( nav2_vol_btn );
+            } else {
+                SG_LOG( SG_COCKPIT, SG_ALERT,
+                        "Can't find nav2-dme-ident sound" );
+            }
+            if ( nav2_last_time <
                 globals->get_time_params()->get_cur_time() - 30 ) {
                nav2_last_time = globals->get_time_params()->get_cur_time();
                nav2_play_count = 0;
@@ -644,64 +651,6 @@ FGRadioStack::update(int dt)
       dme_prev_dist = 0.0;
     }
 
-
-    ////////////////////////////////////////////////////////////////////////
-    // ADF
-    ////////////////////////////////////////////////////////////////////////
-
-    if ( adf_valid ) {
-       // staightline distance
-       station = Point3D( adf_x, adf_y, adf_z );
-       adf_dist = aircraft.distance3D( station );
-
-       // wgs84 heading
-       geo_inverse_wgs_84( elev, lat * SGD_RADIANS_TO_DEGREES, lon * SGD_RADIANS_TO_DEGREES, 
-                           adf_lat, adf_lon,
-                           &az1, &az2, &s );
-       adf_heading = az1;
-       // cout << " heading = " << nav2_heading
-       //      << " dist = " << nav2_dist << endl;
-
-       adf_effective_range = kludgeRange(adf_elev, elev, adf_range);
-       if ( adf_dist < adf_effective_range * SG_NM_TO_METER ) {
-           adf_inrange = true;
-       } else if ( adf_dist < 2 * adf_effective_range * SG_NM_TO_METER ) {
-           adf_inrange = sg_random() < 
-               ( 2 * adf_effective_range * SG_NM_TO_METER - adf_dist ) /
-               (adf_effective_range * SG_NM_TO_METER);
-       } else {
-           adf_inrange = false;
-       }
-    } else {
-       adf_inrange = false;
-    }
-
-#ifdef ENABLE_AUDIO_SUPPORT
-    if ( adf_valid && adf_inrange ) {
-       // play station ident via audio system if on + ident,
-       // otherwise turn it off
-       if ( adf_vol_btn > 0.1 && adf_ident_btn ) {
-           FGSimpleSound *sound;
-           sound = globals->get_soundmgr()->find( "adf-ident" );
-           sound->set_volume( adf_vol_btn * 0.3 );
-           if ( adf_last_time <
-                globals->get_time_params()->get_cur_time() - 30 ) {
-               adf_last_time = globals->get_time_params()->get_cur_time();
-               adf_play_count = 0;
-           }
-           if ( adf_play_count < 4 ) {
-               // play ADF ident
-               if ( !globals->get_soundmgr()->is_playing("adf-ident") ) {
-                   globals->get_soundmgr()->play_once( "adf-ident" );
-                   ++adf_play_count;
-               }
-           }
-       } else {
-           globals->get_soundmgr()->stop( "adf-ident" );
-       }
-    }
-#endif
-
     // marker beacon blinking
     bool light_on = ( outer_blink || middle_blink || inner_blink );
     SGTimeStamp current;
@@ -734,6 +683,8 @@ FGRadioStack::update(int dt)
     }
 
     // cout << outer_blink << " " << middle_blink << " " << inner_blink << endl;
+
+    adf.update( dt );
 }
 
 
@@ -770,7 +721,6 @@ void FGRadioStack::search()
 
     static string last_nav1_ident = "";
     static string last_nav2_ident = "";
-    static string last_adf_ident = "";
     static bool last_nav1_vor = false;
     static bool last_nav2_vor = false;
 
@@ -867,7 +817,11 @@ void FGRadioStack::search()
            FGSimpleSound *sound;
            sound = morse.make_ident( nav1_trans_ident, LO_FREQUENCY );
            sound->set_volume( 0.3 );
-           globals->get_soundmgr()->add( sound, "nav1-vor-ident" );
+           if ( globals->get_soundmgr()->add( sound, "nav1-vor-ident" ) ) {
+                // cout << "Added nav1-vor-ident sound" << endl;
+            } else {
+                // cout << "Failed to add v1-vor-ident sound" << endl;
+            }
 
            if ( globals->get_soundmgr()->exists( "nav1-dme-ident" ) ) {
                globals->get_soundmgr()->remove( "nav1-dme-ident" );
@@ -896,7 +850,9 @@ void FGRadioStack::search()
        nav1_trans_ident = "";
        last_nav1_ident = "";
 #ifdef ENABLE_AUDIO_SUPPORT
-       globals->get_soundmgr()->remove( "nav1-vor-ident" );
+       if ( ! globals->get_soundmgr()->remove( "nav1-vor-ident" ) ) {
+            // cout << "Failed to remove nav1-vor-ident sound" << endl;
+        }
        globals->get_soundmgr()->remove( "nav1-dme-ident" );
 #endif
        // cout << "not picking up vor1. :-(" << endl;
@@ -1128,67 +1084,7 @@ void FGRadioStack::search()
     }
     last_beacon = beacon_type;
 
-
-    ////////////////////////////////////////////////////////////////////////
-    // ADF.
-    ////////////////////////////////////////////////////////////////////////
-
-    if ( current_navlist->query( lon, lat, elev, adf_freq, &nav ) ) {
-       char freq[128];
-#if defined( _MSC_VER ) || defined(__MINGW32__)
-       _snprintf( freq, 10, "%.0f", adf_freq );
-#else
-       snprintf( freq, 10, "%.0f", adf_freq );
-#endif
-       adf_ident = freq;
-       adf_ident += nav.get_ident();
-       // cout << "adf ident = " << adf_ident << endl;
-       adf_valid = true;
-       if ( last_adf_ident != adf_ident ) {
-           last_adf_ident = adf_ident;
-
-           adf_trans_ident = nav.get_trans_ident();
-           adf_lon = nav.get_lon();
-           adf_lat = nav.get_lat();
-           adf_elev = nav.get_elev();
-           adf_range = nav.get_range();
-           adf_effective_range = kludgeRange(adf_elev, elev, adf_range);
-           adf_x = nav.get_x();
-           adf_y = nav.get_y();
-           adf_z = nav.get_z();
-
-#ifdef ENABLE_AUDIO_SUPPORT
-           if ( globals->get_soundmgr()->exists( "adf-ident" ) ) {
-               globals->get_soundmgr()->remove( "adf-ident" );
-           }
-           FGSimpleSound *sound;
-           sound = morse.make_ident( adf_trans_ident, LO_FREQUENCY );
-           sound->set_volume( 0.3 );
-           globals->get_soundmgr()->add( sound, "adf-ident" );
-
-           int offset = (int)(sg_random() * 30.0);
-           adf_play_count = offset / 4;
-           adf_last_time = globals->get_time_params()->get_cur_time() -
-               offset;
-           // cout << "offset = " << offset << " play_count = "
-           //      << adf_play_count << " adf_last_time = "
-           //      << adf_last_time << " current time = "
-           //      << globals->get_time_params()->get_cur_time() << endl;
-#endif
-
-           // cout << "Found an adf station in range" << endl;
-           // cout << " id = " << nav.get_ident() << endl;
-       }
-    } else {
-       adf_valid = false;
-       adf_ident = "";
-       adf_trans_ident = "";
-#ifdef ENABLE_AUDIO_SUPPORT
-       globals->get_soundmgr()->remove( "adf-ident" );
-#endif
-       last_adf_ident = "";
-       // cout << "not picking up adf. :-(" << endl;
-    }
+    adf.search();
 }