2002-05-07 00:03:54 +00:00
|
|
|
|
// environment-ctrl.hxx -- controller for environment information.
|
|
|
|
|
//
|
|
|
|
|
// Written by David Megginson, started May 2002.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2002 David Megginson - david@megginson.com
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
//
|
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
#ifndef _ENVIRONMENT_CTRL_HXX
|
|
|
|
|
#define _ENVIRONMENT_CTRL_HXX
|
|
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
2003-09-24 17:20:55 +00:00
|
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
2004-02-21 12:56:16 +00:00
|
|
|
|
#include <simgear/environment/metar.hxx>
|
2002-05-07 00:03:54 +00:00
|
|
|
|
|
2004-02-25 15:31:01 +00:00
|
|
|
|
#ifdef ENABLE_THREADS
|
|
|
|
|
# include <simgear/threads/SGThread.hxx>
|
|
|
|
|
# include <simgear/threads/SGQueue.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-05-07 00:03:54 +00:00
|
|
|
|
#ifdef SG_HAVE_STD_INCLUDES
|
|
|
|
|
# include <cmath>
|
|
|
|
|
#else
|
|
|
|
|
# include <math.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-06-08 14:47:03 +00:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
SG_USING_STD(vector);
|
|
|
|
|
|
2002-05-07 00:03:54 +00:00
|
|
|
|
class SGPropertyNode;
|
|
|
|
|
|
|
|
|
|
#include "environment.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface to control environment information for a specific location.
|
|
|
|
|
*/
|
2003-09-24 17:20:55 +00:00
|
|
|
|
class FGEnvironmentCtrl : public SGSubsystem
|
2002-05-07 00:03:54 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
FGEnvironmentCtrl ();
|
|
|
|
|
virtual ~FGEnvironmentCtrl ();
|
|
|
|
|
|
|
|
|
|
virtual void setEnvironment (FGEnvironment * environment);
|
|
|
|
|
|
|
|
|
|
virtual FGEnvironment * getEnvironment () const { return _environment; }
|
|
|
|
|
|
|
|
|
|
virtual void setLongitudeDeg (double lon_deg);
|
|
|
|
|
virtual void setLatitudeDeg (double lat_deg);
|
|
|
|
|
virtual void setElevationFt (double elev_ft);
|
|
|
|
|
virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
|
|
|
|
|
|
|
|
|
|
virtual double getLongitudeDeg () const { return _lon_deg; }
|
|
|
|
|
virtual double getLatitudeDeg () const { return _lat_deg; }
|
|
|
|
|
virtual double getElevationFt () const { return _elev_ft; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
FGEnvironment * _environment;
|
|
|
|
|
double _lon_deg;
|
|
|
|
|
double _lat_deg;
|
|
|
|
|
double _elev_ft;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Environment controller using user-supplied parameters.
|
|
|
|
|
*/
|
|
|
|
|
class FGUserDefEnvironmentCtrl : public FGEnvironmentCtrl
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FGUserDefEnvironmentCtrl ();
|
|
|
|
|
virtual ~FGUserDefEnvironmentCtrl ();
|
|
|
|
|
|
|
|
|
|
virtual void init ();
|
2002-05-11 16:28:50 +00:00
|
|
|
|
virtual void update (double dt);
|
2002-05-07 00:03:54 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
SGPropertyNode * _base_wind_speed_node;
|
|
|
|
|
SGPropertyNode * _gust_wind_speed_node;
|
|
|
|
|
|
|
|
|
|
double _current_wind_speed_kt;
|
|
|
|
|
double _delta_wind_speed_kt;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2003-06-08 14:47:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interplation controller using user-supplied parameters.
|
|
|
|
|
*/
|
|
|
|
|
class FGInterpolateEnvironmentCtrl : public FGEnvironmentCtrl
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FGInterpolateEnvironmentCtrl ();
|
|
|
|
|
virtual ~FGInterpolateEnvironmentCtrl ();
|
|
|
|
|
|
|
|
|
|
virtual void init ();
|
|
|
|
|
virtual void reinit ();
|
|
|
|
|
virtual void update (double delta_time_sec);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
struct bucket {
|
|
|
|
|
double altitude_ft;
|
|
|
|
|
FGEnvironment environment;
|
|
|
|
|
bool operator< (const bucket &b) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void read_table (const SGPropertyNode * node, vector<bucket *> &table);
|
|
|
|
|
void do_interpolate (vector<bucket *> &table, double altitude_ft,
|
|
|
|
|
FGEnvironment * environment);
|
|
|
|
|
|
|
|
|
|
FGEnvironment env1, env2; // temporaries
|
|
|
|
|
|
|
|
|
|
vector<bucket *> _boundary_table;
|
|
|
|
|
vector<bucket *> _aloft_table;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2004-02-21 12:56:16 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interplation controller using the SGMetar class
|
|
|
|
|
*/
|
|
|
|
|
class FGMetarEnvironmentCtrl : public FGEnvironmentCtrl
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FGMetarEnvironmentCtrl ();
|
|
|
|
|
virtual ~FGMetarEnvironmentCtrl ();
|
|
|
|
|
|
|
|
|
|
virtual void init ();
|
|
|
|
|
virtual void reinit ();
|
|
|
|
|
virtual void update (double delta_time_sec);
|
|
|
|
|
|
2004-02-21 14:04:40 +00:00
|
|
|
|
virtual void setEnvironment (FGEnvironment * environment);
|
2004-02-21 12:56:16 +00:00
|
|
|
|
|
2004-02-21 14:04:40 +00:00
|
|
|
|
private:
|
|
|
|
|
FGInterpolateEnvironmentCtrl *env;
|
2004-02-21 12:56:16 +00:00
|
|
|
|
|
2004-02-23 01:39:12 +00:00
|
|
|
|
string _icao;
|
2004-02-22 14:21:37 +00:00
|
|
|
|
float station_elevation_ft;
|
2004-02-23 01:39:12 +00:00
|
|
|
|
float update_interval_sec;
|
|
|
|
|
float elapsed;
|
|
|
|
|
bool fetch_data (const string &icao);
|
|
|
|
|
void update_env_config();
|
2004-02-25 15:31:01 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_THREADS
|
|
|
|
|
/**
|
|
|
|
|
* FIFO queue which holds a pointer to the fetched metar data.
|
|
|
|
|
*/
|
|
|
|
|
SGBlockingQueue< SGMetar * > metar_queue;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class represents the thread of execution responsible for
|
|
|
|
|
* fetching the metar data.
|
|
|
|
|
*/
|
|
|
|
|
class MetarThread : public SGThread
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MetarThread( FGMetarEnvironmentCtrl* f ) : fetcher(f) {}
|
|
|
|
|
~MetarThread() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads the tile from disk.
|
|
|
|
|
*/
|
|
|
|
|
void run();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FGMetarEnvironmentCtrl *fetcher;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// not implemented.
|
|
|
|
|
MetarThread();
|
|
|
|
|
MetarThread( const MetarThread& );
|
|
|
|
|
MetarThread& operator=( const MetarThread& );
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
friend class MetarThread;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Metar data fetching thread.
|
|
|
|
|
*/
|
|
|
|
|
MetarThread* thread;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lock and synchronize access to metar queue.
|
|
|
|
|
*/
|
|
|
|
|
SGMutex mutex;
|
|
|
|
|
SGPthreadCond metar_cond;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Thread cleanup handler.
|
|
|
|
|
*/
|
|
|
|
|
friend void metar_cleanup_handler( void* );
|
|
|
|
|
#endif // ENABLE_THREADS
|
2004-02-21 12:56:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-05-07 00:03:54 +00:00
|
|
|
|
#endif // _ENVIRONMENT_CTRL_HXX
|