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"
37 #include "mag_compass.hxx"
38 #include "marker_beacon.hxx"
39 #include "newnavradio.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"
45 #include "wxradar.hxx"
47 #include "mk_viii.hxx"
49 #include "groundradar.hxx"
50 #include "agradar.hxx"
51 #include "rad_alt.hxx"
53 #include "NavDisplay.hxx"
55 FGInstrumentMgr::FGInstrumentMgr () :
60 FGInstrumentMgr::~FGInstrumentMgr ()
64 SGSubsystem::InitStatus FGInstrumentMgr::incrementalInit()
70 void FGInstrumentMgr::init()
72 SGPropertyNode_ptr config_props = new SGPropertyNode;
73 SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
75 SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
79 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
80 SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
83 readProperties( config.str(), config_props );
84 if (!build(config_props)) {
86 "Detected an internal inconsistency in the instrumentation\n"
87 "system specification file. See earlier errors for details.");
89 } catch (const sg_exception& e) {
90 SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
91 << config.str() << ":" << e.getFormattedMessage() );
96 SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument");
97 SGPropertyNode_ptr nd(new SGPropertyNode);
98 nd->setStringValue("name", "gps");
99 nd->setIntValue("number", 0);
100 _instruments.push_back("gps[0]");
101 set_subsystem("gps[0]", new GPS(nd));
104 // bind() created instruments before init.
105 for (unsigned int i=0; i<_instruments.size(); ++i) {
106 const std::string& nm(_instruments[i]);
107 SGSubsystem* instr = get_subsystem(nm);
111 SGSubsystemGroup::init();
114 bool FGInstrumentMgr::build (SGPropertyNode* config_props)
116 for ( int i = 0; i < config_props->nChildren(); ++i ) {
117 SGPropertyNode *node = config_props->getChild(i);
118 string name = node->getName();
120 std::ostringstream subsystemname;
121 subsystemname << "instrument-" << i << '-'
122 << node->getStringValue("name", name.c_str());
123 int index = node->getIntValue("number", 0);
125 subsystemname << '['<< index << ']';
126 string id = subsystemname.str();
127 _instruments.push_back(id);
129 if ( name == "adf" ) {
130 set_subsystem( id, new ADF( node ), 0.15 );
132 } else if ( name == "airspeed-indicator" ) {
133 set_subsystem( id, new AirspeedIndicator( node ) );
135 } else if ( name == "altimeter" ) {
136 set_subsystem( id, new Altimeter( node ) );
138 } else if ( name == "attitude-indicator" ) {
139 set_subsystem( id, new AttitudeIndicator( node ) );
141 } else if ( name == "clock" ) {
142 set_subsystem( id, new Clock( node ), 0.25 );
144 } else if ( name == "dme" ) {
145 set_subsystem( id, new DME( node ), 1.0 );
147 } else if ( name == "encoder" ) {
148 set_subsystem( id, new Altimeter( node ), 0.15 );
150 } else if ( name == "gps" ) {
151 set_subsystem( id, new GPS( node ) );
153 } else if ( name == "gsdi" ) {
154 set_subsystem( id, new GSDI( node ) );
156 } else if ( name == "heading-indicator" ) {
157 set_subsystem( id, new HeadingIndicator( node ) );
159 } else if ( name == "heading-indicator-fg" ) {
160 set_subsystem( id, new HeadingIndicatorFG( node ) );
162 } else if ( name == "heading-indicator-dg" ) {
163 set_subsystem( id, new HeadingIndicatorDG( node ) );
165 } else if ( name == "KR-87" ) {
166 set_subsystem( id, new FGKR_87( node ) );
168 } else if ( name == "KT-70" ) {
169 set_subsystem( id, new FGKT_70( node ) );
171 } else if ( name == "magnetic-compass" ) {
172 set_subsystem( id, new MagCompass( node ) );
174 } else if ( name == "marker-beacon" ) {
175 set_subsystem( id, new FGMarkerBeacon( node ), 0.2 );
177 } else if ( name == "nav-radio" ) {
178 set_subsystem( id, Instrumentation::NavRadio::createInstance( node ) );
180 } else if ( name == "slip-skid-ball" ) {
181 set_subsystem( id, new SlipSkidBall( node ), 0.03 );
183 } else if ( name == "transponder" ) {
184 set_subsystem( id, new Transponder( node ), 0.2 );
186 } else if ( name == "turn-indicator" ) {
187 set_subsystem( id, new TurnIndicator( node ) );
189 } else if ( name == "vertical-speed-indicator" ) {
190 set_subsystem( id, new VerticalSpeedIndicator( node ) );
192 } else if ( name == "radar" ) {
193 set_subsystem( id, new wxRadarBg ( node ) );
195 } else if ( name == "inst-vertical-speed-indicator" ) {
196 set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
198 } else if ( name == "tacan" ) {
199 set_subsystem( id, new TACAN( node ), 0.2 );
201 } else if ( name == "mk-viii" ) {
202 set_subsystem( id, new MK_VIII( node ), 0.2);
204 } else if ( name == "master-reference-gyro" ) {
205 set_subsystem( id, new MasterReferenceGyro( node ) );
207 } else if ( name == "groundradar" ) {
208 set_subsystem( id, new GroundRadar( node ) );
210 } else if ( name == "air-ground-radar" ) {
211 set_subsystem( id, new agRadar( node ) );
213 } else if ( name == "radar-altimeter" ) {
214 set_subsystem( id, new radAlt( node ) );
216 } else if ( name == "tcas" ) {
217 set_subsystem( id, new TCAS( node ), 0.2);
219 } else if ( name == "navigation-display" ) {
220 set_subsystem( id, new NavDisplay( node ) );
223 SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
231 // end of instrument_manager.cxx