- // 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)];
- }
- comm_list_iterator current = stations.begin();
- comm_list_iterator last = stations.end();
-
- // double az1, az2, s;
- SGVec3d aircraft = SGVec3d::fromGeod(SGGeod::fromDegM(lon, lat, elev));
- const double orig_max_d = 1e100;
- double max_d = orig_max_d;
- // TODO - at the moment this loop returns the first match found in range
- // We want to return the closest match in the event of a frequency conflict
- for ( ; current != last ; ++current ) {
- //cout << "testing " << current->get_ident() << endl;
- SGVec3d station(current->x, current->y, current->z);
- //cout << "aircraft = " << aircraft << endl;
- //cout << "station = " << station << endl;
-
- double d = distSqr(aircraft, station);
-
- //cout << " dist = " << sqrt(d)
- // << " range = " << current->range * SG_NM_TO_METER << endl;
-
- // TODO - match up to twice the published range so we can model
- // reduced signal strength
- // NOTE The below is squared since we match to distance3Dsquared (above) to avoid a sqrt.
- if ( d < (current->range * SG_NM_TO_METER
- * current->range * SG_NM_TO_METER ) ) {
- //cout << "matched = " << current->ident << endl;
- if((tp == INVALID) || (tp == (*current).type)) {
- if(d < max_d) {
- max_d = d;
- *ad = *current;
- }
- }
- }
- }
-
- if(max_d < orig_max_d) {
- return true;
- } else {
- return false;
- }
+ comm_list_type stations;
+ stations = commlist_freq[kHz10(freq)];
+ comm_list_iterator current = stations.begin();
+ comm_list_iterator last = stations.end();
+
+ // double az1, az2, s;
+ SGVec3d aircraft = SGVec3d::fromGeod(aPos);
+ const double orig_max_d = 1e100;
+ double max_d = orig_max_d;
+ double d;
+ // TODO - at the moment this loop returns the first match found in range
+ // We want to return the closest match in the event of a frequency conflict
+ for ( ; current != last ; ++current ) {
+ d = distSqr(aircraft, current->cart);
+
+ //cout << " dist = " << sqrt(d)
+ // << " range = " << current->range * SG_NM_TO_METER << endl;
+
+ // TODO - match up to twice the published range so we can model
+ // reduced signal strength
+ // NOTE The below is squared since we match to distance3Dsquared (above) to avoid a sqrt.
+ if ( d < (current->range * SG_NM_TO_METER
+ * current->range * SG_NM_TO_METER ) ) {
+ //cout << "matched = " << current->ident << endl;
+ if((tp == INVALID) || (tp == (*current).type)) {
+ if(d < max_d) {
+ max_d = d;
+ *ad = *current;
+ }
+ }
+ }
+ }
+
+ if(max_d < orig_max_d) {
+ return true;
+ } else {
+ return false;
+ }