]> git.mxchange.org Git - flightgear.git/blob - src/ATC/atcutils.hxx
Merge branch 'syd/ias-limit' into next
[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 class ATCData;
56
57 // Possible types of ATC type that the radios may be tuned to.
58 // INVALID implies not tuned in to anything.
59 enum atc_type {
60         AWOS,
61         ATIS,
62         GROUND,
63         TOWER,
64         APPROACH,
65         DEPARTURE,
66         ENROUTE,
67   INVALID        /* must be last element;  see ATC_NUM_TYPES */
68 };
69
70
71 // A list of ATC stations
72 typedef std::list < ATCData > comm_list_type;
73 typedef comm_list_type::iterator comm_list_iterator;
74 typedef comm_list_type::const_iterator comm_list_const_iterator;
75
76 // A map of ATC station lists
77 typedef std::map < int, comm_list_type > comm_map_type;
78 typedef comm_map_type::iterator comm_map_iterator;
79 typedef comm_map_type::const_iterator comm_map_const_iterator;
80
81
82 class FGCommList {
83     
84 public:
85
86     FGCommList();
87     ~FGCommList();
88
89     // load all comm frequencies and build the map
90     bool init( const SGPath& path );
91
92     // query the database for the specified frequency, lon and lat are
93     // If no atc_type is specified, it returns true if any non-invalid type is found.
94     // If atc_type is specifed, returns true only if the specified type is found.
95     // Returns the station closest to the supplied position.
96     // The data found is written into the passed-in ATCData structure.
97     bool FindByFreq(const SGGeod& aPos, double freq, ATCData* ad, atc_type tp = INVALID );
98     
99     // query the database by location, lon and lat are in degrees, elev is in meters, range is in nautical miles.
100     // Returns the number of stations of the specified atc_type tp that are in range of the position defined by 
101     // lon, lat and elev, and pushes them into stations.
102     // If no atc_type is specifed, returns the number of all stations in range, and pushes them into stations
103     // ** stations is erased before use **
104     int FindByPos(const SGGeod& aPos, double range, comm_list_type* stations, atc_type tp = INVALID );
105     
106     // Returns the distance in meters to the closest station of a given type,
107     // with the details written into ATCData& ad.  If no type is specifed simply
108     // returns the distance to the closest station of any type.
109     // Returns -9999 if no stations found within max_range in nautical miles (default 100 miles).
110     // Note that the search algorithm starts at 10 miles and multiplies by 10 thereafter, so if
111     // say 300 miles is specifed 10, then 100, then 1000 will be searched, breaking at first result 
112     // and giving up after 1000.
113     // !!!Be warned that searching anything over 100 miles will pause the sim unacceptably!!!
114     //  (The ability to search longer ranges should be used during init only).
115     double FindClosest(const SGGeod& aPos, ATCData& ad, atc_type tp = INVALID, double max_range = 100.0 );
116     
117     // Find by Airport code.
118     bool FindByCode( const std::string& ICAO, ATCData& ad, atc_type tp = INVALID );
119
120     // Return the sequence letter for an ATIS transmission given transmission time and airport id
121     // This maybe should get moved somewhere else!!
122     int GetAtisSequence( const std::string& apt_id, const double tstamp, 
123                     const int interval, const int flush=0);
124     
125     // Comm stations mapped by frequency
126     //comm_map_type commlist_freq;    
127     
128     // Comm stations mapped by bucket
129     //comm_map_type commlist_bck;
130
131     // Load comms from a specified path (which must include the filename)   
132 private:
133
134     bool LoadComms(const SGPath& path);
135
136 //----------- This stuff is left over from atislist.[ch]xx and maybe should move somewhere else
137     // Add structure and map for storing a log of atis transmissions
138     // made in this session of FlightGear.  This allows the callsign
139     // to be allocated correctly wrt time.
140     //typedef struct {
141     //        double tstamp;
142     //    int sequence;
143     //} atis_transmission_type;
144
145     //typedef std::map < std::string, atis_transmission_type > atis_log_type;
146     //typedef atis_log_type::iterator atis_log_iterator;
147     //typedef atis_log_type::const_iterator atis_log_const_iterator;
148
149     //atis_log_type atislog;
150 //-----------------------------------------------------------------------------------------------
151
152 };
153
154
155 extern FGCommList *current_commlist;
156
157 // FGATCAlignedProjection - a class to project an area local to a runway onto an orthogonal co-ordinate system
158 // with the origin at the threshold and the runway aligned with the y axis.
159 class FGKln89AlignedProjection {
160
161 public:
162     FGKln89AlignedProjection();
163     FGKln89AlignedProjection(const SGGeod& centre, double heading);
164     ~FGKln89AlignedProjection();
165
166     void Init(const SGGeod& centre, double heading);
167
168     // Convert a lat/lon co-ordinate (degrees) to the local projection (meters)
169     SGVec3d ConvertToLocal(const SGGeod& pt);
170
171     // Convert a local projection co-ordinate (meters) to lat/lon (degrees)
172     SGGeod ConvertFromLocal(const SGVec3d& pt);
173
174 private:
175     SGGeod _origin;     // lat/lon of local area origin (the threshold)
176     double _theta;      // the rotation angle for alignment in radians
177     double _correction_factor;  // Reduction in surface distance per degree of longitude due to latitude.  Saves having to do a cos() every call.
178
179 };
180
181 #endif // #if ENABLE_ATCDCL
182
183 #endif // _FG_ATCUTILS_HXX
184
185