]> git.tdb.fi Git - r2c2.git/commitdiff
React to overcurrent events
authorMikko Rasa <tdb@tdb.fi>
Sun, 6 Apr 2014 20:28:03 +0000 (23:28 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 6 Apr 2014 20:28:03 +0000 (23:28 +0300)
source/libr2c2/arducontrol.cpp
source/libr2c2/arducontrol.h

index 2cdf0c6798440026782b7ba3b9d2ca245b74db9a..1d1ece9adb4eb4fb5e347c373298f8d1a64f869e 100644 (file)
@@ -1214,14 +1214,11 @@ unsigned ArduControl::ControlThread::process_reply(const char *reply, unsigned r
                return type;
        }
        else if(type==POWER_STATE && rlength==2)
+               set_power(reply[1]);
+       else if(type==OVERCURRENT)
        {
-               control.power.set(reply[1]);
-
-               Tag tag;
-               tag.type = Tag::GENERAL;
-               tag.command = POWER;
-               tag.serial = control.power.serial;
-               control.completed_commands.push(tag);
+               set_power(false);
+               IO::print("Overcurrent detected!\n");
        }
        else
        {
@@ -1232,6 +1229,17 @@ unsigned ArduControl::ControlThread::process_reply(const char *reply, unsigned r
        return 0;
 }
 
+void ArduControl::ControlThread::set_power(bool p)
+{
+       control.power.set(p);
+
+       Tag tag;
+       tag.type = Tag::GENERAL;
+       tag.command = POWER;
+       tag.serial = control.power.serial;
+       control.completed_commands.push(tag);
+}
+
 
 ArduControl::Loader::Loader(ArduControl &c):
        DataFile::ObjectLoader<ArduControl>(c)
index 40c7b3c6912d47247024c5ab28461bb497a6a7f1..8d27a2f572d74e561acdbc0266dc20561a777f8c 100644 (file)
@@ -359,6 +359,7 @@ private:
                bool get_work(PendingCommand &);
                unsigned do_command(const PendingCommand &, const Msp::Time::TimeDelta &);
                unsigned process_reply(const char *, unsigned);
+               void set_power(bool);
        };
 
        typedef std::map<unsigned, Locomotive> LocomotiveMap;