]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/atis.hxx
Fix an (unlikely) startup crash
[flightgear.git] / src / ATCDCL / atis.hxx
1 // atis.hxx -- ATIS class
2 //
3 // Written by David Luff, started October 2001.
4 // Based on nav.hxx by Curtis Olson, started April 2000.
5 //
6 // Copyright (C) 2001  David C. Luff - david.luff@nottingham.ac.uk
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifndef _FG_ATIS_HXX
23 #define _FG_ATIS_HXX
24
25 #include <string>
26 #include <iosfwd>
27
28 #include <simgear/compiler.h>
29 #include <simgear/timing/sg_time.hxx>
30 #include <simgear/props/props.hxx>
31
32 #include "ATC.hxx"
33
34 class FGAirport;
35
36 typedef std::map<std::string,std::string> MSS;
37
38 class FGATIS : public FGATC {
39
40     std::string        _name;
41     int                _num;
42
43     SGPropertyNode_ptr _root;
44     SGPropertyNode_ptr _volume;
45     SGPropertyNode_ptr _serviceable;
46     SGPropertyNode_ptr _operable;
47     SGPropertyNode_ptr _electrical;
48     SGPropertyNode_ptr _freq;
49     SGPropertyNode_ptr _atis;
50
51     // Pointers to current users position
52     SGPropertyNode_ptr _lon_node;
53     SGPropertyNode_ptr _lat_node;
54     SGPropertyNode_ptr _elev_node;
55
56     SGPropertyChangeCallback<FGATIS> _cb_attention;
57
58     // The actual ATIS transmission
59     // This is generated from the prevailing conditions when required.
60     // This is the version with markup, suitable for voice synthesis:
61     std::string transmission;
62
63     // Same as above, but in a form more readable as text.
64     std::string transmission_readable;
65
66     // for failure modeling
67     std::string trans_ident; // transmitted ident
68     double old_volume;
69     bool atis_failed;        // atis failed?
70     time_t msg_time;         // for moderating error messages
71     time_t cur_time;
72     int msg_OK;
73     bool _attention;
74     bool _check_transmission;
75
76     bool _prev_display;      // Previous value of _display flag
77     MSS _remap;              // abbreviations to be expanded
78
79     // internal periodic station search timer
80     double _time_before_search_sec;
81     int _last_frequency;
82
83     // temporary buffer for string conversions
84     char buf[100];
85
86     // data for the current ATIS report
87     struct
88     {
89         std::string phonetic_seq_string;
90         bool    US_CA;
91         bool    cavok;
92         bool    concise;
93         bool    ils;
94         int     temp;
95         int     dewpoint;
96         double  psl;
97         double  qnh;
98         double  rain_norm, snow_norm;
99         int     notam;
100         std::string hours,mins;
101     } _report;
102
103 public:
104
105     FGATIS(const std::string& name, int num);
106
107     void init();
108     void reinit();
109
110     void attend(SGPropertyNode* node);
111
112     //run the ATIS instance
113     void update(double dt);
114
115     //inline void set_type(const atc_type tp) {type = tp;}
116     inline const std::string& get_trans_ident() { return trans_ident; }
117
118 protected:
119     virtual FGATCVoice* GetVoicePointer();
120
121 private:
122
123     void createReport       (const FGAirport* apt);
124
125     /** generate the ATIS transmission text */
126     bool genTransmission    (const int regen, bool forceUpdate);
127     void genTimeInfo        (void);
128     void genFacilityInfo    (void);
129     void genPrecipitationInfo(void);
130     bool genVisibilityInfo  (std::string& vis_info);
131     bool genCloudInfo       (std::string& cloud_info);
132     void genWindInfo        (void);
133     void genTemperatureInfo (void);
134     void genTransitionLevel (const FGAirport* apt);
135     void genPressureInfo    (void);
136     void genRunwayInfo      (const FGAirport* apt);
137     void genWarnings        (int position);
138
139     void addTemperature     (int Temp);
140
141     // Put the text into the property tree
142     // (and in debug mode, print it on the console):
143     void treeOut(int msgOK);
144
145     // Search the specified radio for stations on the same frequency and in range.
146     bool search(double dt);
147
148     friend std::istream& operator>> ( std::istream&, FGATIS& );
149 };
150
151 typedef int (FGATIS::*int_getter)() const;
152
153 #endif // _FG_ATIS_HXX