X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fnewnavradio.cxx;h=41b606c152bbe3b49702815e98d9bb4693bc5456;hb=9d995907db00728da7eac9297ecbab93ed8a7400;hp=f98f5aee8294968f9b787b2938bd78689851db26;hpb=312447c565ec410f52353ba22d305cf470e9ba33;p=flightgear.git diff --git a/src/Instrumentation/newnavradio.cxx b/src/Instrumentation/newnavradio.cxx old mode 100755 new mode 100644 index f98f5aee8..41b606c15 --- a/src/Instrumentation/newnavradio.cxx +++ b/src/Instrumentation/newnavradio.cxx @@ -3,7 +3,7 @@ // Written by Curtis Olson, started April 2000. // Rewritten by Torsten Dreyer, August 2011 // -// Copyright (C) 2000 - 2002 Curtis L. Olson - http://www.flightgear.org/~curt +// Copyright (C) 2000 - 2011 Curtis L. Olson - http://www.flightgear.org/~curt // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -29,10 +29,11 @@ #include #include -#include #include #include #include +#include +#include #include
#include @@ -144,10 +145,11 @@ public: virtual double getRange_nm( const SGGeod & aircraftPosition ); virtual void display( NavIndicator & navIndicator ) = 0; virtual bool valid() const { return NULL != _navRecord && true == _serviceable; } + virtual const std::string getIdent() const { return _ident; } protected: virtual double computeSignalQuality_norm( const SGGeod & aircraftPosition ); - virtual FGNavList * getNavaidList() = 0; + virtual FGNavList::TypeFilter* getNavaidFilter() = 0; // General-purpose sawtooth function. Graph looks like this: // /\ . @@ -172,7 +174,7 @@ protected: PropertyObject _trackDistance_m; PropertyObject _slantDistance_m; PropertyObject _heightAboveStation_ft; - PropertyObject _ident; + PropertyObject _ident; PropertyObject _inRange; PropertyObject _range_nm; }; @@ -220,7 +222,7 @@ void NavRadioComponentWithIdent::update( double dt, const SGGeod & aircraftPosit _audioIdent->setIdent("", 0.0 ); return; } - _audioIdent->setIdent( _navRecord->get_trans_ident(), SGMiscd::clip(_identVolume, 0.0, 1.0) ); + _audioIdent->setIdent( _ident, SGMiscd::clip(_identVolume, 0.0, 1.0) ); } NavRadioComponent::NavRadioComponent( const std::string & name, SGPropertyNode_ptr rootNode ) : @@ -257,7 +259,8 @@ double NavRadioComponent::getRange_nm( const SGGeod & aircraftPosition ) void NavRadioComponent::search( double frequency, const SGGeod & aircraftPosition ) { - if( NULL == (_navRecord = getNavaidList()->findByFreq(frequency, aircraftPosition )) ) { + _navRecord = FGNavList::findByFreq(frequency, aircraftPosition, getNavaidFilter() ); + if( NULL == _navRecord ) { SG_LOG(SG_INSTR,SG_ALERT, "No " << _name << " available at " << frequency ); _ident = ""; return; @@ -321,7 +324,7 @@ public: virtual double getRange_nm(const SGGeod & aircraftPosition); protected: virtual double computeSignalQuality_norm( const SGGeod & aircraftPosition ); - virtual FGNavList * getNavaidList(); + virtual FGNavList::TypeFilter* getNavaidFilter(); private: double _totalTime; @@ -375,7 +378,9 @@ double VOR::ServiceVolume::adjustRange( double height_ft, double nominalRange_nm } VOR::VOR( SGPropertyNode_ptr rootNode) : - NavRadioComponentWithIdent("vor", rootNode, new VORAudioIdent(getIdentString(string("vor"), rootNode->getIndex()))), + NavRadioComponentWithIdent("vor", rootNode, + new VORAudioIdent(getIdentString(std::string("vor"), + rootNode->getIndex()))), _totalTime(0.0), _radial( rootNode->getNode(_name,true)->getNode("radial",true) ), _radialInbound( rootNode->getNode(_name,true)->getNode("radial-inbound",true) ) @@ -391,9 +396,10 @@ double VOR::getRange_nm( const SGGeod & aircraftPosition ) return _serviceVolume.adjustRange( _heightAboveStation_ft, _navRecord->get_range() ); } -FGNavList * VOR::getNavaidList() +FGNavList::TypeFilter* VOR::getNavaidFilter() { - return globals->get_navlist(); + static FGNavList::TypeFilter filter(FGPositioned::VOR); + return &filter; } double VOR::computeSignalQuality_norm( const SGGeod & aircraftPosition ) @@ -466,7 +472,7 @@ public: protected: virtual double computeSignalQuality_norm( const SGGeod & aircraftPosition ); - virtual FGNavList * getNavaidList(); + virtual FGNavList::TypeFilter* getNavaidFilter(); private: class ServiceVolume { @@ -519,7 +525,8 @@ double LOC::ServiceVolume::adjustRange( double azimuthAngle_deg, double elevatio } LOC::LOC( SGPropertyNode_ptr rootNode) : - NavRadioComponentWithIdent("loc", rootNode, new LOCAudioIdent(getIdentString(string("loc"), rootNode->getIndex()))), + NavRadioComponentWithIdent("loc", rootNode, new LOCAudioIdent(getIdentString(std::string("loc"), + rootNode->getIndex()))), _serviceVolume(), _localizerOffset_norm( rootNode->getNode(_name,true)->getNode("offset-norm",true) ), _localizerWidth_deg( rootNode->getNode(_name,true)->getNode("width-deg",true) ) @@ -530,9 +537,9 @@ LOC::~LOC() { } -FGNavList * LOC::getNavaidList() +FGNavList::TypeFilter* LOC::getNavaidFilter() { - return globals->get_loclist(); + return FGNavList::locFilter(); } void LOC::search( double frequency, const SGGeod & aircraftPosition ) @@ -616,8 +623,7 @@ public: virtual double getRange_nm(const SGGeod & aircraftPosition); protected: - virtual FGNavList * getNavaidList(); - + virtual FGNavList::TypeFilter* getNavaidFilter(); private: class ServiceVolume { public: @@ -685,9 +691,10 @@ GS::~GS() { } -FGNavList * GS::getNavaidList() +FGNavList::TypeFilter* GS::getNavaidFilter() { - return globals->get_gslist(); + static FGNavList::TypeFilter filter(FGPositioned::GS); + return &filter; } double GS::getRange_nm(const SGGeod & aircraftPosition) @@ -806,7 +813,7 @@ public: void valueChanged (SGPropertyNode * prop) { // format as fixed decimal "nnn.nn" - ostringstream buf; + std::ostringstream buf; buf << std::fixed << std::setw(5) << std::setfill('0') @@ -851,6 +858,11 @@ private: NavRadioImpl * _navRadioImpl; SGPropertyNode_ptr is_valid_node; SGPropertyNode_ptr nav_serviceable_node; + SGPropertyNode_ptr nav_id_node; + SGPropertyNode_ptr id_c1_node; + SGPropertyNode_ptr id_c2_node; + SGPropertyNode_ptr id_c3_node; + SGPropertyNode_ptr id_c4_node; } _legacy; const static int VOR_COMPONENT = 0; @@ -873,7 +885,7 @@ NavRadioImpl::NavRadioImpl( SGPropertyNode_ptr node ) : _legacy( this ), _name(node->getStringValue("name", "nav")), _num(node->getIntValue("number", 0)), - _rootNode(fgGetNode( string("/instrumentation/") + _name, _num, true)), + _rootNode(fgGetNode( std::string("/instrumentation/") + _name, _num, true)), _useFrequencyFormatter( _rootNode->getNode("frequencies/selected-mhz",true), _rootNode->getNode("frequencies/selected-mhz-fmt",true), 0.05 ), _stbyFrequencyFormatter( _rootNode->getNode("frequencies/standby-mhz",true), _rootNode->getNode("frequencies/standby-mhz-fmt",true), 0.05 ), _navIndicator(_rootNode), @@ -892,7 +904,7 @@ NavRadioImpl::~NavRadioImpl() void NavRadioImpl::init() { - if( 0 < _components.size() ) + if( ! _components.empty() ) return; _components.push_back( new VOR(_rootNode) ); @@ -915,7 +927,7 @@ void NavRadioImpl::update( double dt ) try { position = globals->get_aircraft_position(); } - catch( exception & ) { + catch( std::exception & ) { return; } @@ -937,7 +949,7 @@ void NavRadioImpl::update( double dt ) if( _stationTTL <= 0.0 ) _stationTTL = 30.0; - _legacy.init(); + _legacy.update( dt ); } void NavRadioImpl::Legacy::init() @@ -945,6 +957,12 @@ void NavRadioImpl::Legacy::init() is_valid_node = _navRadioImpl->_rootNode->getChild("data-is-valid", 0, true); nav_serviceable_node = _navRadioImpl->_rootNode->getChild("serviceable", 0, true); + nav_id_node = _navRadioImpl->_rootNode->getChild("nav-id", 0, true ); + id_c1_node = _navRadioImpl->_rootNode->getChild("nav-id_asc1", 0, true ); + id_c2_node = _navRadioImpl->_rootNode->getChild("nav-id_asc2", 0, true ); + id_c3_node = _navRadioImpl->_rootNode->getChild("nav-id_asc3", 0, true ); + id_c4_node = _navRadioImpl->_rootNode->getChild("nav-id_asc4", 0, true ); + } void NavRadioImpl::Legacy::update( double dt ) @@ -952,6 +970,18 @@ void NavRadioImpl::Legacy::update( double dt ) is_valid_node->setBoolValue( _navRadioImpl->_components[VOR_COMPONENT]->valid() || _navRadioImpl->_components[LOC_COMPONENT]->valid() ); + + std::string ident = _navRadioImpl->_components[VOR_COMPONENT]->getIdent(); + if( ident.empty() ) + ident = _navRadioImpl->_components[LOC_COMPONENT]->getIdent(); + + nav_id_node->setStringValue( ident ); + + ident = simgear::strutils::rpad( ident, 4, ' ' ); + id_c1_node->setIntValue( (int)ident[0] ); + id_c2_node->setIntValue( (int)ident[1] ); + id_c3_node->setIntValue( (int)ident[2] ); + id_c4_node->setIntValue( (int)ident[3] ); }