From 54c964aed5708291a9bf7cfcef37aee6cb2061f5 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Thu, 27 May 2010 22:22:01 +0200 Subject: [PATCH] Respect different behaviour of RS and SR flip flops No more invalid states here. According to IEC 61131, RS flip flop have dominant reset and SR have dominant set. This is now implemented. --- src/Autopilot/xmlauto.cxx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Autopilot/xmlauto.cxx b/src/Autopilot/xmlauto.cxx index 9c91bff15..189100187 100644 --- a/src/Autopilot/xmlauto.cxx +++ b/src/Autopilot/xmlauto.cxx @@ -918,9 +918,15 @@ void FGXMLAutoLogic::update(double dt) } class FGXMLAutoRSFlipFlop : public FGXMLAutoFlipFlop { +private: + bool _rs; public: FGXMLAutoRSFlipFlop( SGPropertyNode * node ) : - FGXMLAutoFlipFlop( node ) {} + FGXMLAutoFlipFlop( node ) { + // type exists here, otherwise we were not constructed + string val = node->getNode( "type" )->getStringValue(); + _rs = (val == "RS"); + } void updateState( double dt ) { @@ -940,9 +946,13 @@ public: // s == false && q == false: no change, keep state if( s || r ) { bool q = false; - if( s ) q = true; // set - if( r ) q = false; // reset - // s && q: race condition. we let r win + if( _rs ) { // RS: reset is dominant + if( s ) q = true; // set + if( r ) q = false; // reset + } else { // SR: set is dominant + if( r ) q = false; // reset + if( s ) q = true; // set + } if( inverted ) q = !q; if ( debug ) cout << "Updating " << get_name() << ":" @@ -1374,7 +1384,7 @@ bool FGXMLAutopilot::build( SGPropertyNode_ptr config_props ) { string val; if( typeNode != NULL ) val = typeNode->getStringValue(); val = simgear::strutils::strip(val); - if( val == "RS" || val =="SR" ) flipFlop = new FGXMLAutoRSFlipFlop( node ); + if( val == "RS" || val =="SR" ) flipFlop = new FGXMLAutoRSFlipFlop( node ); else if( val == "JK" ) flipFlop = new FGXMLAutoJKFlipFlop( node ); else if( val == "T" ) flipFlop = new FGXMLAutoTFlipFlop( node ); else if( val == "D" ) flipFlop = new FGXMLAutoDFlipFlop( node ); -- 2.39.5