Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d56c5f3ab2ed4a05ef01b2a7d0b31e7cf68fafc1 (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
h1. Tutorial HelloWorld

h2. Scope

In this tutorial you will build your first very simple eTrice model. The goal is to learn the work flow of eTrice and to understand a few basic features of ROOM. You will perform the following steps:

# create a new model from scratch
# add a very simple state machine to an actor
# generate the source code
# run the model
# open the message sequence chart

h2. Create a new model from scratch

The easiest way to create a new eTrice Project is to use the eclipse project wizard. From the eclipse file menu select ??File->New->Project?? and create a new eTrice project and name it ??HelloWorld??

!images/015-HelloWorld10.PNG!

The wizard creates everything that is needed to create, build and run a eTrice model. The resulting project should look like this:

!images/015-HelloWorld11.PNG!

Within the model directory the model file ??HelloWorld.room?? was created. Open the ??HelloWorld.room?? file and position the cursor at the very beginning of the file. Open the content assist with Ctrl+Space and select ??model skeleton??.

!images/015-HelloWorld12.PNG!   

Edit the template variables and remove the artefacts from the wizard. 

The resulting model code should look like this:

bc.. 
RoomModel HelloWorld {

	LogicalSystem System_HelloWorld {
		SubSystemRef subsystem : SubSystem_HelloWorld
	}

	SubSystemClass SubSystem_HelloWorld {
		ActorRef application : HelloWorldTop
	}

	ActorClass HelloWorldTop {
	}
} 
bq. 

The goal of eTrice is to describe distributed systems on a logical level. In the current version not all elements will be supported. But as prerequisite for further versions the following elements are mandatory for an eTrice model:
* the ??LogicalSystem?? 
* at least one ??SubSystemClass??
* at least one ??ActorClass??

The ??LogicalSystem?? represents the complete distributed system and contains at least one ??SubSystemRef??. The ??SubSystemClass?? represents an address space and contains at least one ??ActorRef??. The ??ActorClass?? is the building block of which an application will be built of. It is in general a good idea to define a top level actor that can be used as reference within the subsystem.

The outline view of the textual ROOM editor shows the main modeling elements in an easy to navigate tree.


!images/015-HelloWorld02.PNG!


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??.

!images/015-HelloWorld03.PNG!

The state machine editor will be opened. Drag and drop an ??Initial Point?? from the tool box to the diagram into the top level state. Drag and drop a ??State?? from the tool box to the diagram. Confirm the dialogue with ??ok??. Select the ??Transition?? in the tool box and draw the transition from the ??Initial Point?? to the State. Open the transition dialogue by double clicking the caption of the transition and fill in the action code.

bc. System.out.println("Hello World !");
 
The result should look like this:

!images/015-HelloWorld04.PNG!

Save the diagram and inspect the model file. Note that the textual representation was created after saving the diagram.

!images/015-HelloWorld05.PNG!


h2. Build and run the model

Now the model is finished and source code can be generated. The project wizard has created a workflow that is responsible to generate the source code. From ??HelloWorld/src/workflow?? right click ??HelloWorld.mwe2?? and run it as MWE2Workflow. All model files in the model directory will be generated.

!images/015-HelloWorld06.PNG!

The code will be generated to the src-gen directory. The main function will be contained in ??SubSystem_HelloWorldRunner.java??. Select this file and run it as Java application.

!images/015-HelloWorld07.PNG!


The Hello World application starts and the string will be printed on the console window. To stop the application the user must type ??quit?? in the console window.

!images/015-HelloWorld08.PNG!

h2. Open the Message Sequence Chart

During runtime the application produced a MSC and wrote it to a file. Open /org.eclipse.etrice.doc.tutorials/tmp/log/SubSystem_HelloWorld_Async.seq using Trace2UML (it is open source and can be obtained from  http://trace2uml.tigris.org/). You should see something like this:

!images/015-HelloWorld09.PNG!


h2. Summary

Now you have generated your first eTrice model from scratch. You can switch between diagram editor and model (.room file) and you can see what will be generated during editing and saving the diagram files. 
You should take a look at the generated source files to understand how the state machine is generated and the life cycle of the application. The next tutorials will deal with more complex hierarchies in structure and behavior.
 

Back to the top