summaryrefslogtreecommitdiffstats
path: root/test/samples/w3c/microwave-02.scxml
blob: a96f1fd5c0d57dbbddd4566ffc61224476949982 (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
<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml"
       version="1.0"
       datamodel="ecmascript"
       initial="oven">

  <!-- trivial 5 second microwave oven example -->
  <!-- using parallel and In() predicate -->
  <datamodel>
    <data id="cook_time" expr="5"/>
    <data id="door_closed" expr="true"/>
    <data id="timer" expr="0"/>
  </datamodel>

  <parallel id="oven">

    <!-- this region tracks the microwave state and timer -->
    <state id="engine">
      <transition target="off"/>

      <state id="off">
        <!-- off state -->
        <transition event="turn.on" target="on"/>
      </state>

      <state id="on">
        <transition target="idle"/>
         <!-- on/pause state -->

        <transition event="turn.off" target="off"/>
        <transition cond="timer &gt;= cook_time" target="off"/>

        <state id="idle">
          <transition cond="In('closed')" target="cooking"/>
        </state>

        <state id="cooking">
          <transition cond="In('open')" target="idle"/>

          <!-- a 'time' event is seen once a second -->
          <transition event="time">
            <assign location="timer" expr="timer + 1"/>
          </transition>
        </state>
      </state>
    </state>

    <!-- this region tracks the microwave door state -->
    <state id="door">
      <initial>
        <transition target="closed"/>
      </initial>
      <state id="closed">
        <transition event="door.open" target="open"/>
      </state>
      <state id="open">
        <transition event="door.close" target="closed"/>
       </state>
    </state>

  </parallel>

</scxml>