X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fcentralstation.cpp;h=a41a494c440243c266d10379bd40236ea06fb03c;hb=ce29d0ccf89840c9581314301de0ea2b5b261c43;hp=69bb8a9cf48c78745bf882f764cf0c7270087152;hpb=e61a3ee0847b957152d98ba5945e42325821c357;p=r2c2.git diff --git a/source/libr2c2/centralstation.cpp b/source/libr2c2/centralstation.cpp index 69bb8a9..a41a494 100644 --- a/source/libr2c2/centralstation.cpp +++ b/source/libr2c2/centralstation.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #include #include @@ -90,7 +83,7 @@ unsigned CentralStation::get_protocol_speed_steps(const string &name) const { case MM: return 14; case MM_27: return 27; - case MFX: return 127; + case MFX: return 126; default: return 0; } } @@ -107,6 +100,10 @@ void CentralStation::add_loco(unsigned addr, const string &proto_name, const Veh loco.protocol = proto; loco.address = addr; + const VehicleType::FunctionMap &type_funcs = type.get_functions(); + for(VehicleType::FunctionMap::const_iterator i=type_funcs.begin(); i!=type_funcs.end(); ++i) + loco.func_mask |= 1<first; + if(locos_synced && proto!=MFX) command("create(10)"); } @@ -121,7 +118,12 @@ void CentralStation::set_loco_speed(unsigned addr, unsigned speed) unsigned id = map_address(locos, loco_addr, addr); if(id) + { + Locomotive &loco = locos[id]; + if(loco.protocol==MFX && speed) + ++speed; command(format("set(%d, speedstep[%d])", id, speed)); + } } void CentralStation::set_loco_reverse(unsigned addr, bool rev) @@ -157,7 +159,7 @@ void CentralStation::add_turnout(unsigned addr, const TrackType &type) cross = true; } - unsigned symbol; + unsigned symbol = Turnout::LEFT; if(cross) symbol = Turnout::DOUBLESLIP; else if(left && right) @@ -245,15 +247,6 @@ bool CentralStation::get_sensor(unsigned addr) const void CentralStation::tick() { - Time::TimeStamp t = Time::now(); - for(SensorMap::iterator i=sensors.begin(); i!=sensors.end(); ++i) - if(i->second.off_timeout && t>i->second.off_timeout) - { - i->second.state = false; - i->second.off_timeout = Time::TimeStamp(); - signal_sensor.emit(i->first, i->second.state); - } - while(Message msg = receive()) { if(msg.footer.code) @@ -347,7 +340,12 @@ void CentralStation::process_reply(const Message &msg) if(j!=locos.end()) { command(format("request(%d, view, control, force)", i->first)); - command(format("get(%d, dir, func[0])", i->first)); + string cmd = format("get(%d, dir", i->first); + for(unsigned l=0; j->second.func_mask>>l; ++l) + if((j->second.func_mask>>l)&1) + cmd += format(", func[%d]", l); + cmd += ')'; + command(cmd); locos.insert(LocoMap::value_type(i->first, j->second)); locos.erase(j); @@ -414,6 +412,7 @@ void CentralStation::process_reply(const Message &msg) { s88.push_back(i->first); command(format("request(%d, view)", i->first)); + command(format("get(%d, state)", i->first)); } sensors_synced = true; @@ -523,6 +522,8 @@ void CentralStation::process_object(unsigned id, const Message::AttribMap &attri else if(i->first=="speedstep") { loco.speed = lexical_cast(i->second); + if(loco.protocol==MFX && loco.speed) + --loco.speed; speed_changed = true; } else if(i->first=="dir") @@ -592,17 +593,11 @@ void CentralStation::process_object(unsigned id, const Message::AttribMap &attri unsigned addr = base*16+j+1; Sensor &sensor = sensors[addr]; bool s = state&(1<