X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fadf.cxx;h=8053545e522d3ce6a96dac38f29cb2b535e0e372;hb=68c71d5787f2a0309e35c3e05939950113618cb7;hp=e5303db019f7673c6668d67c4b757d7de834bd22;hpb=2c72f131639d4c2c2f1de7cff65f7ceab95f61c4;p=flightgear.git diff --git a/src/Instrumentation/adf.cxx b/src/Instrumentation/adf.cxx index e5303db01..8053545e5 100644 --- a/src/Instrumentation/adf.cxx +++ b/src/Instrumentation/adf.cxx @@ -3,20 +3,28 @@ // // This file is in the Public Domain and comes with no warranty. +#ifdef HAVE_CONFIG_H +# include +#endif + #include #include #include +#include #include
#include
#include #include "adf.hxx" +#include +#include #include #include #include +using std::string; // Use a bigger number to be more responsive, or a smaller number // to be more sluggish. @@ -54,47 +62,18 @@ 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), - _transmitter_elevation_ft(0), + _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) -{ - 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_elevation_ft(0), - _transmitter_range_nm(0), - _ident_count(0), - _last_ident_time(0), - _last_volume(-1), - name("adf"), - num(0) + _sgr(0) { } @@ -106,44 +85,65 @@ void ADF::init () { string branch; - branch = "/instrumentation/" + name; - - 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); - _heading_node = fgGetNode("/orientation/heading-deg", true); - _serviceable_node = node->getChild("serviceable", 0, true); - _error_node = node->getChild("error-deg", 0, true); - _electrical_node = fgGetNode("/systems/electrical/outputs/adf", true); - branch = branch + "/frequencies"; - SGPropertyNode *fnode = node->getChild("frequencies", 0, true); - _frequency_node = fnode->getChild("selected-khz", 0, true); - _mode_node = node->getChild("mode", 0, true); - _volume_node = node->getChild("volume-norm", 0, true); - _in_range_node = node->getChild("in-range", 0, true); - _bearing_node = node->getChild("indicated-bearing-deg", 0, true); - _ident_node = node->getChild("ident", 0, true); + branch = "/instrumentation/" + _name; + SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true ); + + // instrument properties + _error_node = node->getChild("error-deg", 0, true); + _mode_node = node->getChild("mode", 0, true); + _volume_node = node->getChild("volume-norm", 0, true); + _in_range_node = node->getChild("in-range", 0, true); + _bearing_node = node->getChild("indicated-bearing-deg", 0, true); + _ident_node = node->getChild("ident", 0, true); _ident_audible_node = node->getChild("ident-audible", 0, true); + _serviceable_node = node->getChild("serviceable", 0, true); + _power_btn_node = node->getChild("power-btn", 0, true); + _operable_node = node->getChild("operable", 0, true); + + // frequency properties + SGPropertyNode *fnode = node->getChild("frequencies", 0, true); + _frequency_node = fnode->getChild("selected-khz", 0, true); + + // foreign simulator properties + _electrical_node = fgGetNode("/systems/electrical/outputs/adf", true); + _heading_node = fgGetNode("/orientation/heading-deg", true); + + // backward compatibility check + if (_power_btn_node->getType() == simgear::props::NONE) + _power_btn_node->setBoolValue(true); // front end didn't implement a power button - morse.init(); + // sound support (audible ident code) + SGSoundMgr *smgr = globals->get_soundmgr(); + _sgr = smgr->find("avionics", true); + _sgr->tie_to_listener(); 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()) { - set_bearing(delta_time_sec, 90); + if (_electrical_node->getDoubleValue() < 8.0 + || !_serviceable_node->getBoolValue() + || !_power_btn_node->getBoolValue() ) { + _in_range_node->setBoolValue(false); + _operable_node->setBoolValue(false); _ident_node->setStringValue(""); return; } + _operable_node->setBoolValue(true); + + string mode = _mode_node->getStringValue(); + if (mode == "ant" || mode == "test") set_bearing(delta_time_sec, 90); + if (mode != "bfo" && mode != "adf") { + _in_range_node->setBoolValue(false); + _ident_node->setStringValue(""); + return; + } // Get the frequency int frequency_khz = _frequency_node->getIntValue(); if (frequency_khz != _last_frequency_khz) { @@ -151,46 +151,33 @@ ADF::update (double delta_time_sec) _last_frequency_khz = frequency_khz; } - // Get the aircraft position - double longitude_deg = _longitude_node->getDoubleValue(); - double latitude_deg = _latitude_node->getDoubleValue(); - double altitude_m = _altitude_node->getDoubleValue(); - - double longitude_rad = longitude_deg * SGD_DEGREES_TO_RADIANS; - double latitude_rad = latitude_deg * SGD_DEGREES_TO_RADIANS; - + SGGeod acPos(globals->get_aircraft_position()); + // On timeout, scan again _time_before_search_sec -= delta_time_sec; if (_time_before_search_sec < 0) - search(frequency_khz, longitude_rad, latitude_rad, altitude_m); + search(frequency_khz, acPos); - // If it's off, don't bother. - string mode = _mode_node->getStringValue(); - if (!_transmitter_valid || (mode != "bfo" && mode != "adf")) - { - set_bearing(delta_time_sec, 90); + if (!_transmitter_valid) { + _in_range_node->setBoolValue(false); _ident_node->setStringValue(""); return; } // Calculate the bearing to the transmitter - Point3D location = - sgGeodToCart(Point3D(longitude_rad, latitude_rad, altitude_m)); - - double distance_nm = _transmitter.distance3D(location) * SG_METER_TO_NM; - double range_nm = adjust_range(_transmitter_elevation_ft, - altitude_m * SG_METER_TO_FEET, + SGVec3d location = globals->get_aircraft_position_cart(); + + double distance_nm = dist(_transmitter_cart, location) * SG_METER_TO_NM; + double range_nm = adjust_range(_transmitter_pos.getElevationFt(), + acPos.getElevationFt(), _transmitter_range_nm); + if (distance_nm <= range_nm) { double bearing, az2, s; double heading = _heading_node->getDoubleValue(); - geo_inverse_wgs_84(altitude_m, - latitude_deg, - longitude_deg, - _transmitter_lat_deg, - _transmitter_lon_deg, + geo_inverse_wgs_84(acPos, _transmitter_pos, &bearing, &az2, &s); _in_range_node->setBoolValue(true); @@ -200,9 +187,9 @@ ADF::update (double delta_time_sec) set_bearing(delta_time_sec, bearing); // adf ident sound - double volume; + float volume; if ( _ident_audible_node->getBoolValue() ) - volume = _volume_node->getDoubleValue(); + volume = _volume_node->getFloatValue(); else volume = 0.0; @@ -210,11 +197,11 @@ ADF::update (double delta_time_sec) _last_volume = volume; SGSoundSample *sound; - sound = globals->get_soundmgr()->find( adf_ident ); + sound = _sgr->find( _adf_ident ); if ( sound != NULL ) sound->set_volume( volume ); else - SG_LOG( SG_GENERAL, SG_ALERT, "Can't find adf-ident sound" ); + SG_LOG( SG_INSTR, SG_ALERT, "Can't find adf-ident sound" ); } time_t cur_time = globals->get_time_params()->get_cur_time(); @@ -224,40 +211,34 @@ 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 ( !_sgr->is_playing(_adf_ident) && (volume > 0.05) ) { + _sgr->play_once( _adf_ident ); ++_ident_count; } } } else { _in_range_node->setBoolValue(false); - set_bearing(delta_time_sec, 90); _ident_node->setStringValue(""); - globals->get_soundmgr()->stop( adf_ident ); + _sgr->stop( _adf_ident ); } } void -ADF::search (double frequency_khz, double longitude_rad, - double latitude_rad, double altitude_m) +ADF::search (double frequency_khz, const SGGeod& pos) { string ident = ""; // reset search time _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); + FGNavList::TypeFilter filter(FGPositioned::NDB); + FGNavRecord *nav = FGNavList::findByFreq(frequency_khz, pos, &filter); _transmitter_valid = (nav != NULL); if ( _transmitter_valid ) { ident = nav->get_trans_ident(); if ( ident != _last_ident ) { - _transmitter_lon_deg = nav->get_lon(); - _transmitter_lat_deg = nav->get_lat(); - _transmitter = Point3D(nav->get_x(), nav->get_y(), nav->get_z()); - _transmitter_elevation_ft = nav->get_elev_ft(); + _transmitter_pos = nav->geod(); + _transmitter_cart = nav->cart(); _transmitter_range_nm = nav->get_range(); } } @@ -266,16 +247,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 ( _sgr->exists( _adf_ident ) ) { // stop is required! -- remove alone wouldn't stop immediately - globals->get_soundmgr()->stop( adf_ident ); - globals->get_soundmgr()->remove( adf_ident ); + _sgr->stop( _adf_ident ); + _sgr->remove( _adf_ident ); } SGSoundSample *sound; - sound = morse.make_ident( ident, LO_FREQUENCY ); + sound = FGMorse::instance()->make_ident( ident, FGMorse::LO_FREQUENCY ); sound->set_volume(_last_volume = 0); - globals->get_soundmgr()->add( sound, adf_ident ); + _sgr->add( sound, _adf_ident ); int offset = (int)(sg_random() * 30.0); _ident_count = offset / 4;