X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fintellibox.cpp;h=4c8f2ac783b1e6fbf73bdff9aa73d2f2b1a73e2c;hb=74f8c3beba5a6947a523119e3f26cf745725b511;hp=d4129ec7535162d44deb3225de1608423d76c759;hpb=f4b1ac84400a95e1a9fe68ff00bcd52e44911cf2;p=r2c2.git diff --git a/source/libr2c2/intellibox.cpp b/source/libr2c2/intellibox.cpp index d4129ec..4c8f2ac 100644 --- a/source/libr2c2/intellibox.cpp +++ b/source/libr2c2/intellibox.cpp @@ -13,8 +13,8 @@ using namespace Msp; namespace R2C2 { -Intellibox::Intellibox(const string &dev): - serial(dev), +Intellibox::Intellibox(const Options &opts): + serial(opts.get(string(), "ttyUSB0")), power(false), halted(false), update_sensors(false), @@ -93,7 +93,7 @@ unsigned Intellibox::get_protocol_speed_steps(const string &proto_name) const return 0; } -void Intellibox::add_loco(unsigned addr, const string &proto_name, const VehicleType &type) +unsigned Intellibox::add_loco(unsigned addr, const string &proto_name, const VehicleType &type) { Protocol proto = map_protocol(proto_name); @@ -112,6 +112,13 @@ void Intellibox::add_loco(unsigned addr, const string &proto_name, const Vehicle data[1] = (addr>>8)&0xFF; command(CMD_LOK_STATUS, addr, data, 2); } + + return addr; +} + +void Intellibox::remove_loco(unsigned addr) +{ + locos.erase(addr); } void Intellibox::set_loco_speed(unsigned addr, unsigned speed) @@ -192,12 +199,17 @@ void Intellibox::set_loco_function(unsigned addr, unsigned func, bool state) signal_loco_function.emit(addr, func, state); } -void Intellibox::add_turnout(unsigned addr, const TrackType &type) +unsigned Intellibox::add_turnout(unsigned addr, const TrackType &type) { - add_turnout(addr, type.get_state_bits(), false); + return add_turnout(addr, type.get_state_bits(), false); } -void Intellibox::add_turnout(unsigned addr, unsigned bits, bool signal) +void Intellibox::remove_turnout(unsigned addr) +{ + turnouts.erase(addr); +} + +unsigned Intellibox::add_turnout(unsigned addr, unsigned bits, bool signal) { if(!turnouts.count(addr)) { @@ -219,6 +231,8 @@ void Intellibox::add_turnout(unsigned addr, unsigned bits, bool signal) command(CMD_TURNOUT_STATUS, addr+i, data, 2); } } + + return addr; } void Intellibox::turnout_state_changed(unsigned addr, const Turnout &turnout) const @@ -259,9 +273,14 @@ unsigned Intellibox::get_turnout(unsigned addr) const return 0; } -void Intellibox::add_signal(unsigned addr, const SignalType &) +unsigned Intellibox::add_signal(unsigned addr, const SignalType &) { - add_turnout(addr, 1, true); + return add_turnout(addr, 1, true); +} + +void Intellibox::remove_signal(unsigned addr) +{ + remove_turnout(addr); } void Intellibox::set_signal(unsigned addr, unsigned state) @@ -274,13 +293,21 @@ unsigned Intellibox::get_signal(unsigned addr) const return get_turnout(addr); } -void Intellibox::add_sensor(unsigned addr) +unsigned Intellibox::add_sensor(unsigned addr) { if(!sensors.count(addr)) { sensors[addr]; update_sensors = true; } + + return addr; +} + +void Intellibox::remove_sensor(unsigned addr) +{ + sensors.erase(addr); + update_sensors = true; } bool Intellibox::get_sensor(unsigned addr) const