1 // navradio.hxx -- class to manage a nav radio instance
3 // Written by Curtis Olson, started April 2000.
5 // Copyright (C) 2000 - 2002 Curtis L. Olson - http://www.flightgear.org/~curt
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 #ifndef _FG_NAVRADIO_HXX
25 #define _FG_NAVRADIO_HXX
28 #include <Main/fg_props.hxx>
30 #include <simgear/compiler.h>
31 #include <simgear/structure/subsystem_mgr.hxx>
32 #include <simgear/math/interpolater.hxx>
33 #include <simgear/timing/timestamp.hxx>
35 #include <Navaids/navlist.hxx>
36 #include <Sound/morse.hxx>
38 class FGNavRadio : public SGSubsystem
42 SGInterpTable *term_tbl;
43 SGInterpTable *low_tbl;
44 SGInterpTable *high_tbl;
46 SGPropertyNode *lon_node;
47 SGPropertyNode *lat_node;
48 SGPropertyNode *alt_node;
49 SGPropertyNode *bus_power;
50 SGPropertyNode *nav_serviceable;
51 SGPropertyNode *cdi_serviceable, *gs_serviceable, *tofrom_serviceable;
58 int index; // used for property binding
59 char nav_fx_name[256];
60 char dme_fx_name[256];
68 string nav_trans_ident;
76 double nav_heading; // true heading to nav station
77 double nav_radial; // current radial we are on (taking
78 // into consideration the vor station
79 // alignment which likely doesn't
80 // match the magnetic alignment
82 double nav_sel_radial;
83 double nav_target_radial;
84 double nav_target_radial_true;
85 double nav_target_auto_hdg;
94 double nav_elev; // use gs elev if available
100 double nav_gs_dist_signed;
101 double nav_gs_rate_of_climb;
102 SGTimeStamp prev_time;
103 SGTimeStamp curr_time;
105 double nav_effective_range;
106 double nav_target_gs;
116 // internal periodic station search timer
117 double _time_before_search_sec;
119 // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
120 double adjustNavRange( double stationElev, double aircraftElev,
121 double nominalRange );
123 // model standard ILS service volumes as per AIM 1-1-9
124 double adjustILSRange( double stationElev, double aircraftElev,
125 double offsetDegrees, double distance );
129 FGNavRadio(SGPropertyNode *node);
135 void update (double dt);
137 // Update nav/adf radios based on current postition
140 inline void set_bind_index( int i ) {
142 sprintf( nav_fx_name, "nav%d-vor-ident", index );
143 sprintf( dme_fx_name, "dme%d-vor-ident", index );
147 inline void set_power_btn( bool val ) { power_btn = val; }
148 inline void set_audio_btn( bool val ) { audio_btn = val; }
151 inline void set_nav_freq( double freq ) {
152 nav_freq = freq; need_update = true;
154 inline void set_nav_alt_freq( double freq ) { nav_alt_freq = freq; }
155 inline void set_nav_sel_radial( double radial ) {
156 nav_sel_radial = radial; need_update = true;
158 inline void set_nav_vol_btn( double val ) {
159 if ( val < 0.0 ) val = 0.0;
160 if ( val > 1.0 ) val = 1.0;
163 inline void set_nav_ident_btn( bool val ) { nav_ident_btn = val; }
166 inline bool has_power() const {
167 return power_btn && (bus_power->getDoubleValue() > 1.0);
169 inline bool get_power_btn() const { return power_btn; }
170 inline bool get_audio_btn() const { return audio_btn; }
173 inline double get_nav_freq () const { return nav_freq; }
174 inline double get_nav_alt_freq () const { return nav_alt_freq; }
175 inline double get_nav_sel_radial() const { return nav_sel_radial; }
176 inline double get_nav_target_radial() const { return nav_target_radial; }
177 inline double get_nav_target_radial_true() const {
178 return nav_target_radial_true;
180 inline double get_nav_target_auto_hdg() const {
181 return nav_target_auto_hdg;
184 // Calculated values.
185 inline bool get_nav_inrange() const { return nav_inrange; }
186 bool get_nav_to_flag () const;
187 bool get_nav_from_flag () const;
188 inline bool get_nav_has_dme() const { return nav_has_dme; }
189 inline bool get_nav_dme_inrange () const {
190 return nav_inrange && nav_has_dme;
192 inline bool get_nav_has_gs() const { return nav_has_gs; }
193 inline bool get_nav_loc() const { return nav_loc; }
194 inline double get_nav_loclon() const { return nav_loclon; }
195 inline double get_nav_loclat() const { return nav_loclat; }
196 inline double get_nav_loc_dist() const { return nav_loc_dist; }
197 inline double get_nav_gslon() const { return nav_gslon; }
198 inline double get_nav_gslat() const { return nav_gslat; }
199 inline double get_nav_gs_dist() const { return nav_gs_dist; }
200 inline double get_nav_gs_dist_signed() const { return nav_gs_dist_signed; }
201 inline double get_nav_gs_rate_of_climb() const {
202 return nav_gs_rate_of_climb;
204 inline double get_nav_elev() const { return nav_elev; }
205 double get_nav_heading() const;
206 double get_nav_radial() const;
207 double get_nav_reciprocal_radial() const;
208 inline double get_nav_target_gs() const { return nav_target_gs; }
209 inline double get_nav_twist() const { return nav_twist; }
210 double get_nav_cdi_deflection() const;
211 double get_nav_cdi_xtrack_error() const;
212 double get_nav_gs_deflection() const;
213 inline double get_nav_vol_btn() const { return nav_vol_btn; }
214 inline bool get_nav_ident_btn() const { return nav_ident_btn; }
215 inline const char * get_nav_id() const { return nav_id.c_str(); }
216 inline int get_nav_id_c1() const { return nav_id.c_str()[0]; }
217 inline int get_nav_id_c2() const { return nav_id.c_str()[1]; }
218 inline int get_nav_id_c3() const { return nav_id.c_str()[2]; }
219 inline int get_nav_id_c4() const { return nav_id.c_str()[3]; }
223 #endif // _FG_NAVRADIO_HXX