FlightGear next
CurrentWeatherATISInformationProvider.cxx
Go to the documentation of this file.
1/*
2Provide Data for the ATIS Encoder from metarproperties
3Copyright (C) 2014 Torsten Dreyer
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
21#include <Main/fg_props.hxx>
22
23using std::string;
24
26 _airportId(airportId),
27 _environment(fgGetNode("/environment"))
28{
29}
30
31static inline int roundToInt( double d )
32{
33 return (static_cast<int>(10.0 * (d + .5))) / 10;
34}
35
36static inline int roundToInt( SGPropertyNode_ptr n )
37{
38 return roundToInt( n->getDoubleValue() );
39}
40
41static inline int roundToInt( SGPropertyNode_ptr n, const char * child )
42{
43 return roundToInt( n->getNode(child,true) );
44}
45
46
50
52{
53 return true;
54}
55
57{
58 return _airportId;
59}
60
62{
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 );
66}
67
69{
70 // round to 10 degs
71 int i = 5 + roundToInt( _environment->getNode("config/boundary/entry[0]/wind-from-heading-deg",true) );
72 i /= 10;
73 return i*10;
74}
75
77{
78 return roundToInt( _environment, "config/boundary/entry[0]/wind-speed-kt" );
79}
80
85
87{
88 // TODO: Calculate QNH correctly from environment
89 return roundToInt( _environment->getNode("pressure-sea-level-inhg",true)->getDoubleValue() * SG_INHG_TO_PA / 100 );
90}
91
93{
94 // TODO: Calculate QNH correctly from environment
95 return _environment->getNode("pressure-sea-level-inhg",true)->getDoubleValue();
96}
97
99{
100 return false;
101}
102
104{
105 return roundToInt( _environment, "ground-visibility-m" );
106}
107
109{
110 return "";
111}
112
114{
115 using simgear::PropertyList;
116
118 PropertyList layers = _environment->getNode("clouds",true)->getChildren("layer");
119 for( PropertyList::iterator it = layers.begin(); it != layers.end(); ++it ) {
120 string coverage = (*it)->getStringValue( "coverage", "clear" );
121 int alt = roundToInt( (*it)->getDoubleValue("elevation-ft", -9999 ) ) / 100;
122 alt *= 100;
123
124 if( coverage != "clear" && alt > 0 )
125 cloudEntries[alt] = coverage;
126
127 }
128 return cloudEntries;
129}
130
132{
133 return roundToInt( _environment, "temperature-sea-level-degc" );
134}
135
137{
138 return roundToInt( _environment, "dewpoint-sea-level-degc" );
139}
140
142{
143 return "nosig";
144}
static int roundToInt(double d)
#define i(x)
std::map< int, std::string > CloudEntries
static long makeAtisTime(int day, int hour, int minute)
int fgGetInt(const char *name, int defaultValue)
Get an int value for a property.
Definition fg_props.cxx:532
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27