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
26 #include <simgear/compiler.h>
27 #include <simgear/structure/subsystem_mgr.hxx>
29 #if defined(ENABLE_THREADS)
30 # include <OpenThreads/Thread>
31 # include <simgear/threads/SGQueue.hxx>
37 #include <Navaids/positioned.hxx>
38 #include <Environment/environment.hxx>
46 * Interface to control environment information for a specific location.
48 class FGEnvironmentCtrl : public SGSubsystem
54 virtual ~FGEnvironmentCtrl ();
56 virtual void setEnvironment (FGEnvironment * environment);
58 virtual const FGEnvironment * getEnvironment () const { return _environment; }
60 virtual void setLongitudeDeg (double lon_deg);
61 virtual void setLatitudeDeg (double lat_deg);
62 virtual void setElevationFt (double elev_ft);
63 virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
65 virtual double getLongitudeDeg () const { return _lon_deg; }
66 virtual double getLatitudeDeg () const { return _lat_deg; }
67 virtual double getElevationFt () const { return _elev_ft; }
71 FGEnvironment * _environment;
81 * Interplation controller using user-supplied parameters.
83 class FGInterpolateEnvironmentCtrl : public FGEnvironmentCtrl
86 FGInterpolateEnvironmentCtrl ();
87 virtual ~FGInterpolateEnvironmentCtrl ();
90 virtual void reinit ();
91 virtual void update (double delta_time_sec);
97 FGEnvironment environment;
98 bool operator< (const bucket &b) const;
99 // LessThan predicate for bucket pointers.
100 static bool lessThan(bucket *a, bucket *b);
103 void read_table (const SGPropertyNode * node, std::vector<bucket *> &table);
104 void do_interpolate (std::vector<bucket *> &table, double altitude_ft,
105 FGEnvironment * environment);
107 FGEnvironment env1, env2; // temporaries
109 std::vector<bucket *> _boundary_table;
110 std::vector<bucket *> _aloft_table;
112 SGPropertyNode_ptr altitude_n;
113 SGPropertyNode_ptr altitude_agl_n;
114 SGPropertyNode_ptr boundary_transition_n;
115 SGPropertyNode_ptr boundary_n;
116 SGPropertyNode_ptr aloft_n;
122 * Interplation controller using the FGMetar class
125 class FGMetarCtrl : public SGSubsystem
128 FGMetarCtrl (SGSubsystem * environmentCtrl);
129 virtual ~FGMetarCtrl ();
131 virtual void init ();
132 virtual void reinit ();
133 virtual void update (double delta_time_sec);
135 void set_metar( const char * metar );
136 const char * get_metar(void) const;
137 bool get_valid(void) const { return metar_valid; }
138 void set_enabled(bool _enabled) { enabled = _enabled; }
139 bool get_enabled(void) const { return enabled; }
140 void set_setup_winds_aloft(bool _setup_winds_aloft) { setup_winds_aloft = _setup_winds_aloft; }
141 bool get_setup_winds_aloft(void) const { return setup_winds_aloft; }
147 SGSharedPtr<FGWindModulator> windModulator;
150 bool setup_winds_aloft;
152 bool wind_interpolation_required;
154 double interpolate_prop(const char * currentname, const char * requiredname, double dvalue);
155 double interpolate_val(double currentval, double requiredval, double dvalue);
156 const double EnvironmentUpdatePeriodSec; // Seconds between interpolations
157 const double MaxWindChangeKtsSec; // Max wind change in kts/sec
158 const double MaxVisChangePercentSec; // Max visibility change in %/sec
159 const double MaxPressureChangeInHgSec; // Max pressure change in InHg/sec
160 const double MaxCloudAltitudeChangeFtSec; // Max cloud altitude change in ft/s
161 const double MaxCloudThicknessChangeFtSec; // Max cloud thickness change in ft/s
162 const double MaxCloudInterpolationHeightFt; // Max distance from aircraft to
163 // interpolate at. Any cloud
164 // changes above this height
165 // difference are not interpolated
166 const double MaxCloudInterpolationDeltaFt; // Max difference in altitude to
167 // interpolate. Any cloud changing height
168 // by more than this value is not
171 SGSubsystem * _environmentCtrl;
173 SGPropertyNode_ptr metar_base_n;
174 SGPropertyNode_ptr station_id_n;
175 SGPropertyNode_ptr station_elevation_n;
176 SGPropertyNode_ptr min_visibility_n;
177 SGPropertyNode_ptr max_visibility_n;
178 SGPropertyNode_ptr base_wind_range_from_n;
179 SGPropertyNode_ptr base_wind_range_to_n;
180 SGPropertyNode_ptr base_wind_dir_n;
181 SGPropertyNode_ptr base_wind_speed_n;
182 SGPropertyNode_ptr gust_wind_speed_n;
183 SGPropertyNode_ptr temperature_n;
184 SGPropertyNode_ptr dewpoint_n;
185 SGPropertyNode_ptr humidity_n;
186 SGPropertyNode_ptr pressure_n;
187 SGPropertyNode_ptr clouds_n;
188 SGPropertyNode_ptr environment_clouds_n;
189 SGPropertyNode_ptr rain_n;
190 SGPropertyNode_ptr hail_n;
191 SGPropertyNode_ptr snow_n;
192 SGPropertyNode_ptr snow_cover_n;
193 SGPropertyNode_ptr ground_elevation_n;
194 SGPropertyNode_ptr longitude_n;
195 SGPropertyNode_ptr latitude_n;
196 SGPropertyNode_ptr magnetic_variation_n;
198 SGPropertyNode_ptr boundary_wind_speed_n;
199 SGPropertyNode_ptr boundary_wind_from_heading_n;
200 SGPropertyNode_ptr boundary_visibility_n;
201 SGPropertyNode_ptr boundary_sea_level_pressure_n;
207 * The subsyste to load real world weather
209 class FGMetarFetcher : public SGSubsystem
213 virtual ~FGMetarFetcher();
215 virtual void init ();
216 virtual void reinit ();
217 virtual void update (double delta_time_sec);
220 friend class MetarThread;
221 #if defined(ENABLE_THREADS)
223 * FIFO queue which holds a pointer to the metar requests.
225 SGBlockingQueue <string> request_queue;
227 OpenThreads::Thread * metar_thread;
230 void fetch( const string & id );
232 SGPropertyNode_ptr enable_n;
234 SGPropertyNode_ptr longitude_n;
235 SGPropertyNode_ptr latitude_n;
237 SGPropertyNode_ptr proxy_host_n;
238 SGPropertyNode_ptr proxy_port_n;
239 SGPropertyNode_ptr proxy_auth_n;
240 SGPropertyNode_ptr max_age_n;
242 SGPropertyNode_ptr output_n;
244 string current_airport_id;
255 #endif // _ENVIRONMENT_CTRL_HXX