]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/navradio.hxx
fix another crash on exit by finally converting the rest of unguarded
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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_ptr lon_node;
47     SGPropertyNode_ptr lat_node;
48     SGPropertyNode_ptr alt_node;
49     SGPropertyNode_ptr bus_power_node;
50
51     // property inputs
52     SGPropertyNode_ptr is_valid_node;   // is station data valid (may be way out
53                                      // of range.)
54     SGPropertyNode_ptr power_btn_node;
55     SGPropertyNode_ptr freq_node;       // primary freq
56     SGPropertyNode_ptr alt_freq_node;   // standby freq
57     SGPropertyNode_ptr sel_radial_node; // selected radial
58     SGPropertyNode_ptr vol_btn_node;
59     SGPropertyNode_ptr ident_btn_node;
60     SGPropertyNode_ptr audio_btn_node;
61     SGPropertyNode_ptr nav_serviceable_node;
62     SGPropertyNode_ptr cdi_serviceable_node;
63     SGPropertyNode_ptr gs_serviceable_node;
64     SGPropertyNode_ptr tofrom_serviceable_node;
65
66     // property outputs
67     SGPropertyNode_ptr fmt_freq_node;     // formated frequency
68     SGPropertyNode_ptr fmt_alt_freq_node; // formated alternate frequency
69     SGPropertyNode_ptr heading_node;      // true heading to nav station
70     SGPropertyNode_ptr radial_node;       // current radial we are on (taking
71                                        // into consideration the vor station
72                                        // alignment which likely doesn't
73                                        // match the magnetic alignment
74                                        // exactly.)
75     SGPropertyNode_ptr recip_radial_node; // radial_node(val) + 180 (for
76                                        // convenience)
77     SGPropertyNode_ptr target_radial_true_node;
78                                        // true heading of selected radial
79     SGPropertyNode_ptr target_auto_hdg_node;
80                                        // suggested autopilot heading
81                                        // to intercept selected radial
82     SGPropertyNode_ptr time_to_intercept; // estimated time to intecept selected
83                                        // radial at current speed and heading
84     SGPropertyNode_ptr to_flag_node;
85     SGPropertyNode_ptr from_flag_node;
86     SGPropertyNode_ptr inrange_node;
87     SGPropertyNode_ptr cdi_deflection_node;
88     SGPropertyNode_ptr cdi_xtrack_error_node;
89     SGPropertyNode_ptr cdi_xtrack_hdg_err_node;
90     SGPropertyNode_ptr has_gs_node;
91     SGPropertyNode_ptr loc_node;
92     SGPropertyNode_ptr loc_dist_node;
93     SGPropertyNode_ptr gs_deflection_node;
94     SGPropertyNode_ptr gs_rate_of_climb_node;
95     SGPropertyNode_ptr gs_dist_node;
96     SGPropertyNode_ptr nav_id_node;
97     SGPropertyNode_ptr id_c1_node;
98     SGPropertyNode_ptr id_c2_node;
99     SGPropertyNode_ptr id_c3_node;
100     SGPropertyNode_ptr id_c4_node;
101
102     // gps slaving support
103     SGPropertyNode_ptr nav_slaved_to_gps_node;
104     SGPropertyNode_ptr gps_cdi_deflection_node;
105     SGPropertyNode_ptr gps_to_flag_node;
106     SGPropertyNode_ptr gps_from_flag_node;
107
108     // internal (private) values
109
110     string last_nav_id;
111     bool last_nav_vor;
112     int play_count;
113     time_t last_time;
114
115     int index;                  // used for property binding
116     string nav_fx_name;
117     string dme_fx_name;
118
119     string trans_ident;
120     bool is_valid;
121     bool has_dme;
122     double radial;
123     double target_radial;
124     double loc_lon;
125     double loc_lat;
126     double nav_x;
127     double nav_y;
128     double nav_z;
129     double gs_lon;
130     double gs_lat;
131     double nav_elev;            // use gs elev if available
132     double gs_x;
133     double gs_y;
134     double gs_z;
135     sgdVec3 gs_base_vec;
136     double gs_dist_signed;
137     SGTimeStamp prev_time;
138     SGTimeStamp curr_time;
139     double range;
140     double effective_range;
141     double target_gs;
142     double twist;
143     double horiz_vel;
144     double last_x;
145     double last_loc_dist;
146     double last_xtrack_error;
147
148     string name;
149     int num;
150
151     // internal periodic station search timer
152     double _time_before_search_sec;
153
154     // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
155     double adjustNavRange( double stationElev, double aircraftElev,
156                            double nominalRange );
157
158     // model standard ILS service volumes as per AIM 1-1-9
159     double adjustILSRange( double stationElev, double aircraftElev,
160                            double offsetDegrees, double distance );
161
162 public:
163
164     FGNavRadio(SGPropertyNode *node);
165     ~FGNavRadio();
166
167     void init ();
168     void bind ();
169     void unbind ();
170     void update (double dt);
171
172     // Update nav/adf radios based on current postition
173     void search ();
174 };
175
176
177 #endif // _FG_NAVRADIO_HXX