]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
FSM: Small cleanup
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 16 Apr 2008 06:51:33 +0000 (08:51 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 16 Apr 2008 06:51:33 +0000 (08:51 +0200)
src/fsm/Makefile.omk
src/fsm/fsm.c
src/fsm/tests/timer.c

index cf3eeea563076d19d114acb1f681a7dd0ae246a9..b839b2bb88556e2971369e947f20b2a10b5a3b39 100644 (file)
@@ -4,3 +4,5 @@ lib_LIBRARIES = fsm
 
 fsm_SOURCES = fsm.c
 include_HEADERS = fsm.h fsm_common_events.h
+
+SUBDIRS=tests
\ No newline at end of file
index fdd0e11a53e822827df3c62798eb5a1c01d3f558..1b15863432bd35eda15addb695a0eb079755e312 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "fsm.h"
 #include <stdio.h>
+#include <string.h>
 
 const char *fsm_common_event_str(fsm_event ev)
 {
@@ -178,8 +179,11 @@ handle_event(struct robo_fsm *fsm, fsm_event event)
        fsm->event = event;     /* Set what to handle */
 
        /* This does all the magic */
-       if (fsm->state)
-               while ((ret_code = fsm->state(fsm)) != RC_WAIT);
+       if (fsm->state) {
+               do {
+                       ret_code = fsm->state(fsm);
+               } while (ret_code != RC_WAIT);
+       }
        else
             fprintf(stderr, "FSM %s: fnc->act is NULL!!!\n", fsm->debug_name);
        fsm->event.id = EV_NOEVENT;
@@ -213,6 +217,7 @@ fsm_thread_routine(void *arg)
  */
 void fsm_init(struct robo_fsm *fsm, char *debug_name)
 {
+       memset(fsm, 0, sizeof(*fsm));
        /* Execute EV_INIT immediately after start. */
        fsm_event first_event = { EV_INIT, NULL };
        fsm->sent_event = first_event;
index 673ffa5d104b5c1d2504fbd1318d98d373d0a913..649449e6516bc81cbd8cabb7298ffe7b7b816ecb 100644 (file)
@@ -1,7 +1,9 @@
 #include <unistd.h>
-#include <robot_eb2007.h>
-#include <robodata.h>
 #include <fsm.h>
+#include <stdio.h>
+
+#define DBG(f, a...)           printf(f, ## a)
+#define fsm_event_str fsm_common_event_str
 
 FSM_STATE(state1)
 {