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:
parent
bd8e43c007
commit
99fd9513d9
2 changed files with 26 additions and 4 deletions
|
@ -52,6 +52,7 @@ namespace Environment {
|
||||||
class MetarDataHandler {
|
class MetarDataHandler {
|
||||||
public:
|
public:
|
||||||
virtual void handleMetarData( const std::string & data ) = 0;
|
virtual void handleMetarData( const std::string & data ) = 0;
|
||||||
|
virtual void handleMetarFailure() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MetarRequester {
|
class MetarRequester {
|
||||||
|
@ -73,6 +74,7 @@ public:
|
||||||
|
|
||||||
// implementation of MetarDataHandler
|
// implementation of MetarDataHandler
|
||||||
virtual void handleMetarData( const std::string & data );
|
virtual void handleMetarData( const std::string & data );
|
||||||
|
virtual void handleMetarFailure();
|
||||||
|
|
||||||
static const unsigned MAX_POLLING_INTERVAL_SECONDS = 10;
|
static const unsigned MAX_POLLING_INTERVAL_SECONDS = 10;
|
||||||
static const unsigned DEFAULT_TIME_TO_LIVE_SECONDS = 900;
|
static const unsigned DEFAULT_TIME_TO_LIVE_SECONDS = 900;
|
||||||
|
@ -82,6 +84,7 @@ private:
|
||||||
double _pollingTimer;
|
double _pollingTimer;
|
||||||
MetarRequester * _metarRequester;
|
MetarRequester * _metarRequester;
|
||||||
int _maxAge;
|
int _maxAge;
|
||||||
|
bool _failure;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SGSharedPtr<LiveMetarProperties> LiveMetarProperties_ptr;
|
typedef SGSharedPtr<LiveMetarProperties> LiveMetarProperties_ptr;
|
||||||
|
@ -91,9 +94,11 @@ LiveMetarProperties::LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequ
|
||||||
_timeToLive(0.0),
|
_timeToLive(0.0),
|
||||||
_pollingTimer(0.0),
|
_pollingTimer(0.0),
|
||||||
_metarRequester(metarRequester),
|
_metarRequester(metarRequester),
|
||||||
_maxAge(maxAge)
|
_maxAge(maxAge),
|
||||||
|
_failure(false)
|
||||||
{
|
{
|
||||||
_tiedProperties.Tie("time-to-live", &_timeToLive );
|
_tiedProperties.Tie("time-to-live", &_timeToLive );
|
||||||
|
_tiedProperties.Tie("failure", &_failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveMetarProperties::~LiveMetarProperties()
|
LiveMetarProperties::~LiveMetarProperties()
|
||||||
|
@ -126,6 +131,7 @@ void LiveMetarProperties::handleMetarData( const std::string & data )
|
||||||
}
|
}
|
||||||
catch( sg_io_exception ) {
|
catch( sg_io_exception ) {
|
||||||
SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << data );
|
SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << data );
|
||||||
|
_failure = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,9 +141,15 @@ void LiveMetarProperties::handleMetarData( const std::string & data )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_failure = false;
|
||||||
setMetar( m );
|
setMetar( m );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LiveMetarProperties::handleMetarFailure()
|
||||||
|
{
|
||||||
|
_failure = true;
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
class BasicRealWxController : public RealWxController
|
class BasicRealWxController : public RealWxController
|
||||||
|
@ -440,6 +452,7 @@ void NoaaMetarRealWxController::requestMetar
|
||||||
virtual void onFail()
|
virtual void onFail()
|
||||||
{
|
{
|
||||||
SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failure");
|
SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failure");
|
||||||
|
_metarDataHandler->handleMetarFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -595,6 +595,10 @@ bool initPosition()
|
||||||
|
|
||||||
bool finalizeMetar()
|
bool finalizeMetar()
|
||||||
{
|
{
|
||||||
|
if (!fgGetBool("/environment/realwx/enabled")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
double hdg = fgGetDouble( "/environment/metar/base-wind-dir-deg", 9999.0 );
|
double hdg = fgGetDouble( "/environment/metar/base-wind-dir-deg", 9999.0 );
|
||||||
string apt = fgGetString("/sim/presets/airport-id");
|
string apt = fgGetString("/sim/presets/airport-id");
|
||||||
string rwy = fgGetString("/sim/presets/runway");
|
string rwy = fgGetString("/sim/presets/runway");
|
||||||
|
@ -607,11 +611,16 @@ bool finalizeMetar()
|
||||||
|
|
||||||
if (needMetar) {
|
if (needMetar) {
|
||||||
// timeout so we don't spin forever if the network is down
|
// 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");
|
SG_LOG(SG_GENERAL, SG_WARN, "finalizePosition: timed out waiting for METAR fetch");
|
||||||
return true;
|
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" )) {
|
if (!fgGetBool( "/environment/metar/valid" )) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue