1 // ATCmgr.cxx - Implementation of FGATCMgr - a global Flightgear ATC manager.
3 // Written by David Luff, started February 2002.
5 // Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //#include <Time/event.hxx>
24 #include "atislist.hxx"
27 // periodic radio station search wrapper
28 static void fgATCSearch( void ) {
29 globals->get_ATC_mgr()->Search();
31 */ //This wouldn't compile - including Time/event.hxx breaks it :-(
33 FGATCMgr::FGATCMgr() {
36 FGATCMgr::~FGATCMgr() {
39 void FGATCMgr::bind() {
42 void FGATCMgr::unbind() {
45 void FGATCMgr::init() {
46 comm1_node = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
47 comm2_node = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
48 lon_node = fgGetNode("/position/longitude-deg", true);
49 lat_node = fgGetNode("/position/latitude-deg", true);
50 elev_node = fgGetNode("/position/altitude-ft", true);
51 atc_list_itr = atc_list.begin();
52 // Search for connected ATC stations once per 0.8 seconds or so
53 // global_events.Register( "fgATCSearch()", fgATCSearch,
54 // fgEVENT::FG_EVENT_READY, 800);
55 // For some reason the above doesn't compile - including Time/event.hxx stops compilation.
58 void FGATCMgr::update(int dt) {
59 //Traverse the list of active stations.
60 //Only update one class per update step to avoid the whole ATC system having to calculate between frames.
61 //Eventually we should only update every so many steps.
63 if(atc_list_itr == atc_list.end()) {
64 atc_list_itr = atc_list.begin();
66 (*atc_list_itr)->Update();
70 // Search the tuned frequencies every now and then - this should be done with the event scheduler
79 void FGATCMgr::RemoveFromList(const char* id, atc_type tp) {
80 atc_list_itr = atc_list.begin();
81 while(atc_list_itr != atc_list.end()) {
82 if( (!strcmp((*atc_list_itr)->GetIdent(), id))
83 && ((*atc_list_itr)->GetType() == tp) ) {
84 //Before removing it stop it transmitting!!
85 (*atc_list_itr)->SetNoDisplay();
86 (*atc_list_itr)->Update();
87 delete (*atc_list_itr);
88 atc_list_itr = atc_list.erase(atc_list_itr);
90 } // Note that that can upset where we are in the list but that doesn't really matter
95 void FGATCMgr::Search() {
97 ////////////////////////////////////////////////////////////////////////
99 ////////////////////////////////////////////////////////////////////////
101 comm1_freq = comm1_node->getDoubleValue();
102 double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
103 double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
104 double elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
106 //Search for ATIS first
107 if(current_atislist->query(lon, lat, elev, comm1_freq, &atis)) {
108 //cout << "atis found in radiostack search !!!!" << endl;
109 comm1_ident = atis.GetIdent();
111 if(last_comm1_ident != comm1_ident) {
112 if(last_comm1_ident != "") {
113 RemoveFromList(last_comm1_ident, ATIS);
115 last_comm1_ident = comm1_ident;
116 comm1_elev = atis.get_elev();
117 comm1_range = FG_ATIS_DEFAULT_RANGE;
118 comm1_effective_range = comm1_range;
119 comm1_x = atis.get_x();
120 comm1_y = atis.get_y();
121 comm1_z = atis.get_z();
122 FGATIS* a = new FGATIS;
125 atc_list.push_back(a);
126 //cout << "Found a new atis station in range" << endl;
127 //cout << " id = " << atis.GetIdent() << endl;
131 RemoveFromList(comm1_ident, ATIS);
134 //comm1_trans_ident = "";
135 last_comm1_ident = "";
137 //cout << "not picking up atis" << endl;