]> git.tdb.fi Git - r2c2.git/commitdiff
Track power status
authorMikko Rasa <tdb@tdb.fi>
Thu, 5 Jun 2008 11:09:09 +0000 (11:09 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 5 Jun 2008 11:09:09 +0000 (11:09 +0000)
source/engineer/mainpanel.cpp
source/engineer/mainpanel.h
source/libmarklin/constants.h
source/libmarklin/control.cpp
source/libmarklin/control.h

index 7866a1cf1d1348340f7ccfc7e578a28a10653752..0178eb41e1c754c6ea9bcac2f913f588ccfe3e29 100644 (file)
@@ -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);
+}
index 3e58d12bdca29ba17c14986672fabafff0376d31..3fff2bbeebf9049208c9aa1c4b28668dcf6fbdad 100644 (file)
@@ -24,6 +24,7 @@ private:
        void power_off();
        void new_loc();
        void quit();
+       void power_event(bool);
 };
 
 #endif
index 2db75c2479f60d4a0c8fa3e39d3432d47ae3e19d..52aa5ea5be3c67ddb58fa66c57263f10f7e6891a 100644 (file)
@@ -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,
index bd63f9f66f661c75d110820edd7ddd3610e48d2c..f51dbd09de45a61e171672bccc5ed3a139bca2f6 100644 (file)
@@ -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)
index 0b7b8c0a00d388ed55376a2d418d7769449a6cd2..df8ea1bc3c76ad9cc51b65c0c29c81481be87644 100644 (file)
@@ -30,6 +30,7 @@ private:
        Msp::Time::Timer timer;
 
 public:
+       sigc::signal<void, bool> signal_power_event;
        sigc::signal<void, unsigned, bool> signal_turnout_event;
        sigc::signal<void, unsigned, bool> 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 &);