X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=inline;f=source%2Flibmarklin%2Fcontrol.cpp;h=ecf10348a7890a890bdc155b8ff66f04563baf14;hb=3e9c210ddc036cd015228504cc0803c909e27f84;hp=bd63f9f66f661c75d110820edd7ddd3610e48d2c;hpb=1d735b80482317fd930eb47ca255ab9f1f120a7d;p=r2c2.git diff --git a/source/libmarklin/control.cpp b/source/libmarklin/control.cpp index bd63f9f..ecf1034 100644 --- a/source/libmarklin/control.cpp +++ b/source/libmarklin/control.cpp @@ -1,3 +1,10 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + #include #include #include @@ -39,6 +46,8 @@ void Control::set_power(bool p) command(string(1, CMD_POWER_ON)); else command(string(1, CMD_POWER_OFF)); + + signal_power_event.emit(power); } void Control::set_debug(bool d) @@ -94,8 +103,11 @@ void Control::open(const string &dev) break; } } + if(!ok) throw Exception("IB not detected"); + + command(string(1, CMD_STATUS)).signal_done.connect(sigc::mem_fun(this, &Control::status_done)); } Command &Control::command(const string &cmd) @@ -158,7 +170,7 @@ void Control::tick() if(t>next_event_query) { - next_event_query=t+300*Time::msec; + next_event_query=t+200*Time::msec; command(string(1, CMD_EVENT)).signal_done.connect(sigc::mem_fun(this, &Control::event_query_done)); } @@ -283,6 +295,9 @@ string Control::read_reply(Cmd cmd) } else { + if(cmd==CMD_STATUS) + result+=ERR_NO_ERROR; + unsigned expected_bytes=1; if(cmd==CMD_FUNC_STATUS || cmd==CMD_TURNOUT_STATUS) expected_bytes=2; @@ -305,12 +320,20 @@ string Control::read_reply(Cmd cmd) return result; } +void Control::status_done(Error, const string &resp) +{ + power=((resp[0]&0x08)!=0); + signal_power_event.emit(power); +} + void Control::event_query_done(Error, const string &resp) { if(resp[0]&0x20) command(string(1, CMD_EVENT_TURNOUT)).signal_done.connect(sigc::mem_fun(this, &Control::turnout_event_done)); if(resp[0]&0x04) command(string(1, CMD_EVENT_SENSOR)).signal_done.connect(sigc::mem_fun(this, &Control::sensor_event_done)); + if(resp.size()>1 && (resp[1]&0x40)) + command(string(1, CMD_STATUS)).signal_done.connect(sigc::mem_fun(this, &Control::status_done)); } void Control::turnout_event_done(Error, const string &resp)