]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/navradio.cxx
Add a lower-bound type navaid lookup, and the ability to specify navaid type in the...
[flightgear.git] / src / Instrumentation / navradio.cxx
index 6d00f42b2e08961e816dc712d09c3f3d2b5a1e5a..60347312467e224391e119953dcb9f65575ea379 100644 (file)
@@ -57,6 +57,8 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) :
     audio_btn(true),
     nav_freq(0.0),
     nav_alt_freq(0.0),
+    fmt_freq(""),
+    fmt_alt_freq(""),
     nav_heading(0.0),
     nav_radial(0.0),
     nav_target_radial(0.0),
@@ -68,7 +70,8 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) :
     horiz_vel(0.0),
     last_x(0.0),
     name("nav"),
-    num(0)
+    num(0),
+    _time_before_search_sec(-1.0)
 {
     SGPath path( globals->get_fg_root() );
     SGPath term = path;
@@ -128,9 +131,15 @@ FGNavRadio::init ()
     cdi_serviceable = (node->getChild("cdi", 0, true))
        ->getChild("serviceable", 0, true);
     gs_serviceable = (node->getChild("gs", 0, true))
-       ->getNode("serviceable");
+       ->getChild("serviceable");
     tofrom_serviceable = (node->getChild("to-from", 0, true))
        ->getChild("serviceable", 0, true);
+
+    std::ostringstream temp;
+    temp << name << "nav-ident" << num;
+    nav_fx_name = temp.str();
+    temp << name << "dme-ident" << num;
+    dme_fx_name = temp.str();
 }
 
 void
@@ -142,6 +151,10 @@ FGNavRadio::bind ()
     branch = "/instrumentation/" + name + "[" + temp.str() + "]";
 
                                // User inputs
+    fgTie( (branch + "power-btn").c_str(), this,
+           &FGNavRadio::get_power_btn, &FGNavRadio::set_power_btn );
+    fgSetArchivable( (branch + "power-btn").c_str() );
+
     fgTie( (branch + "/frequencies/selected-mhz").c_str() , this,
          &FGNavRadio::get_nav_freq, &FGNavRadio::set_nav_freq );
     fgSetArchivable( (branch + "/frequencies/selected-mhz").c_str() );
@@ -150,6 +163,14 @@ FGNavRadio::bind ()
            &FGNavRadio::get_nav_alt_freq, &FGNavRadio::set_nav_alt_freq);
     fgSetArchivable( (branch + "/frequencies/standby-mhz").c_str() );
 
+    fgTie( (branch + "/frequencies/selected-mhz-fmt").c_str() , this,
+         &FGNavRadio::get_fmt_freq, &FGNavRadio::set_fmt_freq );
+    fgSetArchivable( (branch + "/frequencies/selected-mhz-fmt").c_str() );
+
+    fgTie( (branch + "/frequencies/standby-mhz-fmt").c_str() , this,
+           &FGNavRadio::get_fmt_alt_freq, &FGNavRadio::set_fmt_alt_freq);
+    fgSetArchivable( (branch + "/frequencies/standby-mhz-fmt").c_str() );
+
     fgTie( (branch + "/radials/selected-deg").c_str() , this,
            &FGNavRadio::get_nav_sel_radial, &FGNavRadio::set_nav_sel_radial );
     fgSetArchivable((branch + "/radials/selected-deg").c_str() );
@@ -176,6 +197,9 @@ FGNavRadio::bind ()
     fgTie( (branch + "/radials/target-radial-deg").c_str(),
           this, &FGNavRadio::get_nav_target_radial_true );
 
+    fgTie( (branch + "/radials/reciprocal-radial-deg").c_str(),
+          this, &FGNavRadio::get_nav_reciprocal_radial );
+
     fgTie( (branch + "/radials/target-auto-hdg-deg").c_str(),
           this, &FGNavRadio::get_nav_target_auto_hdg );
 
@@ -206,6 +230,12 @@ FGNavRadio::bind ()
     fgTie( (branch + "/gs-needle-deflection").c_str(),
           this, &FGNavRadio::get_nav_gs_deflection );
 
+    fgTie( (branch + "/gs-distance").c_str(),
+          this, &FGNavRadio::get_nav_gs_dist_signed );
+
+    fgTie( (branch + "/nav-distance").c_str(),
+          this, &FGNavRadio::get_nav_loc_dist );
+
     fgTie( (branch + "/nav-id").c_str(),
           this, &FGNavRadio::get_nav_id );
 
@@ -324,6 +354,14 @@ FGNavRadio::update(double dt)
     Point3D station;
     double az1, az2, s;
 
+    // Create "formatted" versions of the nav frequencies for
+    // consistant display output.
+    char tmp[16];
+    sprintf( tmp, "%.2f", nav_freq );
+    fmt_freq = tmp;
+    sprintf( tmp, "%.2f", nav_alt_freq );
+    fmt_alt_freq = tmp;
+
     // On timeout, scan again
     _time_before_search_sec -= dt;
     if ( _time_before_search_sec < 0 ) {
@@ -334,11 +372,19 @@ FGNavRadio::update(double dt)
     // Nav.
     ////////////////////////////////////////////////////////////////////////
 
+    // cout << "nav_valid = " << nav_valid
+    //      << " power_btn = " << power_btn
+    //      << " bus_power = " << bus_power->getDoubleValue()
+    //      << " nav_serviceable = " << nav_serviceable->getBoolValue()
+    //      << endl;
+
     if ( nav_valid && power_btn && (bus_power->getDoubleValue() > 1.0)
          && nav_serviceable->getBoolValue() )
     {
        station = Point3D( nav_x, nav_y, nav_z );
        nav_loc_dist = aircraft.distance3D( station );
+        // cout << "station = " << station << " dist = " << nav_loc_dist
+        //      << endl;
 
        if ( nav_has_gs ) {
             // find closest distance to the gs base line