From ec7fd3875d8e0699a92d7d75b504df9afa4a5cdc Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sun, 28 Apr 2013 09:56:08 +0200 Subject: digital/io-hub/src/apbirthday: add FSM transitions debug stat --- digital/io-hub/src/apbirthday/Makefile | 7 ++++++- digital/io-hub/src/apbirthday/robot.cc | 35 ++++++++++++++++++++++++++++++++++ digital/io-hub/src/apbirthday/robot.hh | 3 +++ digital/io-hub/src/common-cc/fsm.hh | 8 +++----- 4 files changed, 47 insertions(+), 6 deletions(-) (limited to 'digital/io-hub') diff --git a/digital/io-hub/src/apbirthday/Makefile b/digital/io-hub/src/apbirthday/Makefile index 7f99d3dd..75c38c98 100644 --- a/digital/io-hub/src/apbirthday/Makefile +++ b/digital/io-hub/src/apbirthday/Makefile @@ -27,6 +27,11 @@ AVR_SOURCES = $(foreach module,$(AVR_MODULES),$($(subst /,_,$(module))_SOURCES)) # FSM. INCLUDES += -I$(BASE)/../ai/src/fsm -I. +FSM_EMBEDDED_STRINGS = n +ifeq ($(FSM_EMBEDDED_STRINGS),y) + ANGFSM_OPTIONS += --ang-embedded-strings + DEFS += -DFSM_EMBEDDED_STRINGS=1 +endif vpath angfsm.host.c $(BASE)/../ai/src/fsm # Common files. @@ -42,6 +47,6 @@ clean.project: obj/main.stm32f4.o: angfsm_gen_arm_AI.h angfsm_gen_arm_AI.arm.c: angfsm_gen_arm_AI.h angfsm_gen_arm_AI.h: apbirthday.host - ./$< --ang-gen arm && mv angfsm_gen_arm_AI.c angfsm_gen_arm_AI.arm.c + ./$< $(ANGFSM_OPTIONS) --ang-gen arm && mv angfsm_gen_arm_AI.c angfsm_gen_arm_AI.arm.c host: all.host diff --git a/digital/io-hub/src/apbirthday/robot.cc b/digital/io-hub/src/apbirthday/robot.cc index 6a425085..08222e22 100644 --- a/digital/io-hub/src/apbirthday/robot.cc +++ b/digital/io-hub/src/apbirthday/robot.cc @@ -29,6 +29,10 @@ #include "ucoolib/arch/arch.hh" #include "ucoolib/utils/bytes.hh" +#ifdef FSM_EMBEDDED_STRINGS +# include +#endif + Robot *robot; Robot::Robot () @@ -328,6 +332,11 @@ Robot::proto_handle (ucoo::Proto &proto, char cmd, const uint8_t *args, int size stats_pressure_cpt_ = stats_pressure_ = args[0]; stats_proto_ = &proto; break; + case c ('T', 0): + // Transitions. + ANGFSM_TRANS_CALLBACK (Robot::trans_callback); + stats_proto_ = &proto; + break; case c ('b', 2): // Candles arm manipulation. // - 00: arm events @@ -499,3 +508,29 @@ Robot::proto_stats () } } +void +Robot::trans_callback (int state, int event, int output_state, int branch) +{ +#ifdef FSM_EMBEDDED_STRINGS + ucoo::Stream *s; + if (robot->stats_proto_ == &robot->dev_proto) + s = &robot->hardware.dev_uart; + else if (robot->stats_proto_ == &robot->zb_proto) + s = &robot->hardware.zb_uart; + else if (robot->stats_proto_ == &robot->usb_proto) + s = &robot->hardware.usb; + else + return; + char buf[256]; + int n = snprintf (buf, sizeof (buf), "%s -> %s -> %s\n", + ANGFSM_STATE_STR (State (state)), + ANGFSM_EVENT_STR (Event (event)), + ANGFSM_STATE_STR (State (output_state))); + s->write (buf, n); +#else + if (robot->stats_proto_) + robot->stats_proto_->send ('T', "BBBB", state, event, output_state, + branch); +#endif +} + diff --git a/digital/io-hub/src/apbirthday/robot.hh b/digital/io-hub/src/apbirthday/robot.hh index eaca4dfb..549415f3 100644 --- a/digital/io-hub/src/apbirthday/robot.hh +++ b/digital/io-hub/src/apbirthday/robot.hh @@ -65,6 +65,9 @@ class Robot : public ucoo::Proto::Handler void proto_handle (ucoo::Proto &proto, char cmd, const uint8_t *args, int size); /// Send stats. void proto_stats (); + /// Transition callback. + static void trans_callback (int state, int event, int output_state, + int branch); public: /// Public access to hardware class. Hardware hardware; diff --git a/digital/io-hub/src/common-cc/fsm.hh b/digital/io-hub/src/common-cc/fsm.hh index 300ea62f..dd4f1b77 100644 --- a/digital/io-hub/src/common-cc/fsm.hh +++ b/digital/io-hub/src/common-cc/fsm.hh @@ -30,14 +30,12 @@ extern "C" { } #ifdef TARGET_host +typedef unsigned State; typedef unsigned Branch; -#else -typedef angfsm_AI_branch_t Branch; -#endif - -#ifdef TARGET_host typedef uint16_t Event; #else +typedef angfsm_AI_state_t State; +typedef angfsm_AI_branch_t Branch; typedef angfsm_AI_event_t Event; #endif -- cgit v1.2.3