+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
#include <fcntl.h>
#include <termios.h>
#include <sys/poll.h>
command(string(1, CMD_POWER_ON));
else
command(string(1, CMD_POWER_OFF));
+
+ signal_power_event.emit(power);
}
void Control::set_debug(bool d)
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)
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));
}
}
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;
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)