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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifndef _ENVIRONMENT_CTRL_HXX
24 #define _ENVIRONMENT_CTRL_HXX
26 #include <simgear/compiler.h>
27 #include <simgear/structure/subsystem_mgr.hxx>
28 #include <simgear/environment/metar.hxx>
30 #if defined(ENABLE_THREADS) && ENABLE_THREADS
31 # include <simgear/threads/SGThread.hxx>
32 # include <simgear/threads/SGQueue.hxx>
35 #ifdef SG_HAVE_STD_INCLUDES
49 #include "environment.hxx"
54 * Interface to control environment information for a specific location.
56 class FGEnvironmentCtrl : public SGSubsystem
62 virtual ~FGEnvironmentCtrl ();
64 virtual void setEnvironment (FGEnvironment * environment);
66 virtual FGEnvironment * getEnvironment () const { return _environment; }
68 virtual void setLongitudeDeg (double lon_deg);
69 virtual void setLatitudeDeg (double lat_deg);
70 virtual void setElevationFt (double elev_ft);
71 virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
73 virtual double getLongitudeDeg () const { return _lon_deg; }
74 virtual double getLatitudeDeg () const { return _lat_deg; }
75 virtual double getElevationFt () const { return _elev_ft; }
79 FGEnvironment * _environment;
89 * Environment controller using user-supplied parameters.
91 class FGUserDefEnvironmentCtrl : public FGEnvironmentCtrl
94 FGUserDefEnvironmentCtrl ();
95 virtual ~FGUserDefEnvironmentCtrl ();
98 virtual void update (double dt);
102 SGPropertyNode * _base_wind_speed_node;
103 SGPropertyNode * _gust_wind_speed_node;
105 double _current_wind_speed_kt;
106 double _delta_wind_speed_kt;
113 * Interplation controller using user-supplied parameters.
115 class FGInterpolateEnvironmentCtrl : public FGEnvironmentCtrl
118 FGInterpolateEnvironmentCtrl ();
119 virtual ~FGInterpolateEnvironmentCtrl ();
121 virtual void init ();
122 virtual void reinit ();
123 virtual void update (double delta_time_sec);
129 FGEnvironment environment;
130 bool operator< (const bucket &b) const;
133 void read_table (const SGPropertyNode * node, vector<bucket *> &table);
134 void do_interpolate (vector<bucket *> &table, double altitude_ft,
135 FGEnvironment * environment);
137 FGEnvironment env1, env2; // temporaries
139 vector<bucket *> _boundary_table;
140 vector<bucket *> _aloft_table;
144 // A convenience wrapper around SGMetar
145 struct FGMetarResult {
153 * Interplation controller using the SGMetar class
155 class FGMetarEnvironmentCtrl : public FGEnvironmentCtrl
158 FGMetarEnvironmentCtrl ();
159 virtual ~FGMetarEnvironmentCtrl ();
161 virtual void init ();
162 virtual void reinit ();
163 virtual void update (double delta_time_sec);
164 virtual void setEnvironment (FGEnvironment * environment);
167 FGInterpolateEnvironmentCtrl *env;
170 float station_elevation_ft;
171 float search_interval_sec;
172 float same_station_interval_sec;
173 float search_elapsed;
176 SGPropertyNode *proxy_host;
177 SGPropertyNode *proxy_port;
178 SGPropertyNode *proxy_auth;
180 FGMetarResult fetch_data( const string &icao );
181 virtual void update_metar_properties( SGMetar *m );
182 void update_env_config();
186 #if defined(ENABLE_THREADS) && ENABLE_THREADS
188 * FIFO queue which holds a pointer to the fetched metar data.
190 SGBlockingQueue < string > request_queue;
193 * FIFO queue which holds a pointer to the fetched metar data.
195 SGBlockingQueue < FGMetarResult > result_queue;
198 * FIFO queue which holds a pointer to the fetched metar data.
200 queue < string > request_queue;
203 * FIFO queue which holds a pointer to the fetched metar data.
205 queue < FGMetarResult > result_queue;
208 #if defined(ENABLE_THREADS) && ENABLE_THREADS
210 * This class represents the thread of execution responsible for
211 * fetching the metar data.
213 class MetarThread : public SGThread
216 MetarThread( FGMetarEnvironmentCtrl* f ) : fetcher(f) {}
220 * Fetche the metar data from the NOAA.
225 FGMetarEnvironmentCtrl *fetcher;
230 MetarThread( const MetarThread& );
231 MetarThread& operator=( const MetarThread& );
234 friend class MetarThread;
237 * Metar data fetching thread.
242 * Lock and synchronize access to metar queue.
245 SGPthreadCond metar_cond;
248 * Thread cleanup handler.
250 friend void metar_cleanup_handler( void* );
252 #endif // ENABLE_THREADS
259 #endif // _ENVIRONMENT_CTRL_HXX