X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSystems%2Felectrical.cxx;h=d711b4dcac67487a4fc9133e6a1c92feb33bcc29;hb=fdbfd6fd0b789eecf2c532d048a75d15f8d35ad8;hp=31a4e5594c5ac4f14ee344583c40855395c85574;hpb=6dd82d05028e3019e142db7e56b8d4f829d2235f;p=flightgear.git diff --git a/src/Systems/electrical.cxx b/src/Systems/electrical.cxx index 31a4e5594..d711b4dca 100644 --- a/src/Systems/electrical.cxx +++ b/src/Systems/electrical.cxx @@ -16,13 +16,20 @@ // // 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
@@ -109,6 +116,7 @@ float FGElectricalSupplier::apply_load( float amps, float dt ) { return available_amps - amps; } else if ( model == FG_EXTERNAL ) { // cout << "external amps = " << 0.0 << endl; + float available_amps = ideal_amps; return available_amps - amps; } else { SG_LOG( SG_ALL, SG_ALERT, "unknown supplier type" ); @@ -329,30 +337,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 ); - } - } - } } @@ -361,7 +350,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 ); @@ -373,9 +362,9 @@ void FGElectricalSystem::init () { SGPropertyNode *path_n = fgGetNode("/sim/systems/electrical/path"); if ( path_n ) { if ( path.length() ) { - SG_LOG( SG_ALL, SG_ALERT, + SG_LOG( SG_ALL, SG_INFO, "NOTICE: System manager configuration specifies an " << - "electrical system model from: " << path << " but it is " << + "electrical system: " << path << " but it is " << "being overridden by the one specified in the -set.xml " << "file: " << path_n->getStringValue() ); } @@ -384,32 +373,33 @@ void FGElectricalSystem::init () { } if ( path.length() ) { - SGPath config( globals->get_fg_root() ); - config.append( path ); - - SG_LOG( SG_ALL, SG_ALERT, "Reading electrical system model from " + SGPath config = globals->resolve_aircraft_path(path); + + // load an obsolete xml configuration + SG_LOG( SG_ALL, SG_WARN, + "Reading deprecated xml electrical system model from\n " << config.str() ); try { readProperties( config.str(), config_props ); - if ( build() ) { + if ( build(config_props) ) { enabled = true; } else { SG_LOG( SG_ALL, SG_ALERT, - "Detected an internal inconsistancy in the electrical"); + "Detected a logic error in the electrical system "); SG_LOG( SG_ALL, SG_ALERT, - " system specification file. See earlier errors for" ); + "specification file. See earlier errors for " ); SG_LOG( SG_ALL, SG_ALERT, - " details."); + "details."); exit(-1); } - } catch (const sg_exception& exc) { - SG_LOG( SG_ALL, SG_ALERT, "Failed to load electrical system model: " + } catch (const sg_exception&) { + SG_LOG( SG_ALL, SG_ALERT, + "Failed to load electrical system model: " << config.str() ); } - } else { - SG_LOG( SG_ALL, SG_WARN, + SG_LOG( SG_ALL, SG_INFO, "No xml-based electrical model specified for this model!"); } @@ -417,7 +407,6 @@ void FGElectricalSystem::init () { _amps_out->setDoubleValue(0); } - delete config_props; } @@ -466,7 +455,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_ALL, SG_ALERT, + "Error drawing more current than available!"); } } } @@ -485,7 +475,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_ALL, SG_ALERT, + "Error drawing more current than available!"); } } } @@ -505,7 +496,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_ALL, SG_ALERT, + "Error drawing more current than available!"); } } } @@ -561,7 +553,7 @@ void FGElectricalSystem::update (double dt) { } -bool FGElectricalSystem::build () { +bool FGElectricalSystem::build (SGPropertyNode* config_props) { SGPropertyNode *node; int i;