From 9ee19a4d7c2abfcf73001c391687250961597337 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sun, 24 Mar 2013 00:15:58 +0100 Subject: digital/io-hub/src/apbirthday: add FSM debug --- digital/io-hub/src/apbirthday/robot.cc | 13 +++++++++++-- digital/io-hub/src/apbirthday/robot.hh | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'digital/io-hub') diff --git a/digital/io-hub/src/apbirthday/robot.cc b/digital/io-hub/src/apbirthday/robot.cc index 25ea7059..2dc3de95 100644 --- a/digital/io-hub/src/apbirthday/robot.cc +++ b/digital/io-hub/src/apbirthday/robot.cc @@ -37,6 +37,7 @@ Robot::Robot () zb_proto (*this, hardware.zb_uart), usb_proto (*this, hardware.usb), chrono (90000 - 1000), + fsm_debug_state_ (FSM_DEBUG_RUN), outputs_set_ (outputs_, lengthof (outputs_)), stats_proto_ (0), stats_chrono_ (false), stats_chrono_last_s_ (-1), @@ -92,8 +93,12 @@ Robot::main_loop () // Handle communications. bool sync = main_i2c_queue_.sync (); // Handle events if synchronised. - if (sync) - fsm_gen_event (); + if (sync && fsm_debug_state_ != FSM_DEBUG_STOP) + { + if (fsm_gen_event () + && fsm_debug_state_ == FSM_DEBUG_STEP) + fsm_debug_state_ = FSM_DEBUG_STOP; + } // Handle commands. dev_proto.accept (); zb_proto.accept (); @@ -147,6 +152,10 @@ Robot::proto_handle (ucoo::Proto &proto, char cmd, const uint8_t *args, int size // Reset. ucoo::arch_reset (); break; + case c ('f', 0): + // Enter FSM debug mode, then step once. + fsm_debug_state_ = FSM_DEBUG_STEP; + break; case c ('m', 5): // Go to position. // 2H: x, y. diff --git a/digital/io-hub/src/apbirthday/robot.hh b/digital/io-hub/src/apbirthday/robot.hh index f7d5e57a..99997fd0 100644 --- a/digital/io-hub/src/apbirthday/robot.hh +++ b/digital/io-hub/src/apbirthday/robot.hh @@ -63,6 +63,17 @@ class Robot : public ucoo::Proto::Handler /// Public access to chrono. Chrono chrono; private: + /// FSM debug mode. + enum FsmDebugState + { + /// Not debugging, running. + FSM_DEBUG_RUN, + /// Will stop after next transition. + FSM_DEBUG_STEP, + /// Stopped, waiting for orders. + FSM_DEBUG_STOP, + }; + FsmDebugState fsm_debug_state_; /// All inputs. ucoo::Io *inputs_[Hardware::inputs_nb]; /// All outputs. -- cgit v1.2.3