]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/navradio.hxx
Merge branch 'vivian/cullsetting'
[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 #include "Sound/morse.hxx"
30
31 #include <simgear/compiler.h>
32 #include <simgear/structure/subsystem_mgr.hxx>
33 #include <simgear/timing/timestamp.hxx>
34
35 // forward decls
36 class SGInterpTable;
37
38 class SGSampleGroup;
39 class FGNavRecord;
40 typedef SGSharedPtr<FGNavRecord> FGNavRecordPtr;
41
42 class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener
43 {
44     FGMorse morse;
45
46     SGInterpTable *term_tbl;
47     SGInterpTable *low_tbl;
48     SGInterpTable *high_tbl;
49
50     SGPropertyNode_ptr _radio_node;
51     SGPropertyNode_ptr lon_node;
52     SGPropertyNode_ptr lat_node;
53     SGPropertyNode_ptr alt_node;
54     SGPropertyNode_ptr bus_power_node;
55
56     // property inputs
57     SGPropertyNode_ptr is_valid_node;   // is station data valid (may be way out
58                                         // of range.)
59     SGPropertyNode_ptr power_btn_node;
60     SGPropertyNode_ptr freq_node;       // primary freq
61     SGPropertyNode_ptr alt_freq_node;   // standby freq
62     SGPropertyNode_ptr sel_radial_node; // selected radial
63     SGPropertyNode_ptr vol_btn_node;
64     SGPropertyNode_ptr ident_btn_node;
65     SGPropertyNode_ptr audio_btn_node;
66     SGPropertyNode_ptr backcourse_node;
67     SGPropertyNode_ptr nav_serviceable_node;
68     SGPropertyNode_ptr cdi_serviceable_node;
69     SGPropertyNode_ptr gs_serviceable_node;
70     SGPropertyNode_ptr tofrom_serviceable_node;
71     SGPropertyNode_ptr dme_serviceable_node;
72     
73     // property outputs
74     SGPropertyNode_ptr fmt_freq_node;     // formated frequency
75     SGPropertyNode_ptr fmt_alt_freq_node; // formated alternate frequency
76     SGPropertyNode_ptr heading_node;      // true heading to nav station
77     SGPropertyNode_ptr radial_node;       // current radial we are on (taking
78                                        // into consideration the vor station
79                                        // alignment which likely doesn't
80                                        // match the magnetic alignment
81                                        // exactly.)
82     SGPropertyNode_ptr recip_radial_node; // radial_node(val) + 180 (for
83                                        // convenience)
84     SGPropertyNode_ptr target_radial_true_node;
85                                        // true heading of selected radial
86     SGPropertyNode_ptr target_auto_hdg_node;
87                                        // suggested autopilot heading
88                                        // to intercept selected radial
89     SGPropertyNode_ptr time_to_intercept; // estimated time to intecept selected
90                                        // radial at current speed and heading
91     SGPropertyNode_ptr to_flag_node;
92     SGPropertyNode_ptr from_flag_node;
93     SGPropertyNode_ptr inrange_node;
94     SGPropertyNode_ptr signal_quality_norm_node;
95     SGPropertyNode_ptr cdi_deflection_node;
96     SGPropertyNode_ptr cdi_deflection_norm_node;
97     SGPropertyNode_ptr cdi_xtrack_error_node;
98     SGPropertyNode_ptr cdi_xtrack_hdg_err_node;
99     SGPropertyNode_ptr has_gs_node;
100     SGPropertyNode_ptr loc_node;
101     SGPropertyNode_ptr loc_dist_node;
102     SGPropertyNode_ptr gs_deflection_node;
103     SGPropertyNode_ptr gs_deflection_deg_node;
104     SGPropertyNode_ptr gs_deflection_norm_node;
105     SGPropertyNode_ptr gs_rate_of_climb_node;
106     SGPropertyNode_ptr gs_rate_of_climb_fpm_node;
107     SGPropertyNode_ptr gs_dist_node;
108     SGPropertyNode_ptr gs_inrange_node;
109     SGPropertyNode_ptr nav_id_node;
110     SGPropertyNode_ptr id_c1_node;
111     SGPropertyNode_ptr id_c2_node;
112     SGPropertyNode_ptr id_c3_node;
113     SGPropertyNode_ptr id_c4_node;
114
115     // gps slaving support
116     SGPropertyNode_ptr nav_slaved_to_gps_node;
117     SGPropertyNode_ptr gps_cdi_deflection_node;
118     SGPropertyNode_ptr gps_to_flag_node;
119     SGPropertyNode_ptr gps_from_flag_node;
120     SGPropertyNode_ptr gps_has_gs_node;
121     SGPropertyNode_ptr gps_course_node;
122     SGPropertyNode_ptr gps_xtrack_error_nm_node;
123     SGPropertyNode_ptr _magvarNode;
124     
125     // realism setting, are false courses and GS lobes enabled?
126     SGPropertyNode_ptr falseCoursesEnabledNode;
127
128     // internal (private) values
129
130     bool _operable; ///< is the unit serviceable, on, powered, etc
131     int play_count;
132     time_t last_time;
133     FGNavRecordPtr _navaid;
134     FGNavRecordPtr _gs;
135     
136     string nav_fx_name;
137     string dme_fx_name;
138
139     double target_radial;
140     SGTimeStamp prev_time;
141     SGTimeStamp curr_time;
142     double effective_range;
143     double target_gs;
144     double twist;
145     double horiz_vel;
146     double last_x;
147     double last_loc_dist;
148     double last_xtrack_error;
149     double xrate_ms;
150     double _localizerWidth; // cached localizer width in degrees
151     
152     string _name;
153     int _num;
154
155     // internal periodic station search timer
156     double _time_before_search_sec;
157
158     SGVec3d _gsCart, _gsAxis, _gsVertical;
159
160     FGNavRecordPtr _dme;
161     bool _dmeInRange;
162     
163     // CDI properties
164     bool _toFlag, _fromFlag;
165     double _cdiDeflection;
166     double _cdiCrossTrackErrorM;
167     double _gsNeedleDeflection;
168     double _gsNeedleDeflectionNorm;
169     
170     SGSharedPtr<SGSampleGroup> _sgr;
171     std::vector<SGPropertyNode_ptr> _tiedNodes;
172     
173     bool updateWithPower(double aDt);
174
175     // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
176     double adjustNavRange( double stationElev, double aircraftElev,
177                            double nominalRange );
178
179     // model standard ILS service volumes as per AIM 1-1-9
180     double adjustILSRange( double stationElev, double aircraftElev,
181                            double offsetDegrees, double distance );
182
183     void updateAudio();
184     void audioNavidChanged();
185
186     void updateReceiver(double dt);
187     void updateDME(const SGVec3d& aircraft);
188     void updateGlideSlope(double dt, const SGVec3d& aircraft, double signal_quality_norm);
189     void updateGPSSlaved();
190     void updateCDI(double dt);
191     
192     void clearOutputs();
193
194     FGNavRecord* findPrimaryNavaid(const SGGeod& aPos, double aFreqMHz);
195     
196     /// accessor for tied, read-only 'operable' property
197     bool isOperable() const
198       { return _operable; }
199       
200     /**
201      * Tied-properties helper, record nodes which are tied for easy un-tie-ing
202      */
203     template <typename T>
204     void tie(const char* aRelPath, const SGRawValue<T>& aRawValue)
205     {
206       SGPropertyNode_ptr nd = _radio_node->getNode(aRelPath, true);
207       _tiedNodes.push_back(nd);
208       nd->tie(aRawValue);
209     }
210     
211   // implement SGPropertyChangeListener
212     virtual void valueChanged (SGPropertyNode * prop);
213 public:
214
215     FGNavRadio(SGPropertyNode *node);
216     ~FGNavRadio();
217
218     void init ();
219     void bind ();
220     void unbind ();
221     void update (double dt);
222
223     // Update nav/adf radios based on current postition
224     void search ();
225 };
226
227
228 #endif // _FG_NAVRADIO_HXX