From: Mikko Rasa Date: Thu, 5 Jun 2008 11:09:09 +0000 (+0000) Subject: Track power status X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ca5b1fcfd52a09e3d3b2c4c011dc91ac9ad19694;p=r2c2.git Track power status --- diff --git a/source/engineer/mainpanel.cpp b/source/engineer/mainpanel.cpp index 7866a1c..0178eb4 100644 --- a/source/engineer/mainpanel.cpp +++ b/source/engineer/mainpanel.cpp @@ -48,6 +48,8 @@ MainPanel::MainPanel(Engineer &e, GLtk::Resources &r): ind_on->set_active(true); else ind_off->set_active(true); + + engineer.get_control().signal_power_event.connect(sigc::mem_fun(this, &MainPanel::power_event)); } void MainPanel::set_status_text(const string &txt) @@ -78,3 +80,9 @@ void MainPanel::quit() { engineer.quit(); } + +void MainPanel::power_event(bool p) +{ + ind_on->set_active(p); + ind_off->set_active(!p); +} diff --git a/source/engineer/mainpanel.h b/source/engineer/mainpanel.h index 3e58d12..3fff2bb 100644 --- a/source/engineer/mainpanel.h +++ b/source/engineer/mainpanel.h @@ -24,6 +24,7 @@ private: void power_off(); void new_loc(); void quit(); + void power_event(bool); }; #endif diff --git a/source/libmarklin/constants.h b/source/libmarklin/constants.h index 2db75c2..52aa5ea 100644 --- a/source/libmarklin/constants.h +++ b/source/libmarklin/constants.h @@ -38,6 +38,7 @@ enum Cmd CMD_SENSOR_STATUS=0x98, CMD_SENSOR_REPORT=0x99, CMD_SENSOR_PARAM_SET=0x9D, + CMD_STATUS=0xA2, CMD_POWER_OFF=0xA6, CMD_POWER_ON=0xA7, CMD_NOP=0xC4, diff --git a/source/libmarklin/control.cpp b/source/libmarklin/control.cpp index bd63f9f..f51dbd0 100644 --- a/source/libmarklin/control.cpp +++ b/source/libmarklin/control.cpp @@ -39,6 +39,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 +96,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 +163,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 +288,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 +313,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) diff --git a/source/libmarklin/control.h b/source/libmarklin/control.h index 0b7b8c0..df8ea1b 100644 --- a/source/libmarklin/control.h +++ b/source/libmarklin/control.h @@ -30,6 +30,7 @@ private: Msp::Time::Timer timer; public: + sigc::signal signal_power_event; sigc::signal signal_turnout_event; sigc::signal signal_sensor_event; @@ -56,6 +57,7 @@ public: private: void read_all(int, char *, int); std::string read_reply(Cmd); + void status_done(Error, const std::string &); void event_query_done(Error, const std::string &); void turnout_event_done(Error, const std::string &); void sensor_event_done(Error, const std::string &);