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 "commradio.hxx"
40 #include "slip_skid_ball.hxx"
41 #include "transponder.hxx"
42 #include "turn_indicator.hxx"
43 #include "vertical_speed_indicator.hxx"
44 #include "inst_vertical_speed_indicator.hxx"
46 #include "mk_viii.hxx"
48 #include "rad_alt.hxx"
51 FGInstrumentMgr::FGInstrumentMgr () :
56 FGInstrumentMgr::~FGInstrumentMgr ()
60 SGSubsystem::InitStatus FGInstrumentMgr::incrementalInit()
66 void FGInstrumentMgr::init()
68 SGPropertyNode_ptr config_props = new SGPropertyNode;
69 SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
71 SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
75 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
76 SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
79 readProperties( config.str(), config_props );
80 if (!build(config_props)) {
82 "Detected an internal inconsistency in the instrumentation\n"
83 "system specification file. See earlier errors for details.");
85 } catch (const sg_exception& e) {
86 SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
87 << config.str() << ":" << e.getFormattedMessage() );
92 SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument");
93 SGPropertyNode_ptr nd(new SGPropertyNode);
94 nd->setStringValue("name", "gps");
95 nd->setIntValue("number", 0);
96 _instruments.push_back("gps[0]");
97 set_subsystem("gps[0]", new GPS(nd, true /* default GPS mode */));
100 // bind() created instruments before init.
101 for (unsigned int i=0; i<_instruments.size(); ++i) {
102 const std::string& nm(_instruments[i]);
103 SGSubsystem* instr = get_subsystem(nm);
107 SGSubsystemGroup::init();
110 bool FGInstrumentMgr::build (SGPropertyNode* config_props)
112 for ( int i = 0; i < config_props->nChildren(); ++i ) {
113 SGPropertyNode *node = config_props->getChild(i);
114 std::string name = node->getName();
116 std::ostringstream subsystemname;
117 subsystemname << "instrument-" << i << '-'
118 << node->getStringValue("name", name.c_str());
119 int index = node->getIntValue("number", 0);
121 subsystemname << '['<< index << ']';
122 std::string id = subsystemname.str();
124 if ( name == "adf" ) {
125 set_subsystem( id, new ADF( node ), 0.15 );
127 } else if ( name == "airspeed-indicator" ) {
128 set_subsystem( id, new AirspeedIndicator( node ) );
130 } else if ( name == "altimeter" ) {
131 set_subsystem( id, new Altimeter( node, "altimeter" ) );
133 } else if ( name == "attitude-indicator" ) {
134 set_subsystem( id, new AttitudeIndicator( node ) );
136 } else if ( name == "clock" ) {
137 set_subsystem( id, new Clock( node ), 0.25 );
139 } else if ( name == "dme" ) {
140 set_subsystem( id, new DME( node ), 1.0 );
142 } else if ( name == "encoder" ) {
143 set_subsystem( id, new Altimeter( node, "encoder" ), 0.15 );
145 } else if ( name == "gps" ) {
146 // post 2.12.0, add a new name (distinct from 'gps'), so
147 // it is possible to create non-default GPS instruments.
148 // then authors of realistic GPS and FMSs can transition to using
149 // that name as they choose.
150 set_subsystem( id, new GPS( node, true /* default GPS mode */ ) );
152 } else if ( name == "gsdi" ) {
153 set_subsystem( id, new GSDI( node ) );
155 } else if ( name == "heading-indicator" ) {
156 set_subsystem( id, new HeadingIndicator( node ) );
158 } else if ( name == "heading-indicator-fg" ) {
159 set_subsystem( id, new HeadingIndicatorFG( node ) );
161 } else if ( name == "heading-indicator-dg" ) {
162 set_subsystem( id, new HeadingIndicatorDG( node ) );
164 } else if ( name == "KR-87" ) {
165 set_subsystem( id, new FGKR_87( node ) );
167 } else if ( name == "magnetic-compass" ) {
168 set_subsystem( id, new MagCompass( node ) );
170 } else if ( name == "marker-beacon" ) {
171 set_subsystem( id, new FGMarkerBeacon( node ), 0.2 );
173 } else if ( name == "comm-radio" ) {
174 set_subsystem( id, Instrumentation::CommRadio::createInstance( node ) );
176 } else if ( name == "nav-radio" ) {
177 set_subsystem( id, Instrumentation::NavRadio::createInstance( node ) );
179 } else if ( name == "slip-skid-ball" ) {
180 set_subsystem( id, new SlipSkidBall( node ), 0.03 );
182 } else if (( name == "transponder" ) || ( name == "KT-70" )) {
183 if (name == "KT-70") {
184 SG_LOG(SG_INSTR, SG_WARN, "KT-70 legacy instrument compatibility. "
185 "Please update aircraft to use transponder directly");
186 // force configuration into compatibility mode
187 node->setBoolValue("kt70-compatibility", true);
189 set_subsystem( id, new Transponder( node ), 0.2 );
191 } else if ( name == "turn-indicator" ) {
192 set_subsystem( id, new TurnIndicator( node ) );
194 } else if ( name == "vertical-speed-indicator" ) {
195 set_subsystem( id, new VerticalSpeedIndicator( node ) );
197 } else if ( name == "inst-vertical-speed-indicator" ) {
198 set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
200 } else if ( name == "tacan" ) {
201 set_subsystem( id, new TACAN( node ), 0.2 );
203 } else if ( name == "mk-viii" ) {
204 set_subsystem( id, new MK_VIII( node ), 0.2);
206 } else if ( name == "master-reference-gyro" ) {
207 set_subsystem( id, new MasterReferenceGyro( node ) );
209 } else if (( name == "groundradar" ) ||
210 ( name == "radar" ) ||
211 ( name == "air-ground-radar" ) ||
212 ( name == "navigation-display" ))
214 // these instruments are handled by the CockpitDisplayManager
215 // catch them here so we can still warn about bogus names in
216 // the instruments file
218 } else if ( name == "radar-altimeter" ) {
219 set_subsystem( id, new RadarAltimeter( node ) );
221 } else if ( name == "tcas" ) {
222 set_subsystem( id, new TCAS( node ), 0.2);
225 SG_LOG( SG_INSTR, SG_ALERT, "Unknown top level section: "
230 // only push to our array if we actually built an insturment
231 _instruments.push_back(id);
232 } // of instruments iteration
236 // end of instrument_manager.cxx