]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/navradio.hxx
dcea24a1e6c739c1864dae4b6584a3736c2297aa
[flightgear.git] / src / Instrumentation / navradio.hxx
1 // navradio.hxx -- class to manage a nav radio instance
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000 - 2002  Curtis L. Olson - http://www.flightgear.org/~curt
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 #ifndef _FG_NAVRADIO_HXX
25 #define _FG_NAVRADIO_HXX
26
27
28 #include <Main/fg_props.hxx>
29
30 #include <simgear/compiler.h>
31 #include <simgear/structure/subsystem_mgr.hxx>
32 #include <simgear/math/interpolater.hxx>
33 #include <simgear/timing/timestamp.hxx>
34
35 #include <Navaids/navlist.hxx>
36 #include <Sound/morse.hxx>
37
38 class FGNavRadio : public SGSubsystem
39 {
40     FGMorse morse;
41
42     SGInterpTable *term_tbl;
43     SGInterpTable *low_tbl;
44     SGInterpTable *high_tbl;
45
46     SGPropertyNode *lon_node;
47     SGPropertyNode *lat_node;
48     SGPropertyNode *alt_node;
49     SGPropertyNode *bus_power;
50
51     // inputs
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;
59
60     // outputs
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
68                                   // exactly.)
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;
90
91     // unfiled
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;
96
97     string last_nav_id;
98     bool last_nav_vor;
99     int nav_play_count;
100     time_t nav_last_time;
101
102     int index;                  // used for property binding
103     string nav_fx_name;
104     string dme_fx_name;
105
106     // internal (unexported) values
107     string nav_trans_ident;
108     bool nav_valid;
109     bool nav_has_dme;
110     double nav_target_radial;
111     double nav_loclon;
112     double nav_loclat;
113     double nav_x;
114     double nav_y;
115     double nav_z;
116     double nav_gslon;
117     double nav_gslat;
118     double nav_elev;            // use gs elev if available
119     double nav_gs_x;
120     double nav_gs_y;
121     double nav_gs_z;
122     sgdVec3 gs_base_vec;
123     double nav_gs_dist_signed;
124     SGTimeStamp prev_time;
125     SGTimeStamp curr_time;
126     double nav_range;
127     double nav_effective_range;
128     double nav_target_gs;
129     double nav_twist;
130     double horiz_vel;
131     double last_x;
132
133     string name;
134     int num;
135
136     // internal periodic station search timer
137     double _time_before_search_sec;
138
139     // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
140     double adjustNavRange( double stationElev, double aircraftElev,
141                            double nominalRange );
142
143     // model standard ILS service volumes as per AIM 1-1-9
144     double adjustILSRange( double stationElev, double aircraftElev,
145                            double offsetDegrees, double distance );
146
147 public:
148
149     FGNavRadio(SGPropertyNode *node);
150     ~FGNavRadio();
151
152     void init ();
153     void bind ();
154     void unbind ();
155     void update (double dt);
156
157     // Update nav/adf radios based on current postition
158     void search ();
159 /*
160     inline void set_bind_index( int i ) {
161         index = i;
162         sprintf( nav_fx_name, "nav%d-vor-ident", index );
163         sprintf( dme_fx_name, "dme%d-vor-ident", index );
164     }
165 */
166
167     // NavCom Accessors
168     inline bool has_power() const {
169         return power_btn->getBoolValue() && (bus_power->getDoubleValue() > 1.0);
170     }
171
172     // NAV Accessors
173     inline double get_nav_target_radial() const { return nav_target_radial; }
174
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;
180     }
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]; }
194 };
195
196
197 #endif // _FG_NAVRADIO_HXX