summaryrefslogtreecommitdiff
path: root/digital/io/src
diff options
context:
space:
mode:
Diffstat (limited to 'digital/io/src')
-rw-r--r--digital/io/src/gutter/Makefile24
-rw-r--r--digital/io/src/gutter/gutter.conf5
-rw-r--r--digital/io/src/gutter/gutter.fsm28
-rw-r--r--digital/io/src/gutter/gutter_robo.h35
-rw-r--r--digital/io/src/gutter/test/Makefile7
-rw-r--r--digital/io/src/gutter/test/main.c84
6 files changed, 183 insertions, 0 deletions
diff --git a/digital/io/src/gutter/Makefile b/digital/io/src/gutter/Makefile
new file mode 100644
index 00000000..63752dc5
--- /dev/null
+++ b/digital/io/src/gutter/Makefile
@@ -0,0 +1,24 @@
+CFLAGS = -O2 -Wall
+
+all: prgm exe dot png
+
+prgm: gutter.fsm gutter.conf
+ python ../../../../tools/dfagen/dfagen.py -o c -d $< -c gutter.conf -p gutter
+
+exe: gutter.fsm gutter.conf
+ make prgm
+ if [ -f gutter_cb.c ]; then patch gutter_cb.c gutter_cb_skel.c; else mv gutter_cb_skel.c gutter_cb.c; fi;
+
+dot: gutter.fsm gutter.conf
+ python ../../../../tools/dfagen/dfagen.py -o dot -d $< -c gutter.conf -p gutter
+
+png: gutter.dot
+ dot -Tpng -o gutter.png gutter.dot
+
+clean:
+ rm -f gutter.h
+ rm -f gutter_cb.c
+ rm -f gutter_cb.h
+ rm -f gutter.dot
+ rm -f gutter.png
+ rm -f gutter.c
diff --git a/digital/io/src/gutter/gutter.conf b/digital/io/src/gutter/gutter.conf
new file mode 100644
index 00000000..2f21fd61
--- /dev/null
+++ b/digital/io/src/gutter/gutter.conf
@@ -0,0 +1,5 @@
+[user]
+type = gutter_t
+type-forward-decl = typedef struct gutter_t gutter_t;
+type-decl = #include "gutter_robo.h"
+field = fsm
diff --git a/digital/io/src/gutter/gutter.fsm b/digital/io/src/gutter/gutter.fsm
new file mode 100644
index 00000000..af15c87a
--- /dev/null
+++ b/digital/io/src/gutter/gutter.fsm
@@ -0,0 +1,28 @@
+#FSM get samples
+get_samples
+
+States:
+ GO_TO_GUTTER
+ OPEN_COLLECTOR
+ CLOSE_COLLECTOR
+ END
+
+Events:
+ position_reached
+ position_failed
+ collector_opened
+ collector_closed
+
+GO_TO_GUTTER:
+ position_reached -> OPEN_COLLECTOR
+ The robo is near the gutter and the door can be opened.
+ position_failed -> .
+ The position failed, shall try another path.
+
+OPEN_COLLECTOR:
+ collector_opened -> CLOSE_COLLECTOR
+ Wait some time and clse the door.
+
+CLOSE_COLLECTOR:
+ collector_closed-> END
+ The samples has been inserted in the gutter.
diff --git a/digital/io/src/gutter/gutter_robo.h b/digital/io/src/gutter/gutter_robo.h
new file mode 100644
index 00000000..251d6f4d
--- /dev/null
+++ b/digital/io/src/gutter/gutter_robo.h
@@ -0,0 +1,35 @@
+#ifndef gutter_robo_h
+#define gutter_robo_h
+/* gutter_robo.h */
+/* {{{
+ *
+ * Copyright (C) 2008 Nélio Laranjeiro
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#include "gutter.h"
+
+struct gutter_t
+{
+ gutter_state_t fsm;
+};
+
+#endif /* gutter_robo_h */
diff --git a/digital/io/src/gutter/test/Makefile b/digital/io/src/gutter/test/Makefile
new file mode 100644
index 00000000..21470810
--- /dev/null
+++ b/digital/io/src/gutter/test/Makefile
@@ -0,0 +1,7 @@
+BASE= ..
+
+all: main.c $(BASE)/gutter.c $(BASE)/gutter_cb.c
+ gcc -g -O2 -Wall main.c $(BASE)/gutter.c $(BASE)/gutter_cb.c -o fsm
+
+clean: fsm
+ rm -f fsm
diff --git a/digital/io/src/gutter/test/main.c b/digital/io/src/gutter/test/main.c
new file mode 100644
index 00000000..08be3342
--- /dev/null
+++ b/digital/io/src/gutter/test/main.c
@@ -0,0 +1,84 @@
+/* main.c */
+/* {{{
+ *
+ * Copyright (C) 2008 Nélio Laranjeiro
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "../gutter.h"
+#include "../gutter_robo.h"
+
+#include <stdio.h>
+
+void
+gutter_print_test (gutter_t *gutter)
+{
+ printf ("Machine state ");
+
+ switch (gutter->fsm)
+ {
+ case GUTTER_STATE_END:
+ printf ("END");
+ break;
+ case GUTTER_STATE_CLOSE_COLLECTOR:
+ printf ("CLOSE COLLECTOR");
+ break;
+ case GUTTER_STATE_GO_TO_GUTTER:
+ printf ("GO_TO_GUTTER");
+ break;
+ case GUTTER_STATE_OPEN_COLLECTOR:
+ printf ("OPEN COLLECTOR");
+ break;
+ default:
+ printf ("STATE_NB");
+ }
+ printf ("\n");
+}
+
+int
+main (void)
+{
+ gutter_t gutter_fsm;
+
+ gutter_init (&gutter_fsm);
+ gutter_print_test (&gutter_fsm);
+
+ gutter_handle_event (&gutter_fsm,
+ GUTTER_EVENT_position_failed);
+
+ gutter_print_test (&gutter_fsm);
+
+ gutter_handle_event (&gutter_fsm,
+ GUTTER_EVENT_position_reached);
+
+ gutter_print_test (&gutter_fsm);
+
+ gutter_handle_event (&gutter_fsm,
+ GUTTER_EVENT_collector_opened);
+
+ gutter_print_test (&gutter_fsm);
+
+ gutter_handle_event (&gutter_fsm,
+ GUTTER_EVENT_collector_closed);
+
+ gutter_print_test (&gutter_fsm);
+
+ return 0;
+}