]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/electrical.cxx
ignore resets for now because every z/Z key press would trigger a call to NOAA. We...
[flightgear.git] / src / Systems / electrical.cxx
index 8e6cbc2b90d42eee8eeb325056a40ea0f37c986d..1b6b39943bec53882559a75ebea04d0056df12d0 100644 (file)
@@ -118,9 +118,15 @@ FGElectricalBus::FGElectricalBus ( SGPropertyNode *node ) {
 
 FGElectricalOutput::FGElectricalOutput ( SGPropertyNode *node ) {
     kind = FG_OUTPUT;
-    output_amps = 0.1;
+    output_amps = 0.1;          // arbitrary default value
 
     name = node->getStringValue("name");
+    SGPropertyNode *draw = node->getNode("rated-draw");
+    if ( draw != NULL ) {
+        output_amps = draw->getDoubleValue();
+    }
+    // cout << "rated draw = " << output_amps << endl;
+
     int i;
     for ( i = 0; i < node->nChildren(); ++i ) {
         SGPropertyNode *child = node->getChild(i);
@@ -132,6 +138,37 @@ FGElectricalOutput::FGElectricalOutput ( SGPropertyNode *node ) {
 }  
 
 
+FGElectricalSwitch::FGElectricalSwitch( SGPropertyNode *node ) :
+    switch_node( NULL ),
+    rating_amps( 0.0f ),
+    circuit_breaker( false )
+{
+    bool initial_state = true;
+    int i;
+    for ( i = 0; i < node->nChildren(); ++i ) {
+        SGPropertyNode *child = node->getChild(i);
+        string cname = child->getName();
+        string cval = child->getStringValue();
+        if ( cname == "prop" ) {
+            switch_node = fgGetNode( cval.c_str(), true );
+            // cout << "switch node = " << cval << endl;
+        } else if ( cname == "initial-state" ) {
+            if ( cval == "off" || cval == "false" ) {
+                initial_state = false;
+            }
+            // cout << "initial state = " << initial_state << endl;
+        } else if ( cname == "rating-amps" ) {
+            rating_amps = atof( cval.c_str() );
+            circuit_breaker = true;
+            // cout << "initial state = " << initial_state << endl;
+        }            
+    }
+
+    switch_node->setBoolValue( initial_state );
+    // cout << "  value = " << switch_node->getBoolValue() << endl;
+}
+
+
 FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node,
                                                FGElectricalSystem *es ) {
     kind = FG_CONNECTOR;
@@ -177,30 +214,11 @@ FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node,
                         << child->getStringValue() );
             }
         } else if ( cname == "switch" ) {
-            // set default value of switch to true
-            // cout << "Switch = " << child->getStringValue() << endl;
-            fgSetBool( child->getStringValue(), true );
-            FGElectricalSwitch s( fgGetNode(child->getStringValue(), true),
-                                  100.0f,
-                                  false );
+             // cout << "Switch = " << child->getStringValue() << endl;
+            FGElectricalSwitch s( child );
             add_switch( s );
         }
     }
-
-    // do a 2nd pass to pick up starting switch value if specified
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        // cout << "  " << cname << " = " << cval << endl;
-        if ( cname == "initial-state" ) {
-            if ( cval == "off" ) {
-                set_switches( false );
-            } else {
-                set_switches( true );
-            }
-        }
-    }
 }  
 
 
@@ -249,7 +267,7 @@ void FGElectricalSystem::init () {
         SGPath config( globals->get_fg_root() );
         config.append( path_n->getStringValue() );
 
-        SG_LOG( SG_ALL, SG_ALERT, "Reading electrical system model from "
+        SG_LOG( SG_ALL, SG_INFO, "Reading electrical system model from "
                 << config.str() );
         try {
             readProperties( config.str(), config_props );
@@ -270,9 +288,10 @@ void FGElectricalSystem::init () {
                     << config.str() );
         }
 
-    } else
-        SG_LOG( SG_ALL, SG_ALERT,
+    } else {
+        SG_LOG( SG_ALL, SG_WARN,
                 "No electrical model specified for this model!");
+    }
 
     delete config_props;
 }