X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fintellibox.cpp;h=73c2057942edb295eba784d596336048048cd941;hb=4529bf980cf3558d86c07266de7d890d3f5e06a6;hp=09e4792e36a0d5837ef12b14a48f7ce9fd04fbac;hpb=8b828fc32fd210b6e335ac6614d269aa892d4d57;p=r2c2.git diff --git a/source/libr2c2/intellibox.cpp b/source/libr2c2/intellibox.cpp index 09e4792..73c2057 100644 --- a/source/libr2c2/intellibox.cpp +++ b/source/libr2c2/intellibox.cpp @@ -42,7 +42,7 @@ Intellibox::Intellibox(const string &dev): } if(!ok) - throw Exception("IB not detected"); + throw runtime_error("IB not detected"); if(p50) serial.write("xZzA1\r", 6); @@ -193,11 +193,17 @@ void Intellibox::set_loco_function(unsigned addr, unsigned func, bool state) } void Intellibox::add_turnout(unsigned addr, const TrackType &type) +{ + add_turnout(addr, type.get_state_bits(), false); +} + +void Intellibox::add_turnout(unsigned addr, unsigned bits, bool signal) { if(!turnouts.count(addr)) { Turnout &turnout = turnouts[addr]; - turnout.bits = type.get_state_bits(); + turnout.bits = bits; + turnout.signal = signal; unsigned char data[2]; data[0] = addr&0xFF; @@ -215,6 +221,14 @@ void Intellibox::add_turnout(unsigned addr, const TrackType &type) } } +void Intellibox::turnout_state_changed(unsigned addr, const Turnout &turnout) const +{ + if(turnout.signal) + signal_signal.emit(addr, turnout.state); + else + signal_turnout.emit(addr, turnout.state); +} + void Intellibox::set_turnout(unsigned addr, unsigned state) { Turnout &turnout = turnouts[addr]; @@ -223,7 +237,7 @@ void Intellibox::set_turnout(unsigned addr, unsigned state) { turnout.state = state; turnout.pending = state; - signal_turnout.emit(addr, state); + turnout_state_changed(addr, turnout); return; } @@ -245,6 +259,21 @@ unsigned Intellibox::get_turnout(unsigned addr) const return 0; } +void Intellibox::add_signal(unsigned addr, const SignalType &) +{ + add_turnout(addr, 1, true); +} + +void Intellibox::set_signal(unsigned addr, unsigned state) +{ + set_turnout(addr, state); +} + +unsigned Intellibox::get_signal(unsigned addr) const +{ + return get_turnout(addr); +} + void Intellibox::add_sensor(unsigned addr) { if(!sensors.count(addr)) @@ -354,7 +383,7 @@ Intellibox::Protocol Intellibox::map_protocol(const string &name) const else if(name=="MM-27") return MM_27; else - throw InvalidParameterValue("Unknown protocol"); + throw invalid_argument("Intellibox::map_protocol"); } void Intellibox::command(Command cmd) @@ -472,7 +501,7 @@ void Intellibox::process_reply(const Time::TimeStamp &t) unsigned bit = !(data[1]&0x80); turnout.state = (turnout.state&~mask) | (bit*mask); turnout.pending = turnout.state; - signal_turnout.emit(addr, turnout.state); + turnout_state_changed(addr,turnout); } } else if(cmd==CMD_EVENT_SENSOR) @@ -541,7 +570,7 @@ void Intellibox::process_reply(const Time::TimeStamp &t) if(turnout.active) { if(turnout.state==turnout.pending) - signal_turnout.emit(addr, turnout.state); + turnout_state_changed(addr, turnout); turnout.off_timeout = t+500*Time::msec; } } @@ -573,7 +602,7 @@ void Intellibox::process_reply(const Time::TimeStamp &t) { turnout.state = (turnout.state&~mask) | (bit*mask); turnout.pending = turnout.state; - signal_turnout.emit(addr, turnout.state); + turnout_state_changed(addr, turnout); } turnout.synced = true; @@ -723,7 +752,8 @@ Intellibox::Turnout::Turnout(): state(0), active(false), synced(false), - pending(0) + pending(0), + signal(false) { }