]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/navradio.hxx
httpd: better handling of first-time notifications
[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 #include <Navaids/navaids_fwd.hxx>
28 #include <Main/fg_props.hxx>
29
30 #include <simgear/compiler.h>
31 #include <simgear/structure/subsystem_mgr.hxx>
32 #include <simgear/timing/timestamp.hxx>
33
34 class SGSampleGroup;
35
36 class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener
37 {
38     SGPropertyNode_ptr _radio_node;
39     SGPropertyNode_ptr bus_power_node;
40
41     // property inputs
42     SGPropertyNode_ptr is_valid_node;   // is station data valid (may be way out
43                                         // of range.)
44     SGPropertyNode_ptr power_btn_node;
45     SGPropertyNode_ptr freq_node;       // primary freq
46     SGPropertyNode_ptr alt_freq_node;   // standby freq
47     SGPropertyNode_ptr is_loc_freq_node;// is the primary freq a loc/gs (paired) freq?
48     SGPropertyNode_ptr sel_radial_node; // selected radial
49     SGPropertyNode_ptr vol_btn_node;
50     SGPropertyNode_ptr ident_btn_node;
51     SGPropertyNode_ptr audio_btn_node;
52     SGPropertyNode_ptr backcourse_node;
53     SGPropertyNode_ptr nav_serviceable_node;
54     SGPropertyNode_ptr cdi_serviceable_node;
55     SGPropertyNode_ptr gs_serviceable_node;
56     SGPropertyNode_ptr tofrom_serviceable_node;
57     
58     // property outputs
59     SGPropertyNode_ptr fmt_freq_node;     // formated frequency
60     SGPropertyNode_ptr fmt_alt_freq_node; // formated alternate frequency
61     SGPropertyNode_ptr heading_node;      // true heading to nav station
62     SGPropertyNode_ptr radial_node;       // current radial we are on (taking
63                                        // into consideration the vor station
64                                        // alignment which likely doesn't
65                                        // match the magnetic alignment
66                                        // exactly.)
67     SGPropertyNode_ptr recip_radial_node; // radial_node(val) + 180 (for
68                                        // convenience)
69     SGPropertyNode_ptr target_radial_true_node;
70                                        // true heading of selected radial
71     SGPropertyNode_ptr target_auto_hdg_node;
72                                        // suggested autopilot heading
73                                        // to intercept selected radial
74     SGPropertyNode_ptr time_to_intercept; // estimated time to intecept selected
75                                        // radial at current speed and heading
76     SGPropertyNode_ptr to_flag_node;
77     SGPropertyNode_ptr from_flag_node;
78     SGPropertyNode_ptr inrange_node;
79     SGPropertyNode_ptr signal_quality_norm_node;
80     SGPropertyNode_ptr cdi_deflection_node;
81     SGPropertyNode_ptr cdi_deflection_norm_node;
82     SGPropertyNode_ptr cdi_xtrack_error_node;
83     SGPropertyNode_ptr cdi_xtrack_hdg_err_node;
84     SGPropertyNode_ptr has_gs_node;
85     SGPropertyNode_ptr loc_node;
86     SGPropertyNode_ptr loc_dist_node;
87     SGPropertyNode_ptr gs_deflection_node;
88     SGPropertyNode_ptr gs_deflection_deg_node;
89     SGPropertyNode_ptr gs_deflection_norm_node;
90     SGPropertyNode_ptr gs_direct_node;
91     SGPropertyNode_ptr gs_rate_of_climb_node;
92     SGPropertyNode_ptr gs_rate_of_climb_fpm_node;
93     SGPropertyNode_ptr gs_dist_node;
94     SGPropertyNode_ptr gs_inrange_node;
95     SGPropertyNode_ptr nav_id_node;
96     SGPropertyNode_ptr id_c1_node;
97     SGPropertyNode_ptr id_c2_node;
98     SGPropertyNode_ptr id_c3_node;
99     SGPropertyNode_ptr id_c4_node;
100
101     // gps slaving support
102     SGPropertyNode_ptr nav_slaved_to_gps_node;
103     SGPropertyNode_ptr gps_cdi_deflection_node;
104     SGPropertyNode_ptr gps_to_flag_node;
105     SGPropertyNode_ptr gps_from_flag_node;
106     SGPropertyNode_ptr gps_has_gs_node;
107     SGPropertyNode_ptr gps_course_node;
108     SGPropertyNode_ptr gps_xtrack_error_nm_node;
109     SGPropertyNode_ptr _magvarNode;
110     
111     // realism setting, are false courses and GS lobes enabled?
112     SGPropertyNode_ptr falseCoursesEnabledNode;
113
114     // internal (private) values
115
116     bool _operable; ///< is the unit serviceable, on, powered, etc
117     int play_count;
118     bool _nav_search;
119     double _last_freq;
120     FGNavRecordRef _navaid;
121     FGNavRecordRef _gs;
122     
123     double target_radial;
124     double effective_range;
125     double target_gs;
126     double twist;
127     double horiz_vel;
128     double last_x;
129     double last_xtrack_error;
130     double xrate_ms;
131     double _localizerWidth; // cached localizer width in degrees
132     
133     std::string _name;
134     int _num;
135
136     // internal periodic station search timer
137     double _time_before_search_sec;
138
139     SGVec3d _gsCart, _gsAxis, _gsVertical, _gsBaseline;
140
141     // CDI properties
142     bool _toFlag, _fromFlag;
143     double _cdiDeflection;
144     double _cdiCrossTrackErrorM;
145     double _gsNeedleDeflection;
146     double _gsNeedleDeflectionNorm;
147     double _gsDirect;
148
149     class AudioIdent * _audioIdent;
150     
151     bool updateWithPower(double aDt);
152
153     // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
154     double adjustNavRange( double stationElev, double aircraftElev,
155                            double nominalRange );
156
157     // model standard ILS service volumes as per AIM 1-1-9
158     double adjustILSRange( double stationElev, double aircraftElev,
159                            double offsetDegrees, double distance );
160
161     void updateAudio( double dt );
162
163     void updateReceiver(double dt);
164     void updateGlideSlope(double dt, const SGVec3d& aircraft, double signal_quality_norm);
165     void updateGPSSlaved();
166     void updateCDI(double dt);
167     
168     void clearOutputs();
169
170     FGNavRecord* findPrimaryNavaid(const SGGeod& aPos, double aFreqMHz);
171     
172     /// accessor for tied, read-only 'operable' property
173     bool isOperable() const
174       { return _operable; }
175       
176   // implement SGPropertyChangeListener
177     virtual void valueChanged (SGPropertyNode * prop);
178 public:
179
180     FGNavRadio(SGPropertyNode *node);
181     ~FGNavRadio();
182
183     void init ();
184     void reinit ();
185     void bind ();
186     void unbind ();
187     void update (double dt);
188
189     // Update nav/adf radios based on current postition
190     void search ();
191     void updateNav();
192 };
193
194
195 #endif // _FG_NAVRADIO_HXX