1 // instrument_mgr.cxx - manage aircraft instruments.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain and comes with no warranty.
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>
19 #include <Main/fg_props.hxx>
20 #include <Main/globals.hxx>
21 #include <Main/util.hxx>
23 #include "instrument_mgr.hxx"
25 #include "airspeed_indicator.hxx"
26 #include "altimeter.hxx"
27 #include "attitude_indicator.hxx"
32 #include "heading_indicator.hxx"
33 #include "heading_indicator_fg.hxx"
34 #include "heading_indicator_dg.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"
45 #include "mk_viii.hxx"
47 #include "rad_alt.hxx"
50 FGInstrumentMgr::FGInstrumentMgr () :
55 FGInstrumentMgr::~FGInstrumentMgr ()
59 SGSubsystem::InitStatus FGInstrumentMgr::incrementalInit()
65 void FGInstrumentMgr::init()
67 SGPropertyNode_ptr config_props = new SGPropertyNode;
68 SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
70 SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
74 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
75 SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
78 readProperties( config.str(), config_props );
79 if (!build(config_props)) {
81 "Detected an internal inconsistency in the instrumentation\n"
82 "system specification file. See earlier errors for details.");
84 } catch (const sg_exception& e) {
85 SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
86 << config.str() << ":" << e.getFormattedMessage() );
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 */));
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);
106 SGSubsystemGroup::init();
109 bool FGInstrumentMgr::build (SGPropertyNode* config_props)
111 for ( int i = 0; i < config_props->nChildren(); ++i ) {
112 SGPropertyNode *node = config_props->getChild(i);
113 std::string name = node->getName();
115 std::ostringstream subsystemname;
116 subsystemname << "instrument-" << i << '-'
117 << node->getStringValue("name", name.c_str());
118 int index = node->getIntValue("number", 0);
120 subsystemname << '['<< index << ']';
121 std::string id = subsystemname.str();
123 if ( name == "adf" ) {
124 set_subsystem( id, new ADF( node ), 0.15 );
126 } else if ( name == "airspeed-indicator" ) {
127 set_subsystem( id, new AirspeedIndicator( node ) );
129 } else if ( name == "altimeter" ) {
130 set_subsystem( id, new Altimeter( node, "altimeter" ) );
132 } else if ( name == "attitude-indicator" ) {
133 set_subsystem( id, new AttitudeIndicator( node ) );
135 } else if ( name == "clock" ) {
136 set_subsystem( id, new Clock( node ), 0.25 );
138 } else if ( name == "dme" ) {
139 set_subsystem( id, new DME( node ), 1.0 );
141 } else if ( name == "encoder" ) {
142 set_subsystem( id, new Altimeter( node, "encoder" ), 0.15 );
144 } else if ( name == "gps" ) {
145 // post 2.12.0, add a new name (distinct from 'gps'), so
146 // it is possible to create non-default GPS instruments.
147 // then authors of realistic GPS and FMSs can transition to using
148 // that name as they choose.
149 set_subsystem( id, new GPS( node, true /* default GPS mode */ ) );
151 } else if ( name == "gsdi" ) {
152 set_subsystem( id, new GSDI( node ) );
154 } else if ( name == "heading-indicator" ) {
155 set_subsystem( id, new HeadingIndicator( node ) );
157 } else if ( name == "heading-indicator-fg" ) {
158 set_subsystem( id, new HeadingIndicatorFG( node ) );
160 } else if ( name == "heading-indicator-dg" ) {
161 set_subsystem( id, new HeadingIndicatorDG( node ) );
163 } else if ( name == "KR-87" ) {
164 set_subsystem( id, new FGKR_87( node ) );
166 } else if ( name == "magnetic-compass" ) {
167 set_subsystem( id, new MagCompass( node ) );
169 } else if ( name == "marker-beacon" ) {
170 set_subsystem( id, new FGMarkerBeacon( node ), 0.2 );
172 } else if ( name == "nav-radio" ) {
173 set_subsystem( id, Instrumentation::NavRadio::createInstance( node ) );
175 } else if ( name == "slip-skid-ball" ) {
176 set_subsystem( id, new SlipSkidBall( node ), 0.03 );
178 } else if (( name == "transponder" ) || ( name == "KT-70" )) {
179 if (name == "KT-70") {
180 SG_LOG(SG_INSTR, SG_WARN, "KT-70 legacy instrument compatibility. "
181 "Please update aircraft to use transponder directly");
182 // force configuration into compatibility mode
183 node->setBoolValue("kt70-compatibility", true);
185 set_subsystem( id, new Transponder( node ), 0.2 );
187 } else if ( name == "turn-indicator" ) {
188 set_subsystem( id, new TurnIndicator( node ) );
190 } else if ( name == "vertical-speed-indicator" ) {
191 set_subsystem( id, new VerticalSpeedIndicator( node ) );
193 } else if ( name == "inst-vertical-speed-indicator" ) {
194 set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
196 } else if ( name == "tacan" ) {
197 set_subsystem( id, new TACAN( node ), 0.2 );
199 } else if ( name == "mk-viii" ) {
200 set_subsystem( id, new MK_VIII( node ), 0.2);
202 } else if ( name == "master-reference-gyro" ) {
203 set_subsystem( id, new MasterReferenceGyro( node ) );
205 } else if (( name == "groundradar" ) ||
206 ( name == "radar" ) ||
207 ( name == "air-ground-radar" ) ||
208 ( name == "navigation-display" ))
210 // these instruments are handled by the CockpitDisplayManager
211 // catch them here so we can still warn about bogus names in
212 // the instruments file
214 } else if ( name == "radar-altimeter" ) {
215 set_subsystem( id, new RadarAltimeter( node ) );
217 } else if ( name == "tcas" ) {
218 set_subsystem( id, new TCAS( node ), 0.2);
221 SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
226 // only push to our array if we actually built an insturment
227 _instruments.push_back(id);
228 } // of instruments iteration
232 // end of instrument_manager.cxx