Debian Codegraph @

src/ATC/CurrentWeatherATISInformationProvider.cxx

raw symbols SCIP
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() const
52 {
53 return true;
54 }
55
56 string CurrentWeatherATISInformationProvider::airportId() const
57 {
58 return _airportId;
59 }
60
61 long CurrentWeatherATISInformationProvider::getTime() const
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() const
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() const
77 {
78 return roundToInt( _environment, "config/boundary/entry[0]/wind-speed-kt" );
79 }
80
81 int CurrentWeatherATISInformationProvider::getGustsKt() const
82 {
83 return 0;
84 }
85
86 int CurrentWeatherATISInformationProvider::getQnh() const
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
92 double CurrentWeatherATISInformationProvider::getQnhInHg() const
93 {
94 // TODO: Calculate QNH correctly from environment
95 return _environment->getNode("pressure-sea-level-inhg",true)->getDoubleValue();
96 }
97
98 bool CurrentWeatherATISInformationProvider::isCavok() const
99 {
100 return false;
101 }
102
103 int CurrentWeatherATISInformationProvider::getVisibilityMeters() const
104 {
105 return roundToInt( _environment, "ground-visibility-m" );
106 }
107
108 string CurrentWeatherATISInformationProvider::getPhenomena() const
109 {
110 return "";
111 }
112
113 ATISInformationProvider::CloudEntries CurrentWeatherATISInformationProvider::getClouds()
114 {
115 using simgear::PropertyList;
116
117 ATISInformationProvider::CloudEntries cloudEntries;
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
131 int CurrentWeatherATISInformationProvider::getTemperatureDeg() const
132 {
133 return roundToInt( _environment, "temperature-sea-level-degc" );
134 }
135
136 int CurrentWeatherATISInformationProvider::getDewpointDeg() const
137 {
138 return roundToInt( _environment, "dewpoint-sea-level-degc" );
139 }
140
141 string CurrentWeatherATISInformationProvider::getTrend() const
142 {
143 return "nosig";
144 }