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>
31 # include <simgear/threads/SGThread.hxx>
32 # include <simgear/threads/SGQueue.hxx>
35 #ifdef SG_HAVE_STD_INCLUDES
47 #include "environment.hxx"
52 * Interface to control environment information for a specific location.
54 class FGEnvironmentCtrl : public SGSubsystem
60 virtual ~FGEnvironmentCtrl ();
62 virtual void setEnvironment (FGEnvironment * environment);
64 virtual FGEnvironment * getEnvironment () const { return _environment; }
66 virtual void setLongitudeDeg (double lon_deg);
67 virtual void setLatitudeDeg (double lat_deg);
68 virtual void setElevationFt (double elev_ft);
69 virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
71 virtual double getLongitudeDeg () const { return _lon_deg; }
72 virtual double getLatitudeDeg () const { return _lat_deg; }
73 virtual double getElevationFt () const { return _elev_ft; }
77 FGEnvironment * _environment;
87 * Environment controller using user-supplied parameters.
89 class FGUserDefEnvironmentCtrl : public FGEnvironmentCtrl
92 FGUserDefEnvironmentCtrl ();
93 virtual ~FGUserDefEnvironmentCtrl ();
96 virtual void update (double dt);
100 SGPropertyNode * _base_wind_speed_node;
101 SGPropertyNode * _gust_wind_speed_node;
103 double _current_wind_speed_kt;
104 double _delta_wind_speed_kt;
111 * Interplation controller using user-supplied parameters.
113 class FGInterpolateEnvironmentCtrl : public FGEnvironmentCtrl
116 FGInterpolateEnvironmentCtrl ();
117 virtual ~FGInterpolateEnvironmentCtrl ();
119 virtual void init ();
120 virtual void reinit ();
121 virtual void update (double delta_time_sec);
127 FGEnvironment environment;
128 bool operator< (const bucket &b) const;
131 void read_table (const SGPropertyNode * node, vector<bucket *> &table);
132 void do_interpolate (vector<bucket *> &table, double altitude_ft,
133 FGEnvironment * environment);
135 FGEnvironment env1, env2; // temporaries
137 vector<bucket *> _boundary_table;
138 vector<bucket *> _aloft_table;
144 * Interplation controller using the SGMetar class
146 class FGMetarEnvironmentCtrl : public FGEnvironmentCtrl
149 FGMetarEnvironmentCtrl ();
150 virtual ~FGMetarEnvironmentCtrl ();
152 virtual void init ();
153 virtual void reinit ();
154 virtual void update (double delta_time_sec);
156 virtual void setEnvironment (FGEnvironment * environment);
159 FGInterpolateEnvironmentCtrl *env;
162 float station_elevation_ft;
163 float update_interval_sec;
165 bool fetch_data (const string &icao);
166 void update_env_config();
170 #ifdef ENABLE_THREADS
172 * FIFO queue which holds a pointer to the fetched metar data.
174 SGBlockingQueue< SGMetar * > metar_queue;
177 * This class represents the thread of execution responsible for
178 * fetching the metar data.
180 class MetarThread : public SGThread
183 MetarThread( FGMetarEnvironmentCtrl* f ) : fetcher(f) {}
187 * Reads the tile from disk.
192 FGMetarEnvironmentCtrl *fetcher;
197 MetarThread( const MetarThread& );
198 MetarThread& operator=( const MetarThread& );
201 friend class MetarThread;
204 * Metar data fetching thread.
209 * Lock and synchronize access to metar queue.
212 SGPthreadCond metar_cond;
215 * Thread cleanup handler.
217 friend void metar_cleanup_handler( void* );
218 #endif // ENABLE_THREADS
221 #endif // _ENVIRONMENT_CTRL_HXX