]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/instrument_mgr.cxx
Changes by Roy Ovesen to begin migrating the avionics out of the Cockpit
[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 #include <iostream>
7 #include <string>
8 #include <sstream>
9
10 #include <simgear/structure/exception.hxx>
11 #include <simgear/misc/sg_path.hxx>
12 #include <simgear/sg_inlines.h>
13
14 #include <Main/fg_props.hxx>
15 #include <Main/globals.hxx>
16 #include <Main/util.hxx>
17
18 #include "instrument_mgr.hxx"
19 #include "adf.hxx"
20 #include "airspeed_indicator.hxx"
21 #include "altimeter.hxx"
22 #include "annunciator.hxx"
23 #include "attitude_indicator.hxx"
24 #include "clock.hxx"
25 #include "dme.hxx"
26 #include "encoder.hxx"
27 #include "gps.hxx"
28 #include "heading_indicator.hxx"
29 #include "kr_87.hxx"
30 #include "kt_70.hxx"
31 #include "mag_compass.hxx"
32 #include "marker_beacon.hxx"
33 #include "navradio.hxx"
34 #include "slip_skid_ball.hxx"
35 #include "transponder.hxx"
36 #include "turn_indicator.hxx"
37 #include "vertical_speed_indicator.hxx"
38
39
40 FGInstrumentMgr::FGInstrumentMgr ()
41 {
42     set_subsystem("annunciator", new Annunciator);
43
44     config_props = new SGPropertyNode;
45
46     SGPropertyNode *path_n = fgGetNode("/sim/instrumentation/path");
47
48     if (path_n) {
49         SGPath config( globals->get_fg_root() );
50         config.append( path_n->getStringValue() );
51
52         SG_LOG( SG_ALL, SG_INFO, "Reading instruments from "
53                 << config.str() );
54         try {
55             readProperties( config.str(), config_props );
56
57             if ( build() ) {
58                 enabled = true;
59             } else {
60                 SG_LOG( SG_ALL, SG_ALERT,
61                         "Detected an internal inconsistancy in the instrumentation");
62                 SG_LOG( SG_ALL, SG_ALERT,
63                         " system specification file.  See earlier errors for" );
64                 SG_LOG( SG_ALL, SG_ALERT,
65                         " details.");
66                 exit(-1);
67             }        
68         } catch (const sg_exception& exc) {
69             SG_LOG( SG_ALL, SG_ALERT, "Failed to load instrumentation system model: "
70                     << config.str() );
71         }
72
73     } else {
74         SG_LOG( SG_ALL, SG_WARN,
75                 "No instrumentation model specified for this model!");
76     }
77
78     delete config_props;
79 }
80
81 FGInstrumentMgr::~FGInstrumentMgr ()
82 {
83 }
84
85 bool FGInstrumentMgr::build ()
86 {
87     SGPropertyNode *node;
88     int i;
89
90     int count = config_props->nChildren();
91     for ( i = 0; i < count; ++i ) {
92         node = config_props->getChild(i);
93         string name = node->getName();
94         std::ostringstream temp;
95         temp << i;
96         if ( name == "adf" ) {
97             set_subsystem( "instrument" + temp.str(), 
98                            new ADF( node ), 0.15 );
99         } else if ( name == "airspeed-indicator" ) {
100             set_subsystem( "instrument" + temp.str(), 
101                            new AirspeedIndicator( node ) );
102         } else if ( name == "altimeter" ) {
103             set_subsystem( "instrument" + temp.str(), 
104                            new Altimeter( node ) );
105         } else if ( name == "attitude-indicator" ) {
106             set_subsystem( "instrument" + temp.str(), 
107                            new AttitudeIndicator( node ) );
108         } else if ( name == "clock" ) {
109             set_subsystem( "instrument" + temp.str(), 
110                            new Clock( node ), 0.25 );
111         } else if ( name == "dme" ) {
112             set_subsystem( "instrument" + temp.str(), 
113                            new DME( node ), 1.0 );
114         } else if ( name == "encoder" ) {
115             set_subsystem( "instrument" + temp.str(), 
116                            new Encoder( node ) );
117         } else if ( name == "gps" ) {
118             set_subsystem( "instrument" + temp.str(), 
119                            new GPS( node ), 0.45 );
120         } else if ( name == "heading-indicator" ) {
121             set_subsystem( "instrument" + temp.str(), 
122                            new HeadingIndicator( node ) );
123         } else if ( name == "KR-87" ) {
124             set_subsystem( "instrument" + temp.str(), 
125                            new FGKR_87( node ) );
126         } else if ( name == "KT-70" ) {
127             set_subsystem( "instrument" + temp.str(), 
128                            new FGKT_70( node ) );
129         } else if ( name == "magnetic-compass" ) {
130             set_subsystem( "instrument" + temp.str(), 
131                            new MagCompass( node ) );
132         } else if ( name == "marker-beacon" ) {
133             set_subsystem( "instrument" + temp.str(), 
134                            new FGMarkerBeacon( node ) );
135         } else if ( name == "nav-radio" ) {
136             set_subsystem( "instrument" + temp.str(), 
137                            new FGNavRadio( node ) );
138         } else if ( name == "slip-skid-ball" ) {
139             set_subsystem( "instrument" + temp.str(), 
140                            new SlipSkidBall( node ) );
141         } else if ( name == "transponder" ) {
142             set_subsystem( "instrument" + temp.str(), 
143                            new Transponder( node ) );
144         } else if ( name == "turn-indicator" ) {
145             set_subsystem( "instrument" + temp.str(), 
146                            new TurnIndicator( node ) );
147         } else if ( name == "vertical-speed-indicator" ) {
148             set_subsystem( "instrument" + temp.str(), 
149                            new VerticalSpeedIndicator( node ) );
150         } else {
151             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " 
152                     << name );
153             return false;
154         }
155     }
156     return true;
157 }
158
159 // end of instrument_manager.cxx