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>
22 #include <Instrumentation/HUD/HUD.hxx>
24 #include "instrument_mgr.hxx"
26 #include "airspeed_indicator.hxx"
27 #include "altimeter.hxx"
28 #include "attitude_indicator.hxx"
33 #include "heading_indicator.hxx"
34 #include "heading_indicator_fg.hxx"
35 #include "heading_indicator_dg.hxx"
38 #include "mag_compass.hxx"
39 #include "marker_beacon.hxx"
40 #include "newnavradio.hxx"
41 #include "slip_skid_ball.hxx"
42 #include "transponder.hxx"
43 #include "turn_indicator.hxx"
44 #include "vertical_speed_indicator.hxx"
45 #include "inst_vertical_speed_indicator.hxx"
46 #include "wxradar.hxx"
48 #include "mk_viii.hxx"
50 #include "groundradar.hxx"
51 #include "agradar.hxx"
52 #include "rad_alt.hxx"
54 #include "NavDisplay.hxx"
56 FGInstrumentMgr::FGInstrumentMgr () :
59 globals->add_subsystem("hud", new HUD, SGSubsystemMgr::DISPLAY);
62 FGInstrumentMgr::~FGInstrumentMgr ()
66 SGSubsystem::InitStatus FGInstrumentMgr::incrementalInit()
72 void FGInstrumentMgr::init()
74 SGPropertyNode_ptr config_props = new SGPropertyNode;
75 SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
77 SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
81 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
82 SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
85 readProperties( config.str(), config_props );
86 if (!build(config_props)) {
88 "Detected an internal inconsistency in the instrumentation\n"
89 "system specification file. See earlier errors for details.");
91 } catch (const sg_exception& e) {
92 SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
93 << config.str() << ":" << e.getFormattedMessage() );
98 SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument");
99 SGPropertyNode_ptr nd(new SGPropertyNode);
100 nd->setStringValue("name", "gps");
101 nd->setIntValue("number", 0);
102 _instruments.push_back("gps[0]");
103 set_subsystem("gps[0]", new GPS(nd));
106 // bind() created instruments before init.
107 for (unsigned int i=0; i<_instruments.size(); ++i) {
108 const std::string& nm(_instruments[i]);
109 SGSubsystem* instr = get_subsystem(nm);
113 SGSubsystemGroup::init();
116 bool FGInstrumentMgr::build (SGPropertyNode* config_props)
118 for ( int i = 0; i < config_props->nChildren(); ++i ) {
119 SGPropertyNode *node = config_props->getChild(i);
120 string name = node->getName();
122 std::ostringstream subsystemname;
123 subsystemname << "instrument-" << i << '-'
124 << node->getStringValue("name", name.c_str());
125 int index = node->getIntValue("number", 0);
127 subsystemname << '['<< index << ']';
128 string id = subsystemname.str();
129 _instruments.push_back(id);
131 if ( name == "adf" ) {
132 set_subsystem( id, new ADF( node ), 0.15 );
134 } else if ( name == "airspeed-indicator" ) {
135 set_subsystem( id, new AirspeedIndicator( node ) );
137 } else if ( name == "altimeter" ) {
138 set_subsystem( id, new Altimeter( node ) );
140 } else if ( name == "attitude-indicator" ) {
141 set_subsystem( id, new AttitudeIndicator( node ) );
143 } else if ( name == "clock" ) {
144 set_subsystem( id, new Clock( node ), 0.25 );
146 } else if ( name == "dme" ) {
147 set_subsystem( id, new DME( node ), 1.0 );
149 } else if ( name == "encoder" ) {
150 set_subsystem( id, new Altimeter( node ), 0.15 );
152 } else if ( name == "gps" ) {
153 set_subsystem( id, new GPS( node ) );
155 } else if ( name == "gsdi" ) {
156 set_subsystem( id, new GSDI( node ) );
158 } else if ( name == "heading-indicator" ) {
159 set_subsystem( id, new HeadingIndicator( node ) );
161 } else if ( name == "heading-indicator-fg" ) {
162 set_subsystem( id, new HeadingIndicatorFG( node ) );
164 } else if ( name == "heading-indicator-dg" ) {
165 set_subsystem( id, new HeadingIndicatorDG( node ) );
167 } else if ( name == "KR-87" ) {
168 set_subsystem( id, new FGKR_87( node ) );
170 } else if ( name == "KT-70" ) {
171 set_subsystem( id, new FGKT_70( node ) );
173 } else if ( name == "magnetic-compass" ) {
174 set_subsystem( id, new MagCompass( node ) );
176 } else if ( name == "marker-beacon" ) {
177 set_subsystem( id, new FGMarkerBeacon( node ), 0.2 );
179 } else if ( name == "nav-radio" ) {
180 set_subsystem( id, Instrumentation::NavRadio::createInstance( node ) );
182 } else if ( name == "slip-skid-ball" ) {
183 set_subsystem( id, new SlipSkidBall( node ), 0.03 );
185 } else if ( name == "transponder" ) {
186 set_subsystem( id, new Transponder( node ), 0.2 );
188 } else if ( name == "turn-indicator" ) {
189 set_subsystem( id, new TurnIndicator( node ) );
191 } else if ( name == "vertical-speed-indicator" ) {
192 set_subsystem( id, new VerticalSpeedIndicator( node ) );
194 } else if ( name == "radar" ) {
195 set_subsystem( id, new wxRadarBg ( 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 set_subsystem( id, new GroundRadar( node ) );
212 } else if ( name == "air-ground-radar" ) {
213 set_subsystem( id, new agRadar( node ) );
215 } else if ( name == "radar-altimeter" ) {
216 set_subsystem( id, new radAlt( node ) );
218 } else if ( name == "tcas" ) {
219 set_subsystem( id, new TCAS( node ), 0.2);
221 } else if ( name == "navigation-display" ) {
222 set_subsystem( id, new NavDisplay( node ) );
225 SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
233 // end of instrument_manager.cxx