From a24ebc695830e0f33c35c6afc743b7c376537b1b Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 2 Jan 2006 23:01:45 +0000 Subject: [PATCH] - Add an "is-valid" property node so other modules can do a quick check if anything in the nav tree is valid or not. - Fix an order problem between caching data values and searching for a new station that could cause odd and unexpected and hard to reproduce results. --- src/Instrumentation/navradio.cxx | 19 ++++++++++++------- src/Instrumentation/navradio.hxx | 3 +++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Instrumentation/navradio.cxx b/src/Instrumentation/navradio.cxx index 0a32ec97c..399e3c507 100644 --- a/src/Instrumentation/navradio.cxx +++ b/src/Instrumentation/navradio.cxx @@ -48,6 +48,7 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) : lon_node(fgGetNode("/position/longitude-deg", true)), lat_node(fgGetNode("/position/latitude-deg", true)), alt_node(fgGetNode("/position/altitude-ft", true)), + is_valid_node(NULL), power_btn_node(NULL), freq_node(NULL), alt_freq_node(NULL), @@ -158,6 +159,7 @@ FGNavRadio::init () fgGetNode(("/systems/electrical/outputs/" + name).c_str(), true); // inputs + is_valid_node = node->getChild("data-is-valid", 0, true); power_btn_node = node->getChild("power-btn", 0, true); power_btn_node->setBoolValue( true ); vol_btn_node = node->getChild("volume", 0, true); @@ -312,6 +314,14 @@ double FGNavRadio::adjustILSRange( double stationElev, double aircraftElev, void FGNavRadio::update(double dt) { + // Do a nav station search only once a second to reduce + // unnecessary work. (Also, make sure to do this before caching + // any values!) + _time_before_search_sec -= dt; + if ( _time_before_search_sec < 0 ) { + search(); + } + // cache a few strategic values locally for speed double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; @@ -337,13 +347,6 @@ FGNavRadio::update(double dt) sprintf( tmp, "%.2f", alt_freq_node->getDoubleValue() ); fmt_alt_freq_node->setStringValue(tmp); - // Do a nav station search only once a second to reduce - // unnecessary work. - _time_before_search_sec -= dt; - if ( _time_before_search_sec < 0 ) { - search(); - } - // cout << "is_valid = " << is_valid // << " power_btn = " << power_btn // << " bus_power = " << bus_power_node->getDoubleValue() @@ -942,6 +945,8 @@ void FGNavRadio::search() // cout << "not picking up vor1. :-(" << endl; } + is_valid_node->setBoolValue( is_valid ); + char tmpid[5]; strncpy( tmpid, nav_id.c_str(), 5 ); id_c1_node->setIntValue( (int)tmpid[0] ); diff --git a/src/Instrumentation/navradio.hxx b/src/Instrumentation/navradio.hxx index 610097c1e..1cb7f7402 100644 --- a/src/Instrumentation/navradio.hxx +++ b/src/Instrumentation/navradio.hxx @@ -49,6 +49,8 @@ class FGNavRadio : public SGSubsystem SGPropertyNode *bus_power_node; // property inputs + SGPropertyNode *is_valid_node; // is station data valid (may be way out + // of range.) SGPropertyNode *power_btn_node; SGPropertyNode *freq_node; // primary freq SGPropertyNode *alt_freq_node; // standby freq @@ -105,6 +107,7 @@ class FGNavRadio : public SGSubsystem // internal (private) values + string nav_id; string last_nav_id; bool last_nav_vor; int play_count;