]> git.mxchange.org Git - flightgear.git/commitdiff
Metar: finalise-position fast if Metar fails
authorJames Turner <zakalawe@mac.com>
Mon, 24 Feb 2014 19:42:52 +0000 (19:42 +0000)
committerJames Turner <zakalawe@mac.com>
Mon, 24 Feb 2014 19:43:21 +0000 (19:43 +0000)
- when METAR lookup fails (as opposed to timing out), report
this immediately so finalise-position doesn't wait.

src/Environment/realwx_ctrl.cxx
src/Main/positioninit.cxx

index 3db5d905845a8c08e5b93a4633935ae82a82e967..afa41c62b123798c634d420b3808e7a29f9a9044 100644 (file)
@@ -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> 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:
index ed60183a12fca99deb8b79033870c99276647c1e..f3bac6f7ed6ae1da6ed455d21d7b5ba7f362cb7c 100644 (file)
@@ -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;
     }