summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Jung2011-05-16 02:34:11 (EDT)
committer Henrik Rentz-Reichert2011-05-16 02:34:11 (EDT)
commitdfbb97017b5482a6aff9768df56ab341542ec79c (patch)
tree4aed88fee8630ed6b96945a22e8b6f8da4a1a581
parent7a464d8e671526a7820d5702d308b30905e39151 (diff)
downloadorg.eclipse.etrice-dfbb97017b5482a6aff9768df56ab341542ec79c.zip
org.eclipse.etrice-dfbb97017b5482a6aff9768df56ab341542ec79c.tar.gz
org.eclipse.etrice-dfbb97017b5482a6aff9768df56ab341542ec79c.tar.bz2
blinky tutorial
contributed from https://bugs.eclipse.org/bugs/show_bug.cgi?id=345825 by Thomas Jung
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/015-getting-started.textile9
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile353
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/etrice-index.txt1
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky01.pngbin0 -> 76433 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky02.pngbin0 -> 33987 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky03.pngbin0 -> 82645 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky04.pngbin0 -> 87665 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky05.pngbin0 -> 51030 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky06.pngbin0 -> 42110 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky07.pngbin0 -> 66597 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky08.pngbin0 -> 10939 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky09.pngbin0 -> 139947 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky10.pngbin0 -> 52521 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky11.pngbin0 -> 79155 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky12.pngbin0 -> 53077 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky13.pngbin0 -> 66735 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky14.pngbin0 -> 60308 bytes
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/images/020-Blinky15.pngbin0 -> 54755 bytes
18 files changed, 359 insertions, 4 deletions
diff --git a/plugins/org.eclipse.etrice.doc/doc/015-getting-started.textile b/plugins/org.eclipse.etrice.doc/doc/015-getting-started.textile
index 131e4d9..390ad22 100644
--- a/plugins/org.eclipse.etrice.doc/doc/015-getting-started.textile
+++ b/plugins/org.eclipse.etrice.doc/doc/015-getting-started.textile
@@ -35,8 +35,9 @@ RoomModel HelloWorld {
ActorClass HelloWorldTop {
}
}
+bc.
-h3. Create a new model file
+h2. Create a new model file
Create a new file in your model directory and name it ??HelloWorld.room?? and select finish.
@@ -48,7 +49,7 @@ The file ending must be ??.room?? for selecting the correct editor. Open the fil
!images/015-HelloWorld02.PNG!
-h3. Create a state machine
+h2. Create a state machine
We will implement the Hello World code on the initial transition of the ??HelloWorldTop?? actor. Therefore open the state machine editor by right clicking the ??HelloWorldTop?? actor in the outline view and select ??Edit Behavior??.
@@ -67,7 +68,7 @@ Save the diagram and inspect the model file. Note that the textual representatio
!images/015-HelloWorld05.PNG!
-h3. Build and run the model
+h2. Build and run the model
Now the model is finished and source code can be generated.
From org.eclipse.etrice.doc.tutorials.scratch.workflow select genAllModells.mwe2 and run it as MWE2Workflow. Currently all models in the directory will be generated.
@@ -83,7 +84,7 @@ The Hello World application starts and the string will be printed on the console
!images/015-HelloWorld08.PNG!
-h3. Open the Message Sequence Chart
+h2. Open the Message Sequence Chart
During runtime the application produces a MSC and wrote it to a file. Open /org.eclipse.etrice.doc.tutorials/tmp/log/SubSystem_HelloWorld_Async.seq. You should see something like this:
diff --git a/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile b/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile
new file mode 100644
index 0000000..7d376f8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile
@@ -0,0 +1,353 @@
+h1. Tutorial Blinky
+
+h2. Scope
+
+This tutorial describes how to use the ??TimingService??, combine a generated model with manual code and how to modeling a hierarchical state machine. The idea of the tutorial is, to switch a LED on and off. The behavior of the LED should be: blinking in a one second interval for 5 seconds, stop blinking for 5 seconds, blinking, stop,...
+For this exercise we will use a little GUI class that will be used in more sophisticated tutorials too. The GUI simulates a pedestrian traffic crossing. For now, just a simple LED simulation will be used from the GUI.
+
+To use the GUI please copy the package ??de.protos.PedLightGUI?? to your ??src?? directory. The package contains four java classes which implements a little window with a 3-light traffic light which simulates the signals for the car traffic and a 2-light traffic light which simulates the pedestrian signals.
+
+The GUI looks like this:
+
+!images/020-Blinky08.PNG!
+
+Within this tutorial we just will switching on and off the yellow light.
+
+You will perform the following steps:
+
+# create a new model from scratch
+# define a protocol
+# create an actor structure
+# create a hierarchical state machine
+# use the predefined ??TimingService??
+# combine manual code with generated code
+# build and run the model
+# open the message sequence chart
+
+h2. Create a new model from scratch
+
+Remember exercise ??HelloWorld??.
+Create a new file in your model folder and name it ??Blinky.room??
+Open the file and copy the following code into the file.
+
+bc..
+RoomModel Blinky {
+
+ LogicalSystem System_Blinky {
+ SubSystemRef subsystem : SubSystem_Blinky
+ }
+
+ SubSystemClass SubSystem_Blinky {
+ ActorRef application : BlinkyTop
+ }
+
+ ActorClass BlinkyTop {
+ }
+}
+bq.
+
+h2. Add two additional actor classes
+
+Position the cursor outside any class definition and right click the mouse within the editor window. From the context menu select ??Content Assist??
+
+!images/020-Blinky02.png!
+
+Select ??ActorClass - actor class skeleton?? and name it ??Blinky??.
+
+!images/020-Blinky01.PNG!
+
+Repeat the described procedure and name the new actor ??BlinkyController??.
+
+Save the model and visit the outline view.
+
+h2. Create a new protocol
+
+With the help of ??Content Assist?? create a ??ProtocolClass?? and name it ??BlinkyControlProtocol??.
+Inside the brackets use the ??Content Assist?? (CTRL+Space) to create two incomming messages called ??start?? and ??stop??.
+
+The resulting code should look like this:
+
+!images/020-Blinky03.PNG!
+
+With Ctrl-Shift+F or selecting ??Format?? from the context menu you can format the text. Mention that all elements are displayed in the outline view.
+
+h2. Import the Timing Service
+
+Switching on and off the LED is timing controlled. Therefore a timing service is needed. To import the timing service in the outline view right click to ??SubSystem_Blinky??. Select ??Edit Structure??. Drag and Drop an ??ActorRef?? to the ??SubSystem_Blinky?? and name it ??application??. From the actor class drop down list select ??BlinkyTop??. Do the same clicks for the timing service. Name it ??timingService?? and from the drop down list select ??room.basic.service.timing.ATimingService??. Draw a ??LayerConnection?? from ??application?? to each service provision point (SPP) of the ??timingService??. The resulting structure should look like this:
+
+!images/020-Blinky06.PNG!
+
+The current version of eTrice does not provide a graphical element for a service access point (SAP). Therefore the SAPs to access the timing service must be added in the .room file. Open the ??Blinky.room?? file and navigate to the ??Blinky?? actor. Add the following line to the structure of the actor:
+
+bc. SAP timer: room.basic.service.timing.PTimeout
+
+Do the same thing for ??BlinkyController??.
+
+The resulting code should look like this:
+
+!images/020-Blinky07.PNG!
+
+
+h2. Finish the model structure
+
+From the outline view right click to ??Blinky?? and select ??Edit Structure??. Drag and Drop an ??Interface Port?? to the boarder of the ??Blinky?? actor. Note that an interface port is not possible inside the the actor. Name the port ??ControlPort?? and select ??BlinkyControlProtocol?? from the drop down list. Uncheck ??Conjugated?? and ??Is Relay Port??. Klick ??ok??. The resulting structure should look like this:
+
+
+!images/020-Blinky04.PNG!
+
+Repeat the above steps for the ??BlinkyController??. Make the port ??Conjugated??
+
+Keep in mind that the protocol defines ??start?? and ??stop?? as incoming messages. ??Blinky?? receives this messages and therefore ??Blinky??'s ??ControlPort?? must be a base port and ??BlinkyController??'s ??ControlPort?? must be a conjugated port.
+
+
+From the outline view right click ??BlinkyTop?? and select ??Edit Structure??.
+
+Drag and Drop an ??ActorRef?? inside the ??BlinkyTop?? actor. Name it ??blinky??. From the actor class drop down list select ??Blinky??. Do the same for ??controller??. Connect the ports via the binding tool. The resulting structure should look like this:
+
+!images/020-Blinky05.PNG!
+
+h2. Implement the Behavior
+
+The application should switch on and off the LED for 5 seconds in a 1 second interval, than stop blinking for 5 seconds and start again. To implement this behavior we will implement two FSMs. One for the 1 second interval and one for the 5 second interval. The 1 second blinking should be implemented in ??Blinky??. The 5 second interval should be implemented in ??BlinkyController??. First implement the Controller.
+
+Right click to ??BlinkyController?? and select ??Edit Behavior??.
+Drag and Drop the ??Initial Point?? and two <cite>State</cite>s into the top state. Name the states ??on?? and ??off??.
+Use the ??Transition?? tool to draw transitions from ??init?? to ??off?? from ??on?? to ??off?? and from ??off?? to ??on??.
+
+Open the transition dialog by double click the arrow to specify the trigger event and the action code of each transition. Note that the initial transition does not have a trigger event.
+
+The dialog should look like this:
+
+!{width=500px}images/020-Blinky09.PNG!
+
+The defined ports will be generated as a member attribute of the actor class from type of the attached protocol. So, to send e message you must state ??port.message(p1,p2);??. In this example ??ControlPort.start()?? sends the ??start?? message via the ??ControlPort?? to the outside world. Assuming that ??Blinky?? is connected to this port, the message will start the one second blinking FSM. It is the same thing with the ??timer??. The SAP is also a port and follows the same rules. So it is clear that ??timer.Start(5000);?? will send the ??Start?? message to the timing service. The timing service will send a ??timeoutTick?? message back after 5000ms.
+
+Within each transition the timer will be restarted and the appropriate message will be sent via the ??ControlPort??.
+
+The resulting state machine should look like this:
+
+!images/020-Blinky10.PNG!
+
+Save the diagram and inspect the ??Blinky.room?? file. The ??BlinkyController?? should look like this:
+
+!images/020-Blinky11.PNG!
+
+Now we will implement ??Blinky??. Due to the fact that ??Blinky?? interacts with the GUI class a view things must to be done in the model file.
+
+Double click ??Blinky?? in the outline view to navigate to ??Blinky?? within the model file.
+Add the following code:
+
+!images/020-Blinky12.PNG!
+
+??usercode1?? will be generated at the beginning of the file, outside the class definition. ??usercode2?? will be generated within the class definition. The code imports the GUI class and instantiates the window class. Attributes for the carLights and pedLights will be declared to easily access the lights in the state machine.
+The Operation ??destroyUser()?? is a predefined operation that will be called during shutdown of the application. Within this operation, cleanup of manual coded classes can be done.
+
+
+
+Now design the FSM of ??Blinky??. Open the behavior diagram of ??Blinky?? by right clicking the ??Blinky?? actor in the outline view. Create two states named ??blinking?? and ??off??. Right click to ??blinking?? and create a subgraph.
+
+!images/020-Blinky13.PNG!
+
+Create the following state machine. The trigger events between ??on?? and ??off?? are the ??timeoutTick?? from the ??timer?? port.
+
+!images/020-Blinky14.PNG!
+
+Create entry code for both states by right clicking the state and select ??Edit State...??
+
+Entry code of ??on?? is:
+
+bc..
+timer.Start(1000);
+carLights.setState(TrafficLight3.YELLOW);
+bq.
+
+
+Entry code of ??off?? is:
+
+bc..
+timer.Start(1000);
+carLights.setState(TrafficLight3.OFF);
+bq.
+
+Navigate to the Top level state by double clicking the ??/blinking?? state. Create the following state machine:
+
+!images/020-Blinky15.PNG!
+
+The trigger event from ??off?? to ??blinking?? is the ??start?? event from the ??ControlPort??.The trigger event from ??blinking?? to ??off?? is the ??stop?? event from the ??ControlPort??.
+
+Action code of the init transition is:
+
+bc..
+carLights = light.getCarLights();
+pedLights = light.getPedLights();
+carLights.setState(TrafficLight3.OFF);
+pedLights.setState(TrafficLight2.OFF);
+bq.
+
+Action code from ??blinking?? to ??off?? is:
+
+bc..
+timer.Kill();
+carLights.setState(TrafficLight3.OFF);
+bq.
+
+The complete resulting model looks like this:
+
+bc..
+RoomModel Blinky {
+
+ LogicalSystem System_Blinky {
+ SubSystemRef subsystem: SubSystem_Blinky
+ }
+
+ SubSystemClass SubSystem_Blinky {
+ ActorRef application: BlinkyTop
+ ActorRef timingService: room.basic.service.timing.ATimingService
+ LayerConnection ref application satisfied_by timingService.timer
+ LayerConnection ref application satisfied_by timingService.timeout
+ }
+
+ ActorClass BlinkyTop {
+ Structure {
+ ActorRef blinky: Blinky
+ ActorRef controller: BlinkyController
+ Binding blinky.ControlPort and controller.ControlPort
+ }
+ Behavior { }
+ }
+
+ ActorClass Blinky {
+ Interface {
+ Port ControlPort: BlinkyControlProtocoll
+ }
+ Structure {
+ usercode1{
+ "import de.protos.PedLightGUI.*;"
+ }
+ usercode2 {
+ "private PedestrianLightWndNoTcp light = new PedestrianLightWndNoTcp();"
+ "private TrafficLight3 carLights;"
+ "private TrafficLight2 pedLights;"
+
+ }
+ external Port ControlPort
+ SAP timer: room.basic.service.timing.PTimeout
+ }
+ Behavior {
+ Operation destroyUser(){
+ "light.closeWindow();"
+ }
+ StateMachine {
+ Transition init: initial -> off {
+ action {
+ "carLights = light.getCarLights();"
+ "pedLights = light.getPedLights();"
+ "carLights.setState(TrafficLight3.OFF);"
+ "pedLights.setState(TrafficLight2.OFF);"
+ }
+ }
+ Transition tr0: off -> tp0 of blinking {
+ triggers {
+ <start: ControlPort>
+ }
+ }
+ Transition tr1: blinking -> off {
+ triggers {
+ <stop: ControlPort>
+ }
+ action {
+ "timer.Kill();"
+ "carLights.setState(TrafficLight3.OFF);"
+ }
+ }
+ State off
+ State blinking {
+ subgraph {
+ Transition tr0: my tp0 -> on
+ Transition tr1: on -> off {
+ triggers {
+ <timeoutTick: timer>
+ }
+ }
+ Transition tr2: off -> on {
+ triggers {
+ <timeoutTick: timer>
+ }
+ }
+ Transition init: initial -> on { }
+ EntryPoint tp0
+ State on {
+ entry {
+ "timer.Start(1000);"
+ "carLights.setState(TrafficLight3.YELLOW);"
+ }
+ }
+ State off {
+ entry {
+ "timer.Start(1000);"
+ "carLights.setState(TrafficLight3.OFF);"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ ActorClass BlinkyController {
+ Interface {
+ conjugated Port ControlPort: BlinkyControlProtocoll
+ }
+ Structure {
+ external Port ControlPort
+ SAP timer: room.basic.service.timing.PTimeout
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> on {
+ action {
+ "timer.Start(5000);"
+ "ControlPort.start();"
+ }
+ }
+ Transition goOff: on -> off {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "ControlPort.stop();"
+ "timer.Start(5000);"
+ }
+ }
+ Transition goOn: off -> on {
+ triggers {
+ <timeoutTick: timer|timeoutTick: timer>
+ }
+ action {
+ "ControlPort.start();"
+ "timer.Start(5000);"
+ }
+ }
+ State on
+ State off
+ }
+ }
+ }
+
+ ProtocolClass BlinkyControlProtocoll {
+ incoming {
+ Message start()
+ Message stop()
+ }
+ outgoing { }
+ }
+
+}
+bq.
+
+The model is complete now. You can run and debug the model as described in getting started. Have fun.
+
+h2. Summary
+
+Run the model and take look at the generated MSCs. Inspect the generated code to understand the runtime model of eTrice. Within this tutorial you have learned how to create a hierarchical FSM with group transitions and history transitions and you have used entry code. You are now familiar with the basic features of eTrice. The further tutorials will take this knowledge as a precondition.
+
diff --git a/plugins/org.eclipse.etrice.doc/doc/etrice-index.txt b/plugins/org.eclipse.etrice.doc/doc/etrice-index.txt
index f59a8e0..3c27ccc 100644
--- a/plugins/org.eclipse.etrice.doc/doc/etrice-index.txt
+++ b/plugins/org.eclipse.etrice.doc/doc/etrice-index.txt
@@ -2,3 +2,4 @@
010-concepts.textile
015-getting-started.textile
+020-tutorial-blinky.textile
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky01.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky01.png
new file mode 100644
index 0000000..bdb82af
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky01.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky02.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky02.png
new file mode 100644
index 0000000..4c95a6f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky02.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky03.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky03.png
new file mode 100644
index 0000000..3c9368d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky03.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky04.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky04.png
new file mode 100644
index 0000000..1eafad9
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky04.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky05.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky05.png
new file mode 100644
index 0000000..77cf2aa
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky05.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky06.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky06.png
new file mode 100644
index 0000000..4952706
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky06.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky07.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky07.png
new file mode 100644
index 0000000..30d86ff
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky07.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky08.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky08.png
new file mode 100644
index 0000000..36950bc
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky08.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky09.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky09.png
new file mode 100644
index 0000000..8c79f07
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky09.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky10.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky10.png
new file mode 100644
index 0000000..c633e3f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky10.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky11.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky11.png
new file mode 100644
index 0000000..6d1b504
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky11.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky12.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky12.png
new file mode 100644
index 0000000..5fc09ec
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky12.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky13.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky13.png
new file mode 100644
index 0000000..7abeb00
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky13.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky14.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky14.png
new file mode 100644
index 0000000..3a83094
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky14.png
Binary files differ
diff --git a/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky15.png b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky15.png
new file mode 100644
index 0000000..df40f7a
--- /dev/null
+++ b/plugins/org.eclipse.etrice.doc/doc/images/020-Blinky15.png
Binary files differ