]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATC.hxx
Major re-work of the comm frequency storage and lookup. Only a small core amount...
[flightgear.git] / src / ATC / ATC.hxx
1 // FGATC - abstract base class for the various actual atc classes 
2 // such as FGATIS, FGTower etc.
3 //
4 // Written by David Luff, started Feburary 2002.
5 //
6 // Copyright (C) 2002  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., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 #ifndef _FG_ATC_HXX
23 #define _FG_ATC_HXX
24
25 #include <simgear/compiler.h>
26 #include <simgear/misc/sgstream.hxx>
27 #include <simgear/math/sg_geodesy.hxx>
28 #include <simgear/debug/logstream.hxx>
29
30 #include STL_IOSTREAM
31 #include STL_STRING
32
33 SG_USING_STD(ostream);
34 SG_USING_STD(string);
35 SG_USING_STD(ios);
36
37 // Possible types of ATC type that the radios may be tuned to.
38 // INVALID implies not tuned in to anything.
39 enum atc_type {
40     INVALID,
41     ATIS,
42     GROUND,
43     TOWER,
44     APPROACH,
45     DEPARTURE,
46     ENROUTE
47 }; 
48
49 // DCL - new experimental ATC data store
50 struct ATCData {
51         atc_type type;
52         float lon, lat, elev;
53         float x, y, z;
54         //int freq;
55         unsigned short int freq;
56         //int range;
57         unsigned short int range;
58         string ident;
59         string name;
60 };
61
62 ostream& operator << (ostream& os, atc_type atc);
63
64 class FGATC {
65
66 public:
67
68     virtual ~FGATC();
69
70     // Run the internal calculations
71     virtual void Update();
72
73     // Add plane to a stack
74     virtual void AddPlane(string pid);
75
76     // Remove plane from stack
77     virtual int RemovePlane();
78
79     // Indicate that this instance should output to the display if appropriate 
80     virtual void SetDisplay();
81
82     // Indicate that this instance should not output to the display
83     virtual void SetNoDisplay();
84
85     // Return the type of ATC station that the class represents
86     virtual atc_type GetType();
87         
88         // Set the core ATC data
89         void SetData(ATCData* d);
90         
91         inline double get_lon() const { return lon; }
92         inline void set_lon(const double ln) {lon = ln;}
93         inline double get_lat() const { return lat; }
94         inline void set_lat(const double lt) {lat = lt;}
95         inline double get_elev() const { return elev; }
96         inline void set_elev(const double ev) {elev = ev;}
97         inline double get_x() const { return x; }
98         inline void set_x(const double ecs) {x = ecs;}
99         inline double get_y() const { return y; }
100         inline void set_y(const double why) {y = why;}
101         inline double get_z() const { return z; }
102         inline void set_z(const double zed) {z = zed;}
103         inline int get_freq() const { return freq; }
104         inline void set_freq(const int fq) {freq = fq;}
105         inline int get_range() const { return range; }
106         inline void set_range(const int rg) {range = rg;}
107         inline const char* get_ident() { return ident.c_str(); }
108         inline void set_ident(const string id) {ident = id;}
109         inline const char* get_name() {return name.c_str();}
110         inline void set_name(const string nm) {name = nm;}
111         
112 protected:
113
114         double lon, lat, elev;
115         double x, y, z;
116         int freq;
117         int range;
118         string ident;           // Code of the airport its at.
119         string name;            // Name transmitted in the broadcast.
120 };
121
122 inline istream&
123 operator >> ( istream& fin, ATCData& a )
124 {
125         double f;
126         char ch;
127         char tp;
128
129         fin >> tp;
130         
131         switch(tp) {
132         case 'I':
133                 a.type = ATIS;
134                 break;
135         case 'T':
136                 a.type = TOWER;
137                 break;
138         case 'G':
139                 a.type = GROUND;
140                 break;
141         case 'A':
142                 a.type = APPROACH;
143                 break;
144         case '[':
145                 a.type = INVALID;
146                 return fin >> skipeol;
147         default:
148                 SG_LOG(SG_GENERAL, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
149                 a.type = INVALID;
150                 return fin >> skipeol;
151         }
152
153         fin >> a.lat >> a.lon >> a.elev >> f >> a.range 
154         >> a.ident;
155         
156         a.name = "";
157         fin >> ch;
158         a.name += ch;
159         while(1) {
160                 //in >> noskipws
161                 fin.unsetf(ios::skipws);
162                 fin >> ch;
163                 a.name += ch;
164                 if((ch == '"') || (ch == 0x0A)) {
165                         break;
166                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
167         }
168         fin.setf(ios::skipws);
169         //cout << "Comm name = " << a.name << '\n';
170         
171         a.freq = (int)(f*100.0 + 0.5);
172         
173         // cout << a.ident << endl;
174         
175         // generate cartesian coordinates
176         Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
177         Point3D cart = sgGeodToCart( geod );
178         a.x = cart.x();
179         a.y = cart.y();
180         a.z = cart.z();
181         
182         return fin >> skipeol;
183 }
184
185
186 #endif  // _FG_ATC_HXX