1
0
Fork 0

For weather fetching from the noaa.gov site: If the closest station hasn't

changed, wait 15 minutes before grabbing it's weather data again.
This commit is contained in:
curt 2004-02-26 18:21:11 +00:00
parent dad0c2de10
commit 8d44c8cecc
2 changed files with 41 additions and 22 deletions

View file

@ -317,11 +317,13 @@ FGInterpolateEnvironmentCtrl::bucket::operator< (const bucket &b) const
FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl () FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
: env( new FGInterpolateEnvironmentCtrl ), : env( new FGInterpolateEnvironmentCtrl ),
_icao( fgGetString("/sim/presets/airport-id") ), _icao( fgGetString("/sim/presets/airport-id") ),
search_interval_sec( 60.0 ), // 1 minute
same_station_interval_sec( 900.0 ), // 15 minutes
search_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) )
update_interval_sec( 60.0 ),
elapsed( 60.0 )
{ {
#ifdef ENABLE_THREADS #ifdef ENABLE_THREADS
thread = new MetarThread(this); thread = new MetarThread(this);
@ -396,8 +398,10 @@ FGMetarEnvironmentCtrl::init ()
true ); true );
if ( fetch_data( a.id ) ) { if ( fetch_data( a.id ) ) {
cout << "closest station w/ metar = " << a.id << endl; cout << "closest station w/ metar = " << a.id << endl;
last_apt = a;
_icao = a.id; _icao = a.id;
elapsed = 0.0; search_elapsed = 0.0;
fetch_elapsed = 0.0;
update_env_config(); update_env_config();
env->init(); env->init();
found_metar = true; found_metar = true;
@ -427,23 +431,34 @@ FGMetarEnvironmentCtrl::update(double delta_time_sec)
= fgGetNode( "/position/longitude-deg", true ); = fgGetNode( "/position/longitude-deg", true );
static const SGPropertyNode *latitude static const SGPropertyNode *latitude
= fgGetNode( "/position/latitude-deg", true ); = fgGetNode( "/position/latitude-deg", true );
elapsed += delta_time_sec; search_elapsed += delta_time_sec;
if ( elapsed > update_interval_sec ) { fetch_elapsed += delta_time_sec;
if ( search_elapsed > search_interval_sec ) {
FGAirport a = globals->get_airports() FGAirport a = globals->get_airports()
->search( longitude->getDoubleValue(), ->search( longitude->getDoubleValue(),
latitude->getDoubleValue(), latitude->getDoubleValue(),
true ); true );
if ( fetch_data( a.id ) ) { if ( last_apt.id != a.id
cout << "closest station w/ metar = " << a.id << endl; || fetch_elapsed > same_station_interval_sec )
_icao = a.id; {
elapsed = 0.0; if ( fetch_data( a.id ) ) {
update_env_config(); cout << "closest station w/ metar = " << a.id << endl;
env->reinit(); last_apt = a;
_icao = a.id;
search_elapsed = 0.0;
fetch_elapsed = 0.0;
update_env_config();
env->reinit();
} else {
// mark as no metar so it doesn't show up in subsequent
// searches.
cout << "no metar at metar = " << a.id << endl;
globals->get_airports()->no_metar( a.id );
}
} else { } else {
// mark as no metar so it doesn't show up in subsequent search_elapsed = 0.0;
// searches. // cout << "same station, waiting = "
cout << "no metar at metar = " << a.id << endl; // << same_station_interval_sec - fetch_elapsed << endl;
globals->get_airports()->no_metar( a.id );
} }
} }

View file

@ -158,17 +158,21 @@ public:
private: private:
FGInterpolateEnvironmentCtrl *env; FGInterpolateEnvironmentCtrl *env;
float station_elevation_ft;
float update_interval_sec;
float elapsed;
bool fetch_data (const string &icao);
void update_env_config();
string _icao; string _icao;
float station_elevation_ft;
float search_interval_sec;
float same_station_interval_sec;
float search_elapsed;
float fetch_elapsed;
FGAirport last_apt;
SGPropertyNode *proxy_host; SGPropertyNode *proxy_host;
SGPropertyNode *proxy_port; SGPropertyNode *proxy_port;
SGPropertyNode *proxy_auth; SGPropertyNode *proxy_auth;
bool fetch_data (const string &icao);
void update_env_config();
private: private:
#ifdef ENABLE_THREADS #ifdef ENABLE_THREADS