2002-03-01 17:39:52 +00:00
|
|
|
// ATCmgr.cxx - Implementation of FGATCMgr - a global Flightgear ATC manager.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
//#include <Time/event.hxx>
|
|
|
|
|
2002-12-04 20:07:12 +00:00
|
|
|
#include <simgear/misc/sg_path.hxx>
|
2002-12-17 17:19:14 +00:00
|
|
|
#include <simgear/misc/commands.hxx>
|
2002-12-04 20:07:12 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
#include "ATCmgr.hxx"
|
2003-02-06 10:42:43 +00:00
|
|
|
#include "commlist.hxx"
|
|
|
|
//#include "atislist.hxx"
|
2002-04-03 23:54:44 +00:00
|
|
|
//#include "groundlist.hxx"
|
2003-02-06 10:42:43 +00:00
|
|
|
//#include "towerlist.hxx"
|
|
|
|
//#include "approachlist.hxx"
|
2002-12-04 20:07:12 +00:00
|
|
|
#include "ATCdisplay.hxx"
|
2002-03-01 17:39:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
// periodic radio station search wrapper
|
|
|
|
static void fgATCSearch( void ) {
|
2002-12-04 20:07:12 +00:00
|
|
|
globals->get_ATC_mgr()->Search();
|
2002-03-01 17:39:52 +00:00
|
|
|
}
|
|
|
|
*/ //This wouldn't compile - including Time/event.hxx breaks it :-(
|
|
|
|
|
2002-12-17 17:19:14 +00:00
|
|
|
static char* t0 = "Request landing clearance";
|
|
|
|
static char* t1 = "Request departure clearance";
|
|
|
|
static char* t2 = "Report Runway vacated";
|
|
|
|
static char** towerOptions = new char*[4];
|
|
|
|
static char* a0 = "Request vectors";
|
|
|
|
static char** approachOptions = new char*[2];
|
|
|
|
|
|
|
|
// For the ATC dialog - copied from the Autopilot new heading dialog code!
|
|
|
|
static puDialogBox* atcDialog;
|
|
|
|
static puFrame* atcDialogFrame;
|
|
|
|
static puText* atcDialogMessage;
|
|
|
|
//static puInput* atcDialogInput;
|
|
|
|
static puOneShot* atcDialogOkButton;
|
|
|
|
static puOneShot* atcDialogCancelButton;
|
|
|
|
static puButtonBox* atcDialogCommunicationOptions;
|
|
|
|
|
|
|
|
static void ATCDialogCancel(puObject *)
|
|
|
|
{
|
|
|
|
//ATCDialogInput->rejectInput();
|
|
|
|
FG_POP_PUI_DIALOG( atcDialog );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ATCDialogOK (puObject *me)
|
|
|
|
{
|
2003-01-07 13:11:00 +00:00
|
|
|
// Note that currently the dialog is hardwired to comm1 only here.
|
|
|
|
switch(globals->get_ATC_mgr()->GetComm1ATCType()) {
|
2002-12-17 17:19:14 +00:00
|
|
|
case INVALID:
|
|
|
|
break;
|
|
|
|
case ATIS:
|
|
|
|
break;
|
|
|
|
case TOWER: {
|
2003-01-07 13:11:00 +00:00
|
|
|
FGTower* twr = (FGTower*)globals->get_ATC_mgr()->GetComm1ATCPointer();
|
2002-12-17 17:19:14 +00:00
|
|
|
switch(atcDialogCommunicationOptions->getValue()) {
|
|
|
|
case 0:
|
2003-01-19 21:31:37 +00:00
|
|
|
//cout << "Option 0 chosen\n";
|
2002-12-17 17:19:14 +00:00
|
|
|
twr->RequestLandingClearance("golf bravo echo");
|
|
|
|
break;
|
|
|
|
case 1:
|
2003-01-19 21:31:37 +00:00
|
|
|
//cout << "Option 1 chosen\n";
|
2002-12-17 17:19:14 +00:00
|
|
|
twr->RequestDepartureClearance("golf bravo echo");
|
|
|
|
break;
|
|
|
|
case 2:
|
2003-01-19 21:31:37 +00:00
|
|
|
//cout << "Option 2 chosen\n";
|
2002-12-17 17:19:14 +00:00
|
|
|
twr->ReportRunwayVacated("golf bravo echo");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GROUND:
|
|
|
|
break;
|
|
|
|
case APPROACH:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ATCDialogCancel(me);
|
|
|
|
//if(error) mkDialog(s.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ATCDialog(puObject *cb)
|
|
|
|
{
|
|
|
|
//ApHeadingDialogInput -> setValue ( heading );
|
|
|
|
//ApHeadingDialogInput -> acceptInput();
|
|
|
|
FG_PUSH_PUI_DIALOG(atcDialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ATCDialogInit()
|
|
|
|
{
|
|
|
|
char defaultATCLabel[] = "Enter desired option to communicate with ATC:";
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
// Option lists hardwired per ATC type
|
2003-01-19 21:31:37 +00:00
|
|
|
towerOptions[0] = new char[strlen(t0)+1];
|
2002-12-17 17:19:14 +00:00
|
|
|
strcpy(towerOptions[0], t0);
|
2003-01-19 21:31:37 +00:00
|
|
|
towerOptions[1] = new char[strlen(t1)+1];
|
2002-12-17 17:19:14 +00:00
|
|
|
strcpy(towerOptions[1], t1);
|
2003-01-19 21:31:37 +00:00
|
|
|
towerOptions[2] = new char[strlen(t2)+1];
|
2002-12-17 17:19:14 +00:00
|
|
|
strcpy(towerOptions[2], t2);
|
|
|
|
towerOptions[3] = NULL;
|
|
|
|
|
2003-01-19 21:31:37 +00:00
|
|
|
approachOptions[0] = new char[strlen(a0)+1];
|
2002-12-17 17:19:14 +00:00
|
|
|
strcpy(approachOptions[0], a0);
|
|
|
|
approachOptions[1] = NULL;
|
|
|
|
|
|
|
|
atcDialog = new puDialogBox (150, 50);
|
|
|
|
{
|
|
|
|
atcDialogFrame = new puFrame (0, 0, 500, 250);
|
|
|
|
|
|
|
|
atcDialogMessage = new puText (250, 220);
|
|
|
|
atcDialogMessage -> setDefaultValue (defaultATCLabel);
|
|
|
|
atcDialogMessage -> getDefaultValue (&s);
|
|
|
|
atcDialogMessage -> setLabel (s);
|
|
|
|
atcDialogMessage -> setLabelPlace (PUPLACE_TOP_CENTERED);
|
|
|
|
|
|
|
|
atcDialogCommunicationOptions = new puButtonBox (50, 50, 450, 210, NULL, true);
|
|
|
|
|
|
|
|
atcDialogOkButton = new puOneShot (50, 10, 110, 50);
|
|
|
|
atcDialogOkButton -> setLegend (gui_msg_OK);
|
|
|
|
atcDialogOkButton -> makeReturnDefault (TRUE);
|
|
|
|
atcDialogOkButton -> setCallback (ATCDialogOK);
|
|
|
|
|
|
|
|
atcDialogCancelButton = new puOneShot (140, 10, 210, 50);
|
|
|
|
atcDialogCancelButton -> setLegend (gui_msg_CANCEL);
|
|
|
|
atcDialogCancelButton -> setCallback (ATCDialogCancel);
|
|
|
|
|
|
|
|
}
|
|
|
|
FG_FINALIZE_PUI_DIALOG(atcDialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For the command manager - maybe eventually this should go in the built in command list
|
|
|
|
static bool do_ATC_dialog(const SGPropertyNode* arg) {
|
|
|
|
globals->get_ATC_mgr()->doStandardDialog();
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
FGATCMgr::FGATCMgr() {
|
2003-02-06 10:42:43 +00:00
|
|
|
comm_ident[0] = "";
|
|
|
|
comm_ident[1] = "";
|
|
|
|
last_comm_ident[0] = "";
|
|
|
|
last_comm_ident[1] = "";
|
2002-12-04 20:07:12 +00:00
|
|
|
approach_ident = "";
|
|
|
|
last_in_range = false;
|
2003-02-06 10:42:43 +00:00
|
|
|
comm_type[0] = INVALID;
|
|
|
|
comm_type[1] = INVALID;
|
|
|
|
comm_atc_ptr[0] = NULL;
|
|
|
|
comm_atc_ptr[1] = NULL;
|
2002-03-01 17:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FGATCMgr::~FGATCMgr() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGATCMgr::bind() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGATCMgr::unbind() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGATCMgr::init() {
|
2003-02-06 10:42:43 +00:00
|
|
|
comm_node[0] = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
|
|
|
|
comm_node[1] = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
|
2002-12-04 20:07:12 +00:00
|
|
|
lon_node = fgGetNode("/position/longitude-deg", true);
|
|
|
|
lat_node = fgGetNode("/position/latitude-deg", true);
|
|
|
|
elev_node = fgGetNode("/position/altitude-ft", true);
|
|
|
|
atc_list_itr = atc_list.begin();
|
|
|
|
// Search for connected ATC stations once per 0.8 seconds or so
|
|
|
|
// global_events.Register( "fgATCSearch()", fgATCSearch,
|
|
|
|
// fgEVENT::FG_EVENT_READY, 800);
|
|
|
|
// For some reason the above doesn't compile - including Time/event.hxx stops compilation.
|
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
// Initialise the frequency search map
|
|
|
|
current_commlist = new FGCommList;
|
|
|
|
SGPath p_comm( globals->get_fg_root() );
|
|
|
|
current_commlist->init( p_comm );
|
|
|
|
|
2002-12-04 20:07:12 +00:00
|
|
|
// Initialise the airport_atc_map - we'll cheat for now and just hardcode KEMT and any others that may be needed for development
|
|
|
|
AirportATC *a = new AirportATC;
|
|
|
|
a->lon = -118.034719;
|
|
|
|
a->lat = 34.086114;
|
|
|
|
a->elev = 296.0;
|
|
|
|
a->atis_freq = 118.75;
|
|
|
|
a->atis_active = false;
|
|
|
|
a->tower_freq = 121.2;
|
|
|
|
a->tower_active = false;
|
|
|
|
a->ground_freq = 125.9;
|
|
|
|
a->ground_active = false;
|
|
|
|
|
|
|
|
//a->set_by_AI = true;
|
|
|
|
//a->set_by_comm_search = false;
|
|
|
|
|
|
|
|
airport_atc_map[(string)"KEMT"] = a;
|
|
|
|
|
|
|
|
#ifdef ENABLE_AUDIO_SUPPORT
|
|
|
|
// Load all available voices.
|
|
|
|
// For now we'll do one hardwired one
|
|
|
|
voiceOK = v1.LoadVoice("default");
|
|
|
|
/* I've loaded the voice even if /sim/sound/audible is false
|
|
|
|
* since I know no way of forcing load of the voice if the user
|
|
|
|
* subsequently switches /sim/sound/audible to true. */
|
|
|
|
#else
|
|
|
|
voice = false;
|
|
|
|
#endif
|
2002-12-17 17:19:14 +00:00
|
|
|
|
|
|
|
// Initialise the ATC Dialogs
|
|
|
|
ATCDialogInit();
|
|
|
|
|
|
|
|
// Add ATC-dialog to the command list
|
|
|
|
globals->get_commands()->addCommand("ATC-dialog", do_ATC_dialog);
|
2002-03-01 17:39:52 +00:00
|
|
|
}
|
|
|
|
|
2002-05-11 16:28:50 +00:00
|
|
|
void FGATCMgr::update(double dt) {
|
2003-02-06 10:42:43 +00:00
|
|
|
//cout << "Entering update..." << endl;
|
2002-12-04 20:07:12 +00:00
|
|
|
//Traverse the list of active stations.
|
|
|
|
//Only update one class per update step to avoid the whole ATC system having to calculate between frames.
|
|
|
|
//Eventually we should only update every so many steps.
|
|
|
|
//cout << "In FGATCMgr::update - atc_list.size = " << atc_list.size() << '\n';
|
|
|
|
if(atc_list.size()) {
|
|
|
|
if(atc_list_itr == atc_list.end()) {
|
|
|
|
atc_list_itr = atc_list.begin();
|
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
//cout << "Updating " << (*atc_list_itr)->get_ident() << ' ' << (*atc_list_itr)->GetType() << '\n';
|
|
|
|
//cout << "Freq = " << (*atc_list_itr)->get_freq() << '\n';
|
2002-12-04 20:07:12 +00:00
|
|
|
(*atc_list_itr)->Update();
|
2003-02-06 10:42:43 +00:00
|
|
|
//cout << "Done ATC update..." << endl;
|
2002-12-04 20:07:12 +00:00
|
|
|
++atc_list_itr;
|
2002-03-01 17:39:52 +00:00
|
|
|
}
|
2002-12-04 20:07:12 +00:00
|
|
|
|
|
|
|
// Search the tuned frequencies every now and then - this should be done with the event scheduler
|
|
|
|
static int i = 0;
|
2003-02-06 10:42:43 +00:00
|
|
|
if(i == 7) {
|
|
|
|
AreaSearch();
|
|
|
|
}
|
2003-01-07 13:11:00 +00:00
|
|
|
if(i == 15) {
|
2003-02-06 10:42:43 +00:00
|
|
|
//cout << "About to search(1)" << endl;
|
|
|
|
FreqSearch(1);
|
2003-01-07 13:11:00 +00:00
|
|
|
}
|
2002-12-04 20:07:12 +00:00
|
|
|
if(i == 30) {
|
2003-02-06 10:42:43 +00:00
|
|
|
//cout << "About to search(2)" << endl;
|
|
|
|
FreqSearch(2);
|
2002-12-04 20:07:12 +00:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
++i;
|
2002-03-01 17:39:52 +00:00
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
|
|
|
|
// Remove from list only if not needed by the AI system or the other comm channel
|
|
|
|
// TODO - implement me!!
|
|
|
|
void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp, int chan) {
|
|
|
|
/*AirportATC a;
|
2002-12-04 20:07:12 +00:00
|
|
|
if(GetAirportATCDetails((string)id, &a)) {
|
|
|
|
if(a.set_by_AI) {
|
|
|
|
// Don't remove
|
|
|
|
a.set_by_comm_search = false;
|
|
|
|
airport_atc_map[(string)id] = a;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// remove
|
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
// Hack - need to implement this properly
|
|
|
|
RemoveFromList(id, tp);
|
2002-12-04 20:07:12 +00:00
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
// Remove from list - should only be called from above or similar
|
2003-02-06 10:42:43 +00:00
|
|
|
// This function *will* remove it from the list regardless of who else might want it.
|
2002-03-01 17:39:52 +00:00
|
|
|
void FGATCMgr::RemoveFromList(const char* id, atc_type tp) {
|
2002-12-04 20:07:12 +00:00
|
|
|
//cout << "Requested type = " << tp << '\n';
|
|
|
|
//cout << "id = " << id << '\n';
|
|
|
|
atc_list_itr = atc_list.begin();
|
|
|
|
while(atc_list_itr != atc_list.end()) {
|
|
|
|
//cout << "type = " << (*atc_list_itr)->GetType() << '\n';
|
2003-02-06 10:42:43 +00:00
|
|
|
//cout << "Ident = " << (*atc_list_itr)->get_ident() << '\n';
|
|
|
|
if( (!strcmp((*atc_list_itr)->get_ident(), id))
|
2002-12-04 20:07:12 +00:00
|
|
|
&& ((*atc_list_itr)->GetType() == tp) ) {
|
|
|
|
//Before removing it stop it transmitting!!
|
|
|
|
//cout << "OBLITERATING FROM LIST!!!\n";
|
|
|
|
(*atc_list_itr)->SetNoDisplay();
|
|
|
|
(*atc_list_itr)->Update();
|
|
|
|
delete (*atc_list_itr);
|
|
|
|
atc_list_itr = atc_list.erase(atc_list_itr);
|
|
|
|
break;
|
|
|
|
} // Note that that can upset where we are in the list but that doesn't really matter
|
|
|
|
++atc_list_itr;
|
|
|
|
}
|
2002-03-01 17:39:52 +00:00
|
|
|
}
|
|
|
|
|
2002-12-04 20:07:12 +00:00
|
|
|
|
2002-10-02 15:27:49 +00:00
|
|
|
// Find in list - return a currently active ATC pointer given ICAO code and type
|
2003-02-06 10:42:43 +00:00
|
|
|
// Return NULL if the given service is not in the list
|
|
|
|
// - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
|
2002-10-02 15:27:49 +00:00
|
|
|
FGATC* FGATCMgr::FindInList(const char* id, atc_type tp) {
|
2002-12-04 20:07:12 +00:00
|
|
|
atc_list_itr = atc_list.begin();
|
|
|
|
while(atc_list_itr != atc_list.end()) {
|
2003-02-06 10:42:43 +00:00
|
|
|
if( (!strcmp((*atc_list_itr)->get_ident(), id))
|
2003-01-07 13:11:00 +00:00
|
|
|
&& ((*atc_list_itr)->GetType() == tp) ) {
|
|
|
|
return(*atc_list_itr);
|
|
|
|
} // Note that that can upset where we are in the list but that shouldn't really matter
|
2002-12-04 20:07:12 +00:00
|
|
|
++atc_list_itr;
|
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
// If we get here it's not in the list
|
2002-12-04 20:07:12 +00:00
|
|
|
return(NULL);
|
2002-10-02 15:27:49 +00:00
|
|
|
}
|
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
// Returns true if the airport is found in the map
|
|
|
|
bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
|
2002-12-04 20:07:12 +00:00
|
|
|
if(airport_atc_map.find(icao) != airport_atc_map.end()) {
|
|
|
|
*a = *airport_atc_map[icao];
|
|
|
|
return(true);
|
|
|
|
} else {
|
|
|
|
return(false);
|
|
|
|
}
|
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
|
|
|
|
// ONLY CALL THIS FUNCTION AFTER FIRST CHECKING THE SERVICE EXISTS BY CALLING GetAirportATCDetails
|
2002-12-04 20:07:12 +00:00
|
|
|
// FIXME - we really ought to take out the necessity for two function calls by simply returning
|
|
|
|
// a NULL pointer if the service doesn't exist and requiring the caller to check for it (NULL).
|
2002-04-03 23:54:44 +00:00
|
|
|
FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
|
2002-12-04 20:07:12 +00:00
|
|
|
AirportATC *a = airport_atc_map[icao];
|
|
|
|
//cout << "a->lon = " << a->lon << '\n';
|
|
|
|
//cout << "a->elev = " << a->elev << '\n';
|
|
|
|
//cout << "a->tower_freq = " << a->tower_freq << '\n';
|
|
|
|
switch(type) {
|
|
|
|
case TOWER:
|
|
|
|
if(a->tower_active) {
|
|
|
|
// Get the pointer from the list
|
|
|
|
return(FindInList(icao.c_str(), type)); // DCL - this untested so far.
|
|
|
|
} else {
|
|
|
|
FGTower* t = new FGTower;
|
2003-02-06 10:42:43 +00:00
|
|
|
ATCData data;
|
|
|
|
if(current_commlist->FindByFreq(a->lon, a->lat, a->elev, a->tower_freq, &data, TOWER)) {
|
|
|
|
t->SetData(&data);
|
2002-12-04 20:07:12 +00:00
|
|
|
atc_list.push_back(t);
|
|
|
|
a->tower_active = true;
|
|
|
|
airport_atc_map[icao] = a;
|
|
|
|
return(t);
|
|
|
|
} else {
|
|
|
|
cout << "ERROR - tower that should exist in FGATCMgr::GetATCPointer for airport " << icao << " not found\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// Lets add the rest to get rid of the compiler warnings even though we don't need them yet.
|
|
|
|
case APPROACH:
|
|
|
|
break;
|
|
|
|
case ATIS:
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR - ATIS station should not be requested from FGATCMgr::GetATCPointer");
|
|
|
|
break;
|
|
|
|
case GROUND:
|
|
|
|
break;
|
|
|
|
case INVALID:
|
|
|
|
break;
|
|
|
|
case ENROUTE:
|
|
|
|
break;
|
|
|
|
case DEPARTURE:
|
|
|
|
break;
|
2002-04-03 23:54:44 +00:00
|
|
|
}
|
2002-12-04 20:07:12 +00:00
|
|
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR IN FGATCMgr - reached end of GetATCPointer");
|
|
|
|
|
|
|
|
return(NULL);
|
2002-04-03 23:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-04 20:07:12 +00:00
|
|
|
// Render a transmission
|
|
|
|
// Outputs the transmission either on screen or as audio depending on user preference
|
2003-01-07 13:11:00 +00:00
|
|
|
// The refname is a string to identify this sample to the sound manager
|
2002-12-04 20:07:12 +00:00
|
|
|
// The repeating flag indicates whether the message should be repeated continuously or played once.
|
2003-01-07 13:11:00 +00:00
|
|
|
void FGATCMgr::Render(string msg, string refname, bool repeating) {
|
2002-12-04 20:07:12 +00:00
|
|
|
#ifdef ENABLE_AUDIO_SUPPORT
|
2003-02-06 16:17:03 +00:00
|
|
|
voice = (voiceOK && fgGetBool("/sim/sound/audible")
|
|
|
|
&& fgGetBool("/sim/sound/voice"));
|
2002-12-04 20:07:12 +00:00
|
|
|
if(voice) {
|
|
|
|
int len;
|
|
|
|
unsigned char* buf = v1.WriteMessage((char*)msg.c_str(), len, voice);
|
|
|
|
if(voice) {
|
|
|
|
FGSimpleSound* simple = new FGSimpleSound(buf, len);
|
2003-02-06 10:42:43 +00:00
|
|
|
// TODO - at the moment the volume is always set off comm1
|
|
|
|
// and can't be changed after the transmission has started.
|
|
|
|
simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume"));
|
2002-12-04 20:07:12 +00:00
|
|
|
globals->get_soundmgr()->add(simple, refname);
|
|
|
|
if(repeating) {
|
|
|
|
globals->get_soundmgr()->play_looped(refname);
|
|
|
|
} else {
|
|
|
|
globals->get_soundmgr()->play_once(refname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] buf;
|
|
|
|
}
|
|
|
|
#endif // ENABLE_AUDIO_SUPPORT
|
|
|
|
if(!voice) {
|
|
|
|
// first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
|
|
|
|
for(unsigned int i = 0; i < msg.length(); ++i) {
|
|
|
|
if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
|
|
|
|
msg[i] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
globals->get_ATC_display()->RegisterRepeatingMessage(msg);
|
|
|
|
}
|
|
|
|
playing = true;
|
|
|
|
}
|
2002-04-03 23:54:44 +00:00
|
|
|
|
|
|
|
|
2002-12-04 20:07:12 +00:00
|
|
|
// Cease rendering a transmission.
|
2003-01-07 13:11:00 +00:00
|
|
|
void FGATCMgr::NoRender(string refname) {
|
2002-12-04 20:07:12 +00:00
|
|
|
if(playing) {
|
|
|
|
if(voice) {
|
|
|
|
#ifdef ENABLE_AUDIO_SUPPORT
|
|
|
|
globals->get_soundmgr()->stop(refname);
|
|
|
|
globals->get_soundmgr()->remove(refname);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
globals->get_ATC_display()->CancelRepeatingMessage();
|
|
|
|
}
|
|
|
|
playing = false;
|
2002-04-03 23:54:44 +00:00
|
|
|
}
|
2002-12-04 20:07:12 +00:00
|
|
|
}
|
2002-04-03 23:54:44 +00:00
|
|
|
|
2002-12-17 17:19:14 +00:00
|
|
|
|
|
|
|
// Display a dialog box with options relevant to the currently tuned ATC service.
|
|
|
|
void FGATCMgr::doStandardDialog() {
|
|
|
|
/* DCL 2002/12/06 - This function currently in development
|
|
|
|
and dosen't display anything usefull to the end-user */
|
|
|
|
//cout << "FGATCMgr::doStandardDialog called..." << endl;
|
|
|
|
|
|
|
|
// First - need to determine which ATC service (if any) the user is tuned to.
|
|
|
|
//cout << "comm1_type = " << comm1_type << endl;
|
|
|
|
|
|
|
|
// Second - customise the dialog box
|
2003-02-06 10:42:43 +00:00
|
|
|
switch(comm_type[0]) {
|
2002-12-17 17:19:14 +00:00
|
|
|
case INVALID:
|
|
|
|
atcDialogCommunicationOptions->newList(NULL);
|
|
|
|
atcDialogMessage->setLabel("Not tuned in to any ATC service.");
|
|
|
|
break;
|
|
|
|
case ATIS:
|
|
|
|
atcDialogCommunicationOptions->newList(NULL);
|
|
|
|
atcDialogMessage->setLabel("Tuned in to ATIS: no communication possible.");
|
|
|
|
break;
|
|
|
|
case TOWER:
|
|
|
|
atcDialogCommunicationOptions->newList(towerOptions);
|
|
|
|
atcDialogMessage->setLabel("Tuned in to Tower - select communication to transmit:");
|
|
|
|
break;
|
|
|
|
case GROUND:
|
|
|
|
atcDialogCommunicationOptions->newList(NULL);
|
|
|
|
atcDialogMessage->setLabel("Tuned in to Ground - select communication to transmit:");
|
|
|
|
break;
|
|
|
|
case APPROACH:
|
|
|
|
atcDialogCommunicationOptions->newList(approachOptions);
|
|
|
|
atcDialogMessage->setLabel("Tuned in to Approach - select communication to transmit:");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
atcDialogCommunicationOptions->newList(NULL);
|
|
|
|
atcDialogMessage->setLabel("Tuned in to unknown ATC service - enter transmission:");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Third - display the dialog without pausing sim.
|
|
|
|
ATCDialog(NULL);
|
|
|
|
|
|
|
|
// Forth - need to direct input back from the dialog to the relevant ATC service.
|
|
|
|
// This is in ATCDialogOK()
|
|
|
|
}
|
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
// Search for ATC stations by frequency
|
|
|
|
void FGATCMgr::FreqSearch(int channel) {
|
|
|
|
int chan = channel - 1; // Convert to zero-based for the arrays
|
|
|
|
|
|
|
|
ATCData data;
|
|
|
|
double freq = comm_node[chan]->getDoubleValue();
|
|
|
|
lon = lon_node->getDoubleValue();
|
|
|
|
lat = lat_node->getDoubleValue();
|
|
|
|
elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
|
2002-12-04 20:07:12 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
// Query the data store and get the closest match if any
|
|
|
|
if(current_commlist->FindByFreq(lon, lat, elev, freq, &data)) {
|
|
|
|
// We have a match
|
|
|
|
// What's the logic?
|
|
|
|
// If this channel not previously valid then easy - add ATC to list
|
|
|
|
// If this channel was valid then - Have we tuned to a different service?
|
|
|
|
// If so - de-register one and add the other
|
|
|
|
if(comm_valid[chan]) {
|
|
|
|
if((comm_ident[chan] == data.ident) && (comm_type[chan] == data.type)) {
|
|
|
|
// Then we're still tuned into the same service so do nought and return
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Something's changed - either the location or the service type
|
|
|
|
// We need to feed the channel in so we're not removing it if we're also tuned in on the other channel
|
|
|
|
CommRemoveFromList(comm_ident[chan], comm_type[chan], chan);
|
2002-12-04 20:07:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
// At this point we can assume that we need to add the service.
|
|
|
|
comm_ident[chan] = (data.ident).c_str();
|
|
|
|
comm_type[chan] = data.type;
|
|
|
|
comm_x[chan] = (double)data.x;
|
|
|
|
comm_y[chan] = (double)data.y;
|
|
|
|
comm_z[chan] = (double)data.z;
|
|
|
|
comm_lon[chan] = (double)data.lon;
|
|
|
|
comm_lat[chan] = (double)data.lat;
|
|
|
|
comm_elev[chan] = (double)data.elev;
|
|
|
|
comm_valid[chan] = true;
|
2003-01-07 13:11:00 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
// This was a switch-case statement but the compiler didn't like the new variable creation with it.
|
|
|
|
if(comm_type[chan] == ATIS) {
|
|
|
|
FGATIS* a = new FGATIS;
|
|
|
|
a->SetData(&data);
|
|
|
|
comm_atc_ptr[chan] = a;
|
|
|
|
a->SetDisplay();
|
|
|
|
//a->set_refname((chan) ? "atis2" : "atis1"); // FIXME - that line is limited to 2 channels
|
|
|
|
atc_list.push_back(a);
|
|
|
|
} else if (comm_type[chan] == TOWER) {
|
|
|
|
FGATC* app = FindInList(comm_ident[chan], TOWER);
|
|
|
|
if(app != NULL) {
|
|
|
|
// The station is already in the ATC list
|
|
|
|
app->SetDisplay();
|
|
|
|
} else {
|
|
|
|
// Generate the station and put in the ATC list
|
2003-01-07 13:11:00 +00:00
|
|
|
FGTower* t = new FGTower;
|
2003-02-06 10:42:43 +00:00
|
|
|
t->SetData(&data);
|
|
|
|
comm_atc_ptr[chan] = t;
|
2003-01-07 13:11:00 +00:00
|
|
|
t->SetDisplay();
|
|
|
|
atc_list.push_back(t);
|
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
} /*else if (comm_type[chan] == APPROACH) {
|
|
|
|
// We have to be a bit more carefull here since approaches are also searched by area
|
|
|
|
FGATC* app = FindInList(comm_ident[chan], APPROACH);
|
|
|
|
if(app != NULL) {
|
|
|
|
// The station is already in the ATC list
|
|
|
|
app->AddPlane("Player");
|
|
|
|
app->SetDisplay();
|
|
|
|
} else {
|
|
|
|
// Generate the station and put in the ATC list
|
|
|
|
FGApproach* a = new FGApproach;
|
|
|
|
a->SetData(&data);
|
|
|
|
a->AddPlane("Player");
|
|
|
|
atc_list.push_back(a);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
} else {
|
|
|
|
if(comm_valid[chan]) {
|
|
|
|
if(comm_type[chan] != APPROACH) {
|
|
|
|
// Currently approaches are removed by Alexander's out-of-range mechanism
|
|
|
|
CommRemoveFromList(comm_ident[chan], comm_type[chan], chan);
|
2003-01-07 13:11:00 +00:00
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
// Note that we *don't* call SetNoDisplay() here because the other comm channel
|
|
|
|
// might be tuned into the same station - this is handled by CommRemoveFromList(...)
|
|
|
|
comm_type[chan] = INVALID;
|
|
|
|
comm_atc_ptr[chan] = NULL;
|
|
|
|
comm_valid[chan] = false;
|
2002-12-04 20:07:12 +00:00
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Search ATC stations by area in order that we appear 'on the radar'
|
|
|
|
void FGATCMgr::AreaSearch() {
|
|
|
|
// Search for Approach stations
|
|
|
|
comm_list_type approaches;
|
|
|
|
comm_list_iterator app_itr;
|
|
|
|
|
|
|
|
lon = lon_node->getDoubleValue();
|
|
|
|
lat = lat_node->getDoubleValue();
|
|
|
|
elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
|
|
|
|
|
|
|
|
// search stations in range
|
|
|
|
int num_app = current_commlist->FindByPos(lon, lat, elev, &approaches, APPROACH);
|
|
|
|
if (num_app != 0) {
|
|
|
|
//cout << num_app << " approaches found in radiostack search !!!!" << endl;
|
2002-12-04 20:07:12 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
for(app_itr = approaches.begin(); app_itr != approaches.end(); app_itr++) {
|
2002-12-04 20:07:12 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
FGATC* app = FindInList((app_itr->ident).c_str(), app_itr->type);
|
|
|
|
if(app != NULL) {
|
|
|
|
// The station is already in the ATC list
|
|
|
|
app->AddPlane("Player");
|
|
|
|
//app->Update();
|
|
|
|
} else {
|
|
|
|
// Generate the station and put in the ATC list
|
|
|
|
FGApproach* a = new FGApproach;
|
|
|
|
a->SetData(&(*app_itr));
|
|
|
|
a->AddPlane("Player");
|
|
|
|
//a->Update();
|
2002-12-04 20:07:12 +00:00
|
|
|
atc_list.push_back(a);
|
|
|
|
}
|
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove planes which are out of range
|
|
|
|
// TODO - I'm not entirely sure that this belongs here.
|
|
|
|
atc_list_itr = atc_list.begin();
|
|
|
|
while(atc_list_itr != atc_list.end()) {
|
|
|
|
if((*atc_list_itr)->GetType() == APPROACH ) {
|
|
|
|
int np = (*atc_list_itr)->RemovePlane();
|
|
|
|
// if approach has no planes left remove it from ATC list
|
|
|
|
if ( np == 0) {
|
|
|
|
(*atc_list_itr)->SetNoDisplay();
|
|
|
|
(*atc_list_itr)->Update();
|
|
|
|
delete (*atc_list_itr);
|
|
|
|
atc_list_itr = atc_list.erase(atc_list_itr);
|
|
|
|
break; // the other stations will be checked next time
|
2002-12-04 20:07:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-06 10:42:43 +00:00
|
|
|
++atc_list_itr;
|
2002-04-03 23:54:44 +00:00
|
|
|
}
|
2002-03-13 14:17:59 +00:00
|
|
|
}
|