]> git.mxchange.org Git - flightgear.git/blob - src/ATC/MetarPropertiesATISInformationProvider.cxx
Code cleanups, code updates and fix at least on (possible) devide-by-zero
[flightgear.git] / src / ATC / MetarPropertiesATISInformationProvider.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 "MetarPropertiesATISInformationProvider.hxx"
21 #include <Main/globals.hxx>
22 #include <simgear/constants.h>
23
24 using std::string;
25
26 MetarPropertiesATISInformationProvider::MetarPropertiesATISInformationProvider( SGPropertyNode_ptr metar ) :
27   _metar( metar )
28 {
29 }
30
31 MetarPropertiesATISInformationProvider::~MetarPropertiesATISInformationProvider()
32 {
33 }
34
35 bool MetarPropertiesATISInformationProvider::isValid()
36 {
37   return _metar->getBoolValue( "valid", false );
38 }
39
40 string MetarPropertiesATISInformationProvider::airportId()
41 {
42   return _metar->getStringValue( "station-id", "xxxx" );
43 }
44
45 long MetarPropertiesATISInformationProvider::getTime()
46 {
47   return makeAtisTime( 0,
48     _metar->getIntValue( "hour" ) % 24, 
49     _metar->getIntValue( "minute" ) % 60 );
50 }
51
52 int MetarPropertiesATISInformationProvider::getWindDeg()
53 {
54    return _metar->getIntValue( "base-wind-dir-deg" );
55 }
56
57 int MetarPropertiesATISInformationProvider::getWindMinDeg()
58 {
59    return _metar->getIntValue( "base-wind-range-from" );
60 }
61 int MetarPropertiesATISInformationProvider::getWindMaxDeg()
62 {
63    return _metar->getIntValue( "base-wind-range-to" );
64 }
65 int MetarPropertiesATISInformationProvider::getWindSpeedKt()
66 {
67   return _metar->getIntValue( "base-wind-speed-kt" );
68 }
69
70 int MetarPropertiesATISInformationProvider::getGustsKt()
71 {
72   return _metar->getIntValue( "gust-wind-speed-kt" );
73 }
74
75 int MetarPropertiesATISInformationProvider::getQnh()
76 {
77   return _metar->getDoubleValue("pressure-inhg") * SG_INHG_TO_PA / 100.0;
78 }
79
80 double MetarPropertiesATISInformationProvider::getQnhInHg()
81 {
82   return _metar->getDoubleValue("pressure-inhg");
83 }
84
85 bool MetarPropertiesATISInformationProvider::isCavok()
86 {
87   return _metar->getBoolValue( "cavok" );
88 }
89
90 int MetarPropertiesATISInformationProvider::getVisibilityMeters()
91 {
92   return _metar->getIntValue( "min-visibility-m" );
93 }
94
95 string MetarPropertiesATISInformationProvider::getPhenomena()
96 {
97   return _metar->getStringValue( "decoded" );
98 }
99
100 ATISInformationProvider::CloudEntries MetarPropertiesATISInformationProvider::getClouds()
101 {
102   CloudEntries reply;
103
104   using simgear::PropertyList;
105   PropertyList layers = _metar->getNode("clouds", true )->getChildren("layer");
106   for( PropertyList::iterator it = layers.begin(); it != layers.end(); ++it ) {
107     const char * coverage = (*it)->getStringValue("coverage","clear");
108     double elevation = (*it)->getDoubleValue("elevation-ft", -9999 );
109     if( elevation > 0 ) {
110       reply[elevation] = coverage;
111     }
112   }
113   return reply;
114 }
115
116 int MetarPropertiesATISInformationProvider::getTemperatureDeg()
117 {
118   return _metar->getIntValue( "temperature-degc" );
119 }
120
121 int MetarPropertiesATISInformationProvider::getDewpointDeg()
122 {
123   return _metar->getIntValue( "dewpoint-degc" );
124 }
125
126 string MetarPropertiesATISInformationProvider::getTrend()
127 {
128   return "nosig";
129 }
130