]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/radiostack.cxx
Patch from Melchior Franz:
[flightgear.git] / src / Cockpit / radiostack.cxx
index b065a8cc2e441c5472ca62995000f739c41757f2..62669ae93fc45db63b7a029c9a1bdc7def8c8013 100644 (file)
 #include <simgear/math/sg_random.h>
 
 #include <Aircraft/aircraft.hxx>
-#include <ATC/ATCdisplay.hxx>
-//#include <Navaids/atis.hxx>
 #include <Navaids/ilslist.hxx>
 #include <Navaids/mkrbeacons.hxx>
 #include <Navaids/navlist.hxx>
-#include <Time/event.hxx>
+#include <Time/FGEventMgr.hxx>
 
 #include "radiostack.hxx"
 
@@ -79,11 +77,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)),
@@ -92,21 +85,29 @@ 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),
     dme_spd(0.0),
     dme_ete(0.0),
+    outer_blink(false),
+    middle_blink(false),
+    inner_blink(false),
     adf_freq(0.0),
-    adf_alt_freq(0.0)
+    adf_alt_freq(0.0),
+    adf_vol_btn(0.0)
 {
     SGPath path( globals->get_fg_root() );
     SGPath term = path;
@@ -145,8 +146,9 @@ FGRadioStack::init ()
     update(1);                 // FIXME: use dt
 
     // 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
@@ -404,9 +406,6 @@ double FGRadioStack::adjustILSRange( double stationElev, double aircraftElev,
 void 
 FGRadioStack::update(int dt) 
 {
-    //DCL
-    string transmission;
-
     double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
     double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
     double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
@@ -417,48 +416,6 @@ FGRadioStack::update(int dt)
     Point3D station;
     double az1, az2, s;
 
-    ////////////////////////////////////////////////////////////////////////
-    // Comm1.
-    ////////////////////////////////////////////////////////////////////////
-
-    static bool repeating_message_registered = false;
-    static int dcl_i = 0;   //Hack to only call the transmission now and then - should use the event scheduler
-    if ( comm1_valid ) {
-       station = Point3D( comm1_x, comm1_y, comm1_z );
-       comm1_dist = aircraft.distance3D( station );
-       if ( comm1_dist < comm1_effective_range * SG_NM_TO_METER ) {
-           comm1_inrange = true;
-           // TODO - only get the transmission and register every now and then
-           if(dcl_i == 0) {
-               transmission = atis.get_transmission();
-               current_atcdisplay->ChangeRepeatingMessage(transmission);
-           }
-           if(!repeating_message_registered) {
-               current_atcdisplay->RegisterRepeatingMessage(transmission);
-               repeating_message_registered = true;
-           }
-           dcl_i++;
-           if(dcl_i == 2000) {
-               dcl_i = 0;
-           }
-       } else {
-           comm1_inrange = false;
-           if(repeating_message_registered) {
-               current_atcdisplay->CancelRepeatingMessage();
-               repeating_message_registered = false;
-           }
-           dcl_i = 0;
-       }
-    } else {
-       comm1_inrange = false;
-       if(repeating_message_registered) {
-           current_atcdisplay->CancelRepeatingMessage();
-           repeating_message_registered = false;
-       }
-       dcl_i = 0;
-       // cout << "not picking up comm1. :-(" << endl;
-    }
-
     ////////////////////////////////////////////////////////////////////////
     // Nav1.
     ////////////////////////////////////////////////////////////////////////
@@ -521,20 +478,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") &&
@@ -612,10 +585,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;
@@ -727,7 +710,11 @@ FGRadioStack::update(int dt)
        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 ( sound != NULL ) {
+                sound->set_volume( adf_vol_btn );
+            } else {
+                SG_LOG( SG_COCKPIT, SG_ALERT, "Can't find adf-ident sound" );
+            }
            if ( adf_last_time <
                 globals->get_time_params()->get_cur_time() - 30 ) {
                adf_last_time = globals->get_time_params()->get_cur_time();
@@ -812,43 +799,12 @@ void FGRadioStack::search()
     FGILS ils;
     FGNav nav;
 
-    static string last_comm1_ident = "";
-    static string last_comm2_ident = "";
     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;
 
-
-    ////////////////////////////////////////////////////////////////////////
-    // Comm1.
-    ////////////////////////////////////////////////////////////////////////
-
-    if ( current_atislist->query( lon, lat, elev, comm1_freq, &atis ) ) {
-       //cout << "atis found in radiostack search !!!!" << endl;
-       comm1_ident = atis.get_ident();
-       comm1_valid = true;
-       if ( last_comm1_ident != comm1_ident ) {
-           //nav1_trans_ident = ils.get_trans_ident();
-           last_comm1_ident = comm1_ident;
-           comm1_elev = atis.get_elev();
-           comm1_range = FG_ATIS_DEFAULT_RANGE;
-           comm1_effective_range = comm1_range;
-           comm1_x = atis.get_x();
-           comm1_y = atis.get_y();
-           comm1_z = atis.get_z();
-           //cout << "Found a new atis station in range" << endl;
-           //cout << " id = " << atis.get_ident() << endl;
-       }
-    } else {
-       comm1_valid = false;
-       comm1_ident = "";
-       //comm1_trans_ident = "";
-       last_comm1_ident = "";
-       // cout << "not picking up atis" << endl;
-    }
-
     ////////////////////////////////////////////////////////////////////////
     // Nav1.
     ////////////////////////////////////////////////////////////////////////
@@ -942,7 +898,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" );
@@ -971,7 +931,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;
@@ -1422,4 +1384,3 @@ FGRadioStack::get_nav2_from_flag () const
     return false;
   }
 }
-