]> git.tdb.fi Git - r2c2.git/commitdiff
Flip turnout path bits so they match the Central Station's idea of states
authorMikko Rasa <tdb@tdb.fi>
Tue, 23 Nov 2010 05:59:11 +0000 (05:59 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 23 Nov 2010 05:59:11 +0000 (05:59 +0000)
Some multi-bit turnout fixes in Intellibox driver

source/libr2c2/intellibox.cpp
tracks.dat

index 64e785582dce0f8895deda28493af96cb5f7974c..7702ed6b1bdde49b9309c2da9ef72f54fd3e2ae6 100644 (file)
@@ -257,7 +257,7 @@ void Intellibox::set_turnout(unsigned addr, unsigned state)
 
        for(unsigned i=0; i<turnout.bits; ++i)
                if((state^turnout.state)&(1<<i))
-                       turnout_command(addr+i, state&(1<<i), true);
+                       turnout_command(addr+i, !(state&(1<<i)), true);
 }
 
 unsigned Intellibox::get_turnout(unsigned addr) const
@@ -309,7 +309,8 @@ void Intellibox::tick()
                {
                        i->second.active = false;
                        i->second.off_timeout = Time::TimeStamp();
-                       turnout_command(i->first, i->second.state, false);
+                       for(unsigned j=0; j<i->second.bits; ++j)
+                               turnout_command(i->first+j, !(i->second.state&(1<<j)), false);
                }
 
        for(map<unsigned, Sensor>::iterator i=sensors.begin(); i!=sensors.end(); ++i)
@@ -490,8 +491,12 @@ void Intellibox::process_reply(const Time::TimeStamp &t)
                        read_all(data, 2);
 
                        unsigned addr = data[0]+((data[1]&7)<<8);
+                       unsigned mask = 1;
+                       for(; !turnouts[addr].bits; --addr, mask<<=1) ;
                        Turnout &turnout = turnouts[addr];
-                       turnout.state = (data[1]&0x80)!=0;
+
+                       unsigned bit = !(data[1]&0x80);
+                       turnout.state = (turnout.state&~mask) | (bit*mask);
                        turnout.pending = turnout.state;
                        signal_turnout.emit(addr, turnout.state);
                }
@@ -553,11 +558,7 @@ void Intellibox::process_reply(const Time::TimeStamp &t)
 
                unsigned addr = queue.front().addr;
                unsigned mask = 1;
-               while(!turnouts[addr].bits)
-               {
-                       --addr;
-                       mask <<= 1;
-               }
+               for(; !turnouts[addr].bits; --addr, mask<<=1) ;
                Turnout &turnout = turnouts[addr];
 
                if(err==ERR_NO_ERROR)
@@ -590,17 +591,13 @@ void Intellibox::process_reply(const Time::TimeStamp &t)
 
                        unsigned addr = queue.front().addr;
                        unsigned mask = 1;
-                       while(!turnouts[addr].bits)
-                       {
-                               --addr;
-                               mask <<= 1;
-                       }
+                       for(; !turnouts[addr].bits; --addr, mask<<=1) ;
                        Turnout &turnout = turnouts[addr];
 
-                       bool state = data&0x04;
-                       if(state!=((turnout.state&mask)!=0))
+                       bool bit = !(data&0x04);
+                       if(bit!=((turnout.state&mask)!=0))
                        {
-                               turnout.state = (turnout.state&~mask) | (state ? mask : 0);
+                               turnout.state = (turnout.state&~mask) | (bit*mask);
                                turnout.pending = turnout.state;
                                signal_turnout.emit(addr, turnout.state);
                        }
index 7a5eb8b9935f1b6cdf5742a0440dabe61a912569..bd3187a9bf25fea01d4d77aa53691659002ea4db 100644 (file)
@@ -236,20 +236,20 @@ track 24671
        part
        {
                length 77.5;
-               path 1;
+               path 0;
        };
        part
        {
                start 77.5 0 0;
                length 30;
                radius 360;
-               path 1;
+               path 0;
        };
        part
        {
                length 30;
                radius 360;
-               path 0;
+               path 1;
        };
 };
 
@@ -259,20 +259,20 @@ track 24672
        part
        {
                length 77.5;
-               path 1;
+               path 0;
        };
        part
        {
                start 77.5 0 0;
                length 30;
                radius -360;
-               path 1;
+               path 0;
        };
        part
        {
                length 30;
                radius -360;
-               path 0;
+               path 1;
        };
 };
 
@@ -284,13 +284,13 @@ track 24611
        part
        {
                length 188.3;
-               path 1;
+               path 0;
        };
        part
        {
                length 24.3;
                radius 437.5;
-               path 0;
+               path 1;
        };
 };
 
@@ -300,13 +300,13 @@ track 24612
        part
        {
                length 188.3;
-               path 1;
+               path 0;
        };
        part
        {
                length 24.3;
                radius -437.5;
-               path 0;
+               path 1;
        };
 };
 
@@ -316,7 +316,7 @@ track 24630
        part
        {
                length 188.3;
-               path 3;
+               path 0;
        };
        part
        {
@@ -339,26 +339,26 @@ track 24624
        part
        {
                length 188.3;
-               path 3;
+               path 0;
        };
        part
        {
                length 24.3;
                radius -437.5;
-               path 2;
+               path 1;
        };
        part
        {
                start 8.34 38.74 -24.3;
                length 188.3;
-               path 1;
+               path 2;
        };
        part
        {
                start 8.34 38.74 -24.3;
                length 24.3;
                radius 437.5;
-               path 0;
+               path 3;
        };
 };
 
@@ -370,13 +370,13 @@ track 24711
        part
        {
                length 236.1;
-               path 1;
+               path 0;
        };
        part
        {
                length 12.1;
                radius 1114.6;
-               path 0;
+               path 1;
        };
 };
 
@@ -386,13 +386,13 @@ track 24712
        part
        {
                length 236.1;
-               path 1;
+               path 0;
        };
        part
        {
                length 12.1;
                radius -1114.6;
-               path 0;
+               path 1;
        };
 };