2002-03-01 17:39:52 +00:00
|
|
|
// ATCMgr.hxx - definition of FGATCMgr
|
|
|
|
// - a global management class for FlightGear generated ATC
|
|
|
|
//
|
|
|
|
// Written by David Luff, started February 2002.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
#ifndef _FG_ATCMGR_HXX
|
|
|
|
#define _FG_ATCMGR_HXX
|
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
2002-12-17 17:19:14 +00:00
|
|
|
#include <GUI/gui.h>
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
#include <string>
|
2002-03-01 17:39:52 +00:00
|
|
|
#include <list>
|
2002-04-03 23:54:44 +00:00
|
|
|
#include <map>
|
2002-03-01 17:39:52 +00:00
|
|
|
|
|
|
|
#include "atis.hxx"
|
2002-04-03 23:54:44 +00:00
|
|
|
#include "tower.hxx"
|
|
|
|
#include "approach.hxx"
|
2002-12-04 20:07:12 +00:00
|
|
|
#include "ground.hxx"
|
2002-03-01 17:39:52 +00:00
|
|
|
#include "ATC.hxx"
|
2002-12-04 20:07:12 +00:00
|
|
|
#include "ATCVoice.hxx"
|
2003-02-13 12:20:25 +00:00
|
|
|
#include "transmissionlist.hxx"
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
SG_USING_STD(string);
|
2002-03-01 17:39:52 +00:00
|
|
|
SG_USING_STD(list);
|
2002-04-03 23:54:44 +00:00
|
|
|
SG_USING_STD(map);
|
|
|
|
|
|
|
|
// Structure for holding details of the ATC frequencies at a given airport, and whether they are in the active list or not.
|
2003-03-06 14:04:02 +00:00
|
|
|
// These can then be cross referenced with the commlists which are stored by frequency or bucket.
|
2002-04-03 23:54:44 +00:00
|
|
|
// Non-available services are denoted by a frequency of zero.
|
2003-03-06 14:04:02 +00:00
|
|
|
// These structures are only intended to be created for in-use airports, and removed when no longer needed.
|
2002-04-03 23:54:44 +00:00
|
|
|
struct AirportATC {
|
2003-03-06 14:04:02 +00:00
|
|
|
AirportATC();
|
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
float lon;
|
|
|
|
float lat;
|
|
|
|
float elev;
|
|
|
|
float atis_freq;
|
|
|
|
bool atis_active;
|
|
|
|
float tower_freq;
|
|
|
|
bool tower_active;
|
|
|
|
float ground_freq;
|
|
|
|
bool ground_active;
|
|
|
|
//float approach_freq;
|
|
|
|
//bool approach_active;
|
|
|
|
//float departure_freq;
|
|
|
|
//bool departure_active;
|
2003-03-07 13:58:33 +00:00
|
|
|
|
|
|
|
// NOTE - the *_active flags determine whether the service is active in atc_list,
|
|
|
|
// *NOT* whether the tower etc is closed or not!!!!
|
2002-04-03 23:54:44 +00:00
|
|
|
|
|
|
|
// Flags to ensure the stations don't get wrongly deactivated
|
|
|
|
bool set_by_AI; // true when the AI manager has activated this station
|
2003-03-07 13:58:33 +00:00
|
|
|
unsigned int numAI; // Ref count of the number of AI planes registered
|
2003-10-11 18:10:28 +00:00
|
|
|
bool set_by_comm[2][ATC_NUM_TYPES]; // true when the relevant comm_freq has activated this station and type
|
2002-04-03 23:54:44 +00:00
|
|
|
};
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
class FGATCMgr : public SGSubsystem
|
2002-03-01 17:39:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2003-09-05 10:23:20 +00:00
|
|
|
bool initDone; // Hack - guard against update getting called before init
|
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
// A map of airport ID vs frequencies and ATC provision
|
|
|
|
typedef map < string, AirportATC* > airport_atc_map_type;
|
|
|
|
typedef airport_atc_map_type::iterator airport_atc_map_iterator;
|
|
|
|
typedef airport_atc_map_type::const_iterator airport_atc_map_const_iterator;
|
|
|
|
|
|
|
|
airport_atc_map_type airport_atc_map;
|
|
|
|
airport_atc_map_iterator airport_atc_map_itr;
|
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
// A list of pointers to all currently active ATC classes
|
|
|
|
typedef list <FGATC*> atc_list_type;
|
|
|
|
typedef atc_list_type::iterator atc_list_iterator;
|
|
|
|
typedef atc_list_type::const_iterator atc_list_const_iterator;
|
|
|
|
|
|
|
|
// Everything put in this list should be created dynamically
|
|
|
|
// on the heap and ***DELETED WHEN REMOVED!!!!!***
|
|
|
|
atc_list_type atc_list;
|
|
|
|
atc_list_iterator atc_list_itr;
|
|
|
|
// Any member function of FGATCMgr is permitted to leave this iterator pointing
|
|
|
|
// at any point in or at the end of the list.
|
|
|
|
// Hence any new access must explicitly first check for atc_list.end() before dereferencing.
|
|
|
|
|
|
|
|
// Position of the Users Aircraft
|
|
|
|
double lon;
|
|
|
|
double lat;
|
|
|
|
double elev;
|
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
// Type of ATC control that the user's radios are tuned to.
|
2003-02-06 10:42:43 +00:00
|
|
|
atc_type comm_type[2];
|
2002-12-17 17:19:14 +00:00
|
|
|
|
|
|
|
// Pointer to the ATC station that the user is currently tuned into.
|
2003-02-06 10:42:43 +00:00
|
|
|
FGATC* comm_atc_ptr[2];
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
double comm_freq[2];
|
2002-03-01 17:39:52 +00:00
|
|
|
|
|
|
|
// Pointers to users current communication frequencies.
|
2003-02-06 10:42:43 +00:00
|
|
|
SGPropertyNode* comm_node[2];
|
2002-03-01 17:39:52 +00:00
|
|
|
|
|
|
|
// Pointers to current users position
|
2002-12-04 20:07:12 +00:00
|
|
|
SGPropertyNode* lon_node;
|
|
|
|
SGPropertyNode* lat_node;
|
|
|
|
SGPropertyNode* elev_node;
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2003-01-07 13:11:00 +00:00
|
|
|
// Position of the ATC that the comm radios are tuned to in order to decide
|
|
|
|
// whether transmission will be received.
|
2003-02-06 10:42:43 +00:00
|
|
|
double comm_x[2], comm_y[2], comm_z[2], comm_lon[2], comm_lat[2], comm_elev[2];
|
|
|
|
|
|
|
|
double comm_range[2], comm_effective_range[2];
|
|
|
|
bool comm_valid[2];
|
2004-01-23 17:18:24 +00:00
|
|
|
string comm_ident[2];
|
|
|
|
//string last_comm_ident[2];
|
|
|
|
//string approach_ident;
|
2003-01-07 13:11:00 +00:00
|
|
|
bool last_in_range;
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
//FGATIS atis;
|
2002-03-01 17:39:52 +00:00
|
|
|
//FGGround ground;
|
2002-04-03 23:54:44 +00:00
|
|
|
FGTower tower;
|
|
|
|
FGApproach approach;
|
2002-03-01 17:39:52 +00:00
|
|
|
//FGDeparture departure;
|
2003-02-18 10:44:01 +00:00
|
|
|
|
|
|
|
// Voice related stuff
|
2002-12-04 20:07:12 +00:00
|
|
|
bool voice; // Flag - true if we are using voice
|
|
|
|
#ifdef ENABLE_AUDIO_SUPPORT
|
|
|
|
bool voiceOK; // Flag - true if at least one voice has loaded OK
|
2003-02-18 10:44:01 +00:00
|
|
|
FGATCVoice* v1;
|
2002-12-04 20:07:12 +00:00
|
|
|
#endif
|
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
FGATCMgr();
|
|
|
|
~FGATCMgr();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
|
void bind();
|
|
|
|
|
|
|
|
void unbind();
|
|
|
|
|
2002-05-11 16:28:50 +00:00
|
|
|
void update(double dt);
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
// Returns true if the airport is found in the map
|
2005-10-25 13:49:55 +00:00
|
|
|
bool GetAirportATCDetails(const string& icao, AirportATC* a);
|
2002-04-03 23:54:44 +00:00
|
|
|
|
|
|
|
// Return a pointer to a given sort of ATC at a given airport and activate if necessary
|
2003-03-07 13:58:33 +00:00
|
|
|
// Returns NULL if service doesn't exist - calling function should check for this.
|
2005-10-25 13:49:55 +00:00
|
|
|
FGATC* GetATCPointer(const string& icao, const atc_type& type);
|
2002-12-04 20:07:12 +00:00
|
|
|
|
2003-02-18 10:44:01 +00:00
|
|
|
// Return a pointer to an appropriate voice for a given type of ATC
|
|
|
|
// creating the voice if necessary - ie. make sure exactly one copy
|
|
|
|
// of every voice in use exists in memory.
|
|
|
|
//
|
|
|
|
// TODO - in the future this will get more complex and dole out country/airport
|
|
|
|
// specific voices, and possible make sure that the same voice doesn't get used
|
|
|
|
// at different airports in quick succession if a large enough selection are available.
|
2005-10-25 13:49:55 +00:00
|
|
|
FGATCVoice* GetVoicePointer(const atc_type& type);
|
2003-02-18 10:44:01 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
atc_type GetComm1ATCType() { return(comm_type[0]); }
|
|
|
|
FGATC* GetComm1ATCPointer() { return(comm_atc_ptr[0]); }
|
|
|
|
atc_type GetComm2ATCType() { return(comm_type[1]); }
|
|
|
|
FGATC* GetComm2ATCPointer() { return(comm_atc_ptr[1]); }
|
2002-12-17 17:19:14 +00:00
|
|
|
|
2003-03-07 13:58:33 +00:00
|
|
|
// Get the frequency of a given service at a given airport
|
|
|
|
// Returns zero if not found
|
2005-10-25 13:49:55 +00:00
|
|
|
unsigned short int GetFrequency(const string& ident, const atc_type& tp);
|
2003-03-07 13:58:33 +00:00
|
|
|
|
|
|
|
// Register the fact that the AI system wants to activate an airport
|
2005-10-25 13:49:55 +00:00
|
|
|
bool AIRegisterAirport(const string& ident);
|
2003-03-07 13:58:33 +00:00
|
|
|
|
|
|
|
// Register the fact that the comm radio is tuned to an airport
|
2005-10-25 13:49:55 +00:00
|
|
|
bool CommRegisterAirport(const string& ident, int chan, const atc_type& tp);
|
2003-03-07 13:58:33 +00:00
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
// Remove a class from the atc_list and delete it from memory
|
2003-02-06 10:42:43 +00:00
|
|
|
// *if* no other comm channel or AI plane is using it.
|
2005-10-25 13:49:55 +00:00
|
|
|
void CommRemoveFromList(const string& id, const atc_type& tp, int chan);
|
2003-02-06 10:42:43 +00:00
|
|
|
|
|
|
|
// Remove a class from the atc_list and delete it from memory
|
|
|
|
// Should be called from the above - not directly!!
|
2005-10-25 13:49:55 +00:00
|
|
|
void RemoveFromList(const string& id, const atc_type& tp);
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
// Return a pointer to a class in the list given ICAO code and type
|
|
|
|
// (external interface to this is through GetATCPointer)
|
|
|
|
// Return NULL if the given service is not in the list
|
|
|
|
// - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
|
2005-10-25 13:49:55 +00:00
|
|
|
FGATC* FindInList(const string& id, const atc_type& tp);
|
2002-10-02 15:27:49 +00:00
|
|
|
|
2003-01-07 13:11:00 +00:00
|
|
|
// Search the specified channel for stations on the same frequency and in range.
|
2003-02-06 10:42:43 +00:00
|
|
|
void FreqSearch(int channel);
|
|
|
|
|
|
|
|
// Search ATC stations by area in order that we appear 'on the radar'
|
|
|
|
void AreaSearch();
|
2002-03-01 17:39:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-03-03 22:47:06 +00:00
|
|
|
#endif // _FG_ATCMGR_HXX
|