diff --git a/src/Environment/realwx_ctrl.cxx b/src/Environment/realwx_ctrl.cxx index 3db5d9058..afa41c62b 100644 --- a/src/Environment/realwx_ctrl.cxx +++ b/src/Environment/realwx_ctrl.cxx @@ -52,6 +52,7 @@ namespace Environment { class MetarDataHandler { public: virtual void handleMetarData( const std::string & data ) = 0; + virtual void handleMetarFailure() = 0; }; class MetarRequester { @@ -73,7 +74,8 @@ public: // implementation of MetarDataHandler virtual void handleMetarData( const std::string & data ); - + virtual void handleMetarFailure(); + static const unsigned MAX_POLLING_INTERVAL_SECONDS = 10; static const unsigned DEFAULT_TIME_TO_LIVE_SECONDS = 900; @@ -82,6 +84,7 @@ private: double _pollingTimer; MetarRequester * _metarRequester; int _maxAge; + bool _failure; }; typedef SGSharedPtr LiveMetarProperties_ptr; @@ -91,9 +94,11 @@ LiveMetarProperties::LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequ _timeToLive(0.0), _pollingTimer(0.0), _metarRequester(metarRequester), - _maxAge(maxAge) + _maxAge(maxAge), + _failure(false) { _tiedProperties.Tie("time-to-live", &_timeToLive ); + _tiedProperties.Tie("failure", &_failure); } LiveMetarProperties::~LiveMetarProperties() @@ -126,6 +131,7 @@ void LiveMetarProperties::handleMetarData( const std::string & data ) } catch( sg_io_exception ) { SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << data ); + _failure = true; return; } @@ -134,10 +140,16 @@ void LiveMetarProperties::handleMetarData( const std::string & data ) SG_LOG( SG_ENVIRONMENT, SG_DEBUG, "Ignoring outdated METAR for " << getStationId()); return; } - + + _failure = false; setMetar( m ); } +void LiveMetarProperties::handleMetarFailure() +{ + _failure = true; +} + /* -------------------------------------------------------------------------------- */ class BasicRealWxController : public RealWxController @@ -440,6 +452,7 @@ void NoaaMetarRealWxController::requestMetar virtual void onFail() { SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failure"); + _metarDataHandler->handleMetarFailure(); } private: diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx index ed60183a1..f3bac6f7e 100644 --- a/src/Main/positioninit.cxx +++ b/src/Main/positioninit.cxx @@ -595,6 +595,10 @@ bool initPosition() bool finalizeMetar() { + if (!fgGetBool("/environment/realwx/enabled")) { + return true; + } + double hdg = fgGetDouble( "/environment/metar/base-wind-dir-deg", 9999.0 ); string apt = fgGetString("/sim/presets/airport-id"); string rwy = fgGetString("/sim/presets/runway"); @@ -607,11 +611,16 @@ bool finalizeMetar() if (needMetar) { // timeout so we don't spin forever if the network is down - if (global_finalizeTime.elapsedMSec() > fgGetInt("/sim/startup/metar-fetch-timeout-msec", 10000)) { + if (global_finalizeTime.elapsedMSec() > fgGetInt("/sim/startup/metar-fetch-timeout-msec", 6000)) { SG_LOG(SG_GENERAL, SG_WARN, "finalizePosition: timed out waiting for METAR fetch"); return true; } + if (fgGetBool( "/environment/metar/failure" )) { + SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failed, not waiting"); + return true; + } + if (!fgGetBool( "/environment/metar/valid" )) { return false; }