]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/instrument_mgr.cxx
Transponder instrument replaces KT-70.
[flightgear.git] / src / Instrumentation / instrument_mgr.cxx
1 // instrument_mgr.cxx - manage aircraft instruments.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #ifdef HAVE_CONFIG_H
7 #  include <config.h>
8 #endif
9
10 #include <iostream>
11 #include <string>
12 #include <sstream>
13
14 #include <simgear/structure/exception.hxx>
15 #include <simgear/misc/sg_path.hxx>
16 #include <simgear/sg_inlines.h>
17 #include <simgear/props/props_io.hxx>
18
19 #include <Main/fg_props.hxx>
20 #include <Main/globals.hxx>
21 #include <Main/util.hxx>
22
23 #include "instrument_mgr.hxx"
24 #include "adf.hxx"
25 #include "airspeed_indicator.hxx"
26 #include "altimeter.hxx"
27 #include "attitude_indicator.hxx"
28 #include "clock.hxx"
29 #include "dme.hxx"
30 #include "gps.hxx"
31 #include "gsdi.hxx"
32 #include "heading_indicator.hxx"
33 #include "heading_indicator_fg.hxx"
34 #include "heading_indicator_dg.hxx"
35 #include "kr_87.hxx"
36 #include "mag_compass.hxx"
37 #include "marker_beacon.hxx"
38 #include "newnavradio.hxx"
39 #include "slip_skid_ball.hxx"
40 #include "transponder.hxx"
41 #include "turn_indicator.hxx"
42 #include "vertical_speed_indicator.hxx"
43 #include "inst_vertical_speed_indicator.hxx"
44 #include "tacan.hxx"
45 #include "mk_viii.hxx"
46 #include "mrg.hxx"
47 #include "rad_alt.hxx"
48 #include "tcas.hxx"
49
50 FGInstrumentMgr::FGInstrumentMgr () :
51   _explicitGps(false)
52 {    
53 }
54
55 FGInstrumentMgr::~FGInstrumentMgr ()
56 {
57 }
58
59 SGSubsystem::InitStatus FGInstrumentMgr::incrementalInit()
60 {
61   init();
62   return INIT_DONE;
63 }
64
65 void FGInstrumentMgr::init()
66 {
67   SGPropertyNode_ptr config_props = new SGPropertyNode;
68   SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
69   if (!path_n) {
70     SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
71     return;
72   }
73
74   SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
75   SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
76
77   try {
78     readProperties( config.str(), config_props );
79     if (!build(config_props)) {
80       throw sg_exception(
81                     "Detected an internal inconsistency in the instrumentation\n"
82                     "system specification file.  See earlier errors for details.");
83     }
84   } catch (const sg_exception& e) {
85     SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
86                     << config.str() << ":" << e.getFormattedMessage() );
87   }
88
89
90   if (!_explicitGps) {
91     SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument");
92     SGPropertyNode_ptr nd(new SGPropertyNode);
93     nd->setStringValue("name", "gps");
94     nd->setIntValue("number", 0);
95     _instruments.push_back("gps[0]");
96     set_subsystem("gps[0]", new GPS(nd, true /* default GPS mode */));
97   }
98
99   // bind() created instruments before init.
100   for (unsigned int i=0; i<_instruments.size(); ++i) {
101     const std::string& nm(_instruments[i]);
102     SGSubsystem* instr = get_subsystem(nm);
103     instr->bind();
104   }
105
106   SGSubsystemGroup::init();
107 }
108
109 bool FGInstrumentMgr::build (SGPropertyNode* config_props)
110 {
111     for ( int i = 0; i < config_props->nChildren(); ++i ) {
112         SGPropertyNode *node = config_props->getChild(i);
113         string name = node->getName();
114
115         std::ostringstream subsystemname;
116         subsystemname << "instrument-" << i << '-'
117                 << node->getStringValue("name", name.c_str());
118         int index = node->getIntValue("number", 0);
119         if (index > 0)
120             subsystemname << '['<< index << ']';
121         string id = subsystemname.str();
122       
123         if ( name == "adf" ) {
124             set_subsystem( id, new ADF( node ), 0.15 );
125
126         } else if ( name == "airspeed-indicator" ) {
127             set_subsystem( id, new AirspeedIndicator( node ) );
128
129         } else if ( name == "altimeter" ) {
130             set_subsystem( id, new Altimeter( node ) );
131
132         } else if ( name == "attitude-indicator" ) {
133             set_subsystem( id, new AttitudeIndicator( node ) );
134
135         } else if ( name == "clock" ) {
136             set_subsystem( id, new Clock( node ), 0.25 );
137
138         } else if ( name == "dme" ) {
139             set_subsystem( id, new DME( node ), 1.0 );
140
141         } else if ( name == "encoder" ) {
142             set_subsystem( id, new Altimeter( node ), 0.15 );
143
144         } else if ( name == "gps" ) {
145             set_subsystem( id, new GPS( node ) );
146             _explicitGps = true;
147         } else if ( name == "gsdi" ) {
148             set_subsystem( id, new GSDI( node ) );
149
150         } else if ( name == "heading-indicator" ) {
151             set_subsystem( id, new HeadingIndicator( node ) );
152
153         } else if ( name == "heading-indicator-fg" ) {
154             set_subsystem( id, new HeadingIndicatorFG( node ) );
155
156         } else if ( name == "heading-indicator-dg" ) {
157             set_subsystem( id, new HeadingIndicatorDG( node ) );
158
159         } else if ( name == "KR-87" ) {
160             set_subsystem( id, new FGKR_87( node ) );
161
162         } else if ( name == "magnetic-compass" ) {
163             set_subsystem( id, new MagCompass( node ) );
164
165         } else if ( name == "marker-beacon" ) {
166             set_subsystem( id, new FGMarkerBeacon( node ), 0.2 );
167
168         } else if ( name == "nav-radio" ) {
169             set_subsystem( id, Instrumentation::NavRadio::createInstance( node ) );
170
171         } else if ( name == "slip-skid-ball" ) {
172             set_subsystem( id, new SlipSkidBall( node ), 0.03 );
173
174         } else if (( name == "transponder" ) || ( name == "KT-70" )) {
175             if  (name == "KT-70") {
176                 SG_LOG(SG_INSTR, SG_WARN, "KT-70 legacy instrument compatability. "
177                        "Please update aircraft to use transponder directly");
178                 // force configuration into compatability mode
179                 node->setBoolValue("kt70-compatability", true);
180             }
181             set_subsystem( id, new Transponder( node ), 0.2 );
182
183         } else if ( name == "turn-indicator" ) {
184             set_subsystem( id, new TurnIndicator( node ) );
185
186         } else if ( name == "vertical-speed-indicator" ) {
187             set_subsystem( id, new VerticalSpeedIndicator( node ) );
188
189         } else if ( name == "inst-vertical-speed-indicator" ) {
190             set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
191
192         } else if ( name == "tacan" ) {
193             set_subsystem( id, new TACAN( node ), 0.2 );
194
195         } else if ( name == "mk-viii" ) {
196             set_subsystem( id, new MK_VIII( node ), 0.2);
197
198         } else if ( name == "master-reference-gyro" ) {
199             set_subsystem( id, new MasterReferenceGyro( node ) );
200
201         } else if (( name == "groundradar" ) ||
202                    ( name == "radar" ) ||
203                    ( name == "air-ground-radar" ) ||
204                    ( name == "navigation-display" ))
205         {
206         // these instruments are handled by the CockpitDisplayManager
207         // catch them here so we can still warn about bogus names in
208         // the instruments file
209           continue;
210         } else if ( name == "radar-altimeter" ) {
211             set_subsystem( id, new RadarAltimeter( node ) );
212
213         } else if ( name == "tcas" ) {
214             set_subsystem( id, new TCAS( node ), 0.2);
215             
216         } else {
217             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
218                     << name );
219             return false;
220         }
221       
222       // only push to our array if we actually built an insturment
223         _instruments.push_back(id);
224     } // of instruments iteration
225     return true;
226 }
227
228 // end of instrument_manager.cxx