From: Mikko Rasa Date: Tue, 23 Nov 2010 05:59:11 +0000 (+0000) Subject: Flip turnout path bits so they match the Central Station's idea of states X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=85362cce505281c1d281c959e135c9f8fa12bd5c;p=r2c2.git Flip turnout path bits so they match the Central Station's idea of states Some multi-bit turnout fixes in Intellibox driver --- diff --git a/source/libr2c2/intellibox.cpp b/source/libr2c2/intellibox.cpp index 64e7855..7702ed6 100644 --- a/source/libr2c2/intellibox.cpp +++ b/source/libr2c2/intellibox.cpp @@ -257,7 +257,7 @@ void Intellibox::set_turnout(unsigned addr, unsigned state) for(unsigned i=0; isecond.active = false; i->second.off_timeout = Time::TimeStamp(); - turnout_command(i->first, i->second.state, false); + for(unsigned j=0; jsecond.bits; ++j) + turnout_command(i->first+j, !(i->second.state&(1<::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); } diff --git a/tracks.dat b/tracks.dat index 7a5eb8b..bd3187a 100644 --- a/tracks.dat +++ b/tracks.dat @@ -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; }; };