]> git.mxchange.org Git - flightgear.git/blob - src/ATC/CurrentWeatherATISInformationProvider.cxx
Cleanup, no functional change
[flightgear.git] / src / ATC / CurrentWeatherATISInformationProvider.cxx
1 /*
2 Provide Data for the ATIS Encoder from metarproperties
3 Copyright (C) 2014 Torsten Dreyer
4
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.
9
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.
14
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.
18 */
19
20 #include "CurrentWeatherATISInformationProvider.hxx"
21 #include <Main/fg_props.hxx>
22
23 using std::string;
24
25 CurrentWeatherATISInformationProvider::CurrentWeatherATISInformationProvider( const std::string & airportId ) :
26   _airportId(airportId),
27   _environment(fgGetNode("/environment"))
28 {
29 }
30
31 static inline int roundToInt( double d )
32 {
33   return (static_cast<int>(10.0 * (d + .5))) / 10;
34 }
35
36 static inline int roundToInt( SGPropertyNode_ptr n )
37 {
38   return roundToInt( n->getDoubleValue() );
39 }
40
41 static inline int roundToInt( SGPropertyNode_ptr n, const char * child )
42 {
43   return roundToInt( n->getNode(child,true) );
44 }
45
46
47 CurrentWeatherATISInformationProvider::~CurrentWeatherATISInformationProvider()
48 {
49 }
50
51 bool CurrentWeatherATISInformationProvider::isValid()
52 {
53   return true;
54 }
55
56 string CurrentWeatherATISInformationProvider::airportId()
57 {
58   return _airportId;
59 }
60
61 long CurrentWeatherATISInformationProvider::getTime()
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
68 int CurrentWeatherATISInformationProvider::getWindDeg()
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
76 int CurrentWeatherATISInformationProvider::getWindSpeedKt()
77 {
78   return roundToInt( _environment, "config/boundary/entry[0]/wind-speed-kt" );
79 }
80
81 int CurrentWeatherATISInformationProvider::getGustsKt()
82 {
83   return 0;
84 }
85
86 int CurrentWeatherATISInformationProvider::getQnh()
87 {
88   return roundToInt( _environment->getNode("pressure-sea-level-inhg",true)->getDoubleValue() * SG_INHG_TO_PA / 100 );
89 }
90
91 bool CurrentWeatherATISInformationProvider::isCavok()
92 {
93   return false;
94 }
95
96 int CurrentWeatherATISInformationProvider::getVisibilityMeters()
97 {
98   return roundToInt( _environment, "ground-visibility-m" );
99 }
100
101 string CurrentWeatherATISInformationProvider::getPhenomena()
102 {
103   return "";
104 }
105
106 ATISInformationProvider::CloudEntries CurrentWeatherATISInformationProvider::getClouds()
107 {
108   using simgear::PropertyList;
109
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;
115     alt *= 100;
116
117     if( coverage != "clear" && alt > 0 )
118       cloudEntries[alt] = coverage;
119     
120   }
121   return cloudEntries;
122 }
123
124 int CurrentWeatherATISInformationProvider::getTemperatureDeg()
125 {
126   return roundToInt( _environment, "temperature-sea-level-degc" );
127 }
128
129 int CurrentWeatherATISInformationProvider::getDewpointDeg()
130 {
131   return roundToInt( _environment, "dewpoint-sea-level-degc" );
132 }
133
134 string CurrentWeatherATISInformationProvider::getTrend()
135 {
136   return "nosig";
137 }
138