]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/commlist.hxx
Update VS2008 projects : use Boost 1.44.0 available in last 3rd Party archive
[flightgear.git] / src / ATCDCL / commlist.hxx
1 // commlist.hxx -- comm frequency lookup class
2 //
3 // Written by David Luff and Alexander Kappes, started Jan 2003.
4 // Based on navlist.hxx by Curtis Olson, started April 2000.
5 //
6 // Copyright (C) 2000  Curtis L. Olson - http://www.flightgear.org/~curt
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 /*****************************************************************
23 *
24 * FGCommList is used to store communication frequency information
25 * for the ATC and AI subsystems.  Two maps are maintained - one
26 * searchable by location and one searchable by frequency.  The
27 * data structure returned from the search is the ATCData struct
28 * defined in ATC.hxx, containing location, frequency, name, range
29 * and type of the returned station.
30 *
31 ******************************************************************/
32
33 #ifndef _FG_COMMLIST_HXX
34 #define _FG_COMMLIST_HXX
35
36
37 #include <simgear/compiler.h>
38
39 #include <map>
40 #include <list>
41 #include <string>
42
43 #include "ATC.hxx"
44 #include "atis.hxx"
45
46 class SGPath;
47
48 // A list of ATC stations
49 typedef std::list < ATCData > comm_list_type;
50 typedef comm_list_type::iterator comm_list_iterator;
51 typedef comm_list_type::const_iterator comm_list_const_iterator;
52
53 // A map of ATC station lists
54 typedef std::map < int, comm_list_type > comm_map_type;
55 typedef comm_map_type::iterator comm_map_iterator;
56 typedef comm_map_type::const_iterator comm_map_const_iterator;
57
58
59 class FGCommList {
60     
61 public:
62
63     FGCommList();
64     ~FGCommList();
65
66     // load all comm frequencies and build the map
67     bool init( const SGPath& path );
68
69     // query the database for the specified frequency, lon and lat are
70     // If no atc_type is specified, it returns true if any non-invalid type is found.
71     // If atc_type is specifed, returns true only if the specified type is found.
72     // Returns the station closest to the supplied position.
73     // The data found is written into the passed-in ATCData structure.
74     bool FindByFreq(const SGGeod& aPos, double freq, ATCData* ad, atc_type tp = INVALID );
75     
76     // query the database by location, lon and lat are in degrees, elev is in meters, range is in nautical miles.
77     // Returns the number of stations of the specified atc_type tp that are in range of the position defined by 
78     // lon, lat and elev, and pushes them into stations.
79     // If no atc_type is specifed, returns the number of all stations in range, and pushes them into stations
80     // ** stations is erased before use **
81     int FindByPos(const SGGeod& aPos, double range, comm_list_type* stations, atc_type tp = INVALID );
82     
83     // Returns the distance in meters to the closest station of a given type,
84     // with the details written into ATCData& ad.  If no type is specifed simply
85     // returns the distance to the closest station of any type.
86     // Returns -9999 if no stations found within max_range in nautical miles (default 100 miles).
87     // Note that the search algorithm starts at 10 miles and multiplies by 10 thereafter, so if
88     // say 300 miles is specifed 10, then 100, then 1000 will be searched, breaking at first result 
89     // and giving up after 1000.
90     // !!!Be warned that searching anything over 100 miles will pause the sim unacceptably!!!
91     //  (The ability to search longer ranges should be used during init only).
92     double FindClosest(const SGGeod& aPos, ATCData& ad, atc_type tp = INVALID, double max_range = 100.0 );
93     
94     // Find by Airport code.
95     bool FindByCode( const std::string& ICAO, ATCData& ad, atc_type tp = INVALID );
96
97     // Return the sequence letter for an ATIS transmission given transmission time and airport id
98     // This maybe should get moved somewhere else!!
99     int GetAtisSequence( const std::string& apt_id, const double tstamp, 
100                     const int interval, const int flush=0);
101     
102     // Comm stations mapped by frequency
103     comm_map_type commlist_freq;    
104     
105     // Comm stations mapped by bucket
106     comm_map_type commlist_bck;
107
108     // Load comms from a specified path (which must include the filename)   
109 private:
110
111     bool LoadComms(const SGPath& path);
112
113 //----------- This stuff is left over from atislist.[ch]xx and maybe should move somewhere else
114     // Add structure and map for storing a log of atis transmissions
115     // made in this session of FlightGear.  This allows the callsign
116     // to be allocated correctly wrt time.
117     typedef struct {
118             double tstamp;
119         int sequence;
120     } atis_transmission_type;
121
122     typedef std::map < std::string, atis_transmission_type > atis_log_type;
123     typedef atis_log_type::iterator atis_log_iterator;
124     typedef atis_log_type::const_iterator atis_log_const_iterator;
125
126     atis_log_type atislog;
127 //-----------------------------------------------------------------------------------------------
128
129 };
130
131
132 extern FGCommList *current_commlist;
133
134 #endif // _FG_COMMLIST_HXX
135
136