FlightGear next
instrument_mgr.cxx
Go to the documentation of this file.
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 <config.h>
7
8#include <iostream>
9#include <string>
10#include <sstream>
11
12#include <simgear/structure/exception.hxx>
13#include <simgear/misc/sg_path.hxx>
14#include <simgear/sg_inlines.h>
15#include <simgear/props/props_io.hxx>
16#include <simgear/debug/ErrorReportingCallback.hxx>
17
18#include <Main/fg_props.hxx>
19#include <Main/globals.hxx>
20#include <Main/util.hxx>
21
22#include "instrument_mgr.hxx"
23#include "adf.hxx"
25#include "altimeter.hxx"
28#include "clock.hxx"
29#include "dme.hxx"
30#include "gps.hxx"
31#include "gsdi.hxx"
32#include "heading_indicator.hxx"
35#include "kr_87.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"
45#include "tacan.hxx"
46#include "mk_viii.hxx"
47#include "mrg.hxx"
48#include "rad_alt.hxx"
49#include "tcas.hxx"
50
52 _explicitGps(false)
53{
54}
55
59
60SGSubsystem::InitStatus FGInstrumentMgr::incrementalInit()
61{
62 init();
63 return INIT_DONE;
64}
65
67{
68 simgear::ErrorReportContext ec("primary-aircraft", "yes");
69
70 SGPropertyNode_ptr config_props = new SGPropertyNode;
71 SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
72 if (!path_n) {
73 SG_LOG(SG_COCKPIT, SG_DEV_WARN, "No instrumentation model specified for this model!");
74 return;
75 }
76
77 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
78 if (!config.exists()) {
79 simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems,
80 "FGInstrumentMgr: Missing instrumentation file", config);
81 return;
82 }
83
84 SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config );
85
86 try {
87 readProperties( config, config_props );
88 if (!build(config_props, config)) {
89 throw sg_exception(
90 "Detected an internal inconsistency in the instrumentation\n"
91 "system specification file. See earlier errors for details.");
92 }
93 } catch (const sg_exception& e) {
94 simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems,
95 "Failed to load instrumentation system:" + e.getFormattedMessage(),
96 e.getLocation());
97 }
98
99
100 if (!_explicitGps) {
101 SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument");
102 SGPropertyNode_ptr nd(new SGPropertyNode);
103 nd->setStringValue("name", "gps");
104 nd->setIntValue("number", 0);
105 _instruments.push_back("gps[0]");
106 set_subsystem("gps[0]", new GPS(nd, true /* default GPS mode */));
107 }
108
109 SGSubsystemGroup::init();
110}
111
112bool FGInstrumentMgr::build (SGPropertyNode* config_props, const SGPath& path)
113{
114 for ( int i = 0; i < config_props->nChildren(); ++i ) {
115 SGPropertyNode *node = config_props->getChild(i);
116 std::string name = node->getNameString();
117
118 std::ostringstream subsystemname;
119 subsystemname << "instrument-" << i << '-'
120 << node->getStringValue("name", name.c_str());
121 int index = node->getIntValue("number", 0);
122 if (index > 0)
123 subsystemname << '['<< index << ']';
124 std::string id = subsystemname.str();
125
126 if ( name == "adf" ) {
127 set_subsystem( id, new ADF( node ), 0.15 );
128
129 } else if ( name == "airspeed-indicator" ) {
130 set_subsystem( id, new AirspeedIndicator( node ) );
131
132 } else if ( name == "altimeter" ) {
133 set_subsystem( id, new Altimeter( node, "altimeter" ) );
134
135 } else if ( name == "attitude-indicator" ) {
136 set_subsystem( id, new AttitudeIndicator( node ) );
137
138 } else if ( name == "attitude-indicator-electric" ) {
139 set_subsystem( id, new AttitudeIndicatorElectric( node ) );
140
141 } else if ( name == "clock" ) {
142 set_subsystem( id, new Clock( node ), 0.25 );
143
144 } else if ( name == "dme" ) {
145 set_subsystem( id, new DME( node ), 1.0 );
146
147 } else if ( name == "encoder" ) {
148 set_subsystem( id, new Altimeter( node, "encoder" ), 0.15 );
149
150 } else if ( name == "gps" ) {
151 // post 2.12.0, add a new name (distinct from 'gps'), so
152 // it is possible to create non-default GPS instruments.
153 // then authors of realistic GPS and FMSs can transition to using
154 // that name as they choose.
155 set_subsystem( id, new GPS( node, true /* default GPS mode */ ) );
156 _explicitGps = true;
157 } else if ( name == "gsdi" ) {
158 set_subsystem( id, new GSDI( node ) );
159
160 } else if ( name == "heading-indicator" ) {
161 set_subsystem( id, new HeadingIndicator( node ) );
162
163 } else if ( name == "heading-indicator-fg" ) {
164 set_subsystem( id, new HeadingIndicatorFG( node ) );
165
166 } else if ( name == "heading-indicator-dg" ) {
167 set_subsystem( id, new HeadingIndicatorDG( node ) );
168
169 } else if ( name == "KR-87" ) {
170 set_subsystem( id, new FGKR_87( node ) );
171
172 } else if ( name == "magnetic-compass" ) {
173 set_subsystem( id, new MagCompass( node ) );
174
175 } else if ( name == "marker-beacon" ) {
176 set_subsystem(id, new FGMarkerBeacon(node));
177
178 } else if ( name == "comm-radio" ) {
179 set_subsystem( id, Instrumentation::CommRadio::createInstance( node ) );
180
181 } else if ( name == "nav-radio" ) {
182 set_subsystem( id, Instrumentation::NavRadio::createInstance( node ) );
183
184 } else if ( name == "slip-skid-ball" ) {
185 set_subsystem( id, new SlipSkidBall( node ), 0.03 );
186
187 } else if (( name == "transponder" ) || ( name == "KT-70" )) {
188 if (name == "KT-70") {
189 SG_LOG(SG_INSTR, SG_DEV_ALERT, "KT-70 legacy instrument compatibility. "
190 "Please update aircraft to use transponder directly");
191 // force configuration into compatibility mode
192 node->setBoolValue("kt70-compatibility", true);
193 }
194 set_subsystem( id, new Transponder( node ), 0.2 );
195
196 } else if ( name == "turn-indicator" ) {
197 set_subsystem( id, new TurnIndicator( node ) );
198
199 } else if ( name == "vertical-speed-indicator" ) {
200 set_subsystem( id, new VerticalSpeedIndicator( node ) );
201
202 } else if ( name == "inst-vertical-speed-indicator" ) {
203 set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
204
205 } else if ( name == "tacan" ) {
206 set_subsystem( id, new TACAN( node ), 0.2 );
207
208 } else if ( name == "mk-viii" ) {
209 set_subsystem( id, new MK_VIII( node ), 0.2);
210
211 } else if ( name == "master-reference-gyro" ) {
212 set_subsystem( id, new MasterReferenceGyro( node ) );
213
214 } else if (( name == "groundradar" ) ||
215 ( name == "radar" ) ||
216 ( name == "air-ground-radar" ) ||
217 ( name == "navigation-display" ))
218 {
219 // these instruments are handled by the CockpitDisplayManager
220 // catch them here so we can still warn about bogus names in
221 // the instruments file
222 continue;
223 } else if ( name == "radar-altimeter" ) {
224 set_subsystem( id, new RadarAltimeter( node ) );
225
226 } else if ( name == "tcas" ) {
227 set_subsystem( id, new TCAS( node ), 0.2);
228
229 } else {
230 simgear::reportFailure(simgear::LoadFailure::Misconfigured, simgear::ErrorCode::AircraftSystems,
231 "Unknown top level section in instrumentation:" + name,
232 path);
233 continue;
234 }
235
236 // only push to our array if we actually built an insturment
237 _instruments.push_back(id);
238 } // of instruments iteration
239 return true;
240}
241
242
243// Register the subsystem.
244SGSubsystemMgr::Registrant<FGInstrumentMgr> registrantFGInstrumentMgr(
245 SGSubsystemMgr::FDM);
246
247// end of instrument_manager.cxx
#define i(x)
Model an ADF radio.
Definition adf.hxx:44
virtual ~FGInstrumentMgr()
InitStatus incrementalInit() override
void init() override
Model a GPS radio.
Definition gps.hxx:63
static SGSubsystem * createInstance(SGPropertyNode_ptr rootNode)
static SGSubsystem * createInstance(SGPropertyNode_ptr rootNode)
const char * name
FGGlobals * globals
Definition globals.cxx:142
SGSubsystemMgr::Registrant< FGInstrumentMgr > registrantFGInstrumentMgr(SGSubsystemMgr::FDM)
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27