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
8 // Written by David Luff and Alexander Kappes, started Jan 2003.
9 // Based on navlist.hxx by Curtis Olson, started April 2000.
11 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
27 /*****************************************************************
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.
36 ******************************************************************/
38 #ifndef _FG_ATCUTILS_HXX
39 #define _FG_ATCUTILS_HXX
43 #include <simgear/compiler.h>
58 // Possible types of ATC type that the radios may be tuned to.
59 // INVALID implies not tuned in to anything.
68 INVALID /* must be last element; see ATC_NUM_TYPES */
72 ATCData() : type(INVALID), cart(0, 0, 0), freq(0), range(0) {}
76 unsigned short int freq;
77 unsigned short int range;
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;
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;
102 // load all comm frequencies and build the map
103 bool init( const SGPath& path );
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 );
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 );
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 );
130 // Find by Airport code.
131 bool FindByCode( const std::string& ICAO, ATCData& ad, atc_type tp = INVALID );
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);
138 // Comm stations mapped by frequency
139 //comm_map_type commlist_freq;
141 // Comm stations mapped by bucket
142 //comm_map_type commlist_bck;
144 // Load comms from a specified path (which must include the filename)
147 bool LoadComms(const SGPath& path);
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.
156 //} atis_transmission_type;
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;
162 //atis_log_type atislog;
163 //-----------------------------------------------------------------------------------------------
168 extern FGCommList *current_commlist;
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 {
175 FGKln89AlignedProjection();
176 FGKln89AlignedProjection(const SGGeod& centre, double heading);
177 ~FGKln89AlignedProjection();
179 void Init(const SGGeod& centre, double heading);
181 // Convert a lat/lon co-ordinate (degrees) to the local projection (meters)
182 SGVec3d ConvertToLocal(const SGGeod& pt);
184 // Convert a local projection co-ordinate (meters) to lat/lon (degrees)
185 SGGeod ConvertFromLocal(const SGVec3d& pt);
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.
194 #endif // #if ENABLE_ATCDCL
196 #endif // _FG_ATCUTILS_HXX