From fe8b45dc60ed7828f0b4af9daa9b4cd0649415ca Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 6 Apr 2014 23:28:03 +0300 Subject: [PATCH] React to overcurrent events --- source/libr2c2/arducontrol.cpp | 22 +++++++++++++++------- source/libr2c2/arducontrol.h | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/source/libr2c2/arducontrol.cpp b/source/libr2c2/arducontrol.cpp index 2cdf0c6..1d1ece9 100644 --- a/source/libr2c2/arducontrol.cpp +++ b/source/libr2c2/arducontrol.cpp @@ -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(c) diff --git a/source/libr2c2/arducontrol.h b/source/libr2c2/arducontrol.h index 40c7b3c..8d27a2f 100644 --- a/source/libr2c2/arducontrol.h +++ b/source/libr2c2/arducontrol.h @@ -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 LocomotiveMap; -- 2.45.2