parent
96a40fe70c
commit
c6221b2c84
3 changed files with 59 additions and 16 deletions
|
@ -183,21 +183,40 @@ MetarProperties::~MetarProperties()
|
|||
|
||||
static const double thickness_value[] = { 0, 65, 600, 750, 1000 };
|
||||
|
||||
void MetarProperties::set_metar( const char * metar )
|
||||
const char* MetarProperties::get_metar() const
|
||||
{
|
||||
_metar = metar;
|
||||
if (!_metar) return "";
|
||||
return _metar->getData();
|
||||
}
|
||||
|
||||
void MetarProperties::set_metar( const char * metarString )
|
||||
{
|
||||
SGSharedPtr<FGMetar> m;
|
||||
if ((metarString == NULL) || (strlen(metarString) == 0)) {
|
||||
setMetar(m);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
m = new FGMetar( _metar );
|
||||
m = new FGMetar( metarString );
|
||||
}
|
||||
catch( sg_io_exception ) {
|
||||
SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << _metar );
|
||||
SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << metarString );
|
||||
_metarValidNode->setBoolValue(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setMetar(m);
|
||||
}
|
||||
|
||||
void MetarProperties::setMetar( SGSharedPtr<FGMetar> m )
|
||||
{
|
||||
_metar = m;
|
||||
_decoded.clear();
|
||||
if (!m) {
|
||||
return;
|
||||
}
|
||||
|
||||
const vector<string> weather = m->getWeather();
|
||||
for( vector<string>::const_iterator it = weather.begin(); it != weather.end(); ++it ) {
|
||||
if( false == _decoded.empty() ) _decoded.append(", ");
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/props/tiedpropertylist.hxx>
|
||||
|
||||
class FGMetar;
|
||||
|
||||
namespace Environment {
|
||||
|
||||
class MagneticVariation;
|
||||
|
@ -41,11 +43,12 @@ public:
|
|||
virtual bool isValid() const { return _metarValidNode->getBoolValue(); }
|
||||
virtual const std::string & getStationId() const { return _station_id; }
|
||||
virtual void setStationId( const std::string & value );
|
||||
virtual void setMetar( const std::string & value ) { set_metar( value.c_str() ); }
|
||||
virtual void setMetar(SGSharedPtr<FGMetar> m);
|
||||
|
||||
private:
|
||||
const char * get_metar() const { return _metar.c_str(); }
|
||||
const char * get_metar() const;
|
||||
void set_metar( const char * metar );
|
||||
|
||||
const char * get_station_id() const { return _station_id.c_str(); }
|
||||
void set_station_id( const char * value );
|
||||
const char * get_decoded() const { return _decoded.c_str(); }
|
||||
|
@ -60,9 +63,10 @@ private:
|
|||
void set_base_wind_dir( double value );
|
||||
void set_wind_speed( double value );
|
||||
|
||||
SGSharedPtr<FGMetar> _metar;
|
||||
SGPropertyNode_ptr _rootNode;
|
||||
SGPropertyNode_ptr _metarValidNode;
|
||||
std::string _metar;
|
||||
|
||||
std::string _station_id;
|
||||
double _station_elevation;
|
||||
double _station_latitude;
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
|
||||
class LiveMetarProperties : public MetarProperties, MetarDataHandler {
|
||||
public:
|
||||
LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequester * metarRequester );
|
||||
LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequester * metarRequester, int maxAge );
|
||||
virtual ~LiveMetarProperties();
|
||||
virtual void update( double dt );
|
||||
|
||||
|
@ -81,15 +81,17 @@ private:
|
|||
double _timeToLive;
|
||||
double _pollingTimer;
|
||||
MetarRequester * _metarRequester;
|
||||
int _maxAge;
|
||||
};
|
||||
|
||||
typedef SGSharedPtr<LiveMetarProperties> LiveMetarProperties_ptr;
|
||||
|
||||
LiveMetarProperties::LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequester * metarRequester ) :
|
||||
LiveMetarProperties::LiveMetarProperties( SGPropertyNode_ptr rootNode, MetarRequester * metarRequester, int maxAge ) :
|
||||
MetarProperties( rootNode ),
|
||||
_timeToLive(0.0),
|
||||
_pollingTimer(0.0),
|
||||
_metarRequester(metarRequester)
|
||||
_metarRequester(metarRequester),
|
||||
_maxAge(maxAge)
|
||||
{
|
||||
_tiedProperties.Tie("time-to-live", &_timeToLive );
|
||||
}
|
||||
|
@ -115,9 +117,25 @@ void LiveMetarProperties::update( double dt )
|
|||
|
||||
void LiveMetarProperties::handleMetarData( const std::string & data )
|
||||
{
|
||||
SG_LOG( SG_ENVIRONMENT, SG_INFO, "LiveMetarProperties::handleMetarData() received METAR for " << getStationId() << ": " << data );
|
||||
SG_LOG( SG_ENVIRONMENT, SG_DEBUG, "LiveMetarProperties::handleMetarData() received METAR for " << getStationId() << ": " << data );
|
||||
_timeToLive = DEFAULT_TIME_TO_LIVE_SECONDS;
|
||||
setMetar( data );
|
||||
|
||||
SGSharedPtr<FGMetar> m;
|
||||
try {
|
||||
m = new FGMetar(data.c_str());
|
||||
}
|
||||
catch( sg_io_exception ) {
|
||||
SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << data );
|
||||
return;
|
||||
}
|
||||
|
||||
if (_maxAge && (m->getAge_min() > _maxAge)) {
|
||||
// METAR is older than max-age, ignore
|
||||
SG_LOG( SG_ENVIRONMENT, SG_DEBUG, "Ignoring outdated METAR for " << getStationId());
|
||||
return;
|
||||
}
|
||||
|
||||
setMetar( m );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------------- */
|
||||
|
@ -216,7 +234,9 @@ BasicRealWxController::BasicRealWxController( SGPropertyNode_ptr rootNode, Metar
|
|||
{
|
||||
// at least instantiate MetarProperties for /environment/metar
|
||||
_metarProperties.push_back( new LiveMetarProperties(
|
||||
fgGetNode( rootNode->getStringValue("metar", "/environment/metar"), true ), metarRequester ));
|
||||
fgGetNode( rootNode->getStringValue("metar", "/environment/metar"), true ),
|
||||
metarRequester,
|
||||
getMetarMaxAgeMin()));
|
||||
|
||||
BOOST_FOREACH( SGPropertyNode_ptr n, rootNode->getChildren("metar") ) {
|
||||
SGPropertyNode_ptr metarNode = fgGetNode( n->getStringValue(), true );
|
||||
|
@ -300,7 +320,7 @@ void BasicRealWxController::addMetarAtPath(const string& propPath, const string&
|
|||
|
||||
SGPropertyNode_ptr metarNode = fgGetNode(propPath, true);
|
||||
SG_LOG( SG_ENVIRONMENT, SG_INFO, "Adding metar properties at " << propPath );
|
||||
LiveMetarProperties_ptr p(new LiveMetarProperties( metarNode, _requester ));
|
||||
LiveMetarProperties_ptr p(new LiveMetarProperties( metarNode, _requester, getMetarMaxAgeMin() ));
|
||||
_metarProperties.push_back(p);
|
||||
p->setStationId(icao);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue