Disable weather fetching if there are 3 errors within a 3 second period. This also solves the problem where FlightGear 'hangs' when real-weather fetching is enabled, but no network connection is present.
This commit is contained in:
parent
4df8f790d5
commit
97114e3159
2 changed files with 41 additions and 5 deletions
|
@ -323,7 +323,9 @@ FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
|
||||||
fetch_elapsed( 9999.0 ),
|
fetch_elapsed( 9999.0 ),
|
||||||
proxy_host( fgGetNode("/sim/presets/proxy/host", true) ),
|
proxy_host( fgGetNode("/sim/presets/proxy/host", true) ),
|
||||||
proxy_port( fgGetNode("/sim/presets/proxy/port", true) ),
|
proxy_port( fgGetNode("/sim/presets/proxy/port", true) ),
|
||||||
proxy_auth( fgGetNode("/sim/presets/proxy/authentication", true) )
|
proxy_auth( fgGetNode("/sim/presets/proxy/authentication", true) ),
|
||||||
|
_error_dt( 0.0 ),
|
||||||
|
_error_count( 0 )
|
||||||
{
|
{
|
||||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||||
thread = new MetarThread(this);
|
thread = new MetarThread(this);
|
||||||
|
@ -391,7 +393,8 @@ FGMetarEnvironmentCtrl::init ()
|
||||||
= fgGetNode( "/position/latitude-deg", true );
|
= fgGetNode( "/position/latitude-deg", true );
|
||||||
|
|
||||||
bool found_metar = false;
|
bool found_metar = false;
|
||||||
while ( !found_metar ) {
|
|
||||||
|
while ( !found_metar && (_error_count < 3) ) {
|
||||||
FGAirport a = globals->get_airports()
|
FGAirport a = globals->get_airports()
|
||||||
->search( longitude->getDoubleValue(),
|
->search( longitude->getDoubleValue(),
|
||||||
latitude->getDoubleValue(),
|
latitude->getDoubleValue(),
|
||||||
|
@ -419,6 +422,9 @@ FGMetarEnvironmentCtrl::init ()
|
||||||
void
|
void
|
||||||
FGMetarEnvironmentCtrl::reinit ()
|
FGMetarEnvironmentCtrl::reinit ()
|
||||||
{
|
{
|
||||||
|
_error_count = 0;
|
||||||
|
_error_dt = 0.0;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
update_env_config();
|
update_env_config();
|
||||||
#endif
|
#endif
|
||||||
|
@ -429,6 +435,11 @@ FGMetarEnvironmentCtrl::reinit ()
|
||||||
void
|
void
|
||||||
FGMetarEnvironmentCtrl::update(double delta_time_sec)
|
FGMetarEnvironmentCtrl::update(double delta_time_sec)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_dt += delta_time_sec;
|
||||||
|
if (_error_count >= 3)
|
||||||
|
return;
|
||||||
|
|
||||||
FGMetarResult result;
|
FGMetarResult result;
|
||||||
|
|
||||||
static const SGPropertyNode *longitude
|
static const SGPropertyNode *longitude
|
||||||
|
@ -468,6 +479,7 @@ FGMetarEnvironmentCtrl::update(double delta_time_sec)
|
||||||
id = request_queue.front();
|
id = request_queue.front();
|
||||||
request_queue.pop();
|
request_queue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !id.empty() ) {
|
if ( !id.empty() ) {
|
||||||
SG_LOG( SG_GENERAL, SG_INFO, "inline fetching = " << id );
|
SG_LOG( SG_GENERAL, SG_INFO, "inline fetching = " << id );
|
||||||
result = fetch_data( id );
|
result = fetch_data( id );
|
||||||
|
@ -510,6 +522,16 @@ FGMetarEnvironmentCtrl::fetch_data( const string &icao )
|
||||||
FGMetarResult result;
|
FGMetarResult result;
|
||||||
result.icao = icao;
|
result.icao = icao;
|
||||||
|
|
||||||
|
// if the last error was more than three seconds ago,
|
||||||
|
// then pretent nothing happened.
|
||||||
|
if (_error_dt < 3) {
|
||||||
|
_error_dt += _dt;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_error_dt = 0.0;
|
||||||
|
_error_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// fetch station elevation if exists
|
// fetch station elevation if exists
|
||||||
FGAirport a = globals->get_airports()->search( icao );
|
FGAirport a = globals->get_airports()->search( icao );
|
||||||
station_elevation_ft = a.elevation;
|
station_elevation_ft = a.elevation;
|
||||||
|
@ -520,12 +542,21 @@ FGMetarEnvironmentCtrl::fetch_data( const string &icao )
|
||||||
string auth = proxy_auth->getStringValue();
|
string auth = proxy_auth->getStringValue();
|
||||||
string port = proxy_port->getStringValue();
|
string port = proxy_port->getStringValue();
|
||||||
result.m = new SGMetar( icao, host, port, auth);
|
result.m = new SGMetar( icao, host, port, auth);
|
||||||
|
|
||||||
} catch (const sg_io_exception& e) {
|
} catch (const sg_io_exception& e) {
|
||||||
SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
|
SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
|
||||||
<< e.getFormattedMessage().c_str() );
|
<< e.getFormattedMessage().c_str() );
|
||||||
|
if (_error_count++ >= 3) {
|
||||||
|
SG_LOG( SG_GENERAL, SG_WARN, "Stop fetching data permanently.");
|
||||||
|
thread->cancel();
|
||||||
|
thread->join();
|
||||||
|
}
|
||||||
|
|
||||||
result.m = NULL;
|
result.m = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_dt = 0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,7 +681,7 @@ FGMetarEnvironmentCtrl::update_metar_properties( SGMetar *m )
|
||||||
void
|
void
|
||||||
FGMetarEnvironmentCtrl::MetarThread::run()
|
FGMetarEnvironmentCtrl::MetarThread::run()
|
||||||
{
|
{
|
||||||
// pthread_cleanup_push( metar_cleanup_handler, fetcher );
|
pthread_cleanup_push( metar_cleanup_handler, fetcher );
|
||||||
while ( true )
|
while ( true )
|
||||||
{
|
{
|
||||||
set_cancel( SGThread::CANCEL_DISABLE );
|
set_cancel( SGThread::CANCEL_DISABLE );
|
||||||
|
@ -663,7 +694,7 @@ FGMetarEnvironmentCtrl::MetarThread::run()
|
||||||
|
|
||||||
fetcher->result_queue.push( result );
|
fetcher->result_queue.push( result );
|
||||||
}
|
}
|
||||||
// pthread_cleanup_pop(1);
|
pthread_cleanup_pop(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -217,7 +217,7 @@ private:
|
||||||
~MetarThread() {}
|
~MetarThread() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetched the metar data from the NOAA.
|
* Fetche the metar data from the NOAA.
|
||||||
*/
|
*/
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
@ -248,6 +248,11 @@ private:
|
||||||
* Thread cleanup handler.
|
* Thread cleanup handler.
|
||||||
*/
|
*/
|
||||||
friend void metar_cleanup_handler( void* );
|
friend void metar_cleanup_handler( void* );
|
||||||
|
|
||||||
|
|
||||||
|
int _error_count;
|
||||||
|
double _dt;
|
||||||
|
double _error_dt;
|
||||||
#endif // ENABLE_THREADS
|
#endif // ENABLE_THREADS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue