X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fcentralstation.cpp;h=fc7855b0726fc9fbcf8183d45e3b05ddd57d35ad;hb=67cd1b26d2833903e51b91e167a3d1f7ae884a31;hp=2138e10702ee27497e70a641edc8fbd12d9d20ab;hpb=ce2ff9a6e154f5b245cfb35114566489ab3e597c;p=r2c2.git diff --git a/source/libr2c2/centralstation.cpp b/source/libr2c2/centralstation.cpp index 2138e10..fc7855b 100644 --- a/source/libr2c2/centralstation.cpp +++ b/source/libr2c2/centralstation.cpp @@ -14,7 +14,7 @@ using namespace Msp; namespace R2C2 { -CentralStation::CentralStation(const string &host): +CentralStation::CentralStation(const Options &opts): socket(Net::INET), pending_commands(0), power(false), @@ -23,7 +23,7 @@ CentralStation::CentralStation(const string &host): accessories_synced(false), sensors_synced(false) { - RefPtr addr = Net::resolve(host+":15471"); + RefPtr addr = Net::resolve(opts.get(string())+":15471"); socket.connect(*addr); IO::print("Connected to central station at %s\n", addr->str()); @@ -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)