1
0
Fork 0

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.
This commit is contained in:
Torsten Dreyer 2010-05-27 22:22:01 +02:00
parent 321bbeb2e8
commit 54c964aed5

View file

@ -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( _rs ) { // RS: reset is dominant
if( s ) q = true; // set
if( r ) q = false; // reset
// s && q: race condition. we let r win
} 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() << ":"