1 // radiostack.cxx -- class to manage an instance of the radio stack
3 // Written by Curtis Olson, started April 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <Aircraft/aircraft.hxx>
25 #include <Navaids/ilslist.hxx>
26 #include <Navaids/navlist.hxx>
28 #include "radiostack.hxx"
31 FGRadioStack *current_radiostack;
35 FGRadioStack::FGRadioStack() {
42 FGRadioStack::~FGRadioStack() {
46 // Search the database for the current frequencies given current location
47 void FGRadioStack::update( double lon, double lat, double elev ) {
50 Point3D aircraft = fgGeodToCart( Point3D( lon, lat, elev ) );
55 // staightline distance
56 station = Point3D( nav1_x, nav1_y, nav1_z );
57 nav1_dist = aircraft.distance3D( station );
59 if ( nav1_dist < nav1_effective_range * NM_TO_METER ) {
63 geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG,
68 // cout << " heading = " << nav1_heading
69 // << " dist = " << nav1_dist << endl;
76 nav1_radial = nav1_sel_radial;
80 // cout << "not picking up vor. :-(" << endl;
84 // staightline distance
85 station = Point3D( nav2_x, nav2_y, nav2_z );
86 nav2_dist = aircraft.distance3D( station );
88 if ( nav2_dist < nav2_effective_range * NM_TO_METER ) {
92 geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG,
97 // cout << " heading = " << nav2_heading
98 // << " dist = " << nav2_dist << endl;
100 nav2_inrange = false;
104 nav2_radial = nav2_sel_radial;
107 nav2_inrange = false;
108 // cout << "not picking up vor. :-(" << endl;
113 // staightline distance
114 station = Point3D( adf_x, adf_y, adf_z );
115 adf_dist = aircraft.distance3D( station );
117 if ( adf_dist < adf_effective_range * NM_TO_METER ) {
121 geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG,
126 // cout << " heading = " << nav2_heading
127 // << " dist = " << nav2_dist << endl;
137 // Update current nav/adf radio stations based on current postition
138 void FGRadioStack::search( double lon, double lat, double elev ) {
143 if ( current_ilslist->query( lon, lat, elev, nav1_freq, &ils ) ) {
148 nav1_lon = ils.get_loclon();
149 nav1_lat = ils.get_loclat();
150 nav1_elev = ils.get_gselev();
151 nav1_effective_range = FG_ILS_DEFAULT_RANGE;
152 nav1_target_gs = ils.get_gsangle();
153 nav1_radial = ils.get_locheading();
154 while ( nav1_radial < 0.0 ) { nav1_radial += 360.0; }
155 while ( nav1_radial > 360.0 ) { nav1_radial -= 360.0; }
156 nav1_x = ils.get_x();
157 nav1_y = ils.get_y();
158 nav1_z = ils.get_z();
159 // cout << "Found an ils station in range" << endl;
160 // cout << " id = " << ils.get_locident() << endl;
161 } else if ( current_navlist->query( lon, lat, elev, nav1_freq, &nav ) ) {
164 nav1_dme = nav.get_dme();
165 nav1_lon = nav.get_lon();
166 nav1_lat = nav.get_lat();
167 nav1_elev = nav.get_elev();
168 nav1_effective_range = nav.get_range();
169 nav1_target_gs = 0.0;
170 nav1_radial = nav1_sel_radial;
171 nav1_x = nav.get_x();
172 nav1_y = nav.get_y();
173 nav1_z = nav.get_z();
174 // cout << "Found a vor station in range" << endl;
175 // cout << " id = " << nav.get_ident() << endl;
178 // cout << "not picking up vor1. :-(" << endl;
181 if ( current_ilslist->query( lon, lat, elev, nav2_freq, &ils ) ) {
186 nav2_lon = ils.get_loclon();
187 nav2_lat = ils.get_loclat();
188 nav2_elev = ils.get_gselev();
189 nav2_effective_range = FG_ILS_DEFAULT_RANGE;
190 nav2_target_gs = ils.get_gsangle();
191 nav2_radial = ils.get_locheading();
192 while ( nav2_radial < 0.0 ) { nav2_radial += 360.0; }
193 while ( nav2_radial > 360.0 ) { nav2_radial -= 360.0; }
194 nav2_x = ils.get_x();
195 nav2_y = ils.get_y();
196 nav2_z = ils.get_z();
197 // cout << "Found an ils station in range" << endl;
198 // cout << " id = " << ils.get_locident() << endl;
199 } else if ( current_navlist->query( lon, lat, elev, nav2_freq, &nav ) ) {
202 nav2_dme = nav.get_dme();
204 nav2_lon = nav.get_lon();
205 nav2_lat = nav.get_lat();
206 nav2_elev = nav.get_elev();
207 nav2_effective_range = nav.get_range();
208 nav2_target_gs = 0.0;
209 nav2_radial = nav2_sel_radial;
210 nav2_x = nav.get_x();
211 nav2_y = nav.get_y();
212 nav2_z = nav.get_z();
213 // cout << "Found a vor station in range" << endl;
214 // cout << " id = " << nav.get_ident() << endl;
217 // cout << "not picking up vor2. :-(" << endl;
221 if ( current_navlist->query( lon, lat, elev, adf_freq, &nav ) ) {
224 adf_lon = nav.get_lon();
225 adf_lat = nav.get_lat();
226 adf_elev = nav.get_elev();
227 adf_effective_range = nav.get_range();
231 // cout << "Found an adf station in range" << endl;
232 // cout << " id = " << nav.get_ident() << endl;
235 // cout << "not picking up adf. :-(" << endl;
240 // periodic radio station search wrapper
241 void fgRadioSearch( void ) {
242 current_radiostack->search( cur_fdm_state->get_Longitude(),
243 cur_fdm_state->get_Latitude(),
244 cur_fdm_state->get_Altitude() * FEET_TO_METER );