summaryrefslogtreecommitdiffhomepage
path: root/digital/io-hub/src
diff options
context:
space:
mode:
authorNicolas Schodet2013-04-28 09:56:08 +0200
committerNicolas Schodet2013-04-28 09:56:08 +0200
commitec7fd3875d8e0699a92d7d75b504df9afa4a5cdc (patch)
tree3f4e9b0da9ecb8c39c4a3aa05ad0d9fe5100103f /digital/io-hub/src
parenta8d0ca5fdee674be6fdbac5fc3927368c745bab0 (diff)
digital/io-hub/src/apbirthday: add FSM transitions debug stat
Diffstat (limited to 'digital/io-hub/src')
-rw-r--r--digital/io-hub/src/apbirthday/Makefile7
-rw-r--r--digital/io-hub/src/apbirthday/robot.cc35
-rw-r--r--digital/io-hub/src/apbirthday/robot.hh3
-rw-r--r--digital/io-hub/src/common-cc/fsm.hh8
4 files changed, 47 insertions, 6 deletions
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 <cstdio>
+#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