| 1 | // Written by James Turner, started 2009. |
| 2 | // |
| 3 | // Copyright (C) 2009 Curtis L. Olson |
| 4 | // |
| 5 | // This program is free software; you can redistribute it and/or |
| 6 | // modify it under the terms of the GNU General Public License as |
| 7 | // published by the Free Software Foundation; either version 2 of the |
| 8 | // License, or (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, but |
| 11 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | // General Public License for more details. |
| 14 | // |
| 15 | // You should have received a copy of the GNU General Public License |
| 16 | // along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | |
| 19 | #include <iostream> |
| 20 | |
| 21 | #include <simgear/misc/sg_path.hxx> |
| 22 | |
| 23 | #include <Navaids/fixlist.hxx> |
| 24 | //#include "ilslist.hxx" |
| 25 | #include <Navaids/navlist.hxx> |
| 26 | //#include "mkrbeacons.hxx" |
| 27 | |
| 28 | #include "test_suite/dataStore.hxx" |
| 29 | |
| 30 | #include "testnavs.hxx" |
| 31 | |
| 32 | |
| 33 | void NavaidsTests::testNavs() |
| 34 | { |
| 35 | double heading, dist; |
| 36 | |
| 37 | DataStore &data = DataStore::get(); |
| 38 | |
| 39 | FGNavList *current_navlist = new FGNavList; |
| 40 | SGPath p_nav = data.getFGRoot() / "/Navaids/default.nav"; |
| 41 | |
| 42 | current_navlist->init( p_nav ); |
| 43 | |
| 44 | FGNavRecord *n; |
| 45 | if ( (n = current_navlist->findByFreq( -93.2 * SG_DEGREES_TO_RADIANS, |
| 46 | 45.14 * SG_DEGREES_TO_RADIANS, |
| 47 | 3000, 117.30)) != NULL ) |
| 48 | { |
| 49 | std::cout << "Found a vor station in range" << std::endl; |
| 50 | std::cout << " id = " << n->get_ident() << std::endl; |
| 51 | } else { |
| 52 | std::cout << "not picking up vor. :-(" << std::endl; |
| 53 | } |
| 54 | |
| 55 | FGNavRecord *dcs; |
| 56 | if ( (dcs = current_navlist->findByIdent( "DCS", |
| 57 | -3.3 * SG_DEGREES_TO_RADIANS, |
| 58 | 55.9 * SG_DEGREES_TO_RADIANS)) |
| 59 | != NULL ) { |
| 60 | |
| 61 | std::cout << "Found DCS by ident" << std::endl; |
| 62 | if (dcs->get_freq() != 11520) |
| 63 | std::cout << "Frequency for DCS VOR is wrong (should be 115.20), it's " |
| 64 | << dcs->get_freq() << std::endl; |
| 65 | } else { |
| 66 | std::cout << "couldn't locate DCS (Dean-Cross) VOR" << std::endl; |
| 67 | } |
| 68 | |
| 69 | // we have to init the marker beacon storage before we parse the ILS file |
| 70 | FGMarkerBeacons *current_beacons = new FGMarkerBeacons; |
| 71 | current_beacons->init(); |
| 72 | |
| 73 | FGILSList *current_ilslist = new FGILSList; |
| 74 | SGPath p_ils = data.getFGRoot() / "/Navaids/default.ils"; |
| 75 | current_ilslist->init( p_ils ); |
| 76 | FGILS *i = current_ilslist->findByFreq( -93.1 * SG_DEGREES_TO_RADIANS, |
| 77 | 45.24 * SG_DEGREES_TO_RADIANS, |
| 78 | 3000, 110.30); |
| 79 | if ( i != NULL ) { |
| 80 | std::cout << "Found an ils station in range" << std::endl; |
| 81 | std::cout << " apt = " << i->get_aptcode() << std::endl; |
| 82 | std::cout << " rwy = " << i->get_rwyno() << std::endl; |
| 83 | } else { |
| 84 | std::cout << "not picking up ils. :-(" << std::endl; |
| 85 | } |
| 86 | |
| 87 | FGFixList *current_fixlist = new FGFixList; |
| 88 | SGPath p_fix = data.getFGRoot() / "/Navaids/default.fix"; |
| 89 | current_fixlist->init( p_fix ); |
| 90 | FGFix fix; |
| 91 | |
| 92 | // attempting to get the position relative to the OTR VOR; heading |
| 93 | // should be 108 degrees, distance 74nm (according to my SimCharts |
| 94 | // v1.5) |
| 95 | if ( current_fixlist->query_and_offset( "DOGGA", |
| 96 | -0.103 * SG_DEGREES_TO_RADIANS, |
| 97 | 53.698 * SG_DEGREES_TO_RADIANS, |
| 98 | 3000, &fix, &heading, &dist) ) |
| 99 | { |
| 100 | std::cout << "Found a matching fix" << std::endl; |
| 101 | std::cout << " id = " << fix.get_ident() << std::endl; |
| 102 | std::cout << " heading = " << heading << " dist = " << dist * SG_METER_TO_NM |
| 103 | << std::endl; |
| 104 | } else { |
| 105 | CPPUNIT_FAIL("did not find fix. :-("); |
| 106 | } |
| 107 | } |