2 Encode an ATIS into spoken words
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 #ifndef __ATIS_ENCODER_HXX
21 #define __ATIS_ENCODER_HXX
24 #include <Airports/airport.hxx>
25 #include <simgear/props/props.hxx>
30 static const char * getSpokenDigit( int i );
31 static std::string getSpokenNumber( std::string number );
32 static std::string getSpokenNumber( int number, bool leadingZero = false, int digits = 1 );
33 static std::string getSpokenAltitude( int altitude );
36 class ATISInformationProvider {
38 virtual ~ATISInformationProvider() {}
39 virtual bool isValid() = 0;
40 virtual std::string airportId() = 0;
42 static long makeAtisTime( int day, int hour, int minute ) {
43 return 100*100l* day + 100l * hour + minute;
45 inline int getAtisTimeDay( long atisTime ) { return atisTime / (100l*100l); }
46 inline int getAtisTimeHour( long atisTime ) { return (atisTime % (100l*100l)) / 100l; }
47 inline int getAtisTimeMinute( long atisTime ) { return atisTime % 100l; }
48 virtual long getTime() = 0; // see makeAtisTime
50 virtual int getWindDeg() = 0;
51 virtual int getWindMinDeg() = 0;
52 virtual int getWindMaxDeg() = 0;
53 virtual int getWindSpeedKt() = 0;
54 virtual int getGustsKt() = 0;
55 virtual int getQnh() = 0;
56 virtual double getQnhInHg() = 0;
57 virtual bool isCavok() = 0;
58 virtual int getVisibilityMeters() = 0;
59 virtual std::string getPhenomena() = 0;
61 typedef std::map<int,std::string> CloudEntries;
62 virtual CloudEntries getClouds() = 0;
63 virtual int getTemperatureDeg() = 0;
64 virtual int getDewpointDeg() = 0;
65 virtual std::string getTrend() = 0;
68 class ATISEncoder : public ATCSpeech {
71 virtual ~ATISEncoder();
72 virtual std::string encodeATIS( ATISInformationProvider * atisInformationProvider );
75 virtual std::string getAtisId( SGPropertyNode_ptr );
76 virtual std::string getAirportName( SGPropertyNode_ptr );
77 virtual std::string getTime( SGPropertyNode_ptr );
78 virtual std::string getApproachType( SGPropertyNode_ptr );
79 virtual std::string getLandingRunway( SGPropertyNode_ptr );
80 virtual std::string getTakeoffRunway( SGPropertyNode_ptr );
81 virtual std::string getTransitionLevel( SGPropertyNode_ptr );
82 virtual std::string getWindDirection( SGPropertyNode_ptr );
83 virtual std::string getWindMinDirection( SGPropertyNode_ptr );
84 virtual std::string getWindMaxDirection( SGPropertyNode_ptr );
85 virtual std::string getWindspeedKnots( SGPropertyNode_ptr );
86 virtual std::string getGustsKnots( SGPropertyNode_ptr );
87 virtual std::string getCavok( SGPropertyNode_ptr );
88 virtual std::string getVisibilityMetric( SGPropertyNode_ptr );
89 virtual std::string getVisibilityMiles( SGPropertyNode_ptr );
90 virtual std::string getPhenomena( SGPropertyNode_ptr );
91 virtual std::string getClouds( SGPropertyNode_ptr );
92 virtual std::string getCloudsBrief( SGPropertyNode_ptr );
93 virtual std::string getTemperatureDeg( SGPropertyNode_ptr );
94 virtual std::string getDewpointDeg( SGPropertyNode_ptr );
95 virtual std::string getQnh( SGPropertyNode_ptr );
96 virtual std::string getInhgInteger( SGPropertyNode_ptr );
97 virtual std::string getInhgFraction( SGPropertyNode_ptr );
98 virtual std::string getInhg( SGPropertyNode_ptr );
99 virtual std::string getTrend( SGPropertyNode_ptr );
101 typedef std::string (ATISEncoder::*handler_t)( SGPropertyNode_ptr baseNode );
102 typedef std::map<std::string, handler_t > HandlerMap;
103 HandlerMap handlerMap;
105 SGPropertyNode_ptr atisSchemaNode;
107 std::string processTokens( SGPropertyNode_ptr baseNode );
108 std::string processToken( SGPropertyNode_ptr baseNode );
110 std::string processTextToken( SGPropertyNode_ptr baseNode );
111 std::string processTokenToken( SGPropertyNode_ptr baseNode );
112 std::string processIfToken( SGPropertyNode_ptr baseNode );
114 bool checkEmptyCondition( SGPropertyNode_ptr node, bool isEmpty );
116 // Wrappers that can be passed as function pointers to checkCondition
117 // @see simgear::strutils::starts_with
118 // @see simgear::strutils::ends_with
119 static bool contains(const string &s, const string &substring)
120 { return s.find(substring) != std::string::npos; };
121 static bool equals(const string &s1, const string &s2)
122 { return s1 == s2; };
124 bool checkCondition( SGPropertyNode_ptr node, bool notInverted,
125 bool (*fp)(const std::string &, const std::string &),
126 const std::string &name );
128 FGAirportRef airport;
129 ATISInformationProvider * _atis;