]> git.mxchange.org Git - flightgear.git/blob - src/ATC/atcutils.hxx
Properly compile kln89 code without reliance on ATCDCL.
[flightgear.git] / src / ATC / atcutils.hxx
1 // atcutils.hxx 
2 //
3 // This file contains a collection of classes from David Luff's
4 // AI/ATC code that are shared by non-AI parts of FlightGear.
5 // more specifcially, it contains implementations of FGCommList and
6 // FGATCAlign
7 //
8 // Written by David Luff and Alexander Kappes, started Jan 2003.
9 // Based on navlist.hxx by Curtis Olson, started April 2000.
10 //
11 // Copyright (C) 2000  Curtis L. Olson - http://www.flightgear.org/~curt
12 //
13 // This program is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU General Public License as
15 // published by the Free Software Foundation; either version 2 of the
16 // License, or (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 // General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
27 /*****************************************************************
28 *
29 * FGCommList is used to store communication frequency information
30 * for the ATC and AI subsystems.  Two maps are maintained - one
31 * searchable by location and one searchable by frequency.  The
32 * data structure returned from the search is the ATCData struct
33 * defined in ATC.hxx, containing location, frequency, name, range
34 * and type of the returned station.
35 *
36 ******************************************************************/
37
38 #ifndef _FG_ATCUTILS_HXX
39 #define _FG_ATCUTILS_HXX
40
41
42
43 #include <simgear/compiler.h>
44
45 #include <map>
46 #include <list>
47 #include <string>
48
49 //#include "ATC.hxx"
50 //#include "atis.hxx"
51
52 #if !ENABLE_ATCDCL
53
54 class SGPath;
55
56
57
58 // Possible types of ATC type that the radios may be tuned to.
59 // INVALID implies not tuned in to anything.
60 enum atc_type {
61         AWOS,
62         ATIS,
63         GROUND,
64         TOWER,
65         APPROACH,
66         DEPARTURE,
67         ENROUTE,
68   INVALID        /* must be last element;  see ATC_NUM_TYPES */
69 };
70
71 struct ATCData {
72         ATCData() : type(INVALID), cart(0, 0, 0), freq(0), range(0) {}
73         atc_type type;
74         SGGeod geod;
75         SGVec3d cart;
76         unsigned short int freq;
77         unsigned short int range;
78         std::string ident;
79         std::string name;
80 };
81
82
83
84 // A list of ATC stations
85 typedef std::list < ATCData > comm_list_type;
86 typedef comm_list_type::iterator comm_list_iterator;
87 typedef comm_list_type::const_iterator comm_list_const_iterator;
88
89 // A map of ATC station lists
90 typedef std::map < int, comm_list_type > comm_map_type;
91 typedef comm_map_type::iterator comm_map_iterator;
92 typedef comm_map_type::const_iterator comm_map_const_iterator;
93
94
95 class FGCommList {
96     
97 public:
98
99     FGCommList();
100     ~FGCommList();
101
102     // load all comm frequencies and build the map
103     bool init( const SGPath& path );
104
105     // query the database for the specified frequency, lon and lat are
106     // If no atc_type is specified, it returns true if any non-invalid type is found.
107     // If atc_type is specifed, returns true only if the specified type is found.
108     // Returns the station closest to the supplied position.
109     // The data found is written into the passed-in ATCData structure.
110     bool FindByFreq(const SGGeod& aPos, double freq, ATCData* ad, atc_type tp = INVALID );
111     
112     // query the database by location, lon and lat are in degrees, elev is in meters, range is in nautical miles.
113     // Returns the number of stations of the specified atc_type tp that are in range of the position defined by 
114     // lon, lat and elev, and pushes them into stations.
115     // If no atc_type is specifed, returns the number of all stations in range, and pushes them into stations
116     // ** stations is erased before use **
117     int FindByPos(const SGGeod& aPos, double range, comm_list_type* stations, atc_type tp = INVALID );
118     
119     // Returns the distance in meters to the closest station of a given type,
120     // with the details written into ATCData& ad.  If no type is specifed simply
121     // returns the distance to the closest station of any type.
122     // Returns -9999 if no stations found within max_range in nautical miles (default 100 miles).
123     // Note that the search algorithm starts at 10 miles and multiplies by 10 thereafter, so if
124     // say 300 miles is specifed 10, then 100, then 1000 will be searched, breaking at first result 
125     // and giving up after 1000.
126     // !!!Be warned that searching anything over 100 miles will pause the sim unacceptably!!!
127     //  (The ability to search longer ranges should be used during init only).
128     double FindClosest(const SGGeod& aPos, ATCData& ad, atc_type tp = INVALID, double max_range = 100.0 );
129     
130     // Find by Airport code.
131     bool FindByCode( const std::string& ICAO, ATCData& ad, atc_type tp = INVALID );
132
133     // Return the sequence letter for an ATIS transmission given transmission time and airport id
134     // This maybe should get moved somewhere else!!
135     int GetAtisSequence( const std::string& apt_id, const double tstamp, 
136                     const int interval, const int flush=0);
137     
138     // Comm stations mapped by frequency
139     //comm_map_type commlist_freq;    
140     
141     // Comm stations mapped by bucket
142     //comm_map_type commlist_bck;
143
144     // Load comms from a specified path (which must include the filename)   
145 private:
146
147     bool LoadComms(const SGPath& path);
148
149 //----------- This stuff is left over from atislist.[ch]xx and maybe should move somewhere else
150     // Add structure and map for storing a log of atis transmissions
151     // made in this session of FlightGear.  This allows the callsign
152     // to be allocated correctly wrt time.
153     //typedef struct {
154     //        double tstamp;
155     //    int sequence;
156     //} atis_transmission_type;
157
158     //typedef std::map < std::string, atis_transmission_type > atis_log_type;
159     //typedef atis_log_type::iterator atis_log_iterator;
160     //typedef atis_log_type::const_iterator atis_log_const_iterator;
161
162     //atis_log_type atislog;
163 //-----------------------------------------------------------------------------------------------
164
165 };
166
167
168 extern FGCommList *current_commlist;
169
170 // FGATCAlignedProjection - a class to project an area local to a runway onto an orthogonal co-ordinate system
171 // with the origin at the threshold and the runway aligned with the y axis.
172 class FGKln89AlignedProjection {
173
174 public:
175     FGKln89AlignedProjection();
176     FGKln89AlignedProjection(const SGGeod& centre, double heading);
177     ~FGKln89AlignedProjection();
178
179     void Init(const SGGeod& centre, double heading);
180
181     // Convert a lat/lon co-ordinate (degrees) to the local projection (meters)
182     SGVec3d ConvertToLocal(const SGGeod& pt);
183
184     // Convert a local projection co-ordinate (meters) to lat/lon (degrees)
185     SGGeod ConvertFromLocal(const SGVec3d& pt);
186
187 private:
188     SGGeod _origin;     // lat/lon of local area origin (the threshold)
189     double _theta;      // the rotation angle for alignment in radians
190     double _correction_factor;  // Reduction in surface distance per degree of longitude due to latitude.  Saves having to do a cos() every call.
191
192 };
193
194 #endif // #if ENABLE_ATCDCL
195
196 #endif // _FG_ATCUTILS_HXX
197
198