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