From: Mikko Rasa Date: Thu, 7 Nov 2013 22:01:03 +0000 (+0200) Subject: Refer to things in the driver with abstract ids instead of addresses X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=73e4a36bbf828e07b83a779b696875e1f80045cc;p=r2c2.git Refer to things in the driver with abstract ids instead of addresses Since different protocols can and do have overlapping address spaces, the address alone isn't sufficient to identify a thing. Passing both address and protocol in every function and signal would make the interface too complicated. At the moment only locomotives can have a protocol specified, but there's no technical reason why other types of things couldn't have different protocols as well. --- diff --git a/source/libr2c2/arducontrol.cpp b/source/libr2c2/arducontrol.cpp index 213a848..9cf8383 100644 --- a/source/libr2c2/arducontrol.cpp +++ b/source/libr2c2/arducontrol.cpp @@ -70,7 +70,7 @@ unsigned ArduControl::get_protocol_speed_steps(const string &proto_name) const return 0; } -void ArduControl::add_loco(unsigned addr, const string &proto_name, const VehicleType &) +unsigned ArduControl::add_loco(unsigned addr, const string &proto_name, const VehicleType &) { if(!addr) throw invalid_argument("ArduControl::add_loco"); @@ -83,19 +83,22 @@ void ArduControl::add_loco(unsigned addr, const string &proto_name, const Vehicl throw invalid_argument("ArduControl::add_loco"); } - insert_unique(locomotives, addr, Locomotive(proto, addr)); + Locomotive loco(proto, addr); + insert_unique(locomotives, loco.id, loco); + + return loco.id; } -void ArduControl::remove_loco(unsigned addr) +void ArduControl::remove_loco(unsigned id) { - Locomotive &loco = get_item(locomotives, addr); + Locomotive &loco = get_item(locomotives, id); remove_loco_from_refresh(loco); - locomotives.erase(addr); + locomotives.erase(id); } -void ArduControl::set_loco_speed(unsigned addr, unsigned speed) +void ArduControl::set_loco_speed(unsigned id, unsigned speed) { - Locomotive &loco = get_item(locomotives, addr); + Locomotive &loco = get_item(locomotives, id); if(loco.speed.set(speed)) { QueuedCommand cmd(loco, Locomotive::SPEED); @@ -105,9 +108,9 @@ void ArduControl::set_loco_speed(unsigned addr, unsigned speed) } } -void ArduControl::set_loco_reverse(unsigned addr, bool rev) +void ArduControl::set_loco_reverse(unsigned id, bool rev) { - Locomotive &loco = get_item(locomotives, addr); + Locomotive &loco = get_item(locomotives, id); if(loco.reverse.set(rev)) { QueuedCommand cmd(loco, Locomotive::REVERSE); @@ -117,9 +120,9 @@ void ArduControl::set_loco_reverse(unsigned addr, bool rev) } } -void ArduControl::set_loco_function(unsigned addr, unsigned func, bool state) +void ArduControl::set_loco_function(unsigned id, unsigned func, bool state) { - Locomotive &loco = get_item(locomotives, addr); + Locomotive &loco = get_item(locomotives, id); unsigned mask = 1<=n_s88_octets) n_s88_octets = octet_index+1; + + return addr; } void ArduControl::remove_sensor(unsigned addr) @@ -314,7 +320,7 @@ void ArduControl::tick() } else if(tag.type==Tag::LOCOMOTIVE) { - LocomotiveMap::iterator i = locomotives.find(tag.address); + LocomotiveMap::iterator i = locomotives.find(tag.id); if(i==locomotives.end()) continue; @@ -322,12 +328,12 @@ void ArduControl::tick() if(tag.command==Locomotive::SPEED) { if(loco.speed.commit(tag.serial)) - signal_loco_speed.emit(loco.address, loco.speed, loco.reverse); + signal_loco_speed.emit(loco.id, loco.speed, loco.reverse); } else if(tag.command==Locomotive::REVERSE) { if(loco.reverse.commit(tag.serial)) - signal_loco_speed.emit(loco.address, loco.speed, loco.reverse); + signal_loco_speed.emit(loco.id, loco.speed, loco.reverse); } else if(tag.command==Locomotive::FUNCTIONS) { @@ -337,13 +343,13 @@ void ArduControl::tick() unsigned changed = old^loco.funcs; for(unsigned j=0; changed>>j; ++j) if((changed>>j)&1) - signal_loco_function.emit(loco.address, j, (loco.funcs>>j)&1); + signal_loco_function.emit(loco.id, j, (loco.funcs>>j)&1); } } } else if(tag.type==Tag::ACCESSORY) { - AccessoryMap::iterator i = accessories.find(tag.address); + AccessoryMap::iterator i = accessories.find(tag.id); if(i==accessories.end()) continue; @@ -370,7 +376,7 @@ void ArduControl::tick() } else if(tag.type==Tag::SENSOR) { - SensorMap::iterator i = sensors.find(tag.address); + SensorMap::iterator i = sensors.find(tag.id); if(i==sensors.end()) continue; @@ -456,11 +462,12 @@ ArduControl::Tag::Tag(): type(NONE), command(0), serial(0), - address(0) + id(0) { } ArduControl::Locomotive::Locomotive(Protocol p, unsigned a): + id((p<<16)|a), proto(p), address(a), speed(0), @@ -667,7 +674,7 @@ void ArduControl::ControlThread::main() stag.type = Tag::SENSOR; stag.command = Sensor::STATE; stag.serial = i->second.state.serial; - stag.address = i->first; + stag.id = i->first; control.push_completed_tag(stag); } @@ -697,7 +704,7 @@ ArduControl::QueuedCommand::QueuedCommand(Locomotive &loco, Locomotive::Command { tag.type = Tag::LOCOMOTIVE; tag.command = cmd; - tag.address = loco.address; + tag.id = loco.id; if(cmd==Locomotive::SPEED) { tag.serial = loco.speed.serial; @@ -721,7 +728,7 @@ ArduControl::QueuedCommand::QueuedCommand(Accessory &acc, Accessory::Command cmd { tag.type = Tag::ACCESSORY; tag.command = cmd; - tag.address = acc.address; + tag.id = acc.address; if(cmd==Accessory::ACTIVATE || cmd==Accessory::DEACTIVATE) { tag.serial = acc.state.serial; diff --git a/source/libr2c2/arducontrol.h b/source/libr2c2/arducontrol.h index cbdecad..f0c14f9 100644 --- a/source/libr2c2/arducontrol.h +++ b/source/libr2c2/arducontrol.h @@ -52,7 +52,7 @@ private: Type type; unsigned char command; unsigned short serial; - unsigned address; + unsigned id; Tag(); @@ -95,6 +95,7 @@ private: FUNCTIONS }; + unsigned id; Protocol proto; unsigned address; ControlledVariable speed; @@ -216,7 +217,7 @@ private: public: virtual unsigned get_protocol_speed_steps(const std::string &) const; - virtual void add_loco(unsigned, const std::string &, const VehicleType &); + virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &); virtual void remove_loco(unsigned); virtual void set_loco_speed(unsigned, unsigned); virtual void set_loco_reverse(unsigned, bool); @@ -228,24 +229,24 @@ private: void advance_next_refresh(); public: - virtual void add_turnout(unsigned, const TrackType &); + virtual unsigned add_turnout(unsigned, const TrackType &); virtual void remove_turnout(unsigned); virtual void set_turnout(unsigned, unsigned); virtual unsigned get_turnout(unsigned) const; - virtual void add_signal(unsigned, const SignalType &); + virtual unsigned add_signal(unsigned, const SignalType &); virtual void remove_signal(unsigned); virtual void set_signal(unsigned, unsigned); virtual unsigned get_signal(unsigned) const; private: - void add_accessory(Accessory::Kind, unsigned, unsigned); + unsigned add_accessory(Accessory::Kind, unsigned, unsigned); void remove_accessory(Accessory::Kind, unsigned); void set_accessory(Accessory::Kind, unsigned, unsigned); unsigned get_accessory(Accessory::Kind, unsigned) const; public: - virtual void add_sensor(unsigned); + virtual unsigned add_sensor(unsigned); virtual void remove_sensor(unsigned); virtual void set_sensor(unsigned, bool) { } virtual bool get_sensor(unsigned) const; diff --git a/source/libr2c2/centralstation.cpp b/source/libr2c2/centralstation.cpp index 2138e10..124c1be 100644 --- a/source/libr2c2/centralstation.cpp +++ b/source/libr2c2/centralstation.cpp @@ -88,7 +88,7 @@ unsigned CentralStation::get_protocol_speed_steps(const string &name) const } } -void CentralStation::add_loco(unsigned addr, const string &proto_name, const VehicleType &type) +unsigned CentralStation::add_loco(unsigned addr, const string &proto_name, const VehicleType &type) { Protocol proto = map_protocol(proto_name); @@ -109,6 +109,8 @@ void CentralStation::add_loco(unsigned addr, const string &proto_name, const Veh } else command(format("request(%d, view, control, force)", id)); + + return addr; } void CentralStation::remove_loco(unsigned addr) @@ -147,7 +149,7 @@ void CentralStation::set_loco_function(unsigned addr, unsigned func, bool state) command(format("set(%d, func[%d, %d])", id, func, state)); } -void CentralStation::add_turnout(unsigned addr, const TrackType &type) +unsigned CentralStation::add_turnout(unsigned addr, const TrackType &type) { unsigned straight = type.get_paths(); bool left = false; @@ -180,6 +182,8 @@ void CentralStation::add_turnout(unsigned addr, const TrackType &type) MagnetAccessory &turnout = add_accessory(addr, MagnetAccessory::TURNOUT, symbol); turnout.bits = type.get_state_bits(); + + return addr; } void CentralStation::remove_turnout(unsigned addr) @@ -197,9 +201,10 @@ unsigned CentralStation::get_turnout(unsigned addr) const return get_accessory_state(addr, MagnetAccessory::TURNOUT); } -void CentralStation::add_signal(unsigned addr, const SignalType &) +unsigned CentralStation::add_signal(unsigned addr, const SignalType &) { add_accessory(addr, MagnetAccessory::SIGNAL, MagnetAccessory::SEMAPHORE_HOME); + return addr; } void CentralStation::remove_signal(unsigned addr) @@ -298,7 +303,7 @@ void CentralStation::accessory_state_changed(const MagnetAccessory &accessory) c signal_signal.emit(accessory.address, accessory.state); } -void CentralStation::add_sensor(unsigned addr) +unsigned CentralStation::add_sensor(unsigned addr) { sensors.insert(SensorMap::value_type(addr, Sensor())); @@ -307,6 +312,8 @@ void CentralStation::add_sensor(unsigned addr) if(addr>s88.size()*16) command("create(26, add[0])"); } + + return addr; } void CentralStation::remove_sensor(unsigned) diff --git a/source/libr2c2/centralstation.h b/source/libr2c2/centralstation.h index a34a3e3..acfc7d6 100644 --- a/source/libr2c2/centralstation.h +++ b/source/libr2c2/centralstation.h @@ -137,18 +137,18 @@ public: virtual const char *enumerate_protocols(unsigned) const; virtual unsigned get_protocol_speed_steps(const std::string &) const; - virtual void add_loco(unsigned, const std::string &, const VehicleType &); + virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &); virtual void remove_loco(unsigned); virtual void set_loco_speed(unsigned, unsigned); virtual void set_loco_reverse(unsigned, bool); virtual void set_loco_function(unsigned, unsigned, bool); - virtual void add_turnout(unsigned, const TrackType &); + virtual unsigned add_turnout(unsigned, const TrackType &); virtual void remove_turnout(unsigned); virtual void set_turnout(unsigned, unsigned); virtual unsigned get_turnout(unsigned) const; - virtual void add_signal(unsigned, const SignalType &); + virtual unsigned add_signal(unsigned, const SignalType &); virtual void remove_signal(unsigned); virtual void set_signal(unsigned, unsigned); virtual unsigned get_signal(unsigned) const; @@ -161,7 +161,7 @@ private: void accessory_state_changed(const MagnetAccessory &) const; public: - virtual void add_sensor(unsigned); + virtual unsigned add_sensor(unsigned); virtual void remove_sensor(unsigned); virtual void set_sensor(unsigned, bool) { } virtual bool get_sensor(unsigned) const; diff --git a/source/libr2c2/driver.h b/source/libr2c2/driver.h index 9648c92..1014260 100644 --- a/source/libr2c2/driver.h +++ b/source/libr2c2/driver.h @@ -33,23 +33,23 @@ public: virtual const char *enumerate_protocols(unsigned) const = 0; virtual unsigned get_protocol_speed_steps(const std::string &) const = 0; - virtual void add_loco(unsigned, const std::string &, const VehicleType &) = 0; + virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &) = 0; virtual void remove_loco(unsigned) = 0; virtual void set_loco_speed(unsigned, unsigned) = 0; virtual void set_loco_reverse(unsigned, bool) = 0; virtual void set_loco_function(unsigned, unsigned, bool) = 0; - virtual void add_turnout(unsigned, const TrackType &) = 0; + virtual unsigned add_turnout(unsigned, const TrackType &) = 0; virtual void remove_turnout(unsigned) = 0; virtual void set_turnout(unsigned, unsigned) = 0; virtual unsigned get_turnout(unsigned) const = 0; - virtual void add_signal(unsigned, const SignalType &) = 0; + virtual unsigned add_signal(unsigned, const SignalType &) = 0; virtual void remove_signal(unsigned) = 0; virtual void set_signal(unsigned, unsigned) = 0; virtual unsigned get_signal(unsigned) const = 0; - virtual void add_sensor(unsigned) = 0; + virtual unsigned add_sensor(unsigned) = 0; virtual void remove_sensor(unsigned) = 0; virtual void set_sensor(unsigned, bool) = 0; virtual bool get_sensor(unsigned) const = 0; diff --git a/source/libr2c2/dummy.cpp b/source/libr2c2/dummy.cpp index cb625dd..9ccb1bc 100644 --- a/source/libr2c2/dummy.cpp +++ b/source/libr2c2/dummy.cpp @@ -42,9 +42,10 @@ unsigned Dummy::get_protocol_speed_steps(const string &) const return 0; } -void Dummy::add_turnout(unsigned addr, const TrackType &) +unsigned Dummy::add_turnout(unsigned addr, const TrackType &) { turnouts[addr]; + return addr; } void Dummy::set_turnout(unsigned addr, unsigned state) diff --git a/source/libr2c2/dummy.h b/source/libr2c2/dummy.h index 933fce6..4c43d14 100644 --- a/source/libr2c2/dummy.h +++ b/source/libr2c2/dummy.h @@ -40,23 +40,23 @@ public: virtual const char *enumerate_protocols(unsigned) const; virtual unsigned get_protocol_speed_steps(const std::string &) const; - virtual void add_loco(unsigned, const std::string &, const VehicleType &) { } + virtual unsigned add_loco(unsigned a, const std::string &, const VehicleType &) { return a; } virtual void remove_loco(unsigned) { } virtual void set_loco_speed(unsigned, unsigned); virtual void set_loco_reverse(unsigned, bool); virtual void set_loco_function(unsigned, unsigned, bool); - virtual void add_turnout(unsigned, const TrackType &); + virtual unsigned add_turnout(unsigned, const TrackType &); virtual void remove_turnout(unsigned) { } virtual void set_turnout(unsigned, unsigned); virtual unsigned get_turnout(unsigned) const; - virtual void add_signal(unsigned, const SignalType &) { } + virtual unsigned add_signal(unsigned a, const SignalType &) { return a; } virtual void remove_signal(unsigned) { } virtual void set_signal(unsigned, unsigned) { } virtual unsigned get_signal(unsigned) const { return 0; } - virtual void add_sensor(unsigned) { } + virtual unsigned add_sensor(unsigned a) { return a; } virtual void remove_sensor(unsigned) { } virtual void set_sensor(unsigned, bool); virtual bool get_sensor(unsigned) const; diff --git a/source/libr2c2/intellibox.cpp b/source/libr2c2/intellibox.cpp index 338aed2..975c143 100644 --- a/source/libr2c2/intellibox.cpp +++ b/source/libr2c2/intellibox.cpp @@ -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,8 @@ 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) @@ -197,9 +199,9 @@ 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::remove_turnout(unsigned addr) @@ -207,7 +209,7 @@ void Intellibox::remove_turnout(unsigned addr) turnouts.erase(addr); } -void Intellibox::add_turnout(unsigned addr, unsigned bits, bool signal) +unsigned Intellibox::add_turnout(unsigned addr, unsigned bits, bool signal) { if(!turnouts.count(addr)) { @@ -229,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 @@ -269,9 +273,9 @@ 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) @@ -289,13 +293,15 @@ 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) diff --git a/source/libr2c2/intellibox.h b/source/libr2c2/intellibox.h index 46c769b..8058aab 100644 --- a/source/libr2c2/intellibox.h +++ b/source/libr2c2/intellibox.h @@ -136,28 +136,28 @@ public: virtual const char *enumerate_protocols(unsigned) const; virtual unsigned get_protocol_speed_steps(const std::string &) const; - virtual void add_loco(unsigned, const std::string &, const VehicleType &); + virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &); virtual void remove_loco(unsigned); virtual void set_loco_speed(unsigned, unsigned); virtual void set_loco_reverse(unsigned, bool); virtual void set_loco_function(unsigned, unsigned, bool); - virtual void add_turnout(unsigned, const TrackType &); + virtual unsigned add_turnout(unsigned, const TrackType &); virtual void remove_turnout(unsigned); private: - void add_turnout(unsigned, unsigned, bool); + unsigned add_turnout(unsigned, unsigned, bool); void turnout_state_changed(unsigned, const Turnout &) const; public: virtual void set_turnout(unsigned, unsigned); virtual unsigned get_turnout(unsigned) const; - virtual void add_signal(unsigned, const SignalType &); + virtual unsigned add_signal(unsigned, const SignalType &); virtual void remove_signal(unsigned); virtual void set_signal(unsigned, unsigned); virtual unsigned get_signal(unsigned) const; public: - virtual void add_sensor(unsigned); + virtual unsigned add_sensor(unsigned); virtual void remove_sensor(unsigned); virtual void set_sensor(unsigned, bool) { } virtual bool get_sensor(unsigned) const; diff --git a/source/libr2c2/sensor.cpp b/source/libr2c2/sensor.cpp index 618a06b..ecd0647 100644 --- a/source/libr2c2/sensor.cpp +++ b/source/libr2c2/sensor.cpp @@ -9,6 +9,7 @@ namespace R2C2 { Sensor::Sensor(Layout &l): layout(l), address(0), + id(0), invert(false), state(INACTIVE) { @@ -28,11 +29,13 @@ Sensor::~Sensor() void Sensor::set_address(unsigned a) { Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0); - if(driver && address) - driver->remove_sensor(address); + if(driver && id) + driver->remove_sensor(id); address = a; if(driver && address) - driver->add_sensor(address); + id = driver->add_sensor(address); + else + id = 0; } void Sensor::tick(const Time::TimeDelta &dt) @@ -52,9 +55,9 @@ void Sensor::tick(const Time::TimeDelta &dt) } } -void Sensor::event(unsigned a, bool s) +void Sensor::event(unsigned i, bool s) { - if(a==address) + if(i==id) { if(s!=invert && stateremove_turnout(turnout_addr); + if(driver && turnout_id) + driver->remove_turnout(turnout_id); turnout_addr = a; layout.create_blocks(*this); layout.update_routes(); if(driver && turnout_addr) - driver->add_turnout(turnout_addr, type); + turnout_id = driver->add_turnout(turnout_addr, type); + else + turnout_id = 0; } void Track::set_sensor_address(unsigned a) @@ -186,14 +188,14 @@ void Track::set_sensor_address(unsigned a) void Track::set_active_path(unsigned p) { - if(!turnout_addr) + if(!type.is_turnout()) throw logic_error("not a turnout"); if(!(type.get_paths()&(1< &st) const st.push_back((DataFile::Statement("flex"), true)); } -void Track::turnout_event(unsigned addr, unsigned state) +void Track::turnout_event(unsigned id, unsigned state) { - if(addr==turnout_addr) + if(id==turnout_id) { active_path = state; path_changing = false; diff --git a/source/libr2c2/track.h b/source/libr2c2/track.h index 1d8cd71..ad4ad21 100644 --- a/source/libr2c2/track.h +++ b/source/libr2c2/track.h @@ -43,6 +43,7 @@ private: float slope; bool flex; unsigned turnout_addr; + unsigned turnout_id; unsigned sensor_addr; std::vector links; unsigned active_path; diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 50ad137..bb82fe4 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -58,7 +58,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p): layout.add_train(*this); - layout.get_driver().add_loco(address, protocol, loco_type); + loco_id = layout.get_driver().add_loco(address, protocol, loco_type); layout.get_driver().signal_loco_speed.connect(sigc::mem_fun(this, &Train::loco_speed_event)); layout.get_driver().signal_loco_function.connect(sigc::mem_fun(this, &Train::loco_func_event)); @@ -140,7 +140,7 @@ void Train::set_function(unsigned func, bool state) { if(!loco_type.get_functions().count(func)) throw invalid_argument("Train::set_function"); - layout.get_driver().set_loco_function(address, func, state); + layout.get_driver().set_loco_function(loco_id, func, state); } float Train::get_control(const string &ctrl) const @@ -317,7 +317,7 @@ void Train::tick(const Time::TimeDelta &dt) bool r = reverse; if(loco_type.get_swap_direction()) r = !r; - driver.set_loco_reverse(address, r); + driver.set_loco_reverse(loco_id, r); allocator.reverse(); last_entry_block = BlockIter(); @@ -329,7 +329,7 @@ void Train::tick(const Time::TimeDelta &dt) if(speed_step!=current_speed_step && !speed_changing && !driver.is_halted() && driver.get_power()) { speed_changing = true; - driver.set_loco_speed(address, speed_step); + driver.set_loco_speed(loco_id, speed_step); pure_speed = false; } @@ -404,24 +404,24 @@ void Train::control_changed(const Controller::Control &ctrl) signal_control_changed.emit(ctrl.name, ctrl.value); } -void Train::loco_speed_event(unsigned addr, unsigned speed, bool rev) +void Train::loco_speed_event(unsigned id, unsigned speed, bool rev) { - if(addr==address) + if(id==loco_id) { current_speed_step = speed; bool r = reverse; if(loco_type.get_swap_direction()) r = !r; if(rev!=r) - layout.get_driver().set_loco_reverse(address, r); + layout.get_driver().set_loco_reverse(loco_id, r); speed_changing = false; pure_speed = false; } } -void Train::loco_func_event(unsigned addr, unsigned func, bool state) +void Train::loco_func_event(unsigned id, unsigned func, bool state) { - if(addr==address) + if(id==loco_id) { if(state) functions |= 1< vehicles;