From 1154a0dae220ee6eecb773e1b1f81c1b164554cf Mon Sep 17 00:00:00 2001 From: daveluff Date: Thu, 6 Mar 2003 14:06:34 +0000 Subject: [PATCH] Added FindByCode (airport ICAO code) to commlist. This is basically a wrapper around Flightgear's airport lookup and FindByPos --- src/ATC/commlist.cxx | 33 +++++++++++++++++++++++++++++---- src/ATC/commlist.hxx | 10 +++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/ATC/commlist.cxx b/src/ATC/commlist.cxx index 5494088a1..509b095c3 100644 --- a/src/ATC/commlist.cxx +++ b/src/ATC/commlist.cxx @@ -29,9 +29,11 @@ #include #include #include +#include #include "commlist.hxx" //#include "atislist.hxx" +#include "ATCutils.hxx" FGCommList *current_commlist; @@ -86,13 +88,13 @@ bool FGCommList::LoadComms(SGPath path) { ATCData a; fin >> a; if(a.type == INVALID) { - cout << "WARNING - INVALID type found in " << path.str() << '\n'; + SG_LOG(SG_GENERAL, SG_ALERT, "WARNING - INVALID type found in " << path.str() << '\n'); } else { // Push all stations onto frequency map commlist_freq[a.freq].push_back(a); - // Push approach stations onto bucket map as well - if(a.type == APPROACH) { + // Push non-atis stations onto bucket map as well + if(a.type != ATIS) { // get bucket number SGBucket bucket(a.lon, a.lat); int bucknum = bucket.gen_index(); @@ -154,7 +156,6 @@ bool FGCommList::FindByFreq( double lon, double lat, double elev, double freq, return false; } - int FGCommList::FindByPos(double lon, double lat, double elev, comm_list_type* stations, atc_type tp) { // number of relevant stations found within range @@ -202,6 +203,30 @@ int FGCommList::FindByPos(double lon, double lat, double elev, comm_list_type* s } +// Find by Airport code. +// This is basically a wrapper for a call to the airport database to get the airport +// position followed by a call to FindByPos(...) +bool FGCommList::FindByCode( string ICAO, ATCData& ad, atc_type tp ) { + FGAirport a; + if ( dclFindAirportID( ICAO, &a ) ) { + comm_list_type stations; + int found = FindByPos(a.longitude, a.latitude, a.elevation, &stations, tp); + if(found) { + comm_list_iterator itr = stations.begin(); + while(itr != stations.end()) { + if(((*itr).ident == ICAO) && ((*itr).type == tp)) { + ad = *itr; + return true; + } + } + } + } else { + return false; + } + return false; +} + + // TODO - this function should move somewhere else eventually! // Return an appropriate call-sign for an ATIS transmission. int FGCommList::GetCallSign( string apt_id, int hours, int mins ) diff --git a/src/ATC/commlist.hxx b/src/ATC/commlist.hxx index 482ad6adf..033b90afa 100644 --- a/src/ATC/commlist.hxx +++ b/src/ATC/commlist.hxx @@ -70,9 +70,10 @@ public: bool init( SGPath path ); // query the database for the specified frequency, lon and lat are - // in degrees, elev is in meters - // If no atc_type is specified, it returns true if any non-invalid type is found - // If atc_type is specifed, returns true only if the specified type is found + // in degrees, elev is in meters. + // If no atc_type is specified, it returns true if any non-invalid type is found. + // If atc_type is specifed, returns true only if the specified type is found. + // Returns the station closest to the supplied position. // The data found is written into the passed-in ATCData structure. bool FindByFreq( double lon, double lat, double elev, double freq, ATCData* ad, atc_type tp = INVALID ); @@ -82,6 +83,9 @@ public: // If atc_type is specifed, returns the number of all stations in range, and pushes them into stations // ** stations is erased before use ** int FindByPos( double lon, double lat, double elev, comm_list_type* stations, atc_type tp = INVALID ); + + // Find by Airport code. + bool FindByCode( string ICAO, ATCData& ad, atc_type tp = INVALID ); // Return the callsign for an ATIS transmission given transmission time and airpord id // This maybe should get moved somewhere else!!