Changes to support voice rendering of ATC
This commit is contained in:
parent
d3e33e8b53
commit
c65c5f3a4a
2 changed files with 439 additions and 349 deletions
src/ATC
|
@ -20,33 +20,37 @@
|
||||||
|
|
||||||
//#include <Time/event.hxx>
|
//#include <Time/event.hxx>
|
||||||
|
|
||||||
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
|
||||||
#include "ATCmgr.hxx"
|
#include "ATCmgr.hxx"
|
||||||
#include "atislist.hxx"
|
#include "atislist.hxx"
|
||||||
//#include "groundlist.hxx"
|
//#include "groundlist.hxx"
|
||||||
#include "towerlist.hxx"
|
#include "towerlist.hxx"
|
||||||
#include "approachlist.hxx"
|
#include "approachlist.hxx"
|
||||||
|
#include "ATCdisplay.hxx"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// periodic radio station search wrapper
|
// periodic radio station search wrapper
|
||||||
static void fgATCSearch( void ) {
|
static void fgATCSearch( void ) {
|
||||||
globals->get_ATC_mgr()->Search();
|
globals->get_ATC_mgr()->Search();
|
||||||
}
|
}
|
||||||
*/ //This wouldn't compile - including Time/event.hxx breaks it :-(
|
*/ //This wouldn't compile - including Time/event.hxx breaks it :-(
|
||||||
|
|
||||||
FGATCMgr::FGATCMgr() {
|
FGATCMgr::FGATCMgr() {
|
||||||
comm1_ident = "";
|
comm1_ident = "";
|
||||||
comm1_atis_ident = "";
|
comm1_atis_ident = "";
|
||||||
comm1_tower_ident = "";
|
comm1_tower_ident = "";
|
||||||
comm1_approach_ident = "";
|
comm1_approach_ident = "";
|
||||||
last_comm1_ident = "";
|
last_comm1_ident = "";
|
||||||
last_comm1_atis_ident = "";
|
last_comm1_atis_ident = "";
|
||||||
last_comm1_tower_ident = "";
|
last_comm1_tower_ident = "";
|
||||||
last_comm1_approach_ident = "";
|
last_comm1_approach_ident = "";
|
||||||
approach_ident = "";
|
approach_ident = "";
|
||||||
last_in_range = false;
|
last_in_range = false;
|
||||||
comm1_atis_valid = false;
|
comm1_atis_valid = false;
|
||||||
comm1_tower_valid = false;
|
comm1_tower_valid = false;
|
||||||
comm1_approach_valid = false;
|
comm1_approach_valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGATCMgr::~FGATCMgr() {
|
FGATCMgr::~FGATCMgr() {
|
||||||
|
@ -59,374 +63,440 @@ void FGATCMgr::unbind() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGATCMgr::init() {
|
void FGATCMgr::init() {
|
||||||
comm1_node = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
|
comm1_node = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
|
||||||
comm2_node = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
|
comm2_node = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
|
||||||
lon_node = fgGetNode("/position/longitude-deg", true);
|
lon_node = fgGetNode("/position/longitude-deg", true);
|
||||||
lat_node = fgGetNode("/position/latitude-deg", true);
|
lat_node = fgGetNode("/position/latitude-deg", true);
|
||||||
elev_node = fgGetNode("/position/altitude-ft", true);
|
elev_node = fgGetNode("/position/altitude-ft", true);
|
||||||
atc_list_itr = atc_list.begin();
|
atc_list_itr = atc_list.begin();
|
||||||
// Search for connected ATC stations once per 0.8 seconds or so
|
// Search for connected ATC stations once per 0.8 seconds or so
|
||||||
// global_events.Register( "fgATCSearch()", fgATCSearch,
|
// global_events.Register( "fgATCSearch()", fgATCSearch,
|
||||||
// fgEVENT::FG_EVENT_READY, 800);
|
// fgEVENT::FG_EVENT_READY, 800);
|
||||||
// For some reason the above doesn't compile - including Time/event.hxx stops compilation.
|
// For some reason the above doesn't compile - including Time/event.hxx stops compilation.
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
// Initialise the airport_atc_map - we'll cheat for now and just hardcode KEMT and any others that may be needed for development
|
#ifdef ENABLE_AUDIO_SUPPORT
|
||||||
AirportATC *a = new AirportATC;
|
// Load all available voices.
|
||||||
a->lon = -118.034719;
|
// For now we'll do one hardwired one
|
||||||
a->lat = 34.086114;
|
voiceOK = v1.LoadVoice("default");
|
||||||
a->elev = 296.0;
|
/* I've loaded the voice even if /sim/sound/audible is false
|
||||||
a->atis_freq = 118.75;
|
* since I know no way of forcing load of the voice if the user
|
||||||
a->atis_active = false;
|
* subsequently switches /sim/sound/audible to true. */
|
||||||
a->tower_freq = 121.2;
|
#else
|
||||||
a->tower_active = false;
|
voice = false;
|
||||||
a->ground_freq = 125.9;
|
#endif
|
||||||
a->ground_active = false;
|
|
||||||
|
|
||||||
//a->set_by_AI = true;
|
|
||||||
//a->set_by_comm_search = false;
|
|
||||||
|
|
||||||
airport_atc_map[(string)"KEMT"] = a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGATCMgr::update(double dt) {
|
void FGATCMgr::update(double dt) {
|
||||||
//Traverse the list of active stations.
|
//Traverse the list of active stations.
|
||||||
//Only update one class per update step to avoid the whole ATC system having to calculate between frames.
|
//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.
|
//Eventually we should only update every so many steps.
|
||||||
//cout << "In FGATCMgr::update - atc_list.size = " << atc_list.size() << '\n';
|
//cout << "In FGATCMgr::update - atc_list.size = " << atc_list.size() << '\n';
|
||||||
if(atc_list.size()) {
|
if(atc_list.size()) {
|
||||||
if(atc_list_itr == atc_list.end()) {
|
if(atc_list_itr == atc_list.end()) {
|
||||||
atc_list_itr = atc_list.begin();
|
atc_list_itr = atc_list.begin();
|
||||||
|
}
|
||||||
|
(*atc_list_itr)->Update();
|
||||||
|
++atc_list_itr;
|
||||||
}
|
}
|
||||||
(*atc_list_itr)->Update();
|
|
||||||
++atc_list_itr;
|
// Search the tuned frequencies every now and then - this should be done with the event scheduler
|
||||||
}
|
static int i = 0;
|
||||||
|
if(i == 30) {
|
||||||
// Search the tuned frequencies every now and then - this should be done with the event scheduler
|
Search();
|
||||||
static int i = 0;
|
i = 0;
|
||||||
if(i == 30) {
|
}
|
||||||
Search();
|
++i;
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
// Remove from list only if not needed by the AI system
|
// Remove from list only if not needed by the AI system
|
||||||
void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp) {
|
void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp) {
|
||||||
AirportATC a;
|
AirportATC a;
|
||||||
if(GetAirportATCDetails((string)id, &a)) {
|
if(GetAirportATCDetails((string)id, &a)) {
|
||||||
if(a.set_by_AI) {
|
if(a.set_by_AI) {
|
||||||
// Don't remove
|
// Don't remove
|
||||||
a.set_by_comm_search = false;
|
a.set_by_comm_search = false;
|
||||||
airport_atc_map[(string)id] = a;
|
airport_atc_map[(string)id] = a;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// remove
|
// remove
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Remove from list - should only be called from above or similar
|
// Remove from list - should only be called from above or similar
|
||||||
void FGATCMgr::RemoveFromList(const char* id, atc_type tp) {
|
void FGATCMgr::RemoveFromList(const char* id, atc_type tp) {
|
||||||
//cout << "Requested type = " << tp << '\n';
|
//cout << "Requested type = " << tp << '\n';
|
||||||
//cout << "id = " << id << '\n';
|
//cout << "id = " << id << '\n';
|
||||||
atc_list_itr = atc_list.begin();
|
atc_list_itr = atc_list.begin();
|
||||||
while(atc_list_itr != atc_list.end()) {
|
while(atc_list_itr != atc_list.end()) {
|
||||||
//cout << "type = " << (*atc_list_itr)->GetType() << '\n';
|
//cout << "type = " << (*atc_list_itr)->GetType() << '\n';
|
||||||
//cout << "Ident = " << (*atc_list_itr)->GetIdent() << '\n';
|
//cout << "Ident = " << (*atc_list_itr)->GetIdent() << '\n';
|
||||||
if( (!strcmp((*atc_list_itr)->GetIdent(), id))
|
if( (!strcmp((*atc_list_itr)->GetIdent(), id))
|
||||||
&& ((*atc_list_itr)->GetType() == tp) ) {
|
&& ((*atc_list_itr)->GetType() == tp) ) {
|
||||||
//Before removing it stop it transmitting!!
|
//Before removing it stop it transmitting!!
|
||||||
//cout << "OBLITERATING FROM LIST!!!\n";
|
//cout << "OBLITERATING FROM LIST!!!\n";
|
||||||
(*atc_list_itr)->SetNoDisplay();
|
(*atc_list_itr)->SetNoDisplay();
|
||||||
(*atc_list_itr)->Update();
|
(*atc_list_itr)->Update();
|
||||||
delete (*atc_list_itr);
|
delete (*atc_list_itr);
|
||||||
atc_list_itr = atc_list.erase(atc_list_itr);
|
atc_list_itr = atc_list.erase(atc_list_itr);
|
||||||
break;
|
break;
|
||||||
} // Note that that can upset where we are in the list but that doesn't really matter
|
} // Note that that can upset where we are in the list but that doesn't really matter
|
||||||
++atc_list_itr;
|
++atc_list_itr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//DCL - this routine untested so far.
|
//DCL - this routine untested so far.
|
||||||
// Find in list - return a currently active ATC pointer given ICAO code and type
|
// Find in list - return a currently active ATC pointer given ICAO code and type
|
||||||
FGATC* FGATCMgr::FindInList(const char* id, atc_type tp) {
|
FGATC* FGATCMgr::FindInList(const char* id, atc_type tp) {
|
||||||
atc_list_itr = atc_list.begin();
|
atc_list_itr = atc_list.begin();
|
||||||
while(atc_list_itr != atc_list.end()) {
|
while(atc_list_itr != atc_list.end()) {
|
||||||
if( (!strcmp((*atc_list_itr)->GetIdent(), id))
|
if( (!strcmp((*atc_list_itr)->GetIdent(), id))
|
||||||
&& ((*atc_list_itr)->GetType() == tp) ) {
|
&& ((*atc_list_itr)->GetType() == tp) ) {
|
||||||
return(*atc_list_itr);
|
return(*atc_list_itr);
|
||||||
} // Note that that can upset where we are in the list but that shouldn't really matter
|
} // Note that that can upset where we are in the list but that shouldn't really matter
|
||||||
++atc_list_itr;
|
++atc_list_itr;
|
||||||
}
|
}
|
||||||
// We need a fallback position
|
// We need a fallback position
|
||||||
cout << "*** Failed to find FGATC* in FGATCMgr::FindInList - this should not happen!" << endl;
|
SG_LOG(SG_GENERAL, SG_ALERT, "*** Failed to find FGATC* in FGATCMgr::FindInList - this should not happen!");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the airport is found in the map
|
// Returns true if the airport is found in the map
|
||||||
bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
|
bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
|
||||||
if(airport_atc_map.find(icao) != airport_atc_map.end()) {
|
if(airport_atc_map.find(icao) != airport_atc_map.end()) {
|
||||||
*a = *airport_atc_map[icao];
|
*a = *airport_atc_map[icao];
|
||||||
return(true);
|
return(true);
|
||||||
} else {
|
} else {
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return a pointer to a given sort of ATC at a given airport and activate if necessary
|
// 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
|
// ONLY CALL THIS FUNCTION AFTER FIRST CHECKING THE SERVICE EXISTS BY CALLING GetAirportATCDetails
|
||||||
|
// 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).
|
||||||
FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
|
FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
|
||||||
AirportATC *a = airport_atc_map[icao];
|
AirportATC *a = airport_atc_map[icao];
|
||||||
//cout << "a->lon = " << a->lon << '\n';
|
//cout << "a->lon = " << a->lon << '\n';
|
||||||
//cout << "a->elev = " << a->elev << '\n';
|
//cout << "a->elev = " << a->elev << '\n';
|
||||||
//cout << "a->tower_freq = " << a->tower_freq << '\n';
|
//cout << "a->tower_freq = " << a->tower_freq << '\n';
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case TOWER:
|
case TOWER:
|
||||||
if(a->tower_active) {
|
if(a->tower_active) {
|
||||||
// Get the pointer from the list
|
// Get the pointer from the list
|
||||||
return(FindInList(icao.c_str(), type)); // DCL - this untested so far.
|
return(FindInList(icao.c_str(), type)); // DCL - this untested so far.
|
||||||
} else {
|
} else {
|
||||||
FGTower* t = new FGTower;
|
FGTower* t = new FGTower;
|
||||||
if(current_towerlist->query(a->lon, a->lat, a->elev, a->tower_freq, &tower)) {
|
if(current_towerlist->query(a->lon, a->lat, a->elev, a->tower_freq, &tower)) {
|
||||||
*t = tower;
|
*t = tower;
|
||||||
atc_list.push_back(t);
|
atc_list.push_back(t);
|
||||||
a->tower_active = true;
|
a->tower_active = true;
|
||||||
airport_atc_map[icao] = a;
|
airport_atc_map[icao] = a;
|
||||||
return(t);
|
return(t);
|
||||||
} else {
|
} else {
|
||||||
cout << "ERROR - tower that should exist in FGATCMgr::GetATCPointer for airport " << icao << " not found\n";
|
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;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
// Lets add the rest to get rid of the compiler warnings even though we don't need them yet.
|
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR IN FGATCMgr - reached end of GetATCPointer");
|
||||||
case APPROACH:
|
|
||||||
break;
|
return(NULL);
|
||||||
case ATIS:
|
|
||||||
cout << "ERROR - ATIS station should not be requested from FGATCMgr::GetATCPointer" << endl;
|
|
||||||
break;
|
|
||||||
case GROUND:
|
|
||||||
break;
|
|
||||||
case INVALID:
|
|
||||||
break;
|
|
||||||
case ENROUTE:
|
|
||||||
break;
|
|
||||||
case DEPARTURE:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "ERROR IN FGATCMgr - reached end of GetATCPointer\n";
|
|
||||||
|
|
||||||
return(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Render a transmission
|
||||||
|
// Outputs the transmission either on screen or as audio depending on user preference
|
||||||
|
// The repeating flag indicates whether the message should be repeated continuously or played once.
|
||||||
|
void FGATCMgr::Render(string msg, bool repeating) {
|
||||||
|
#ifdef ENABLE_AUDIO_SUPPORT
|
||||||
|
voice = voiceOK && fgGetBool("/sim/sound/audible");
|
||||||
|
if(voice) {
|
||||||
|
int len;
|
||||||
|
unsigned char* buf = v1.WriteMessage((char*)msg.c_str(), len, voice);
|
||||||
|
if(voice) {
|
||||||
|
FGSimpleSound* simple = new FGSimpleSound(buf, len);
|
||||||
|
simple->set_volume(2.0);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Cease rendering a transmission.
|
||||||
|
// At the moment this can handle one transmission active at a time only.
|
||||||
|
void FGATCMgr::NoRender() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FGATCMgr::Search() {
|
void FGATCMgr::Search() {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Comm1.
|
// Comm1.
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
//cout << "In FGATCMgr::Search() - atc_list.size = " << atc_list.size() << '\n';
|
//cout << "In FGATCMgr::Search() - atc_list.size = " << atc_list.size() << '\n';
|
||||||
|
|
||||||
comm1_freq = comm1_node->getDoubleValue();
|
comm1_freq = comm1_node->getDoubleValue();
|
||||||
//cout << "************* comm1_freq = " << comm1_freq << '\n';
|
//cout << "************* comm1_freq = " << comm1_freq << '\n';
|
||||||
double lon = lon_node->getDoubleValue();
|
double lon = lon_node->getDoubleValue();
|
||||||
double lat = lat_node->getDoubleValue();
|
double lat = lat_node->getDoubleValue();
|
||||||
double elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
|
double elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
|
||||||
|
|
||||||
// Store the comm1_type
|
// Store the comm1_type
|
||||||
//atc_type old_comm1_type = comm1_type;
|
//atc_type old_comm1_type = comm1_type;
|
||||||
|
|
||||||
// We must be able to generalise some of the repetetive searching below!
|
// We must be able to generalise some of the repetetive searching below!
|
||||||
|
|
||||||
//Search for ATIS first
|
//Search for ATIS first
|
||||||
if(current_atislist->query(lon, lat, elev, comm1_freq, &atis)) {
|
if(current_atislist->query(lon, lat, elev, comm1_freq, &atis)) {
|
||||||
//cout << "atis found in radiostack search !!!!" << endl;
|
//cout << "atis found in radiostack search !!!!" << endl;
|
||||||
//cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
|
//cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
|
||||||
//cout << "comm1_type " << comm1_type << '\n';
|
//cout << "comm1_type " << comm1_type << '\n';
|
||||||
comm1_atis_ident = atis.GetIdent();
|
comm1_atis_ident = atis.GetIdent();
|
||||||
comm1_atis_valid = true;
|
comm1_atis_valid = true;
|
||||||
if(last_comm1_atis_ident != comm1_atis_ident) {
|
if(last_comm1_atis_ident != comm1_atis_ident) {
|
||||||
if(last_comm1_atis_ident != "") {
|
if(last_comm1_atis_ident != "") {
|
||||||
RemoveFromList(last_comm1_atis_ident, ATIS);
|
RemoveFromList(last_comm1_atis_ident, ATIS);
|
||||||
}
|
}
|
||||||
last_comm1_atis_ident = comm1_atis_ident;
|
last_comm1_atis_ident = comm1_atis_ident;
|
||||||
//cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
|
//cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
|
||||||
comm1_type = ATIS;
|
comm1_type = ATIS;
|
||||||
comm1_elev = atis.get_elev();
|
comm1_elev = atis.get_elev();
|
||||||
comm1_range = FG_ATIS_DEFAULT_RANGE;
|
comm1_range = FG_ATIS_DEFAULT_RANGE;
|
||||||
comm1_effective_range = comm1_range;
|
comm1_effective_range = comm1_range;
|
||||||
comm1_x = atis.get_x();
|
comm1_x = atis.get_x();
|
||||||
comm1_y = atis.get_y();
|
comm1_y = atis.get_y();
|
||||||
comm1_z = atis.get_z();
|
comm1_z = atis.get_z();
|
||||||
FGATIS* a = new FGATIS;
|
FGATIS* a = new FGATIS;
|
||||||
*a = atis;
|
*a = atis;
|
||||||
a->SetDisplay();
|
a->SetDisplay();
|
||||||
atc_list.push_back(a);
|
atc_list.push_back(a);
|
||||||
//cout << "Found a new atis station in range" << endl;
|
//cout << "Found a new atis station in range" << endl;
|
||||||
//cout << " id = " << atis.GetIdent() << endl;
|
//cout << " id = " << atis.GetIdent() << endl;
|
||||||
return; //This rather assumes that we never have more than one type of station in range.
|
return; //This rather assumes that we never have more than one type of station in range.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(comm1_atis_valid) {
|
||||||
|
//cout << "Removing ATIS " << comm1_atis_ident << " from list\n";
|
||||||
|
RemoveFromList(comm1_atis_ident, ATIS);
|
||||||
|
comm1_atis_valid = false;
|
||||||
|
if(comm1_type == ATIS) {
|
||||||
|
comm1_type = INVALID;
|
||||||
|
}
|
||||||
|
comm1_atis_ident = "";
|
||||||
|
//comm1_trans_ident = "";
|
||||||
|
last_comm1_atis_ident = "";
|
||||||
|
}
|
||||||
|
//cout << "not picking up atis" << endl;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if(comm1_atis_valid) {
|
//Next search for tower
|
||||||
//cout << "Removing ATIS " << comm1_atis_ident << " from list\n";
|
//cout << "comm1_freq = " << comm1_freq << '\n';
|
||||||
RemoveFromList(comm1_atis_ident, ATIS);
|
if(current_towerlist->query(lon, lat, elev, comm1_freq, &tower)) {
|
||||||
comm1_atis_valid = false;
|
//cout << "tower found in radiostack search !!!!" << endl;
|
||||||
if(comm1_type == ATIS) {
|
comm1_tower_ident = tower.GetIdent();
|
||||||
comm1_type = INVALID;
|
//cout << "comm1_tower_ident = " << comm1_tower_ident << '\n';
|
||||||
}
|
comm1_tower_valid = true;
|
||||||
comm1_atis_ident = "";
|
if(last_comm1_tower_ident != comm1_tower_ident) {
|
||||||
//comm1_trans_ident = "";
|
if(last_comm1_tower_ident != "") {
|
||||||
last_comm1_atis_ident = "";
|
RemoveFromList(last_comm1_tower_ident, TOWER);
|
||||||
|
}
|
||||||
|
last_comm1_tower_ident = comm1_tower_ident;
|
||||||
|
comm1_type = TOWER;
|
||||||
|
comm1_elev = tower.get_elev();
|
||||||
|
comm1_range = FG_TOWER_DEFAULT_RANGE;
|
||||||
|
comm1_effective_range = comm1_range;
|
||||||
|
comm1_x = tower.get_x();
|
||||||
|
comm1_y = tower.get_y();
|
||||||
|
comm1_z = tower.get_z();
|
||||||
|
FGTower* t = new FGTower;
|
||||||
|
*t = tower;
|
||||||
|
t->SetDisplay();
|
||||||
|
atc_list.push_back(t);
|
||||||
|
//cout << "Found a new tower station in range" << endl;
|
||||||
|
//cout << " id = " << tower.GetIdent() << endl;
|
||||||
|
return; //This rather assumes that we never have more than one type of station in range.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(comm1_tower_valid) {
|
||||||
|
//cout << "removing tower\n";
|
||||||
|
RemoveFromList(comm1_tower_ident, TOWER);
|
||||||
|
//comm1_valid = false;
|
||||||
|
if(comm1_type == TOWER) {
|
||||||
|
comm1_type = INVALID; // Only invalidate if we haven't switched it to something else
|
||||||
|
}
|
||||||
|
comm1_tower_valid = false;
|
||||||
|
comm1_tower_ident = "";
|
||||||
|
last_comm1_tower_ident = "";
|
||||||
|
//comm1_ident = "";
|
||||||
|
//comm1_trans_ident = "";
|
||||||
|
//last_comm1_ident = "";
|
||||||
|
}
|
||||||
|
//cout << "not picking up tower" << endl;
|
||||||
}
|
}
|
||||||
//cout << "not picking up atis" << endl;
|
/*
|
||||||
}
|
//Next search for Ground control
|
||||||
|
if(current_groundlist->query(lon, lat, elev, comm1_freq, &ground)) {
|
||||||
//Next search for tower
|
//cout << "Ground Control found in radiostack search !!!!" << endl;
|
||||||
//cout << "comm1_freq = " << comm1_freq << '\n';
|
comm1_ident = ground.GetIdent();
|
||||||
if(current_towerlist->query(lon, lat, elev, comm1_freq, &tower)) {
|
comm1_valid = true;
|
||||||
//cout << "tower found in radiostack search !!!!" << endl;
|
if((last_comm1_ident != comm1_ident) || (comm1_type != GROUND)) {
|
||||||
comm1_tower_ident = tower.GetIdent();
|
if(last_comm1_ident != "") {
|
||||||
//cout << "comm1_tower_ident = " << comm1_tower_ident << '\n';
|
RemoveFromList(last_comm1_ident, GROUND);
|
||||||
comm1_tower_valid = true;
|
}
|
||||||
if(last_comm1_tower_ident != comm1_tower_ident) {
|
last_comm1_ident = comm1_ident;
|
||||||
if(last_comm1_tower_ident != "") {
|
comm1_type = GROUND;
|
||||||
RemoveFromList(last_comm1_tower_ident, TOWER);
|
comm1_elev = ground.get_elev();
|
||||||
}
|
comm1_range = FG_GROUND_DEFAULT_RANGE;
|
||||||
last_comm1_tower_ident = comm1_tower_ident;
|
comm1_effective_range = comm1_range;
|
||||||
comm1_type = TOWER;
|
comm1_x = ground.get_x();
|
||||||
comm1_elev = tower.get_elev();
|
comm1_y = ground.get_y();
|
||||||
comm1_range = FG_TOWER_DEFAULT_RANGE;
|
comm1_z = ground.get_z();
|
||||||
comm1_effective_range = comm1_range;
|
FGGround* g = new FGGround;
|
||||||
comm1_x = tower.get_x();
|
*g = ground;
|
||||||
comm1_y = tower.get_y();
|
g->SetDisplay();
|
||||||
comm1_z = tower.get_z();
|
atc_list.push_back(g);
|
||||||
FGTower* t = new FGTower;
|
// For now we will automatically make contact with ground when the radio is tuned.
|
||||||
*t = tower;
|
// This rather assumes that the user tunes the radio at the appropriate place
|
||||||
t->SetDisplay();
|
// (ie. having just turned off the runway) and only uses ground control on arrival
|
||||||
atc_list.push_back(t);
|
// but its a start!
|
||||||
//cout << "Found a new tower station in range" << endl;
|
g->NewArrival(current_plane);
|
||||||
//cout << " id = " << tower.GetIdent() << endl;
|
//cout << "Found a new ground station in range" << endl;
|
||||||
return; //This rather assumes that we never have more than one type of station in range.
|
//cout << " id = " << ground.GetIdent() << endl;
|
||||||
|
return; //This rather assumes that we never have more than one type of station in range.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if((comm1_valid) && (comm1_type == GROUND)) {
|
||||||
|
RemoveFromList(comm1_ident, GROUND);
|
||||||
|
comm1_valid = false;
|
||||||
|
comm1_type = INVALID;
|
||||||
|
comm1_ident = "";
|
||||||
|
//comm1_trans_ident = "";
|
||||||
|
last_comm1_ident = "";
|
||||||
|
}
|
||||||
|
//cout << "not picking up ground control" << endl;
|
||||||
}
|
}
|
||||||
} else {
|
*/
|
||||||
if(comm1_tower_valid) {
|
// ================================================================================
|
||||||
//cout << "removing tower\n";
|
// Search for Approach stations
|
||||||
RemoveFromList(comm1_tower_ident, TOWER);
|
// ================================================================================
|
||||||
//comm1_valid = false;
|
// init number of approach stations reachable by plane
|
||||||
if(comm1_type == TOWER) {
|
int num_app = 0;
|
||||||
comm1_type = INVALID; // Only invalidate if we haven't switched it to something else
|
|
||||||
}
|
// search stations in range
|
||||||
comm1_tower_valid = false;
|
current_approachlist->query_bck(lon, lat, elev, approaches, max_app, num_app);
|
||||||
comm1_tower_ident = "";
|
if (num_app != 0) {
|
||||||
last_comm1_tower_ident = "";
|
//cout << num_app << " approaches found in radiostack search !!!!" << endl;
|
||||||
//comm1_ident = "";
|
|
||||||
//comm1_trans_ident = "";
|
for ( int i=0; i<num_app; i++ ) {
|
||||||
//last_comm1_ident = "";
|
bool new_app = true;
|
||||||
|
approach_ident = approaches[i].GetIdent();
|
||||||
|
|
||||||
|
// check if station already exists on ATC stack
|
||||||
|
atc_list_itr = atc_list.begin();
|
||||||
|
while(atc_list_itr != atc_list.end()) {
|
||||||
|
//cout << "ATC list: " << (*atc_list_itr)->GetIdent() << endl;
|
||||||
|
if((!strcmp((*atc_list_itr)->GetIdent(), approach_ident))
|
||||||
|
&& ((*atc_list_itr)->GetType() == APPROACH) ) {
|
||||||
|
new_app = false;
|
||||||
|
string pid = "Player";
|
||||||
|
(*atc_list_itr)->AddPlane(pid);
|
||||||
|
(*atc_list_itr)->Update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++atc_list_itr;
|
||||||
|
}
|
||||||
|
// generate new Approach on ATC stack
|
||||||
|
if (new_app) {
|
||||||
|
FGApproach* a = new FGApproach;
|
||||||
|
*a = approaches[i];
|
||||||
|
string pid = "Player";
|
||||||
|
a->AddPlane(pid);
|
||||||
|
a->Update();
|
||||||
|
a->SetDisplay();
|
||||||
|
atc_list.push_back(a);
|
||||||
|
//cout << "Found a new approach station in range: Id = "
|
||||||
|
// << approaches[i].GetIdent() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//cout << "not picking up tower" << endl;
|
|
||||||
}
|
// remove planes which are out of range
|
||||||
/*
|
|
||||||
//Next search for Ground control
|
|
||||||
if(current_groundlist->query(lon, lat, elev, comm1_freq, &ground)) {
|
|
||||||
//cout << "Ground Control found in radiostack search !!!!" << endl;
|
|
||||||
comm1_ident = ground.GetIdent();
|
|
||||||
comm1_valid = true;
|
|
||||||
if((last_comm1_ident != comm1_ident) || (comm1_type != GROUND)) {
|
|
||||||
if(last_comm1_ident != "") {
|
|
||||||
RemoveFromList(last_comm1_ident, GROUND);
|
|
||||||
}
|
|
||||||
last_comm1_ident = comm1_ident;
|
|
||||||
comm1_type = GROUND;
|
|
||||||
comm1_elev = ground.get_elev();
|
|
||||||
comm1_range = FG_GROUND_DEFAULT_RANGE;
|
|
||||||
comm1_effective_range = comm1_range;
|
|
||||||
comm1_x = ground.get_x();
|
|
||||||
comm1_y = ground.get_y();
|
|
||||||
comm1_z = ground.get_z();
|
|
||||||
FGGround* g = new FGGround;
|
|
||||||
*g = ground;
|
|
||||||
g->SetDisplay();
|
|
||||||
atc_list.push_back(g);
|
|
||||||
// For now we will automatically make contact with ground when the radio is tuned.
|
|
||||||
// This rather assumes that the user tunes the radio at the appropriate place
|
|
||||||
// (ie. having just turned off the runway) and only uses ground control on arrival
|
|
||||||
// but its a start!
|
|
||||||
g->NewArrival(current_plane);
|
|
||||||
//cout << "Found a new ground station in range" << endl;
|
|
||||||
//cout << " id = " << ground.GetIdent() << endl;
|
|
||||||
return; //This rather assumes that we never have more than one type of station in range.
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if((comm1_valid) && (comm1_type == GROUND)) {
|
|
||||||
RemoveFromList(comm1_ident, GROUND);
|
|
||||||
comm1_valid = false;
|
|
||||||
comm1_type = INVALID;
|
|
||||||
comm1_ident = "";
|
|
||||||
//comm1_trans_ident = "";
|
|
||||||
last_comm1_ident = "";
|
|
||||||
}
|
|
||||||
//cout << "not picking up ground control" << endl;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// ================================================================================
|
|
||||||
// Search for Approach stations
|
|
||||||
// ================================================================================
|
|
||||||
// init number of approach stations reachable by plane
|
|
||||||
int num_app = 0;
|
|
||||||
|
|
||||||
// search stations in range
|
|
||||||
current_approachlist->query_bck(lon, lat, elev, approaches, max_app, num_app);
|
|
||||||
if (num_app != 0) {
|
|
||||||
//cout << num_app << " approaches found in radiostack search !!!!" << endl;
|
|
||||||
|
|
||||||
for ( int i=0; i<num_app; i++ ) {
|
|
||||||
bool new_app = true;
|
|
||||||
approach_ident = approaches[i].GetIdent();
|
|
||||||
|
|
||||||
// check if station already exists on ATC stack
|
|
||||||
atc_list_itr = atc_list.begin();
|
atc_list_itr = atc_list.begin();
|
||||||
while(atc_list_itr != atc_list.end()) {
|
while(atc_list_itr != atc_list.end()) {
|
||||||
//cout << "ATC list: " << (*atc_list_itr)->GetIdent() << endl;
|
if((*atc_list_itr)->GetType() == APPROACH ) {
|
||||||
if((!strcmp((*atc_list_itr)->GetIdent(), approach_ident))
|
int np = (*atc_list_itr)->RemovePlane();
|
||||||
&& ((*atc_list_itr)->GetType() == APPROACH) ) {
|
// if approach has no planes left remove it from ATC list
|
||||||
new_app = false;
|
if ( np == 0) {
|
||||||
string pid = "Player";
|
(*atc_list_itr)->SetNoDisplay();
|
||||||
(*atc_list_itr)->AddPlane(pid);
|
(*atc_list_itr)->Update();
|
||||||
(*atc_list_itr)->Update();
|
delete (*atc_list_itr);
|
||||||
break;
|
atc_list_itr = atc_list.erase(atc_list_itr);
|
||||||
}
|
break; // the other stations will be checked next time
|
||||||
++atc_list_itr;
|
}
|
||||||
|
}
|
||||||
|
++atc_list_itr;
|
||||||
}
|
}
|
||||||
// generate new Approach on ATC stack
|
|
||||||
if (new_app) {
|
|
||||||
FGApproach* a = new FGApproach;
|
|
||||||
*a = approaches[i];
|
|
||||||
string pid = "Player";
|
|
||||||
a->AddPlane(pid);
|
|
||||||
a->Update();
|
|
||||||
a->SetDisplay();
|
|
||||||
atc_list.push_back(a);
|
|
||||||
//cout << "Found a new approach station in range: Id = "
|
|
||||||
// << approaches[i].GetIdent() << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove planes which are out of range
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++atc_list_itr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <Main/fgfs.hxx>
|
#include <Main/fgfs.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Sound/soundmgr.hxx>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -32,8 +33,9 @@
|
||||||
#include "atis.hxx"
|
#include "atis.hxx"
|
||||||
#include "tower.hxx"
|
#include "tower.hxx"
|
||||||
#include "approach.hxx"
|
#include "approach.hxx"
|
||||||
//#include "ground.hxx"
|
#include "ground.hxx"
|
||||||
#include "ATC.hxx"
|
#include "ATC.hxx"
|
||||||
|
#include "ATCVoice.hxx"
|
||||||
|
|
||||||
SG_USING_STD(string);
|
SG_USING_STD(string);
|
||||||
SG_USING_STD(list);
|
SG_USING_STD(list);
|
||||||
|
@ -104,13 +106,13 @@ private:
|
||||||
double comm2_freq;
|
double comm2_freq;
|
||||||
|
|
||||||
// Pointers to users current communication frequencies.
|
// Pointers to users current communication frequencies.
|
||||||
SGPropertyNode *comm1_node;
|
SGPropertyNode* comm1_node;
|
||||||
SGPropertyNode *comm2_node;
|
SGPropertyNode* comm2_node;
|
||||||
|
|
||||||
// Pointers to current users position
|
// Pointers to current users position
|
||||||
SGPropertyNode *lon_node;
|
SGPropertyNode* lon_node;
|
||||||
SGPropertyNode *lat_node;
|
SGPropertyNode* lat_node;
|
||||||
SGPropertyNode *elev_node;
|
SGPropertyNode* elev_node;
|
||||||
|
|
||||||
// Position of the ATC that the comm radios are tuned to in order to decide whether transmission
|
// Position of the ATC that the comm radios are tuned to in order to decide whether transmission
|
||||||
// will be received
|
// will be received
|
||||||
|
@ -143,6 +145,15 @@ private:
|
||||||
FGApproach approach;
|
FGApproach approach;
|
||||||
//FGDeparture departure;
|
//FGDeparture departure;
|
||||||
|
|
||||||
|
// Rendering related stuff
|
||||||
|
bool voice; // Flag - true if we are using voice
|
||||||
|
bool playing; // Indicates a message in progress
|
||||||
|
#ifdef ENABLE_AUDIO_SUPPORT
|
||||||
|
string refname; // FIXME - A hack - assumes only one sound to track.
|
||||||
|
bool voiceOK; // Flag - true if at least one voice has loaded OK
|
||||||
|
FGATCVoice v1;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGATCMgr();
|
FGATCMgr();
|
||||||
|
@ -161,7 +172,16 @@ public:
|
||||||
|
|
||||||
// Return a pointer to a given sort of ATC at a given airport and activate if necessary
|
// Return a pointer to a given sort of ATC at a given airport and activate if necessary
|
||||||
FGATC* GetATCPointer(string icao, atc_type type);
|
FGATC* GetATCPointer(string icao, atc_type type);
|
||||||
|
|
||||||
|
// Render a transmission
|
||||||
|
// Outputs the transmission either on screen or as audio depending on user preference
|
||||||
|
// The repeating flag indicates whether the message should be repeated continuously or played once.
|
||||||
|
void Render(string msg, bool repeating);
|
||||||
|
|
||||||
|
// Cease rendering a transmission.
|
||||||
|
// At the moment this can handle one transmission active at a time only.
|
||||||
|
void NoRender();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Remove a class from the atc_list and delete it from memory
|
// Remove a class from the atc_list and delete it from memory
|
||||||
|
|
Loading…
Add table
Reference in a new issue