X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSystems%2Felectrical.cxx;h=b83984dd6cf986f0b18b21d02b1e81a718c29452;hb=46ec7a6ff78b0718c6eb09e5abb45c67c153d2f5;hp=9c17a7c1b8dc62838a32af2811f6c529b1dda6a1;hpb=a760dcdf1332ce6abbccbd591cfdcc11e4d98fc9;p=flightgear.git diff --git a/src/Systems/electrical.cxx b/src/Systems/electrical.cxx index 9c17a7c1b..b83984dd6 100644 --- a/src/Systems/electrical.cxx +++ b/src/Systems/electrical.cxx @@ -16,15 +16,22 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include #include #include +#include +#include -#include #include
#include
@@ -113,7 +120,7 @@ float FGElectricalSupplier::apply_load( float amps, float dt ) { float available_amps = ideal_amps; return available_amps - amps; } else { - SG_LOG( SG_ALL, SG_ALERT, "unknown supplier type" ); + SG_LOG( SG_SYSTEMS, SG_ALERT, "unknown supplier type" ); } return 0.0; @@ -145,7 +152,7 @@ float FGElectricalSupplier::get_output_volts() { // cout << "external amps = " << 0.0 << endl; return ideal_volts; } else { - SG_LOG( SG_ALL, SG_ALERT, "unknown supplier type" ); + SG_LOG( SG_SYSTEMS, SG_ALERT, "unknown supplier type" ); } return 0.0; @@ -174,7 +181,7 @@ float FGElectricalSupplier::get_output_amps() { // cout << "external amps = " << 0.0 << endl; return ideal_amps; } else { - SG_LOG( SG_ALL, SG_ALERT, "unknown supplier type" ); + SG_LOG( SG_SYSTEMS, SG_ALERT, "unknown supplier type" ); } return 0.0; @@ -268,12 +275,12 @@ FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node, } else if ( s->get_kind() == FG_BUS ) { s->add_output( this ); } else { - SG_LOG( SG_ALL, SG_ALERT, + SG_LOG( SG_SYSTEMS, SG_ALERT, "Attempt to connect to something that can't provide an output: " << child->getStringValue() ); } } else { - SG_LOG( SG_ALL, SG_ALERT, "Can't find named source: " + SG_LOG( SG_SYSTEMS, SG_ALERT, "Can't find named source: " << child->getStringValue() ); } } else if ( cname == "output" ) { @@ -289,12 +296,12 @@ FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node, == FGElectricalSupplier::FG_BATTERY ) { s->add_output( this ); } else { - SG_LOG( SG_ALL, SG_ALERT, + SG_LOG( SG_SYSTEMS, SG_ALERT, "Attempt to connect to something that can't provide an input: " << child->getStringValue() ); } } else { - SG_LOG( SG_ALL, SG_ALERT, "Can't find named source: " + SG_LOG( SG_SYSTEMS, SG_ALERT, "Can't find named source: " << child->getStringValue() ); } } else if ( cname == "switch" ) { @@ -331,30 +338,11 @@ bool FGElectricalConnector::get_state() { FGElectricalSystem::FGElectricalSystem ( SGPropertyNode *node ) : - name("electrical"), - num(0), - path(""), + name(node->getStringValue("name", "electrical")), + num(node->getIntValue("number", 0)), + path(node->getStringValue("path")), enabled(false) { - int i; - for ( i = 0; i < node->nChildren(); ++i ) { - SGPropertyNode *child = node->getChild(i); - string cname = child->getName(); - string cval = child->getStringValue(); - if ( cname == "name" ) { - name = cval; - } else if ( cname == "number" ) { - num = child->getIntValue(); - } else if ( cname == "path" ) { - path = cval; - } else { - SG_LOG( SG_SYSTEMS, SG_WARN, - "Error in electrical system config logic" ); - if ( name.length() ) { - SG_LOG( SG_SYSTEMS, SG_WARN, "Section = " << name ); - } - } - } } @@ -363,7 +351,7 @@ FGElectricalSystem::~FGElectricalSystem () { void FGElectricalSystem::init () { - config_props = new SGPropertyNode; + SGPropertyNode_ptr config_props = new SGPropertyNode; _volts_out = fgGetNode( "/systems/electrical/volts", true ); _amps_out = fgGetNode( "/systems/electrical/amps", true ); @@ -375,7 +363,7 @@ void FGElectricalSystem::init () { SGPropertyNode *path_n = fgGetNode("/sim/systems/electrical/path"); if ( path_n ) { if ( path.length() ) { - SG_LOG( SG_ALL, SG_INFO, + SG_LOG( SG_SYSTEMS, SG_INFO, "NOTICE: System manager configuration specifies an " << "electrical system: " << path << " but it is " << "being overridden by the one specified in the -set.xml " << @@ -386,34 +374,28 @@ void FGElectricalSystem::init () { } if ( path.length() ) { - SGPath config( globals->get_fg_root() ); - config.append( path ); - + SGPath config = globals->resolve_aircraft_path(path); +#if defined(ENABLE_DEV_WARNINGS) // load an obsolete xml configuration - SG_LOG( SG_ALL, SG_ALERT, - "Reading xml electrical system model from " + SG_LOG( SG_SYSTEMS, SG_WARN, + "Reading deprecated xml electrical system model from\n " << config.str() ); +#endif try { - readProperties( config.str(), config_props ); + readProperties( config, config_props ); - if ( build() ) { + if ( build(config_props) ) { enabled = true; } else { - SG_LOG( SG_ALL, SG_ALERT, - "Detected a logic error in the electrical system "); - SG_LOG( SG_ALL, SG_ALERT, - "specification file. See earlier errors for " ); - SG_LOG( SG_ALL, SG_ALERT, - "details."); - exit(-1); + throw sg_exception("Logic error in electrical system file."); } - } catch (const sg_exception& exc) { - SG_LOG( SG_ALL, SG_ALERT, + } catch (const sg_exception&) { + SG_LOG( SG_SYSTEMS, SG_ALERT, "Failed to load electrical system model: " - << config.str() ); + << config ); } } else { - SG_LOG( SG_ALL, SG_INFO, + SG_LOG( SG_SYSTEMS, SG_INFO, "No xml-based electrical model specified for this model!"); } @@ -421,7 +403,6 @@ void FGElectricalSystem::init () { _amps_out->setDoubleValue(0); } - delete config_props; } @@ -470,7 +451,8 @@ void FGElectricalSystem::update (double dt) { " " ); if ( node->apply_load( load, dt ) < 0.0 ) { - cout << "Error drawing more current than available!" << endl; + SG_LOG(SG_SYSTEMS, SG_ALERT, + "Error drawing more current than available!"); } } } @@ -489,7 +471,8 @@ void FGElectricalSystem::update (double dt) { " " ); if ( node->apply_load( load, dt ) < 0.0 ) { - cout << "Error drawing more current than available!" << endl; + SG_LOG(SG_SYSTEMS, SG_ALERT, + "Error drawing more current than available!"); } } } @@ -509,7 +492,8 @@ void FGElectricalSystem::update (double dt) { // cout << "battery load = " << load << endl; if ( node->apply_load( load, dt ) < 0.0 ) { - cout << "Error drawing more current than available!" << endl; + SG_LOG(SG_SYSTEMS, SG_ALERT, + "Error drawing more current than available!"); } } } @@ -565,7 +549,7 @@ void FGElectricalSystem::update (double dt) { } -bool FGElectricalSystem::build () { +bool FGElectricalSystem::build (SGPropertyNode* config_props) { SGPropertyNode *node; int i; @@ -591,7 +575,7 @@ bool FGElectricalSystem::build () { new FGElectricalConnector( node, this ); connectors.push_back( c ); } else { - SG_LOG( SG_ALL, SG_ALERT, "Unknown component type specified: " + SG_LOG( SG_SYSTEMS, SG_ALERT, "Unknown component type specified: " << name ); return false; } @@ -649,7 +633,7 @@ float FGElectricalSystem::propagate( FGElectricalComponent *node, double dt, } // cout << s << " input_volts = " << volts << endl; } else { - SG_LOG( SG_ALL, SG_ALERT, "unkown node type" ); + SG_LOG( SG_SYSTEMS, SG_ALERT, "unknown node type" ); } int i;