2 Provide Data for the ATIS Encoder from metarproperties
3 Copyright (C) 2014 Torsten Dreyer
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "CurrentWeatherATISInformationProvider.hxx"
21 #include <Main/fg_props.hxx>
25 CurrentWeatherATISInformationProvider::CurrentWeatherATISInformationProvider( const std::string & airportId ) :
26 _airportId(airportId),
27 _environment(fgGetNode("/environment"))
31 static inline int roundToInt( double d )
33 return (static_cast<int>(10.0 * (d + .5))) / 10;
36 static inline int roundToInt( SGPropertyNode_ptr n )
38 return roundToInt( n->getDoubleValue() );
41 static inline int roundToInt( SGPropertyNode_ptr n, const char * child )
43 return roundToInt( n->getNode(child,true) );
47 CurrentWeatherATISInformationProvider::~CurrentWeatherATISInformationProvider()
51 bool CurrentWeatherATISInformationProvider::isValid()
56 string CurrentWeatherATISInformationProvider::airportId()
61 long CurrentWeatherATISInformationProvider::getTime()
63 int h = fgGetInt( "/sim/time/utc/hour", 12 );
64 int m = 20 + fgGetInt( "/sim/time/utc/minute", 0 ) / 30 ; // fake twice per hour
65 return makeAtisTime( 0, h, m );
68 int CurrentWeatherATISInformationProvider::getWindDeg()
71 int i = 5 + roundToInt( _environment->getNode("config/boundary/entry[0]/wind-from-heading-deg",true) );
76 int CurrentWeatherATISInformationProvider::getWindSpeedKt()
78 return roundToInt( _environment, "config/boundary/entry[0]/wind-speed-kt" );
81 int CurrentWeatherATISInformationProvider::getGustsKt()
86 int CurrentWeatherATISInformationProvider::getQnh()
88 return roundToInt( _environment->getNode("pressure-sea-level-inhg",true)->getDoubleValue() * SG_INHG_TO_PA / 100 );
91 bool CurrentWeatherATISInformationProvider::isCavok()
96 int CurrentWeatherATISInformationProvider::getVisibilityMeters()
98 return roundToInt( _environment, "ground-visibility-m" );
101 string CurrentWeatherATISInformationProvider::getPhenomena()
106 ATISInformationProvider::CloudEntries CurrentWeatherATISInformationProvider::getClouds()
108 using simgear::PropertyList;
110 ATISInformationProvider::CloudEntries cloudEntries;
111 PropertyList layers = _environment->getNode("clouds",true)->getChildren("layer");
112 for( PropertyList::iterator it = layers.begin(); it != layers.end(); ++it ) {
113 string coverage = (*it)->getStringValue( "coverage", "clear" );
114 int alt = roundToInt( (*it)->getDoubleValue("elevation-ft", -9999 ) ) / 100;
117 if( coverage != "clear" && alt > 0 )
118 cloudEntries[alt] = coverage;
124 int CurrentWeatherATISInformationProvider::getTemperatureDeg()
126 return roundToInt( _environment, "temperature-sea-level-degc" );
129 int CurrentWeatherATISInformationProvider::getDewpointDeg()
131 return roundToInt( _environment, "dewpoint-sea-level-degc" );
134 string CurrentWeatherATISInformationProvider::getTrend()