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;
52 SGPropertyNode *power_btn;
53 SGPropertyNode *nav_freq; // primary freq
54 SGPropertyNode *nav_alt_freq; // standby freq
55 SGPropertyNode *nav_sel_radial; // selected radial
56 SGPropertyNode *nav_vol_btn;
57 SGPropertyNode *nav_ident_btn;
58 SGPropertyNode *audio_btn;
61 SGPropertyNode *fmt_freq; // formated frequency
62 SGPropertyNode *fmt_alt_freq; // formated alternate frequency
63 SGPropertyNode *nav_heading; // true heading to nav station
64 SGPropertyNode *nav_radial; // current radial we are on (taking
65 // into consideration the vor station
66 // alignment which likely doesn't
67 // match the magnetic alignment
69 SGPropertyNode *reciprocal_radial;
70 // nav_radial + 180 (convenience value)
71 SGPropertyNode *nav_target_radial_true;
72 // true heading of selected radial
73 SGPropertyNode *nav_target_auto_hdg;
74 SGPropertyNode *nav_to_flag;
75 SGPropertyNode *nav_from_flag;
76 SGPropertyNode *nav_inrange;
77 SGPropertyNode *nav_cdi_deflection;
78 SGPropertyNode *nav_cdi_xtrack_error;
79 SGPropertyNode *nav_has_gs;
80 SGPropertyNode *nav_loc;
81 SGPropertyNode *nav_loc_dist;
82 SGPropertyNode *nav_gs_deflection;
83 SGPropertyNode *nav_gs_rate_of_climb;
84 SGPropertyNode *nav_gs_dist;
85 SGPropertyNode *nav_id;
86 SGPropertyNode *nav_id_c1;
87 SGPropertyNode *nav_id_c2;
88 SGPropertyNode *nav_id_c3;
89 SGPropertyNode *nav_id_c4;
92 SGPropertyNode *nav_serviceable;
93 SGPropertyNode *cdi_serviceable, *gs_serviceable, *tofrom_serviceable;
94 SGPropertyNode *nav_slaved_to_gps;
95 SGPropertyNode *gps_cdi_deflection, *gps_to_flag, *gps_from_flag;
100 time_t nav_last_time;
102 int index; // used for property binding
106 // internal (unexported) values
107 string nav_trans_ident;
110 double nav_target_radial;
118 double nav_elev; // use gs elev if available
123 double nav_gs_dist_signed;
124 SGTimeStamp prev_time;
125 SGTimeStamp curr_time;
127 double nav_effective_range;
128 double nav_target_gs;
136 // internal periodic station search timer
137 double _time_before_search_sec;
139 // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
140 double adjustNavRange( double stationElev, double aircraftElev,
141 double nominalRange );
143 // model standard ILS service volumes as per AIM 1-1-9
144 double adjustILSRange( double stationElev, double aircraftElev,
145 double offsetDegrees, double distance );
149 FGNavRadio(SGPropertyNode *node);
155 void update (double dt);
157 // Update nav/adf radios based on current postition
160 inline void set_bind_index( int i ) {
162 sprintf( nav_fx_name, "nav%d-vor-ident", index );
163 sprintf( dme_fx_name, "dme%d-vor-ident", index );
168 inline bool has_power() const {
169 return power_btn->getBoolValue() && (bus_power->getDoubleValue() > 1.0);
173 inline double get_nav_target_radial() const { return nav_target_radial; }
175 // Calculated values.
176 bool get_nav_to_flag () const;
177 inline bool get_nav_has_dme() const { return nav_has_dme; }
178 inline bool get_nav_dme_inrange () const {
179 return nav_inrange->getBoolValue() && nav_has_dme;
181 inline double get_nav_loclon() const { return nav_loclon; }
182 inline double get_nav_loclat() const { return nav_loclat; }
183 inline double get_nav_gslon() const { return nav_gslon; }
184 inline double get_nav_gslat() const { return nav_gslat; }
185 inline double get_nav_gs_dist_signed() const { return nav_gs_dist_signed; }
186 inline double get_nav_elev() const { return nav_elev; }
187 inline double get_nav_target_gs() const { return nav_target_gs; }
188 inline double get_nav_twist() const { return nav_twist; }
189 //inline const char * get_nav_id() const { return nav_id.c_str(); }
190 //inline int get_nav_id_c1() const { return nav_id.c_str()[0]; }
191 //inline int get_nav_id_c2() const { return nav_id.c_str()[1]; }
192 //inline int get_nav_id_c3() const { return nav_id.c_str()[2]; }
193 //inline int get_nav_id_c4() const { return nav_id.c_str()[3]; }
197 #endif // _FG_NAVRADIO_HXX