summaryrefslogtreecommitdiff
path: root/tools/dfagen/examples/ex2_cb.c.patch
blob: 09f03791a00f8962f16d025ce1a66ca4669b5af4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- ex2_cb_skel.c	2008-06-10 17:47:09.000000000 +0200
+++ ex2_cb.c	2008-06-10 17:47:09.000000000 +0200
@@ -6,6 +6,9 @@
  * A barman robot.
  */
 #include "ex2_cb.h"
+#include "ex2_robot.h"
+
+#include <stdio.h>
 
 /*
  * IDLE =command=>
@@ -19,9 +22,25 @@
 ex2_branch_t
 ex2_idle_command (robot_t *user)
 {
-    return ex2_next_branch (IDLE, command, with_ice);
-    return ex2_next_branch (IDLE, command, without_ice);
-    return ex2_next_branch (IDLE, command, empty_bottle);
+    if (user->bottle)
+      {
+	user->bottle--;
+	if (user->ice)
+	  {
+	    puts ("open the ice door");
+	    return ex2_next_branch (IDLE, command, with_ice);
+	  }
+	else
+	  {
+	    puts ("start filling");
+	    return ex2_next_branch (IDLE, command, without_ice);
+	  }
+      }
+    else
+      {
+	puts ("empty bottle, please replace it");
+	return ex2_next_branch (IDLE, command, empty_bottle);
+      }
 }
 
 /*
@@ -32,6 +51,8 @@
 ex2_branch_t
 ex2_idle_replace (robot_t *user)
 {
+    puts ("reset glass counter");
+    user->bottle = 3;
     return ex2_next (IDLE, replace_bottle);
 }
 
@@ -44,6 +65,8 @@
 ex2_branch_t
 ex2__DROPPING_ICE__ice_dropped (robot_t *user)
 {
+    puts ("close the ice door");
+    puts ("start filling");
     return ex2_next (DROPPING_ICE, ice_dropped);
 }
 
@@ -77,6 +100,7 @@
 ex2_branch_t
 ex2__FILLING_GLASS__glass_filled (robot_t *user)
 {
+    puts ("stop filling");
     return ex2_next (FILLING_GLASS, glass_filled);
 }