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 ) ) {
147 nav1_lon = ils.get_loclon();
148 nav1_lat = ils.get_loclat();
149 nav1_elev = ils.get_gselev();
150 nav1_effective_range = FG_ILS_DEFAULT_RANGE;
151 nav1_target_gs = ils.get_gsangle();
152 nav1_radial = ils.get_locheading();
153 while ( nav1_radial < 0.0 ) { nav1_radial += 360.0; }
154 while ( nav1_radial > 360.0 ) { nav1_radial -= 360.0; }
155 nav1_x = ils.get_x();
156 nav1_y = ils.get_y();
157 nav1_z = ils.get_z();
158 // cout << "Found an ils station in range" << endl;
159 // cout << " id = " << ils.get_locident() << endl;
160 } else if ( current_navlist->query( lon, lat, elev, nav1_freq, &nav ) ) {
164 nav1_lon = nav.get_lon();
165 nav1_lat = nav.get_lat();
166 nav1_elev = nav.get_elev();
167 nav1_effective_range = nav.get_range();
168 nav1_target_gs = 0.0;
169 nav1_radial = nav1_sel_radial;
170 nav1_x = nav.get_x();
171 nav1_y = nav.get_y();
172 nav1_z = nav.get_z();
173 // cout << "Found a vor station in range" << endl;
174 // cout << " id = " << nav.get_ident() << endl;
177 // cout << "not picking up vor1. :-(" << endl;
180 if ( current_ilslist->query( lon, lat, elev, nav2_freq, &ils ) ) {
184 nav2_lon = ils.get_loclon();
185 nav2_lat = ils.get_loclat();
186 nav2_elev = ils.get_gselev();
187 nav2_effective_range = FG_ILS_DEFAULT_RANGE;
188 nav2_target_gs = ils.get_gsangle();
189 nav2_radial = ils.get_locheading();
190 while ( nav2_radial < 0.0 ) { nav2_radial += 360.0; }
191 while ( nav2_radial > 360.0 ) { nav2_radial -= 360.0; }
192 nav2_x = ils.get_x();
193 nav2_y = ils.get_y();
194 nav2_z = ils.get_z();
195 // cout << "Found an ils station in range" << endl;
196 // cout << " id = " << ils.get_locident() << endl;
197 } else if ( current_navlist->query( lon, lat, elev, nav2_freq, &nav ) ) {
201 nav2_lon = nav.get_lon();
202 nav2_lat = nav.get_lat();
203 nav2_elev = nav.get_elev();
204 nav2_effective_range = nav.get_range();
205 nav2_target_gs = 0.0;
206 nav2_radial = nav2_sel_radial;
207 nav2_x = nav.get_x();
208 nav2_y = nav.get_y();
209 nav2_z = nav.get_z();
210 // cout << "Found a vor station in range" << endl;
211 // cout << " id = " << nav.get_ident() << endl;
214 // cout << "not picking up vor2. :-(" << endl;
218 if ( current_navlist->query( lon, lat, elev, adf_freq, &nav ) ) {
221 adf_lon = nav.get_lon();
222 adf_lat = nav.get_lat();
223 adf_elev = nav.get_elev();
224 adf_effective_range = nav.get_range();
228 // cout << "Found an adf station in range" << endl;
229 // cout << " id = " << nav.get_ident() << endl;
232 // cout << "not picking up adf. :-(" << endl;
237 // periodic radio station search wrapper
238 void fgRadioSearch( void ) {
239 current_radiostack->search( cur_fdm_state->get_Longitude(),
240 cur_fdm_state->get_Latitude(),
241 cur_fdm_state->get_Altitude() * FEET_TO_METER );