diff --git a/src/ATC/approach.cxx b/src/ATC/approach.cxx index 44784ab..98307cb 100644 --- a/src/ATC/approach.cxx +++ b/src/ATC/approach.cxx @@ -122,7 +122,7 @@ void FGApproach::Update(double dt) { int num_trans = 0; // is the frequency of the station tuned in? - if ( freq == (int)(comm1_freq*100.0 + 0.5) ) { + if ( freq == kHz10(comm1_freq) ) { current_transmissionlist->query_station( station, tmissions, max_trans, num_trans ); // loop over all transmissions for station for ( j=0; j<=num_trans-1; j++ ) { diff --git a/src/Navaids/navlist.cxx b/src/Navaids/navlist.cxx index a7eca98..5deb425 100644 --- a/src/Navaids/navlist.cxx +++ b/src/Navaids/navlist.cxx @@ -30,6 +30,7 @@ #include #include "navlist.hxx" +#include "../ATC/ATC.hxx" #include "strx.hxx" @@ -149,7 +150,7 @@ bool FGNavList::add( FGNavRecord *n ) FGNavRecord *FGNavList::findByFreq( const double freq, const double lon, const double lat, const double elev ) { - const nav_list_type& stations = navaids[(int)(freq*100.0 + 0.5)]; + const nav_list_type& stations = navaids[kHz10(freq)]; SGGeod geod = SGGeod::fromRadM(lon, lat, elev); SGVec3d aircraft = SGVec3d::fromGeod(geod); @@ -292,7 +293,7 @@ FGNavRecord *FGNavList::findByIdentAndFreq( const char* ident, const double freq if ( freq > 0.0 ) { // sometimes there can be duplicated idents. If a freq is // specified, use it to refine the search. - int f = (int)(freq*100.0 + 0.5); + int f = kHz10(freq); for ( unsigned int i = 0; i < stations.size(); ++i ) { if ( f == stations[i]->get_freq() ) { return stations[i]; @@ -444,7 +445,7 @@ FGNavRecord *FGNavList::findClosest( double lon_rad, double lat_rad, // Given a frequency, return the first matching station. FGNavRecord *FGNavList::findStationByFreq( double freq ) { - const nav_list_type& stations = navaids[(int)(freq*100.0 + 0.5)]; + const nav_list_type& stations = navaids[kHz10(freq)]; SG_LOG( SG_INSTR, SG_DEBUG, "findStationByFreq " << freq << " size " << stations.size() ); --- /tmp/ATC.hxx 2007-07-07 01:22:14.000000000 -0400 +++ b/src/ATC/ATC.hxx 2007-07-07 01:23:20.000000000 -0400 @@ -37,6 +37,22 @@ SG_USING_STD(string); SG_USING_STD(ios); + + +// Convert a frequency in MHz to tens of kHz +// so we can use it e.g. as an index into commlist_freq +// +// If freq > 1000 assume it's already in tens of KHz; +// otherwise assume MHz. +// +// Note: 122.375 must be rounded DOWN to 12237 +// in order to be consistent with apt.dat et cetera. +inline int kHz10(double freq){ + if (freq > 1000.) return int(freq); + return int(freq*100.0 + 0.25); +} + + enum plane_type { UNKNOWN, GA_SINGLE, @@ -297,7 +313,7 @@ fin.setf(ios::skipws); //cout << "Comm name = " << a.name << '\n'; - a.freq = (int)(f*100.0 + 0.5); + a.freq = kHz10(f); // cout << a.ident << endl; --- commlist.cxx 2007/07/07 05:35:22 1.1 +++ b/src/ATC/commlist.cxx 2007/07/07 05:35:45 @@ -124,14 +124,8 @@ lon *= SGD_DEGREES_TO_RADIANS; lat *= SGD_DEGREES_TO_RADIANS; - // HACK - if freq > 1000 assume it's in KHz, otherwise assume MHz. - // A bit ugly but it works for now!!!! comm_list_type stations; - if(freq > 1000.0) { - stations = commlist_freq[(int)freq]; - } else { - stations = commlist_freq[(int)(freq*100.0 + 0.5)]; - } + stations = commlist_freq[kHz10(freq)]; comm_list_iterator current = stations.begin(); comm_list_iterator last = stations.end();