1
0
Fork 0

Metar: finalise-position fast if Metar fails

- when METAR lookup fails (as opposed to timing out), report
this immediately so finalise-position doesn't wait.
This commit is contained in:
James Turner 2014-02-24 19:42:52 +00:00
parent bd8e43c007
commit 99fd9513d9
2 changed files with 26 additions and 4 deletions

View 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:

View 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;
}