]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/navcom.cxx
Split Nav/Com units out into their own source code file to continue the
[flightgear.git] / src / Cockpit / navcom.cxx
1 // navcom.cxx -- class to manage a navcom instance
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000 - 2002  Curtis L. Olson - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <stdio.h>      // snprintf
29
30 #include <simgear/compiler.h>
31 #include <simgear/math/sg_random.h>
32
33 #include <Aircraft/aircraft.hxx>
34 #include <Navaids/ilslist.hxx>
35 #include <Navaids/mkrbeacons.hxx>
36 #include <Navaids/navlist.hxx>
37 #include <Time/FGEventMgr.hxx>
38
39 #include "navcom.hxx"
40
41 #include <string>
42 SG_USING_STD(string);
43
44
45 /**
46  * Boy, this is ugly!  Make the VOR range vary by altitude difference.
47  */
48 static double kludgeRange ( double stationElev, double aircraftElev,
49                             double nominalRange)
50 {
51     // Assume that the nominal range (usually 50nm) applies at a 5,000
52     // ft difference.  Just a wild guess!
53     double factor = ((aircraftElev*SG_METER_TO_FEET) - stationElev) / 5000.0;
54     double range = fabs(nominalRange * factor);
55
56     // Clamp the range to keep it sane; for now, never less than 25%
57     // or more than 500% of nominal range.
58     if (range < nominalRange/4.0) {
59         range = nominalRange/4.0;
60     } else if (range > nominalRange*5.0) {
61         range = nominalRange*5.0;
62     }
63
64     return range;
65 }
66
67
68 // Constructor
69 FGNavCom::FGNavCom() :
70     lon_node(fgGetNode("/position/longitude-deg", true)),
71     lat_node(fgGetNode("/position/latitude-deg", true)),
72     alt_node(fgGetNode("/position/altitude-ft", true)),
73     last_nav_ident(""),
74     last_nav_vor(false),
75     nav_play_count(0),
76     nav_last_time(0),
77     need_update(true),
78     comm_freq(0.0),
79     comm_alt_freq(0.0),
80     comm_vol_btn(0.0),
81     nav_freq(0.0),
82     nav_alt_freq(0.0),
83     nav_radial(0.0),
84     nav_vol_btn(0.0)
85 {
86     SGPath path( globals->get_fg_root() );
87     SGPath term = path;
88     term.append( "Navaids/range.term" );
89     SGPath low = path;
90     low.append( "Navaids/range.low" );
91     SGPath high = path;
92     high.append( "Navaids/range.high" );
93
94     term_tbl = new SGInterpTable( term.str() );
95     low_tbl = new SGInterpTable( low.str() );
96     high_tbl = new SGInterpTable( high.str() );
97
98 }
99
100
101 // Destructor
102 FGNavCom::~FGNavCom() 
103 {
104     unbind();           // FIXME: should be called externally
105
106     delete term_tbl;
107     delete low_tbl;
108     delete high_tbl;
109 }
110
111
112 void
113 FGNavCom::init ()
114 {
115     morse.init();
116     beacon.init();
117
118     search();
119
120     update(0);                  // FIXME: use dt
121 }
122
123 void
124 FGNavCom::bind ()
125 {
126     char propname[256];
127
128                                 // User inputs
129     sprintf( propname, "/radios/comm[%d]/frequencies/selected-mhz", index );
130     fgTie( propname, this, &FGNavCom::get_comm_freq, &FGNavCom::set_comm_freq );
131     fgSetArchivable( propname );
132
133     sprintf( propname, "/radios/comm[%d]/frequencies/standby-mhz", index );
134     fgTie( propname, this,
135            &FGNavCom::get_comm_alt_freq, &FGNavCom::set_comm_alt_freq );
136     fgSetArchivable( propname );
137
138     sprintf( propname, "/radios/comm[%d]/volume", index );
139     fgTie( propname, this,
140            &FGNavCom::get_comm_vol_btn, &FGNavCom::set_comm_vol_btn );
141     fgSetArchivable( propname );
142
143     sprintf( propname, "/radios/comm[%d]/ident", index );
144     fgTie( propname, this,
145           &FGNavCom::get_comm_ident_btn, &FGNavCom::set_comm_ident_btn );
146     fgSetArchivable( propname );
147
148     sprintf( propname, "/radios/nav[%d]/frequencies/selected-mhz", index );
149     fgTie( propname, this,
150           &FGNavCom::get_nav_freq, &FGNavCom::set_nav_freq );
151     fgSetArchivable( propname );
152
153     sprintf( propname, "/radios/nav[%d]/frequencies/standby-mhz", index );
154     fgTie( propname , this,
155            &FGNavCom::get_nav_alt_freq, &FGNavCom::set_nav_alt_freq);
156     fgSetArchivable( propname );
157
158     sprintf( propname, "/radios/nav[%d]/radials/selected-deg", index );
159     fgTie( propname, this,
160            &FGNavCom::get_nav_sel_radial, &FGNavCom::set_nav_sel_radial );
161     fgSetArchivable( propname );
162
163     sprintf( propname, "/radios/nav[%d]/volume", index );
164     fgTie( propname, this,
165            &FGNavCom::get_nav_vol_btn, &FGNavCom::set_nav_vol_btn );
166     fgSetArchivable( propname );
167
168     sprintf( propname, "/radios/nav[%d]/ident", index );
169     fgTie( propname, this,
170            &FGNavCom::get_nav_ident_btn, &FGNavCom::set_nav_ident_btn );
171     fgSetArchivable( propname );
172
173                                 // Radio outputs
174     sprintf( propname, "/radios/nav[%d]/radials/actual-deg", index );
175     fgTie( propname,  this, &FGNavCom::get_nav_radial );
176
177     sprintf( propname, "/radios/nav[%d]/to-flag", index );
178     fgTie( propname, this, &FGNavCom::get_nav_to_flag );
179
180     sprintf( propname, "/radios/nav[%d]/from-flag", index );
181     fgTie( propname, this, &FGNavCom::get_nav_from_flag );
182
183     sprintf( propname, "/radios/nav[%d]/in-range", index );
184     fgTie( propname, this, &FGNavCom::get_nav_inrange );
185
186     sprintf( propname, "/radios/nav[%d]/heading-needle-deflection", index );
187     fgTie( propname, this, &FGNavCom::get_nav_heading_needle_deflection );
188
189     sprintf( propname, "/radios/nav[%d]/gs-needle-deflection", index );
190     fgTie( propname, this, &FGNavCom::get_nav_gs_needle_deflection );
191 }
192
193
194 void
195 FGNavCom::unbind ()
196 {
197     char propname[256];
198
199     sprintf( propname, "/radios/comm[%d]/frequencies/selected-mhz", index );
200     fgUntie( propname );
201     sprintf( propname, "/radios/comm[%d]/frequencies/standby-mhz", index );
202     fgUntie( propname );
203     sprintf( propname, "/radios/comm[%d]/on", index );
204     fgUntie( propname );
205     sprintf( propname, "/radios/comm[%d]/ident", index );
206     fgUntie( propname );
207
208     sprintf( propname, "/radios/nav[%d]/frequencies/selected-mhz", index );
209     fgUntie( propname );
210     sprintf( propname, "/radios/nav[%d]/frequencies/standby-mhz", index );
211     fgUntie( propname );
212     sprintf( propname, "/radios/nav[%d]/radials/actual-deg", index );
213     fgUntie( propname );
214     sprintf( propname, "/radios/nav[%d]/radials/selected-deg", index );
215     fgUntie( propname );
216     sprintf( propname, "/radios/nav[%d]/on", index );
217     fgUntie( propname );
218     sprintf( propname, "/radios/nav[%d]/ident", index );
219     fgUntie( propname );
220     sprintf( propname, "/radios/nav[%d]/to-flag", index );
221     fgUntie( propname );
222     sprintf( propname, "/radios/nav[%d]/from-flag", index );
223     fgUntie( propname );
224     sprintf( propname, "/radios/nav[%d]/in-range", index );
225     fgUntie( propname );
226     sprintf( propname, "/radios/nav[%d]/heading-needle-deflection", index );
227     fgUntie( propname );
228     sprintf( propname, "/radios/nav[%d]/gs-needle-deflection", index );
229     fgUntie( propname );
230 }
231
232
233 // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
234 double FGNavCom::adjustNavRange( double stationElev, double aircraftElev,
235                               double nominalRange )
236 {
237     // extend out actual usable range to be 1.3x the published safe range
238     const double usability_factor = 1.3;
239
240     // assumptions we model the standard service volume, plus
241     // ... rather than specifying a cylinder, we model a cone that
242     // contains the cylinder.  Then we put an upside down cone on top
243     // to model diminishing returns at too-high altitudes.
244
245     // altitude difference
246     double alt = ( aircraftElev * SG_METER_TO_FEET - stationElev );
247     // cout << "aircraft elev = " << aircraftElev * SG_METER_TO_FEET
248     //      << " station elev = " << stationElev << endl;
249
250     if ( nominalRange < 25.0 + SG_EPSILON ) {
251         // Standard Terminal Service Volume
252         return term_tbl->interpolate( alt ) * usability_factor;
253     } else if ( nominalRange < 50.0 + SG_EPSILON ) {
254         // Standard Low Altitude Service Volume
255         // table is based on range of 40, scale to actual range
256         return low_tbl->interpolate( alt ) * nominalRange / 40.0
257             * usability_factor;
258     } else {
259         // Standard High Altitude Service Volume
260         // table is based on range of 130, scale to actual range
261         return high_tbl->interpolate( alt ) * nominalRange / 130.0
262             * usability_factor;
263     }
264 }
265
266
267 // model standard ILS service volumes as per AIM 1-1-9
268 double FGNavCom::adjustILSRange( double stationElev, double aircraftElev,
269                                      double offsetDegrees, double distance )
270 {
271     // assumptions we model the standard service volume, plus
272
273     // altitude difference
274     // double alt = ( aircraftElev * SG_METER_TO_FEET - stationElev );
275     double offset = fabs( offsetDegrees );
276
277     if ( offset < 10 ) {
278         return FG_ILS_DEFAULT_RANGE;
279     } else if ( offset < 35 ) {
280         return 10 + (35 - offset) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
281     } else if ( offset < 45 ) {
282         return (45 - offset);
283     } else if ( offset > 170 ) {
284         return FG_ILS_DEFAULT_RANGE;
285     } else if ( offset > 145 ) {
286         return 10 + (offset - 145) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
287     } else if ( offset > 135 ) {
288         return (offset - 135);
289     } else {
290         return 0;
291     }
292 }
293
294
295 // Update the various nav values based on position and valid tuned in navs
296 void 
297 FGNavCom::update(double dt) 
298 {
299     double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
300     double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
301     double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
302
303     need_update = false;
304
305     Point3D aircraft = sgGeodToCart( Point3D( lon, lat, elev ) );
306     Point3D station;
307     double az1, az2, s;
308
309     ////////////////////////////////////////////////////////////////////////
310     // Nav.
311     ////////////////////////////////////////////////////////////////////////
312
313     if ( nav_valid ) {
314         station = Point3D( nav_x, nav_y, nav_z );
315         nav_loc_dist = aircraft.distance3D( station );
316
317         if ( nav_has_gs ) {
318             station = Point3D( nav_gs_x, nav_gs_y, nav_gs_z );
319             nav_gs_dist = aircraft.distance3D( station );
320         } else {
321             nav_gs_dist = 0.0;
322         }
323         
324         // wgs84 heading
325         geo_inverse_wgs_84( elev, lat * SGD_RADIANS_TO_DEGREES, lon * SGD_RADIANS_TO_DEGREES, 
326                             nav_loclat, nav_loclon,
327                             &az1, &az2, &s );
328         // cout << "az1 = " << az1 << " magvar = " << nav_magvar << endl;
329         nav_heading = az1 - nav_magvar;
330         // cout << " heading = " << nav_heading
331         //      << " dist = " << nav_dist << endl;
332
333         if ( nav_loc ) {
334             double offset = nav_heading - nav_radial;
335             while ( offset < -180.0 ) { offset += 360.0; }
336             while ( offset > 180.0 ) { offset -= 360.0; }
337             // cout << "ils offset = " << offset << endl;
338             nav_effective_range = adjustILSRange(nav_elev, elev, offset,
339                                                   nav_loc_dist * SG_METER_TO_NM );
340         } else {
341             nav_effective_range = adjustNavRange(nav_elev, elev, nav_range);
342         }
343         // cout << "nav range = " << nav_effective_range
344         //      << " (" << nav_range << ")" << endl;
345
346         if ( nav_loc_dist < nav_effective_range * SG_NM_TO_METER ) {
347             nav_inrange = true;
348         } else if ( nav_loc_dist < 2 * nav_effective_range * SG_NM_TO_METER ) {
349             nav_inrange = sg_random() < 
350                 ( 2 * nav_effective_range * SG_NM_TO_METER - nav_loc_dist ) /
351                 (nav_effective_range * SG_NM_TO_METER);
352         } else {
353             nav_inrange = false;
354         }
355
356         if ( !nav_loc ) {
357             nav_radial = nav_sel_radial;
358         }
359     } else {
360         nav_inrange = false;
361         // cout << "not picking up vor. :-(" << endl;
362     }
363
364 #ifdef ENABLE_AUDIO_SUPPORT
365     if ( nav_valid && nav_inrange ) {
366         // play station ident via audio system if on + ident,
367         // otherwise turn it off
368         if ( nav_vol_btn > 0.1 && nav_ident_btn ) {
369             FGSimpleSound *sound;
370             sound = globals->get_soundmgr()->find( nav_fx_name );
371             if ( sound != NULL ) {
372                 sound->set_volume( nav_vol_btn );
373             } else {
374                 SG_LOG( SG_COCKPIT, SG_ALERT,
375                         "Can't find nav-vor-ident sound" );
376             }
377             sound = globals->get_soundmgr()->find( dme_fx_name );
378             if ( sound != NULL ) {
379                 sound->set_volume( nav_vol_btn );
380             } else {
381                 SG_LOG( SG_COCKPIT, SG_ALERT,
382                         "Can't find nav-dme-ident sound" );
383             }
384             cout << "nav_last_time = " << nav_last_time << " ";
385             cout << "cur_time = " << globals->get_time_params()->get_cur_time();
386             if ( nav_last_time <
387                  globals->get_time_params()->get_cur_time() - 30 ) {
388                 nav_last_time = globals->get_time_params()->get_cur_time();
389                 nav_play_count = 0;
390             }
391             cout << " nav_play_count = " << nav_play_count << endl;
392             cout << "playing = "
393                  << globals->get_soundmgr()->is_playing(nav_fx_name)
394                  << endl;
395             if ( nav_play_count < 4 ) {
396                 // play VOR ident
397                 if ( !globals->get_soundmgr()->is_playing(nav_fx_name) ) {
398                     globals->get_soundmgr()->play_once( nav_fx_name );
399                     ++nav_play_count;
400                 }
401             } else if ( nav_play_count < 5 && nav_has_dme ) {
402                 // play DME ident
403                 if ( !globals->get_soundmgr()->is_playing(nav_fx_name) &&
404                      !globals->get_soundmgr()->is_playing(dme_fx_name) ) {
405                     globals->get_soundmgr()->play_once( dme_fx_name );
406                     ++nav_play_count;
407                 }
408             }
409         } else {
410             globals->get_soundmgr()->stop( nav_fx_name );
411             globals->get_soundmgr()->stop( dme_fx_name );
412         }
413     }
414 #endif
415
416 }
417
418
419 // Update current nav/adf radio stations based on current postition
420 void FGNavCom::search() 
421 {
422     double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
423     double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
424     double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
425
426     FGILS ils;
427     FGNav nav;
428
429     ////////////////////////////////////////////////////////////////////////
430     // Nav.
431     ////////////////////////////////////////////////////////////////////////
432
433     if ( current_ilslist->query( lon, lat, elev, nav_freq, &ils ) ) {
434         nav_ident = ils.get_locident();
435         nav_valid = true;
436         if ( last_nav_ident != nav_ident || last_nav_vor ) {
437             nav_trans_ident = ils.get_trans_ident();
438             last_nav_ident = nav_ident;
439             last_nav_vor = false;
440             nav_loc = true;
441             nav_has_dme = ils.get_has_dme();
442             nav_has_gs = ils.get_has_gs();
443
444             nav_loclon = ils.get_loclon();
445             nav_loclat = ils.get_loclat();
446             nav_gslon = ils.get_gslon();
447             nav_gslat = ils.get_gslat();
448             nav_elev = ils.get_gselev();
449             nav_magvar = 0;
450             nav_range = FG_ILS_DEFAULT_RANGE;
451             nav_effective_range = nav_range;
452             nav_target_gs = ils.get_gsangle();
453             nav_radial = ils.get_locheading();
454             while ( nav_radial <   0.0 ) { nav_radial += 360.0; }
455             while ( nav_radial > 360.0 ) { nav_radial -= 360.0; }
456             nav_x = ils.get_x();
457             nav_y = ils.get_y();
458             nav_z = ils.get_z();
459             nav_gs_x = ils.get_gs_x();
460             nav_gs_y = ils.get_gs_y();
461             nav_gs_z = ils.get_gs_z();
462
463 #ifdef ENABLE_AUDIO_SUPPORT
464             if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
465                 globals->get_soundmgr()->remove( nav_fx_name );
466             }
467             FGSimpleSound *sound;
468             sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY );
469             sound->set_volume( 0.3 );
470             globals->get_soundmgr()->add( sound, nav_fx_name );
471
472             if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
473                 globals->get_soundmgr()->remove( dme_fx_name );
474             }
475             sound = morse.make_ident( nav_trans_ident, HI_FREQUENCY );
476             sound->set_volume( 0.3 );
477             globals->get_soundmgr()->add( sound, dme_fx_name );
478
479             int offset = (int)(sg_random() * 30.0);
480             nav_play_count = offset / 4;
481             nav_last_time = globals->get_time_params()->get_cur_time() -
482                 offset;
483             cout << "offset = " << offset << " play_count = "
484                  << nav_play_count
485                  << " nav_last_time = " << nav_last_time
486                  << " current time = "
487                  << globals->get_time_params()->get_cur_time() << endl;
488 #endif
489
490             // cout << "Found an ils station in range" << endl;
491             // cout << " id = " << ils.get_locident() << endl;
492         }
493     } else if ( current_navlist->query( lon, lat, elev, nav_freq, &nav ) ) {
494         nav_ident = nav.get_ident();
495         nav_valid = true;
496         if ( last_nav_ident != nav_ident || !last_nav_vor ) {
497             last_nav_ident = nav_ident;
498             last_nav_vor = true;
499             nav_trans_ident = nav.get_trans_ident();
500             nav_loc = false;
501             nav_has_dme = nav.get_has_dme();
502             nav_has_gs = false;
503             nav_loclon = nav.get_lon();
504             nav_loclat = nav.get_lat();
505             nav_elev = nav.get_elev();
506             nav_magvar = nav.get_magvar();
507             nav_range = nav.get_range();
508             nav_effective_range = adjustNavRange(nav_elev, elev, nav_range);
509             nav_target_gs = 0.0;
510             nav_radial = nav_sel_radial;
511             nav_x = nav.get_x();
512             nav_y = nav.get_y();
513             nav_z = nav.get_z();
514
515 #ifdef ENABLE_AUDIO_SUPPORT
516             if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
517                 globals->get_soundmgr()->remove( nav_fx_name );
518             }
519             FGSimpleSound *sound;
520             sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY );
521             sound->set_volume( 0.3 );
522             if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) {
523                 cout << "Added nav-vor-ident sound" << endl;
524             } else {
525                 cout << "Failed to add v1-vor-ident sound" << endl;
526             }
527
528             if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
529                 globals->get_soundmgr()->remove( dme_fx_name );
530             }
531             sound = morse.make_ident( nav_trans_ident, HI_FREQUENCY );
532             sound->set_volume( 0.3 );
533             globals->get_soundmgr()->add( sound, dme_fx_name );
534
535             int offset = (int)(sg_random() * 30.0);
536             nav_play_count = offset / 4;
537             nav_last_time = globals->get_time_params()->get_cur_time() -
538                 offset;
539             cout << "offset = " << offset << " play_count = "
540                  << nav_play_count << " nav_last_time = "
541                  << nav_last_time << " current time = "
542                  << globals->get_time_params()->get_cur_time() << endl;
543 #endif
544
545             // cout << "Found a vor station in range" << endl;
546             // cout << " id = " << nav.get_ident() << endl;
547         }
548     } else {
549         nav_valid = false;
550         nav_ident = "";
551         nav_radial = 0;
552         nav_trans_ident = "";
553         last_nav_ident = "";
554 #ifdef ENABLE_AUDIO_SUPPORT
555         if ( ! globals->get_soundmgr()->remove( nav_fx_name ) ) {
556             cout << "Failed to remove nav-vor-ident sound" << endl;
557         }
558         globals->get_soundmgr()->remove( dme_fx_name );
559 #endif
560         // cout << "not picking up vor1. :-(" << endl;
561     }
562 }
563
564
565 // return the amount of heading needle deflection, returns a value
566 // clamped to the range of ( -10 , 10 )
567 double FGNavCom::get_nav_heading_needle_deflection() const {
568     double r;
569
570     if ( nav_inrange ) {
571         r = nav_heading - nav_radial;
572         // cout << "Radial = " << nav_radial 
573         //      << "  Bearing = " << nav_heading << endl;
574     
575         while ( r >  180.0 ) { r -= 360.0;}
576         while ( r < -180.0 ) { r += 360.0;}
577         if ( fabs(r) > 90.0 ) {
578             r = ( r<0.0 ? -r-180.0 : -r+180.0 );
579             if ( nav_loc ) {
580                 r = -r;
581             }
582         }
583
584         // According to Robin Peel, the ILS is 4x more sensitive than a vor
585         if ( nav_loc ) { r *= 4.0; }
586         if ( r < -10.0 ) { r = -10.0; }
587         if ( r >  10.0 ) { r = 10.0; }
588     } else {
589         r = 0.0;
590     }
591
592     return r;
593 }
594
595
596 // return the amount of glide slope needle deflection (.i.e. the
597 // number of degrees we are off the glide slope * 5.0
598 double FGNavCom::get_nav_gs_needle_deflection() const {
599     if ( nav_inrange && nav_has_gs ) {
600         double x = nav_gs_dist;
601         double y = (fgGetDouble("/position/altitude-ft") - nav_elev)
602             * SG_FEET_TO_METER;
603         double angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES;
604         return (nav_target_gs - angle) * 5.0;
605     } else {
606         return 0.0;
607     }
608 }
609
610
611 /**
612  * Return true if the NAV TO flag should be active.
613  */
614 bool 
615 FGNavCom::get_nav_to_flag () const
616 {
617   if (nav_inrange) {
618     double offset = fabs(nav_heading - nav_radial);
619     if (nav_loc)
620       return true;
621     else
622       return (offset <= 90.0 || offset >= 270.0);
623   } else {
624     return false;
625   }
626 }
627
628
629 /**
630  * Return true if the NAV FROM flag should be active.
631  */
632 bool
633 FGNavCom::get_nav_from_flag () const
634 {
635   if (nav_inrange) {
636     double offset = fabs(nav_heading - nav_radial);
637     if (nav_loc)
638       return false;
639     else
640       return (offset > 90.0 && offset < 270.0);
641   } else {
642     return false;
643   }
644 }