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. There are some more steps to do in C compared to Java. You will perform the following steps:
You will perform the following steps:
Make sure that you have set up the workspace as described in Setting up the Workspace for C.
Before you can create a new C-model, you have to create a new C project as described in Setting up the Workspace for C Projects.
Your project explorer should look like this:
The next step is to add the model folder: Right click on the new project. Select New->Folder and name it model.
Add the model file to the folder. Right click on the new folder. Select New->file and name it HelloWorldC.room.
Since the file extension .room is recognised as an Xtext based format, the tool will ask you to add the Xtext nature. Answer with Yes.
Open the HelloWorld.room file and delete the contents of the file. Open the content assist with <Ctrl>+<Space> and select RoomModel - model skeleton.
Edit the template variables by typing the new names and jumping with <Tab> from name to name.
The resulting model code should look like this:
Now create the file model/HelloWorldC.etphys for the physical model and insert (<Ctrl>+<Space>) the code template PhysicalModel - model skeleton without changes.
Listing for HelloWorldC.etphys :
The physical model defines the setup of your nodes with their attributes like threads and mode of execution. In this case we define one node with one thread.
The mapping model we will create now defines the mapping (deployment) of the logical elements in the .room model to the physical elements int the .etphys model. Now create the file model/HelloWorldC.etmap for the mapping model and insert (Ctrl+Space) the code template MappingModel - model skeleton with some changes (jump with <Tab> between the template variables):
Now the workspace should look like this:
The goal of eTrice is to describe distributed systems on a logical level. In the current version not all elements will be used. But as prerequisite for further versions the following elements can be defined:
The LogicalSystem represents the complete distributed system and contains at least one SubSystemRef. The SubSystemClass represents an address space (e.g. a linux process or an image for a microcontroller) and contains at least one ActorRef. The ActorClass is the building block for building the hierachical structure of an application. A good point to start is to define a top level actor that can be used as structural root within the subsystem.
The outline view of the textual ROOM editor shows the main modeling elements in a navigation tree. You can jump to an element in the textual editor by double clicking the element in the outline view.
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.
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 transition arrow and fill in the action code. Be aware of the different action code in Java and C.
action code for Java
action code for C
The result should look like this:
Save the diagram and inspect the model (HelloWorld.room) file. Note that the textual representation was changed after saving the diagram.
room model for Java
room model for C
Unlike in Java a launch configuration for the C code generator must be created.
From the main menu Run or the context menu Run As in the Project Explorer select Run Configurations .
Within the dialog select eTrice C Generator and click the New button to create a new launch configuration.
A new configuration should be created. Name it gen_HelloWorld and add the mapping model HelloWorld.etmap model via one of the add buttons.
The mapping model is the root model for the code generator.
To save your launch configuration, select Shared file in the tab Common and add the HelloWorldC project via the Browse button.
Apply your changes. The new configuration should now exist in your workspace.
Now you can generate the code. Right click on the launch configuration and run it as gen_HelloWorldC.
The code should be generated and placed in the src-gen folder.
Before you can build the application you must setup the include and library pathes for the runtime system.
Right click the project and select Properties -> C/C++ Build -> Settings -> Includes. Add the include path for the current project src-gen and the runtime source folders common, config and the chosen platform ( MT_WIN_MinGW or MT_POSIX_GENERIC_GCC ).
Add the runtime library: Properties -> C/C++ Build -> Settings -> Libraries.
The name of the library is org.eclipse.etrice.runtime.c but the actual filename for the library is liborg.eclipse.etrice.runtime.c.a .
Exclude the folder src-gen-info from the build path. This folder is used to store temporary files for the incremetal code generation and must not be compiled in order to avoid multiple definition of symbols.
Now you can build the application. Click the build button (hammer symbol) to build the application. Run the application in the folder Binary as Local C/C++ Application. The output in the Console View should contain the message Hello World.
For debugging and learning purposes, the application produced a Message Sequence Chart and wrote it to a file. Open the file subSysRef1_Async.seq or msc.seq in the folder HelloWorld/tmp/log/ using the tool Trace2UML. Create the path if not already there.
Trace2UML is an open source MSC viewer and can be obtained here:
After opening the file, you should see something like this:
The Actor with the instance path /LogSys1/subSysRef1/actorRef1 is in the state state0. This is the simplest possible MSC. The MSCs for further tutorials will contain more information.
You are now familiar with all necessary steps to create, build and run an eTrice C model from scratch. You are able to create a launch configuration to start the code generator and to perform all necessary settings to compile and link the application.
The next tutorial provides an exercise to get more familiar with these working steps.