static const double thickness_value[] = { 0, 65, 600, 750, 1000 };
-void MetarProperties::set_metar( const char * metar )
+const char* MetarProperties::get_metar() const
+{
+ if (!_metar) return "";
+ return _metar->getData();
+}
+
+void MetarProperties::set_metar( const char * metarString )
{
- _metar = metar;
-
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(", ");
#include <simgear/props/props.hxx>
#include <simgear/props/tiedpropertylist.hxx>
+class FGMetar;
+
namespace Environment {
class MagneticVariation;
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(); }
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;
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 );
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 );
}
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 );
}
/* -------------------------------------------------------------------------------- */
{
// 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 );
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);
}