-}
-
-void NoaaMetarRealWxController::update( bool first, double dt )
-{
- _http.update();
-
- _positionTimeToLive -= dt;
- _requestTimer -= dt;
-
- if( _positionTimeToLive <= 0.0 ) {
- // check nearest airport
- SG_LOG(SG_ALL, SG_INFO, "NoaaMetarRealWxController::update(): (re) checking nearby airport with METAR" );
- _positionTimeToLive = 60.0;
-
- SGGeod pos = SGGeod::fromDeg(_longitude_n->getDoubleValue(), _latitude_n->getDoubleValue());
-
- FGAirport * nearestAirport = FGAirport::findClosest(pos, 10000.0, MetarAirportFilter::instance() );
- if( nearestAirport == NULL ) {
- SG_LOG(SG_ALL,SG_WARN,"RealWxController::update can't find airport with METAR within 10000NM" );
- return;
- }
-
- SG_LOG(SG_ALL, SG_INFO,
- "NoaaMetarRealWxController::update(): nearest airport with METAR is: " << nearestAirport->ident() );
-
- // if it has changed, invalidate the associated METAR
- if( _metarProperties[0]->getStationId() != nearestAirport->ident() ) {
- SG_LOG(SG_ALL, SG_INFO,
- "NoaaMetarRealWxController::update(): nearest airport with METAR has changed. Old: '" <<
- _metarProperties[0]->getStationId() <<
- "', new: '" << nearestAirport->ident() << "'" );
- _metarProperties[0]->setStationId( nearestAirport->ident() );
- _metarProperties[0]->setTimeToLive( 0.0 );
+ static const std::string NOAA_BASE_URL =
+ "http://weather.noaa.gov/pub/data/observations/metar/stations/";
+ class NoaaMetarGetRequest:
+ public simgear::HTTP::MemoryRequest
+ {
+ public:
+ NoaaMetarGetRequest( MetarDataHandler* metarDataHandler,
+ const std::string& stationId ):
+ MemoryRequest(NOAA_BASE_URL + stationId + ".TXT"),
+ _metarDataHandler(metarDataHandler)
+ {
+ std::ostringstream buf;
+ buf << globals->get_time_params()->get_cur_time();
+ requestHeader("X-TIME") = buf.str();
+ }
+
+ virtual void onDone()
+ {
+ if( responseCode() != 200 )
+ {
+ SG_LOG
+ (
+ SG_ENVIRONMENT,
+ SG_WARN,
+ "metar download failed:" << url() << ": reason:" << responseReason()
+ );
+ return;