1 // environment-ctrl.hxx -- controller for environment information.
3 // Written by David Megginson, started May 2002.
5 // Copyright (C) 2002 David Megginson - david@megginson.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef _ENVIRONMENT_CTRL_HXX
24 #define _ENVIRONMENT_CTRL_HXX
30 #include <simgear/compiler.h>
31 #include <simgear/structure/subsystem_mgr.hxx>
32 #include <simgear/environment/metar.hxx>
34 #if defined(ENABLE_THREADS)
35 # include <simgear/threads/SGThread.hxx>
36 # include <simgear/threads/SGQueue.hxx>
39 #ifdef SG_HAVE_STD_INCLUDES
54 #include "environment.hxx"
55 #include "fgmetar.hxx"
60 * Interface to control environment information for a specific location.
62 class FGEnvironmentCtrl : public SGSubsystem
68 virtual ~FGEnvironmentCtrl ();
70 virtual void setEnvironment (FGEnvironment * environment);
72 virtual const FGEnvironment * getEnvironment () const { return _environment; }
74 virtual void setLongitudeDeg (double lon_deg);
75 virtual void setLatitudeDeg (double lat_deg);
76 virtual void setElevationFt (double elev_ft);
77 virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
79 virtual double getLongitudeDeg () const { return _lon_deg; }
80 virtual double getLatitudeDeg () const { return _lat_deg; }
81 virtual double getElevationFt () const { return _elev_ft; }
85 FGEnvironment * _environment;
95 * Environment controller using user-supplied parameters.
97 class FGUserDefEnvironmentCtrl : public FGEnvironmentCtrl
100 FGUserDefEnvironmentCtrl ();
101 virtual ~FGUserDefEnvironmentCtrl ();
103 virtual void init ();
104 virtual void update (double dt);
108 SGPropertyNode_ptr _base_wind_speed_node;
109 SGPropertyNode_ptr _gust_wind_speed_node;
111 double _current_wind_speed_kt;
112 double _delta_wind_speed_kt;
119 * Interplation controller using user-supplied parameters.
121 class FGInterpolateEnvironmentCtrl : public FGEnvironmentCtrl
124 FGInterpolateEnvironmentCtrl ();
125 virtual ~FGInterpolateEnvironmentCtrl ();
127 virtual void init ();
128 virtual void reinit ();
129 virtual void update (double delta_time_sec);
135 FGEnvironment environment;
136 bool operator< (const bucket &b) const;
139 void read_table (const SGPropertyNode * node, vector<bucket *> &table);
140 void do_interpolate (vector<bucket *> &table, double altitude_ft,
141 FGEnvironment * environment);
143 FGEnvironment env1, env2; // temporaries
145 vector<bucket *> _boundary_table;
146 vector<bucket *> _aloft_table;
150 // A convenience wrapper around FGMetar
151 struct FGMetarResult {
159 * Interplation controller using the FGMetar class
161 class FGMetarEnvironmentCtrl : public FGEnvironmentCtrl
164 FGMetarEnvironmentCtrl ();
165 virtual ~FGMetarEnvironmentCtrl ();
167 virtual void init ();
168 virtual void reinit ();
169 virtual void update (double delta_time_sec);
170 virtual void setEnvironment (FGEnvironment * environment);
173 FGInterpolateEnvironmentCtrl *env;
176 float station_elevation_ft;
177 float search_interval_sec;
178 float same_station_interval_sec;
179 float search_elapsed;
181 const FGAirport *last_apt;
182 SGPropertyNode_ptr proxy_host;
183 SGPropertyNode_ptr proxy_port;
184 SGPropertyNode_ptr proxy_auth;
185 SGPropertyNode_ptr metar_max_age;
187 FGMetarResult fetch_data( const string &icao );
188 virtual void update_metar_properties( const FGMetar *m );
189 void update_env_config();
193 #if defined(ENABLE_THREADS)
195 * FIFO queue which holds a pointer to the fetched metar data.
197 SGBlockingQueue < string > request_queue;
200 * FIFO queue which holds a pointer to the fetched metar data.
202 SGLockedQueue < FGMetarResult > result_queue;
205 * FIFO queue which holds a pointer to the fetched metar data.
207 queue < string > request_queue;
210 * FIFO queue which holds a pointer to the fetched metar data.
212 queue < FGMetarResult > result_queue;
215 #if defined(ENABLE_THREADS)
217 * This class represents the thread of execution responsible for
218 * fetching the metar data.
220 class MetarThread : public SGThread
223 MetarThread( FGMetarEnvironmentCtrl* f ) : fetcher(f) {}
227 * Fetche the metar data from the NOAA.
232 FGMetarEnvironmentCtrl *fetcher;
237 MetarThread( const MetarThread& );
238 MetarThread& operator=( const MetarThread& );
241 friend class MetarThread;
244 * Metar data fetching thread.
249 #endif // ENABLE_THREADS
257 #endif // _ENVIRONMENT_CTRL_HXX