X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fadf.cxx;h=053812a0df61c6a4845a545458b3fc03c3f72074;hb=43880b201cea2b120fefd99696ae0b43227358dc;hp=efae4aa34c2699b0ac5405086047e612e6fc827e;hpb=ef52b23e3a1aaf44d1a2283c920a70367960abff;p=flightgear.git diff --git a/src/Instrumentation/adf.cxx b/src/Instrumentation/adf.cxx index efae4aa34..053812a0d 100644 --- a/src/Instrumentation/adf.cxx +++ b/src/Instrumentation/adf.cxx @@ -10,6 +10,7 @@ #include #include #include +#include #include
#include
@@ -58,6 +59,8 @@ adjust_range (double transmitter_elevation_ft, double aircraft_altitude_ft, ADF::ADF (SGPropertyNode *node ) : + _name(node->getStringValue("name", "adf")), + _num(node->getIntValue("number", 0)), _time_before_search_sec(0), _last_frequency_khz(-1), _transmitter_valid(false), @@ -66,41 +69,7 @@ ADF::ADF (SGPropertyNode *node ) _transmitter_range_nm(0), _ident_count(0), _last_ident_time(0), - _last_volume(-1), - name("adf"), - num(0) -{ - int i; - for ( i = 0; i < node->nChildren(); ++i ) { - SGPropertyNode *child = node->getChild(i); - string cname = child->getName(); - string cval = child->getStringValue(); - if ( cname == "name" ) { - name = cval; - } else if ( cname == "number" ) { - num = child->getIntValue(); - } else { - SG_LOG( SG_INSTR, SG_WARN, "Error in adf config logic" ); - if ( name.length() ) { - SG_LOG( SG_INSTR, SG_WARN, "Section = " << name ); - } - } - } -} - - -ADF::ADF () - : _time_before_search_sec(0), - _last_frequency_khz(-1), - _transmitter_valid(false), - _transmitter_pos(SGGeod::fromDeg(0, 0)), - _transmitter_cart(0, 0, 0), - _transmitter_range_nm(0), - _ident_count(0), - _last_ident_time(0), - _last_volume(-1), - name("adf"), - num(0) + _last_volume(-1) { } @@ -112,9 +81,9 @@ void ADF::init () { string branch; - branch = "/instrumentation/" + name; + branch = "/instrumentation/" + _name; - SGPropertyNode *node = fgGetNode(branch.c_str(), num, true ); + SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true ); _longitude_node = fgGetNode("/position/longitude-deg", true); _latitude_node = fgGetNode("/position/latitude-deg", true); _altitude_node = fgGetNode("/position/altitude-ft", true); @@ -135,16 +104,16 @@ ADF::init () morse.init(); std::ostringstream temp; - temp << name << num; - adf_ident = temp.str(); + temp << _name << _num; + _adf_ident = temp.str(); } void ADF::update (double delta_time_sec) { // If it's off, don't waste any time. - if (!_electrical_node->getBoolValue() || - !_serviceable_node->getBoolValue()) { + if (_electrical_node->getDoubleValue() < 1.0 + || !_serviceable_node->getBoolValue()) { set_bearing(delta_time_sec, 90); _ident_node->setStringValue(""); return; @@ -212,7 +181,7 @@ ADF::update (double delta_time_sec) _last_volume = volume; SGSoundSample *sound; - sound = globals->get_soundmgr()->find( adf_ident ); + sound = globals->get_soundmgr()->find( _adf_ident ); if ( sound != NULL ) sound->set_volume( volume ); else @@ -226,8 +195,8 @@ ADF::update (double delta_time_sec) } if ( _ident_count < 4 ) { - if ( !globals->get_soundmgr()->is_playing(adf_ident) ) { - globals->get_soundmgr()->play_once( adf_ident ); + if ( !globals->get_soundmgr()->is_playing(_adf_ident) ) { + globals->get_soundmgr()->play_once( _adf_ident ); ++_ident_count; } } @@ -235,7 +204,7 @@ ADF::update (double delta_time_sec) _in_range_node->setBoolValue(false); set_bearing(delta_time_sec, 90); _ident_node->setStringValue(""); - globals->get_soundmgr()->stop( adf_ident ); + globals->get_soundmgr()->stop( _adf_ident ); } } @@ -248,16 +217,15 @@ ADF::search (double frequency_khz, double longitude_rad, _time_before_search_sec = 1.0; // try the ILS list first - FGNavRecord *nav = - globals->get_navlist()->findByFreq(frequency_khz, longitude_rad, - latitude_rad, altitude_m); + FGNavRecord *nav = globals->get_navlist()->findByFreq(frequency_khz, + SGGeod::fromRadM(longitude_rad, latitude_rad, altitude_m)); _transmitter_valid = (nav != NULL); if ( _transmitter_valid ) { ident = nav->get_trans_ident(); if ( ident != _last_ident ) { - _transmitter_pos = nav->get_pos(); - _transmitter_cart = nav->get_cart(); + _transmitter_pos = nav->geod(); + _transmitter_cart = nav->cart(); _transmitter_range_nm = nav->get_range(); } } @@ -266,16 +234,16 @@ ADF::search (double frequency_khz, double longitude_rad, _last_ident = ident; _ident_node->setStringValue(ident.c_str()); - if ( globals->get_soundmgr()->exists( adf_ident ) ) { + if ( globals->get_soundmgr()->exists( _adf_ident ) ) { // stop is required! -- remove alone wouldn't stop immediately - globals->get_soundmgr()->stop( adf_ident ); - globals->get_soundmgr()->remove( adf_ident ); + globals->get_soundmgr()->stop( _adf_ident ); + globals->get_soundmgr()->remove( _adf_ident ); } SGSoundSample *sound; sound = morse.make_ident( ident, LO_FREQUENCY ); sound->set_volume(_last_volume = 0); - globals->get_soundmgr()->add( sound, adf_ident ); + globals->get_soundmgr()->add( sound, _adf_ident ); int offset = (int)(sg_random() * 30.0); _ident_count = offset / 4;