From 3e6ac8acfe6d8ab9ac0b78f767d79ea936861fbe Mon Sep 17 00:00:00 2001 From: Henrik Rentz-Reichert Date: Wed, 3 Aug 2011 10:43:52 +0200 Subject: [doc] minor changes and typos also fixed footer of PDF to display eTrice 0.1 Change-Id: I378cbe74c6d6aaf6d3d73b9b942a5db32a5ba5cc --- .../org.eclipse.etrice.doc/build/etrice.textile | 279 ++++++- plugins/org.eclipse.etrice.doc/build/etrice.xml | 469 ++++++++++-- .../doc/015-getting-started.textile | 12 +- .../doc/020-tutorial-blinky.textile | 16 +- .../doc/025-tutorial-sending-data.textile | 810 +++++++++++---------- .../doc/030-tutorial-ped-lights.textile | 474 ++++++------ .../org.eclipse.etrice.doc/help/Addadataclass.html | 120 +-- .../help/Buildandrunthemodel.html | 2 +- .../help/CreateMrPingandMrPongActors.html | 202 ++--- .../help/Createanewmodelfromscratch.html | 4 +- .../help/Createanewmodelfromscratch3.html | 106 +-- .../help/Createanewprotocol.html | 4 +- .../help/Createanewprotocol2.html | 102 +-- .../help/DefineActorStructureandBehavior.html | 183 +++++ .../help/DefinetheActorsStructureandBehavior.html | 183 ----- .../help/Definethetoplevel.html | 387 +++++----- .../help/Finishthemodelstructure.html | 2 +- .../help/Generateandrunthemodel.html | 158 ++-- .../help/ImplementtheBehavior.html | 2 +- .../help/OpentheMessageSequenceChart.html | 2 +- .../org.eclipse.etrice.doc/help/ROOMConcepts.html | 2 +- .../org.eclipse.etrice.doc/help/Setupthemodel.html | 316 ++++++++ plugins/org.eclipse.etrice.doc/help/Summary.html | 2 +- plugins/org.eclipse.etrice.doc/help/Summary2.html | 2 +- plugins/org.eclipse.etrice.doc/help/Summary3.html | 72 +- .../help/TutorialBlinky.html | 6 +- .../help/TutorialHelloWorld.html | 2 +- .../help/TutorialPedestrianLights.html | 84 +++ .../help/TutorialSendingData.html | 182 ++--- .../help/Whydoesitworkandwhyisitsafe.html | 48 ++ .../help/images/025-SendigData03.png | Bin 9756 -> 0 bytes .../help/images/030-PedLights01.png | Bin 0 -> 40586 bytes .../help/images/030-PedLights02.png | Bin 0 -> 59926 bytes .../help/images/030-PedLights03.png | Bin 0 -> 91507 bytes .../help/images/030-PedLights04.png | Bin 0 -> 57514 bytes plugins/org.eclipse.etrice.doc/html/etrice.html | 561 ++++++++++++-- .../html/images/025-SendigData03.png | Bin 9756 -> 0 bytes .../html/images/030-PedLights01.png | Bin 0 -> 40586 bytes .../html/images/030-PedLights02.png | Bin 0 -> 59926 bytes .../html/images/030-PedLights03.png | Bin 0 -> 91507 bytes .../html/images/030-PedLights04.png | Bin 0 -> 57514 bytes plugins/org.eclipse.etrice.doc/manual/etrice.pdf | Bin 2701349 -> 2939168 bytes plugins/org.eclipse.etrice.doc/styles/fopdf.xsl | 2 +- plugins/org.eclipse.etrice.doc/styles/xmpp.xsl | 4 +- plugins/org.eclipse.etrice.doc/toc.xml | 11 +- 45 files changed, 3129 insertions(+), 1682 deletions(-) create mode 100644 plugins/org.eclipse.etrice.doc/help/DefineActorStructureandBehavior.html delete mode 100644 plugins/org.eclipse.etrice.doc/help/DefinetheActorsStructureandBehavior.html create mode 100644 plugins/org.eclipse.etrice.doc/help/Setupthemodel.html create mode 100644 plugins/org.eclipse.etrice.doc/help/TutorialPedestrianLights.html create mode 100644 plugins/org.eclipse.etrice.doc/help/Whydoesitworkandwhyisitsafe.html delete mode 100644 plugins/org.eclipse.etrice.doc/help/images/025-SendigData03.png create mode 100644 plugins/org.eclipse.etrice.doc/help/images/030-PedLights01.png create mode 100644 plugins/org.eclipse.etrice.doc/help/images/030-PedLights02.png create mode 100644 plugins/org.eclipse.etrice.doc/help/images/030-PedLights03.png create mode 100644 plugins/org.eclipse.etrice.doc/help/images/030-PedLights04.png delete mode 100644 plugins/org.eclipse.etrice.doc/html/images/025-SendigData03.png create mode 100644 plugins/org.eclipse.etrice.doc/html/images/030-PedLights01.png create mode 100644 plugins/org.eclipse.etrice.doc/html/images/030-PedLights02.png create mode 100644 plugins/org.eclipse.etrice.doc/html/images/030-PedLights03.png create mode 100644 plugins/org.eclipse.etrice.doc/html/images/030-PedLights04.png diff --git a/plugins/org.eclipse.etrice.doc/build/etrice.textile b/plugins/org.eclipse.etrice.doc/build/etrice.textile index 059f85413..ff1173635 100644 --- a/plugins/org.eclipse.etrice.doc/build/etrice.textile +++ b/plugins/org.eclipse.etrice.doc/build/etrice.textile @@ -27,7 +27,7 @@ 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: +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 @@ -74,9 +74,9 @@ The goal of eTrice is to describe distributed systems on a logical level. In the * 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 build of. It is a good idea to define a top level actor that can be used as reference within the subsystem. +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. -Mention that a outline view was created that represents all currently existing model elements in a graphical way. +The outline view of the textual ROOM editor shows the main modeling elements in an easy to navigate tree. !images/015-HelloWorld02.PNG! @@ -107,7 +107,7 @@ Now the model is finished and source code can be generated. The project wizard h !images/015-HelloWorld06.PNG! -The code will be generated to the src-gen directory. The main class will be contained in ??SubSystem_HelloWorldRunner.java??. Select this file and run it as Java application. +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! @@ -118,7 +118,7 @@ The Hello World application starts and the string will be printed on the console 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: +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! @@ -126,23 +126,23 @@ During runtime the application produces a MSC and wrote it to a file. Open /org. 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 deals with more complex state machines hierarchies in structure and behavior. +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. 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,... +This tutorial describes how to use the ??TimingService??, how to combine a generated model with manual code and how to model 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. +To use the GUI please copy the package ??de.protos.PedLightGUI?? to your ??src?? directory. The package contains four java classes which implement a small 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. +Within this tutorial we just will toggle the yellow light. You will perform the following steps: @@ -194,13 +194,13 @@ 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??. +Inside the brackets use the ??Content Assist?? (CTRL+Space) to create two incoming 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. +With Ctrl-Shift+F or selecting ??Format?? from the context menu you can format the text. Note that all elements are displayed in the outline view. h2. Import the Timing Service @@ -228,7 +228,7 @@ From the outline view right click to ??Blinky?? and select ??Edit Structure??. D 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. +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 regular port and ??BlinkyController??'s ??ControlPort?? must be a conjugated port. From the outline view right click ??BlinkyTop?? and select ??Edit Structure??. @@ -251,7 +251,7 @@ 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. +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(param);??. 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??. @@ -480,7 +480,7 @@ The model is complete now. You can run and debug the model as described in getti 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. +Run the model and take a 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. h1. Tutorial Sending Data @@ -488,7 +488,7 @@ h1. Tutorial Sending Data h2. Scope This tutorial shows how data will be sent in a eTrice model. Within the example you will create two actors (MrPing and MrPong). MrPong will simply loop back every data it received. -MrPing will sent data and verify the result. +MrPing will send data and verify the result. You will perform the following steps: @@ -505,6 +505,7 @@ Remember exercise ??HelloWorld??. Create a new eTrice project and name it ??SendingData?? Open the ??SendingData.room?? file and copy the following code into the file or use content assist to create the model. + bc.. RoomModel SendingData { LogicalSystem SendingData_LogSystem { @@ -610,7 +611,7 @@ The outline view should look like this: !images/025-SendingData03.png! -h2. Define the Actors Structure and Behavior +h2. Define Actor Structure and Behavior Save the model and visit the outline view. Within the outline view, right click on the ??MrPong?? actor and select ??Edit Structure??. Select an ??Interface Port?? from the toolbox and add it to MrPong. Name the Port ??PingPongPort?? and select the ??PingPongProtocol?? @@ -685,7 +686,6 @@ Open the Structure from SendingDataTop and add MrPing and MrPong as a reference. The model is finished now and the model file should look like this: -pre.. bc.. RoomModel SendingData { @@ -831,7 +831,7 @@ h2. Generate and run the model With the MWe2 workflow generate the code and run the model. The output should look like this: - +bq.. type 'quit' to exit /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping @@ -879,13 +879,252 @@ d.stringVal: some contents /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong quit echo: quit +bq. h2. Summary -Within the first loop a integer value will be incremented from ??MrPong?? and sent back to ??MrPing??. Is long as the guard is true ??MrPing?? sends back the value. +Within the first loop an integer value will be incremented from ??MrPong?? and sent back to ??MrPing??. As long as the guard is true ??MrPing?? sends back the value. Within the ??next?? transition, ??MrPing?? creates a data class and sends the default values. Than ??MrPing?? changes the values and sends the class again. At this point you should note that during the send operation, a copy of the data class will be created and sent. Otherwise it would not be possible to send the same object two times, even more it would not be possible to send a stack object at all. -In later versions of eTrice a additional mechanism to send references will be implemented. However, keep in mind that sending references takes the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. +In future versions of eTrice an additional mechanism to send references will be implemented. However, keep in mind that sending references transfers the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. + + + +h1. Tutorial Pedestrian Lights + +h2. Scope + +The scope of this tutorial is to demonstrate how to receive model messages from outside the model. Calling methods which are not part of the model is simple and you have already done this within the blinky tutorial (this is the other way round: model => external code). Receiving events from outside the model is a very common problem and a very frequently asked question. Therefore this tutorial shows how an external event (outside the model) can be received from the model. + +This tutorial is not like hello world or blinky. Being familiar with the basic tool features is mandatory for this tutorial. The goal is to understand the mechanism not to learn the tool features. + +The idea behind the exercise is, to control a Pedestrian crossing light. We will use the same GUI as for the blinky tutorial but now we will use the ??REQUEST?? button to start a FSM, which controls the traffic lights. + +!images/020-Blinky08.PNG! + +The ??REQUEST?? must lead to a model message which starts the activity of the lights. + +There are several possibilities to receive external events (e.g. TCP/UDP Socket, using OS messaging mechanism), but the easiest way is, to make a port usable from outside the model. To do that a few steps are necessary: +# specify the messages (within a protocol) which should be sent into the model +# model an actor with a port (which uses the specified protocol) and connect the port to the receiver +# the external code should know the port (import of the port class) +# the external code should provide a registration method, so that the actor is able to allow access to this port +# the port can be used from the external code + +h2. Setup the model + +* Use the ??New Model Wizzard?? to create a new eTrice project and name it ??PedLightsController??. +* Copy the package ??de.protos.PedLightGUI?? to your ??src?? directory (see blinky tutorial). +* In PedestrianLightWndNoTcp.jav uncomment line 15 (import), 36, 122 (usage) and 132-134 (registration). +* Copy the following model to your model file: + +bc.. +RoomModel PedLightsController { + + LogicalSystem LogSys_PedLights { + SubSystemRef application: SubSys_PedLights + } + + SubSystemClass SubSys_PedLights { + ActorRef PedLightsTopRef: PedLightsTop + ActorRef timingService: room.basic.service.timing.ATimingService + LayerConnection ref PedLightsTopRef satisfied_by timingService.timer + LayerConnection ref PedLightsTopRef satisfied_by timingService.timeout + } + + ActorClass PedLightsTop { + Structure { + ActorRef adapter: GuiAdapter + ActorRef controller: Controller + Binding adapter.ControlPort and controller.ControlPort + } + Behavior { } + } + + ActorClass GuiAdapter { + Interface { + conjugated Port ControlPort: PedControlProtocol + } + Structure { + usercode1 { + "import PedLightGUI.*;" + } + usercode2 { + "private PedestrianLightWndNoTcp lights = new PedestrianLightWndNoTcp(\"Pedestrian Lights\",\" external port connection \");" + "private TrafficLight3 carLights;" + "private TrafficLight2 pedLights;" + } + external Port ControlPort + } + Behavior { + Operation destroyUser() { + "lights.closeWindow();" + } + StateMachine { + Transition init: initial -> running { + action { + "carLights=lights.getCarLights();" + "pedLights=lights.getPedLights();" + "carLights.setState(TrafficLight3.OFF);" + "pedLights.setState(TrafficLight2.OFF);" + "lights.setPort(ControlPort);" + } + } + Transition tr0: running -> running { + triggers { + + } + action { + "carLights.setState(state);" + } + } + Transition tr1: running -> running { + triggers { + + } + action { + "pedLights.setState(state);" + } + } + State running + } + } + } + + ActorClass Controller { + Interface { + Port ControlPort: PedControlProtocol + } + Structure { + usercode1 { + "import PedLightGUI.*;" + } + external Port ControlPort + SAP timer: room.basic.service.timing.PTimeout + } + Behavior { + StateMachine { + Transition init: initial -> off { } + Transition tr0: off -> carsGreen { + triggers { + + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.GREEN);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr1: carsGreen -> carsYellow { + triggers { + + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.YELLOW);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr2: carsYellow -> carsRed { + triggers { + + } + action { + "timer.Start(1500);" + "ControlPort.setCarLights(TrafficLight3.RED);" + "ControlPort.setPedLights(TrafficLight2.GREEN);" + } + } + Transition tr3: carsRed -> carsYellowRed { + triggers { + + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.YELLOW_RED);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr4: carsYellowRed -> carsGreen2 { + triggers { + + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.GREEN);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr5: carsGreen2 -> off { + triggers { + + } + action { + "ControlPort.setCarLights(TrafficLight3.OFF);" + "ControlPort.setPedLights(TrafficLight2.OFF);" + } + } + State off + State carsGreen + State carsYellow + State carsRed + State carsYellowRed + State carsGreen2 + } + } + } + + ProtocolClass PedControlProtocol { + incoming { + Message start() + } + outgoing { + Message setCarLights(state: int32) + Message setPedLights(state: int32) + } + } +} +bq. + +* Arrange the Structure and the Statemachines to understand the model + +!images/030-PedLights01.PNG! +The ??GuiAdapter?? represents the interface to the external code. It registers its ??ControlPort?? by the external code. + +!images/030-PedLights02.PNG! +Visit the initial transition to understand the registration. The actor handles the incoming messages as usual and controls the traffic lights as known from blinky. + +!images/030-PedLights03.PNG! +The ??Controller?? receives the ??start?? message and controls the timing of the lights. Note that the ??start?? message will be sent from the external code whenever the ??REQUEST?? button is pressed. + +* Visit the model and take a closer look to the following elements: +# PedControlProtocol => notice that the start message is defined as usual +# Initial transition of the ??GuiAdapter?? => see the registration +# The ??Controller?? => notice that the ??Controller?? receives the external message (not the ??GuiAdapter??). The ??GuiAdapter?? just provides its port and handles the incoming messages. +# Visit the hand written code => see the import statement of the protocol class and the usage of the port. + +* Generate and test the model +* Take a look at the generated MSC => notice that the start message will shown as if the ??GuiAdapter?? had sent it. + +!images/030-PedLights04.PNG! + +h2. Why does it work and why is it safe? + +The tutorial shows that it is generally possible to use every port from outside the model as long as the port knows its peer. This is guaranteed by describing protocol and the complete structure (especially the bindings) within the model. +The only remaining question is: Why is it safe and does not violate the "run to completion" semantic. To answer this question, take a look at the ??MessageService.java?? from the runtime environment. There you will find the receive method which puts each message into the queue. + +bc.. + @Override + public synchronized void receive(Message msg) { + if (msg!=null) { + messageQueue.push(msg); + notifyAll(); // wake up thread to compute message + } + } +bq. + +This method is synchronized. That means, regardless who sends the message, the queue is secured. If we later on (e.g. for performance reasons in C/C++) distinguish between internal and external senders (same thread or not), care must be taken to use the external (secure) queue. + diff --git a/plugins/org.eclipse.etrice.doc/build/etrice.xml b/plugins/org.eclipse.etrice.doc/build/etrice.xml index 3ee57b607..76cc63cba 100644 --- a/plugins/org.eclipse.etrice.doc/build/etrice.xml +++ b/plugins/org.eclipse.etrice.doc/build/etrice.xml @@ -29,7 +29,7 @@ Tutorial HelloWorld
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: + 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 @@ -123,9 +123,9 @@ 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 build of. It is a good idea to define a top level actor that can be used as reference within the subsystem. + 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. - Mention that a outline view was created that represents all currently existing model elements in a graphical way. + The outline view of the textual ROOM editor shows the main modeling elements in an easy to navigate tree. @@ -187,7 +187,7 @@ - The code will be generated to the src-gen directory. The main class will be contained in + 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. @@ -210,7 +210,7 @@
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: + 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: @@ -222,7 +222,7 @@
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 deals with more complex state machines hierarchies in structure and behavior. + 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.
@@ -230,12 +230,12 @@
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,... + TimingService, how to combine a generated model with manual code and how to model 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. + src directory. The package contains four java classes which implement a small 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: @@ -245,7 +245,7 @@ - Within this tutorial we just will switching on and off the yellow light. + Within this tutorial we just will toggle the yellow light. You will perform the following steps: @@ -338,7 +338,7 @@ ProtocolClass and name it BlinkyControlProtocol. Inside the brackets use the - Content Assist (CTRL+Space) to create two incomming messages called + Content Assist (CTRL+Space) to create two incoming messages called start and stop. @@ -351,7 +351,7 @@ 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. + Format from the context menu you can format the text. Note that all elements are displayed in the outline view.
@@ -423,7 +423,7 @@ stop as incoming messages. Blinky receives this messages and therefore Blinky's - ControlPort must be a base port and + ControlPort must be a regular port and BlinkyController's ControlPort must be a conjugated port. @@ -479,7 +479,7 @@ 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 + port.message(param);. In this example ControlPort.start() sends the start message via the ControlPort to the outside world. Assuming that @@ -779,7 +779,7 @@ carLights.setState(TrafficLight3.OFF);
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. + Run the model and take a 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.
@@ -787,7 +787,7 @@ carLights.setState(TrafficLight3.OFF);
Scope This tutorial shows how data will be sent in a eTrice model. Within the example you will create two actors (MrPing and MrPong). MrPong will simply loop back every data it received. - MrPing will sent data and verify the result. + MrPing will send data and verify the result. You will perform the following steps: @@ -949,8 +949,8 @@ carLights.setState(TrafficLight3.OFF);
-
- Define the Actors Structure and Behavior +
+ Define Actor Structure and Behavior Save the model and visit the outline view. Within the outline view, right click on the MrPong actor and select Edit Structure. Select an @@ -1090,7 +1090,6 @@ carLights.setState(TrafficLight3.OFF); The model is finished now and the model file should look like this: - RoomModel SendingData { LogicalSystem SendingData_LogSystem { @@ -1237,67 +1236,401 @@ carLights.setState(TrafficLight3.OFF); Generate and run the model With the MWe2 workflow generate the code and run the model. The output should look like this: - type ‚quit’ to exit - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 1 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 2 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 3 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 4 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 5 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 6 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 7 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 8 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 9 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 10 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - d.int32Val: 4711 - d.float64Val: 0,000000 - d.int8Array: 1 2 3 4 5 6 7 8 9 10 - d.stringVal: empty - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - d.int32Val: 815 - d.float64Val: 3,141234 - d.int8Array: 100 101 102 103 104 105 106 107 108 109 - d.stringVal: some contents - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - quit - echo: quit +
+ + type ‚quit’ to exit + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 1 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 2 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 3 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 4 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 5 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 6 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 7 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 8 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 9 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 10 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + d.int32Val: 4711 + d.float64Val: 0,000000 + d.int8Array: 1 2 3 4 5 6 7 8 9 10 + d.stringVal: empty + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + d.int32Val: 815 + d.float64Val: 3,141234 + d.int8Array: 100 101 102 103 104 105 106 107 108 109 + d.stringVal: some contents + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + quit + echo: quit +
+
+ +
Summary - Within the first loop a integer value will be incremented from + Within the first loop an integer value will be incremented from MrPong and sent back to - MrPing. Is long as the guard is true + MrPing. As long as the guard is true MrPing sends back the value. Within the next transition, MrPing creates a data class and sends the default values. Than MrPing changes the values and sends the class again. At this point you should note that during the send operation, a copy of the data class will be created and sent. Otherwise it would not be possible to send the same object two times, even more it would not be possible to send a stack object at all. - In later versions of eTrice a additional mechanism to send references will be implemented. However, keep in mind that sending references takes the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. + In future versions of eTrice an additional mechanism to send references will be implemented. However, keep in mind that sending references transfers the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. + +
+ + + Tutorial Pedestrian Lights +
+ Scope + The scope of this tutorial is to demonstrate how to receive model messages from outside the model. Calling methods which are not part of the model is simple and you have already done this within the blinky tutorial (this is the other way round: model => external code). Receiving events from outside the model is a very common problem and a very frequently asked question. Therefore this tutorial shows how an external event (outside the model) can be received from the model. + This tutorial is not like hello world or blinky. Being familiar with the basic tool features is mandatory for this tutorial. The goal is to understand the mechanism not to learn the tool features. + The idea behind the exercise is, to control a Pedestrian crossing light. We will use the same GUI as for the blinky tutorial but now we will use the + REQUEST button to start a FSM, which controls the traffic lights. + + + + + + + + + The + REQUEST must lead to a model message which starts the activity of the lights. + + There are several possibilities to receive external events (e.g. TCP/UDP Socket, using OS messaging mechanism), but the easiest way is, to make a port usable from outside the model. To do that a few steps are necessary: + + + specify the messages (within a protocol) which should be sent into the model + + + model an actor with a port (which uses the specified protocol) and connect the port to the receiver + + + the external code should know the port (import of the port class) + + + the external code should provide a registration method, so that the actor is able to allow access to this port + + + the port can be used from the external code + + +
+
+ Setup the model + + + Use the + New Model Wizzard to create a new eTrice project and name it + PedLightsController. + + + + Copy the package + de.protos.PedLightGUI to your + src directory (see blinky tutorial). + + + + In PedestrianLightWndNoTcp.jav uncomment line 15 (import), 36, 122 (usage) and 132-134 (registration). + + + Copy the following model to your model file: + + + RoomModel PedLightsController { + + LogicalSystem LogSys_PedLights { + SubSystemRef application: SubSys_PedLights + } + + SubSystemClass SubSys_PedLights { + ActorRef PedLightsTopRef: PedLightsTop + ActorRef timingService: room.basic.service.timing.ATimingService + LayerConnection ref PedLightsTopRef satisfied_by timingService.timer + LayerConnection ref PedLightsTopRef satisfied_by timingService.timeout + } + + ActorClass PedLightsTop { + Structure { + ActorRef adapter: GuiAdapter + ActorRef controller: Controller + Binding adapter.ControlPort and controller.ControlPort + } + Behavior { } + } + + ActorClass GuiAdapter { + Interface { + conjugated Port ControlPort: PedControlProtocol + } + Structure { + usercode1 { + "import PedLightGUI.*;" + } + usercode2 { + "private PedestrianLightWndNoTcp lights = new PedestrianLightWndNoTcp(\"Pedestrian Lights\",\" external port connection \");" + "private TrafficLight3 carLights;" + "private TrafficLight2 pedLights;" + } + external Port ControlPort + } + Behavior { + Operation destroyUser() { + "lights.closeWindow();" + } + StateMachine { + Transition init: initial -> running { + action { + "carLights=lights.getCarLights();" + "pedLights=lights.getPedLights();" + "carLights.setState(TrafficLight3.OFF);" + "pedLights.setState(TrafficLight2.OFF);" + "lights.setPort(ControlPort);" + } + } + Transition tr0: running -> running { + triggers { + <setCarLights: ControlPort> + } + action { + "carLights.setState(state);" + } + } + Transition tr1: running -> running { + triggers { + <setPedLights: ControlPort> + } + action { + "pedLights.setState(state);" + } + } + State running + } + } + } + + ActorClass Controller { + Interface { + Port ControlPort: PedControlProtocol + } + Structure { + usercode1 { + "import PedLightGUI.*;" + } + external Port ControlPort + SAP timer: room.basic.service.timing.PTimeout + } + Behavior { + StateMachine { + Transition init: initial -> off { } + Transition tr0: off -> carsGreen { + triggers { + <start: ControlPort> + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.GREEN);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr1: carsGreen -> carsYellow { + triggers { + <timeoutTick: timer> + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.YELLOW);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr2: carsYellow -> carsRed { + triggers { + <timeoutTick: timer> + } + action { + "timer.Start(1500);" + "ControlPort.setCarLights(TrafficLight3.RED);" + "ControlPort.setPedLights(TrafficLight2.GREEN);" + } + } + Transition tr3: carsRed -> carsYellowRed { + triggers { + <timeoutTick: timer> + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.YELLOW_RED);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr4: carsYellowRed -> carsGreen2 { + triggers { + <timeoutTick: timer> + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.GREEN);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr5: carsGreen2 -> off { + triggers { + <timeoutTick: timer> + } + action { + "ControlPort.setCarLights(TrafficLight3.OFF);" + "ControlPort.setPedLights(TrafficLight2.OFF);" + } + } + State off + State carsGreen + State carsYellow + State carsRed + State carsYellowRed + State carsGreen2 + } + } + } + + ProtocolClass PedControlProtocol { + incoming { + Message start() + } + outgoing { + Message setCarLights(state: int32) + Message setPedLights(state: int32) + } + } +} + +
+ +
+ + + Arrange the Structure and the Statemachines to understand the model + + + + + + + + + The + GuiAdapter represents the interface to the external code. It registers its + ControlPort by the external code. + + + + + + + + Visit the initial transition to understand the registration. The actor handles the incoming messages as usual and controls the traffic lights as known from blinky. + + + + + + + + The + Controller receives the + start message and controls the timing of the lights. Note that the + start message will be sent from the external code whenever the + REQUEST button is pressed. + + + Visit the model and take a closer look to the following elements: + + + + + PedControlProtocol => notice that the start message is defined as usual + + + Initial transition of the + GuiAdapter => see the registration + + + + The + Controller => notice that the + Controller receives the external message (not the + GuiAdapter). The + GuiAdapter just provides its port and handles the incoming messages. + + + + Visit the hand written code => see the import statement of the protocol class and the usage of the port. + + + + + Generate and test the model + + + Take a look at the generated MSC => notice that the start message will shown as if the + GuiAdapter had sent it. + + + + + + + + + + +
+
+ Why does it work and why is it safe? + The tutorial shows that it is generally possible to use every port from outside the model as long as the port knows its peer. This is guaranteed by describing protocol and the complete structure (especially the bindings) within the model. + The only remaining question is: Why is it safe and does not violate the „run to completion” semantic. To answer this question, take a look at the + MessageService.java from the runtime environment. There you will find the receive method which puts each message into the queue. + + @Override + public synchronized void receive(Message msg) { + if (msg!=null) { + messageQueue.push(msg); + notifyAll(); // wake up thread to compute message + } + } + +
+ +
+ This method is synchronized. That means, regardless who sends the message, the queue is secured. If we later on (e.g. for performance reasons in C/C++) distinguish between internal and external senders (same thread or not), care must be taken to use the external (secure) queue.
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 bd9ff38d1..d56c5f3ab 100644 --- a/plugins/org.eclipse.etrice.doc/doc/015-getting-started.textile +++ b/plugins/org.eclipse.etrice.doc/doc/015-getting-started.textile @@ -2,7 +2,7 @@ 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: +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 @@ -49,9 +49,9 @@ The goal of eTrice is to describe distributed systems on a logical level. In the * 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 build of. It is a good idea to define a top level actor that can be used as reference within the subsystem. +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. -Mention that a outline view was created that represents all currently existing model elements in a graphical way. +The outline view of the textual ROOM editor shows the main modeling elements in an easy to navigate tree. !images/015-HelloWorld02.PNG! @@ -82,7 +82,7 @@ Now the model is finished and source code can be generated. The project wizard h !images/015-HelloWorld06.PNG! -The code will be generated to the src-gen directory. The main class will be contained in ??SubSystem_HelloWorldRunner.java??. Select this file and run it as Java application. +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! @@ -93,7 +93,7 @@ The Hello World application starts and the string will be printed on the console 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: +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! @@ -101,5 +101,5 @@ During runtime the application produces a MSC and wrote it to a file. Open /org. 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 deals with more complex state machines hierarchies in structure and behavior. +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. diff --git a/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile b/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile index 7553874ea..5265e873a 100644 --- a/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile +++ b/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile @@ -2,16 +2,16 @@ 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,... +This tutorial describes how to use the ??TimingService??, how to combine a generated model with manual code and how to model 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. +To use the GUI please copy the package ??de.protos.PedLightGUI?? to your ??src?? directory. The package contains four java classes which implement a small 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. +Within this tutorial we just will toggle the yellow light. You will perform the following steps: @@ -63,13 +63,13 @@ 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??. +Inside the brackets use the ??Content Assist?? (CTRL+Space) to create two incoming 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. +With Ctrl-Shift+F or selecting ??Format?? from the context menu you can format the text. Note that all elements are displayed in the outline view. h2. Import the Timing Service @@ -97,7 +97,7 @@ From the outline view right click to ??Blinky?? and select ??Edit Structure??. D 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. +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 regular port and ??BlinkyController??'s ??ControlPort?? must be a conjugated port. From the outline view right click ??BlinkyTop?? and select ??Edit Structure??. @@ -120,7 +120,7 @@ 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. +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(param);??. 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??. @@ -349,5 +349,5 @@ The model is complete now. You can run and debug the model as described in getti 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. +Run the model and take a 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/025-tutorial-sending-data.textile b/plugins/org.eclipse.etrice.doc/doc/025-tutorial-sending-data.textile index 5a46d9bdf..09e276501 100644 --- a/plugins/org.eclipse.etrice.doc/doc/025-tutorial-sending-data.textile +++ b/plugins/org.eclipse.etrice.doc/doc/025-tutorial-sending-data.textile @@ -1,404 +1,406 @@ -h1. Tutorial Sending Data - -h2. Scope - -This tutorial shows how data will be sent in a eTrice model. Within the example you will create two actors (MrPing and MrPong). MrPong will simply loop back every data it received. -MrPing will sent data and verify the result. - -You will perform the following steps: - -# create a new model from scratch -# create a data class -# define a protocol with attached data -# create an actor structure -# create two simple state machines -# build and run the model - -h2. Create a new model from scratch - -Remember exercise ??HelloWorld??. -Create a new eTrice project and name it ??SendingData?? -Open the ??SendingData.room?? file and copy the following code into the file or use content assist to create the model. - -bc.. -RoomModel SendingData { - LogicalSystem SendingData_LogSystem { - SubSystemRef SendingDataAppl:SendingData_SubSystem - } - SubSystemClass SendingData_SubSystem { - ActorRef SendigDataTopRef:SendingDataTop - } - ActorClass SendingDataTop { - } - } -bq. - -h2. Add a data class - -Position the cursor outside any class definition and right click the mouse within the editor window. From the context menu select ??Content Assist?? (or Ctrl+Space). - -!images/025-SendingData01.png! - -Select ??DataClass - data class skeleton?? and name it ??DemoData??. -Remove the operations and ass the following Attributes: - -bc.. - DataClass DemoData { - Attribute int32Val: int32 = "4711" - Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}" - Attribute float64Val: float64 = "0.0" - Attribute stringVal: string = "\"empty\"" - } -bq. - -Save the model and visit the outline view. -Note that the outline view contains all data elements as defined in the model. - -h2. Create a new protocol - -With the help of ??Content Assist?? create a ??ProtocolClass?? and name it ??PingPongProtocol??. Create the following messages: - -bc.. -ProtocolClass PingPongProtocol { - incoming { - Message ping(data: DemoData) - Message pingSimple(data:int32) - } - outgoing { - Message pong(data: DemoData) - Message pongSimple(data:int32) - } - } -bq. - -h2. Create MrPing and MrPong Actors - -With the help of ??Content Assist?? create two new actor classes and name them ??MrPing?? and ??MrPong??. The resulting model should look like this: - -bc.. -RoomModel SendingData { - - LogicalSystem SendingData_LogSystem { - SubSystemRef SendingDataAppl: SendingData_SubSystem - } - - SubSystemClass SendingData_SubSystem { - ActorRef SendigDataTopRef: SendingDataTop - } - - ActorClass SendingDataTop { } - - DataClass DemoData { - Attribute int32Val: int32 = "4711" - Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}" - Attribute float64Val: float64 = "0.0" - Attribute stringVal: string = "\"empty\"" - } - - ProtocolClass PingPongProtocol { - incoming { - Message ping(data: DemoData) - Message pingSimple(data: int32) - } - outgoing { - Message pong(data: DemoData) - Message pongSimple(data: int32) - } - } - - ActorClass MrPing { - Interface { } - Structure { } - Behavior { } - } - - ActorClass MrPong { - Interface { } - Structure { } - Behavior { } - } -} - -bq. - -The outline view should look like this: - -!images/025-SendingData03.png! - -h2. Define the Actors Structure and Behavior - -Save the model and visit the outline view. Within the outline view, right click on the ??MrPong?? actor and select ??Edit Structure??. Select an ??Interface Port?? from the toolbox and add it to MrPong. Name the Port ??PingPongPort?? and select the ??PingPongProtocol?? - -!images/025-SendingData02.png! - -Do the same with MrPing but mark the port as ??conjugated?? - -h3. Define MrPongs behavior - -Within the outline view, right click MrPong and select ??Edit Behavior??. Create the following state machine: - -!images/025-SendingData04.png! - -The transition dialogues should look like this: -For ??ping??: - -!images/025-SendingData05.png! - -For ??pingSimple??: - -!images/025-SendingData06.png! - - -h3. Define MrPing behavior - -Within the outline view double click MrPing. Navigate the cursor to the behavior of MrPing. With the help of content assist create a new operation. - -!images/025-SendingData07.png! - -Name the operation ??printData?? and define the DemoData as a parameter. - -Fill in the following code: - -bc.. -Operation printData(d: DemoData) : void { - "System.out.printf(\"d.int32Val: %d\\n\",d.int32Val);" - "System.out.printf(\"d.float64Val: %f\\n\",d.float64Val);" - "System.out.printf(\"d.int8Array: \");" - "for(int i = 0; i waitForPong { - triggers { - - } - action { - "printData(data);" - } - } - Transition wait1: waitForPongSimple -> waitForPongSimple { - triggers { - - } - action { - "// keep in mind that MrPong increments" - "PingPongPort.pingSimple(data);" - "System.out.printf(\"data: %d\\n\",data);" - } - } - Transition next: waitForPongSimple -> waitForPong { - triggers { - - } - action { - "System.out.printf(\"data: %d\\n\",data);" - "" - "DemoData d = new DemoData();" - "// send the default values" - "PingPongPort.ping(d);" - "d.int32Val=815;" - "for (int i = 0; i waitForPongSimple { - action { - "PingPongPort.pingSimple(0);" - } - } - State waitForPong - State waitForPongSimple - } - } - } - - ActorClass MrPong { - Interface { - Port PingPongPort: PingPongProtocol - } - Structure { - external Port PingPongPort - } - Behavior { - StateMachine { - Transition init: initial -> looping { } - Transition tr0: looping -> looping { - triggers { - - } - action { - "PingPongPort.pong(data);" - } - } - Transition tr1: looping -> looping { - triggers { - - } - action { - "PingPongPort.pongSimple(data+1);" - } - } - State looping - } - } - } - - ProtocolClass PingPongProtocol { - incoming { - Message ping(data: DemoData) - Message pingSimple(data: int32) - } - outgoing { - Message pong(data: DemoData) - Message pongSimple(data: int32) - } - } - - DataClass DemoData { - Attribute int32Val: int32 = "4711" - Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}" - Attribute float64Val: float64 = "0.0" - Attribute stringVal: string = "\"empty\"" - } -} -bq. - -h2. Generate and run the model - -With the MWe2 workflow generate the code and run the model. -The output should look like this: - - -type 'quit' to exit -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 1 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 2 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 3 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 4 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 5 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 6 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 7 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 8 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 9 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -data: 10 -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping -d.int32Val: 4711 -d.float64Val: 0,000000 -d.int8Array: 1 2 3 4 5 6 7 8 9 10 -d.stringVal: empty -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong -d.int32Val: 815 -d.float64Val: 3,141234 -d.int8Array: 100 101 102 103 104 105 106 107 108 109 -d.stringVal: some contents -/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong -quit -echo: quit - -h2. Summary - -Within the first loop a integer value will be incremented from ??MrPong?? and sent back to ??MrPing??. Is long as the guard is true ??MrPing?? sends back the value. - -Within the ??next?? transition, ??MrPing?? creates a data class and sends the default values. Than ??MrPing?? changes the values and sends the class again. At this point you should note that during the send operation, a copy of the data class will be created and sent. Otherwise it would not be possible to send the same object two times, even more it would not be possible to send a stack object at all. -In later versions of eTrice a additional mechanism to send references will be implemented. However, keep in mind that sending references takes the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. - - +h1. Tutorial Sending Data + +h2. Scope + +This tutorial shows how data will be sent in a eTrice model. Within the example you will create two actors (MrPing and MrPong). MrPong will simply loop back every data it received. +MrPing will send data and verify the result. + +You will perform the following steps: + +# create a new model from scratch +# create a data class +# define a protocol with attached data +# create an actor structure +# create two simple state machines +# build and run the model + +h2. Create a new model from scratch + +Remember exercise ??HelloWorld??. +Create a new eTrice project and name it ??SendingData?? +Open the ??SendingData.room?? file and copy the following code into the file or use content assist to create the model. + + +bc.. +RoomModel SendingData { + LogicalSystem SendingData_LogSystem { + SubSystemRef SendingDataAppl:SendingData_SubSystem + } + SubSystemClass SendingData_SubSystem { + ActorRef SendigDataTopRef:SendingDataTop + } + ActorClass SendingDataTop { + } + } +bq. + +h2. Add a data class + +Position the cursor outside any class definition and right click the mouse within the editor window. From the context menu select ??Content Assist?? (or Ctrl+Space). + +!images/025-SendingData01.png! + +Select ??DataClass - data class skeleton?? and name it ??DemoData??. +Remove the operations and ass the following Attributes: + +bc.. + DataClass DemoData { + Attribute int32Val: int32 = "4711" + Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}" + Attribute float64Val: float64 = "0.0" + Attribute stringVal: string = "\"empty\"" + } +bq. + +Save the model and visit the outline view. +Note that the outline view contains all data elements as defined in the model. + +h2. Create a new protocol + +With the help of ??Content Assist?? create a ??ProtocolClass?? and name it ??PingPongProtocol??. Create the following messages: + +bc.. +ProtocolClass PingPongProtocol { + incoming { + Message ping(data: DemoData) + Message pingSimple(data:int32) + } + outgoing { + Message pong(data: DemoData) + Message pongSimple(data:int32) + } + } +bq. + +h2. Create MrPing and MrPong Actors + +With the help of ??Content Assist?? create two new actor classes and name them ??MrPing?? and ??MrPong??. The resulting model should look like this: + +bc.. +RoomModel SendingData { + + LogicalSystem SendingData_LogSystem { + SubSystemRef SendingDataAppl: SendingData_SubSystem + } + + SubSystemClass SendingData_SubSystem { + ActorRef SendigDataTopRef: SendingDataTop + } + + ActorClass SendingDataTop { } + + DataClass DemoData { + Attribute int32Val: int32 = "4711" + Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}" + Attribute float64Val: float64 = "0.0" + Attribute stringVal: string = "\"empty\"" + } + + ProtocolClass PingPongProtocol { + incoming { + Message ping(data: DemoData) + Message pingSimple(data: int32) + } + outgoing { + Message pong(data: DemoData) + Message pongSimple(data: int32) + } + } + + ActorClass MrPing { + Interface { } + Structure { } + Behavior { } + } + + ActorClass MrPong { + Interface { } + Structure { } + Behavior { } + } +} + +bq. + +The outline view should look like this: + +!images/025-SendingData03.png! + +h2. Define Actor Structure and Behavior + +Save the model and visit the outline view. Within the outline view, right click on the ??MrPong?? actor and select ??Edit Structure??. Select an ??Interface Port?? from the toolbox and add it to MrPong. Name the Port ??PingPongPort?? and select the ??PingPongProtocol?? + +!images/025-SendingData02.png! + +Do the same with MrPing but mark the port as ??conjugated?? + +h3. Define MrPongs behavior + +Within the outline view, right click MrPong and select ??Edit Behavior??. Create the following state machine: + +!images/025-SendingData04.png! + +The transition dialogues should look like this: +For ??ping??: + +!images/025-SendingData05.png! + +For ??pingSimple??: + +!images/025-SendingData06.png! + + +h3. Define MrPing behavior + +Within the outline view double click MrPing. Navigate the cursor to the behavior of MrPing. With the help of content assist create a new operation. + +!images/025-SendingData07.png! + +Name the operation ??printData?? and define the DemoData as a parameter. + +Fill in the following code: + +bc.. +Operation printData(d: DemoData) : void { + "System.out.printf(\"d.int32Val: %d\\n\",d.int32Val);" + "System.out.printf(\"d.float64Val: %f\\n\",d.float64Val);" + "System.out.printf(\"d.int8Array: \");" + "for(int i = 0; i waitForPong { + triggers { + + } + action { + "printData(data);" + } + } + Transition wait1: waitForPongSimple -> waitForPongSimple { + triggers { + + } + action { + "// keep in mind that MrPong increments" + "PingPongPort.pingSimple(data);" + "System.out.printf(\"data: %d\\n\",data);" + } + } + Transition next: waitForPongSimple -> waitForPong { + triggers { + + } + action { + "System.out.printf(\"data: %d\\n\",data);" + "" + "DemoData d = new DemoData();" + "// send the default values" + "PingPongPort.ping(d);" + "d.int32Val=815;" + "for (int i = 0; i waitForPongSimple { + action { + "PingPongPort.pingSimple(0);" + } + } + State waitForPong + State waitForPongSimple + } + } + } + + ActorClass MrPong { + Interface { + Port PingPongPort: PingPongProtocol + } + Structure { + external Port PingPongPort + } + Behavior { + StateMachine { + Transition init: initial -> looping { } + Transition tr0: looping -> looping { + triggers { + + } + action { + "PingPongPort.pong(data);" + } + } + Transition tr1: looping -> looping { + triggers { + + } + action { + "PingPongPort.pongSimple(data+1);" + } + } + State looping + } + } + } + + ProtocolClass PingPongProtocol { + incoming { + Message ping(data: DemoData) + Message pingSimple(data: int32) + } + outgoing { + Message pong(data: DemoData) + Message pongSimple(data: int32) + } + } + + DataClass DemoData { + Attribute int32Val: int32 = "4711" + Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}" + Attribute float64Val: float64 = "0.0" + Attribute stringVal: string = "\"empty\"" + } +} +bq. + +h2. Generate and run the model + +With the MWe2 workflow generate the code and run the model. +The output should look like this: + +bq.. +type 'quit' to exit +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 1 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 2 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 3 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 4 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 5 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 6 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 7 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 8 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 9 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +data: 10 +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +/SendingData_SubSystem/SendigDataTopRef/ref1 -> looping +d.int32Val: 4711 +d.float64Val: 0,000000 +d.int8Array: 1 2 3 4 5 6 7 8 9 10 +d.stringVal: empty +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong +d.int32Val: 815 +d.float64Val: 3,141234 +d.int8Array: 100 101 102 103 104 105 106 107 108 109 +d.stringVal: some contents +/SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong +quit +echo: quit +bq. + +h2. Summary + +Within the first loop an integer value will be incremented from ??MrPong?? and sent back to ??MrPing??. As long as the guard is true ??MrPing?? sends back the value. + +Within the ??next?? transition, ??MrPing?? creates a data class and sends the default values. Than ??MrPing?? changes the values and sends the class again. At this point you should note that during the send operation, a copy of the data class will be created and sent. Otherwise it would not be possible to send the same object two times, even more it would not be possible to send a stack object at all. +In future versions of eTrice an additional mechanism to send references will be implemented. However, keep in mind that sending references transfers the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. + + diff --git a/plugins/org.eclipse.etrice.doc/doc/030-tutorial-ped-lights.textile b/plugins/org.eclipse.etrice.doc/doc/030-tutorial-ped-lights.textile index c6a22d28b..3083dd045 100644 --- a/plugins/org.eclipse.etrice.doc/doc/030-tutorial-ped-lights.textile +++ b/plugins/org.eclipse.etrice.doc/doc/030-tutorial-ped-lights.textile @@ -1,237 +1,237 @@ -h1. Tutorial Pedestrian Lights - -h2. Scope - -The scope of this tutorial is to demonstrate how to receive model messages from outside the model. Calling methods which are not part of the model is simple and you have already done this within the blinky tutorial (this is the other way round model => external code). Receiving events from outside the model is a very common problem and a very frequently asked question. Therefore this tutorial shows how an external event (outside the model) can be received from the model. - -This tutorial is not like hello world or blinky. Be familiar with the basic tool features is a precondition for this tutorial. The goal is to understand the mechanism not to learn the tool features. - -The idea behind the exercise is, to control a Pedestrian crossing light. We will use the same GUI as for the blinky tutorial but now we will use the ??REQUEST?? button to start a FSM, which controls the traffic lights. - -!images/020-Blinky08.PNG! - -The ??REQUEST?? must lead to a model message which starts the activity of the lights. - -There are a view possibilities to receive external events (e.g. TCP/UDP Socket, using OS messaging mechanism), but the easiest way is, to make a port usable from outside the model. To do that a view steps are necessary: -# specify the messages (within a protocol) which should be sent into the model -# model an actor with a port (which uses the specified protocol) and connect the port to the receiver -# the external code should know the port (import of the port class) -# the external code should provide a registration method, so that the actor is able to allow access to this port -# the port can be used from the external code - -h2. Setup the model - -* Use the ??New Model Wizzard?? to create a new eTrice project and name it ??PedLightsController??. -* Copy the package ??de.protos.PedLightGUI?? to your ??src?? directory (see blinky tutorial). -* Uncoment line 15 (import), 36, 122 (usage) and 132-134 (registration). -* Copy the following model to your model file: - -bc.. -RoomModel PedLightsController { - - LogicalSystem LogSys_PedLights { - SubSystemRef application: SubSys_PedLights - } - - SubSystemClass SubSys_PedLights { - ActorRef PedLightsTopRef: PedLightsTop - ActorRef timingService: room.basic.service.timing.ATimingService - LayerConnection ref PedLightsTopRef satisfied_by timingService.timer - LayerConnection ref PedLightsTopRef satisfied_by timingService.timeout - } - - ActorClass PedLightsTop { - Structure { - ActorRef adapter: GuiAdapter - ActorRef controller: Controller - Binding adapter.ControlPort and controller.ControlPort - } - Behavior { } - } - - ActorClass GuiAdapter { - Interface { - conjugated Port ControlPort: PedControlProtocol - } - Structure { - usercode1 { - "import PedLightGUI.*;" - } - usercode2 { - "private PedestrianLightWndNoTcp lights = new PedestrianLightWndNoTcp(\"Pedestrian Lights\",\" external port connection \");" - "private TrafficLight3 carLights;" - "private TrafficLight2 pedLights;" - } - external Port ControlPort - } - Behavior { - Operation destroyUser() { - "lights.closeWindow();" - } - StateMachine { - Transition init: initial -> running { - action { - "carLights=lights.getCarLights();" - "pedLights=lights.getPedLights();" - "carLights.setState(TrafficLight3.OFF);" - "pedLights.setState(TrafficLight2.OFF);" - "lights.setPort(ControlPort);" - } - } - Transition tr0: running -> running { - triggers { - - } - action { - "carLights.setState(state);" - } - } - Transition tr1: running -> running { - triggers { - - } - action { - "pedLights.setState(state);" - } - } - State running - } - } - } - - ActorClass Controller { - Interface { - Port ControlPort: PedControlProtocol - } - Structure { - usercode1 { - "import PedLightGUI.*;" - } - external Port ControlPort - SAP timer: room.basic.service.timing.PTimeout - } - Behavior { - StateMachine { - Transition init: initial -> off { } - Transition tr0: off -> carsGreen { - triggers { - - } - action { - "timer.Start(700);" - "ControlPort.setCarLights(TrafficLight3.GREEN);" - "ControlPort.setPedLights(TrafficLight2.RED);" - } - } - Transition tr1: carsGreen -> carsYellow { - triggers { - - } - action { - "timer.Start(700);" - "ControlPort.setCarLights(TrafficLight3.YELLOW);" - "ControlPort.setPedLights(TrafficLight2.RED);" - } - } - Transition tr2: carsYellow -> carsRed { - triggers { - - } - action { - "timer.Start(1500);" - "ControlPort.setCarLights(TrafficLight3.RED);" - "ControlPort.setPedLights(TrafficLight2.GREEN);" - } - } - Transition tr3: carsRed -> carsYellowRed { - triggers { - - } - action { - "timer.Start(700);" - "ControlPort.setCarLights(TrafficLight3.YELLOW_RED);" - "ControlPort.setPedLights(TrafficLight2.RED);" - } - } - Transition tr4: carsYellowRed -> carsGreen2 { - triggers { - - } - action { - "timer.Start(700);" - "ControlPort.setCarLights(TrafficLight3.GREEN);" - "ControlPort.setPedLights(TrafficLight2.RED);" - } - } - Transition tr5: carsGreen2 -> off { - triggers { - - } - action { - "ControlPort.setCarLights(TrafficLight3.OFF);" - "ControlPort.setPedLights(TrafficLight2.OFF);" - } - } - State off - State carsGreen - State carsYellow - State carsRed - State carsYellowRed - State carsGreen2 - } - } - } - - ProtocolClass PedControlProtocol { - incoming { - Message start() - } - outgoing { - Message setCarLights(state: int32) - Message setPedLights(state: int32) - } - } -} -bq. - -* Arrange the Structure and the Statemachines to understand the model - -!images/030-PedLights01.PNG! -The ??GuiAdapter?? represents the interface to the external code. It registers its ??ControlPort?? by the external code. - -!images/030-PedLights02.PNG! -Visit the initial transition to understand the registration. The actor handles the incoming messages as usual and controls the traffic lights as known from blinky. - -!images/030-PedLights03.PNG! -The ??Controller?? receives the ??start?? message and controls the timing of the lights. Note that the ??start?? message will be sent from the external code whenever the ??REQUEST?? button is pressed. - -* Visit the model and take a closer look to the following elements: -# PedControlProtocol => notice that the start message is defined as usual -# Initial transition of the ??GuiAdapter?? => see the registration -# The ??Controller?? => notice that the ??Controller?? receives the external message (not the ??GuiAdapter??). The ??GuiAdapter?? just provides its port and handles the incoming messages. -# Visit the hand written code => see the import statement of the protocol class and the usage of the port. - -* Generate and test the model -* Take a look at the generated MSC => notice that the start message will shown as if the ??GuiAdapter?? had sent it. - -!images/030-PedLights04.PNG! - -h2. Why does it work and why is it save? - -The tutorial shows that it is generally possible to use every port from outside the model as long as the port knows its peer. This is guaranteed by describing protocol and the complete structure (especially the bindings) within the model. -The only remaining question is: Why is it save and does not hurt the "run to completion" semantic. To answer this question, take a look at the ??MessageService.java?? from the runtime environment. There you will find the receive method which puts each message into the queue. - -bc.. - @Override - public synchronized void receive(Message msg) { - if (msg!=null) { - messageQueue.push(msg); - notifyAll(); // wake up thread to compute message - } - } -bq. - -This method is synchronized. That means, regardless who sends the message, the queue is secured. If we later on (e.g. for performance reasons in C/C++) distinguish between internal and external senders (same thread or not), care must be taken to use the external (secure) queue. - - - +h1. Tutorial Pedestrian Lights + +h2. Scope + +The scope of this tutorial is to demonstrate how to receive model messages from outside the model. Calling methods which are not part of the model is simple and you have already done this within the blinky tutorial (this is the other way round: model => external code). Receiving events from outside the model is a very common problem and a very frequently asked question. Therefore this tutorial shows how an external event (outside the model) can be received from the model. + +This tutorial is not like hello world or blinky. Being familiar with the basic tool features is mandatory for this tutorial. The goal is to understand the mechanism not to learn the tool features. + +The idea behind the exercise is, to control a Pedestrian crossing light. We will use the same GUI as for the blinky tutorial but now we will use the ??REQUEST?? button to start a FSM, which controls the traffic lights. + +!images/020-Blinky08.PNG! + +The ??REQUEST?? must lead to a model message which starts the activity of the lights. + +There are several possibilities to receive external events (e.g. TCP/UDP Socket, using OS messaging mechanism), but the easiest way is, to make a port usable from outside the model. To do that a few steps are necessary: +# specify the messages (within a protocol) which should be sent into the model +# model an actor with a port (which uses the specified protocol) and connect the port to the receiver +# the external code should know the port (import of the port class) +# the external code should provide a registration method, so that the actor is able to allow access to this port +# the port can be used from the external code + +h2. Setup the model + +* Use the ??New Model Wizzard?? to create a new eTrice project and name it ??PedLightsController??. +* Copy the package ??de.protos.PedLightGUI?? to your ??src?? directory (see blinky tutorial). +* In PedestrianLightWndNoTcp.jav uncomment line 15 (import), 36, 122 (usage) and 132-134 (registration). +* Copy the following model to your model file: + +bc.. +RoomModel PedLightsController { + + LogicalSystem LogSys_PedLights { + SubSystemRef application: SubSys_PedLights + } + + SubSystemClass SubSys_PedLights { + ActorRef PedLightsTopRef: PedLightsTop + ActorRef timingService: room.basic.service.timing.ATimingService + LayerConnection ref PedLightsTopRef satisfied_by timingService.timer + LayerConnection ref PedLightsTopRef satisfied_by timingService.timeout + } + + ActorClass PedLightsTop { + Structure { + ActorRef adapter: GuiAdapter + ActorRef controller: Controller + Binding adapter.ControlPort and controller.ControlPort + } + Behavior { } + } + + ActorClass GuiAdapter { + Interface { + conjugated Port ControlPort: PedControlProtocol + } + Structure { + usercode1 { + "import PedLightGUI.*;" + } + usercode2 { + "private PedestrianLightWndNoTcp lights = new PedestrianLightWndNoTcp(\"Pedestrian Lights\",\" external port connection \");" + "private TrafficLight3 carLights;" + "private TrafficLight2 pedLights;" + } + external Port ControlPort + } + Behavior { + Operation destroyUser() { + "lights.closeWindow();" + } + StateMachine { + Transition init: initial -> running { + action { + "carLights=lights.getCarLights();" + "pedLights=lights.getPedLights();" + "carLights.setState(TrafficLight3.OFF);" + "pedLights.setState(TrafficLight2.OFF);" + "lights.setPort(ControlPort);" + } + } + Transition tr0: running -> running { + triggers { + + } + action { + "carLights.setState(state);" + } + } + Transition tr1: running -> running { + triggers { + + } + action { + "pedLights.setState(state);" + } + } + State running + } + } + } + + ActorClass Controller { + Interface { + Port ControlPort: PedControlProtocol + } + Structure { + usercode1 { + "import PedLightGUI.*;" + } + external Port ControlPort + SAP timer: room.basic.service.timing.PTimeout + } + Behavior { + StateMachine { + Transition init: initial -> off { } + Transition tr0: off -> carsGreen { + triggers { + + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.GREEN);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr1: carsGreen -> carsYellow { + triggers { + + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.YELLOW);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr2: carsYellow -> carsRed { + triggers { + + } + action { + "timer.Start(1500);" + "ControlPort.setCarLights(TrafficLight3.RED);" + "ControlPort.setPedLights(TrafficLight2.GREEN);" + } + } + Transition tr3: carsRed -> carsYellowRed { + triggers { + + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.YELLOW_RED);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr4: carsYellowRed -> carsGreen2 { + triggers { + + } + action { + "timer.Start(700);" + "ControlPort.setCarLights(TrafficLight3.GREEN);" + "ControlPort.setPedLights(TrafficLight2.RED);" + } + } + Transition tr5: carsGreen2 -> off { + triggers { + + } + action { + "ControlPort.setCarLights(TrafficLight3.OFF);" + "ControlPort.setPedLights(TrafficLight2.OFF);" + } + } + State off + State carsGreen + State carsYellow + State carsRed + State carsYellowRed + State carsGreen2 + } + } + } + + ProtocolClass PedControlProtocol { + incoming { + Message start() + } + outgoing { + Message setCarLights(state: int32) + Message setPedLights(state: int32) + } + } +} +bq. + +* Arrange the Structure and the Statemachines to understand the model + +!images/030-PedLights01.PNG! +The ??GuiAdapter?? represents the interface to the external code. It registers its ??ControlPort?? by the external code. + +!images/030-PedLights02.PNG! +Visit the initial transition to understand the registration. The actor handles the incoming messages as usual and controls the traffic lights as known from blinky. + +!images/030-PedLights03.PNG! +The ??Controller?? receives the ??start?? message and controls the timing of the lights. Note that the ??start?? message will be sent from the external code whenever the ??REQUEST?? button is pressed. + +* Visit the model and take a closer look to the following elements: +# PedControlProtocol => notice that the start message is defined as usual +# Initial transition of the ??GuiAdapter?? => see the registration +# The ??Controller?? => notice that the ??Controller?? receives the external message (not the ??GuiAdapter??). The ??GuiAdapter?? just provides its port and handles the incoming messages. +# Visit the hand written code => see the import statement of the protocol class and the usage of the port. + +* Generate and test the model +* Take a look at the generated MSC => notice that the start message will shown as if the ??GuiAdapter?? had sent it. + +!images/030-PedLights04.PNG! + +h2. Why does it work and why is it safe? + +The tutorial shows that it is generally possible to use every port from outside the model as long as the port knows its peer. This is guaranteed by describing protocol and the complete structure (especially the bindings) within the model. +The only remaining question is: Why is it safe and does not violate the "run to completion" semantic. To answer this question, take a look at the ??MessageService.java?? from the runtime environment. There you will find the receive method which puts each message into the queue. + +bc.. + @Override + public synchronized void receive(Message msg) { + if (msg!=null) { + messageQueue.push(msg); + notifyAll(); // wake up thread to compute message + } + } +bq. + +This method is synchronized. That means, regardless who sends the message, the queue is secured. If we later on (e.g. for performance reasons in C/C++) distinguish between internal and external senders (same thread or not), care must be taken to use the external (secure) queue. + + + diff --git a/plugins/org.eclipse.etrice.doc/help/Addadataclass.html b/plugins/org.eclipse.etrice.doc/help/Addadataclass.html index 796c4b898..67b7989d1 100644 --- a/plugins/org.eclipse.etrice.doc/help/Addadataclass.html +++ b/plugins/org.eclipse.etrice.doc/help/Addadataclass.html @@ -1,60 +1,60 @@ - - - -Add a data class - - - - - - - - -

Add a data class

-
-
-
-
-

-Add a data class

-
-
-
-

Position the cursor outside any class definition and right click the mouse within the editor window. From the context menu select - [Content Assist] (or Ctrl+Space). -

-

- -

-
-
-

- -

-

Select - [DataClass – data class skeleton] and name it - [DemoData]. - Remove the operations and ass the following Attributes: -

-
-

- DataClass DemoData {
- Attribute int32Val: int32 = "4711"
- Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}"
- Attribute float64Val: float64 = "0.0"
- Attribute stringVal: string = "\"empty\""
- }
- -
-

-
-
-
-

-
-
-

Save the model and visit the outline view. - Note that the outline view contains all data elements as defined in the model.

-
- - + + + +Add a data class + + + + + + + + +

Add a data class

+
+
+
+
+

+Add a data class

+
+
+
+

Position the cursor outside any class definition and right click the mouse within the editor window. From the context menu select + [Content Assist] (or Ctrl+Space). +

+

+ +

+
+
+

+ +

+

Select + [DataClass – data class skeleton] and name it + [DemoData]. + Remove the operations and ass the following Attributes: +

+
+

+ DataClass DemoData {
+ Attribute int32Val: int32 = "4711"
+ Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}"
+ Attribute float64Val: float64 = "0.0"
+ Attribute stringVal: string = "\"empty\""
+ }
+ +
+

+
+
+
+

+
+
+

Save the model and visit the outline view. + Note that the outline view contains all data elements as defined in the model.

+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/Buildandrunthemodel.html b/plugins/org.eclipse.etrice.doc/help/Buildandrunthemodel.html index 367b9f2d1..3d65d1e8d 100644 --- a/plugins/org.eclipse.etrice.doc/help/Buildandrunthemodel.html +++ b/plugins/org.eclipse.etrice.doc/help/Buildandrunthemodel.html @@ -32,7 +32,7 @@

-

The code will be generated to the src-gen directory. The main class will be contained in +

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.

diff --git a/plugins/org.eclipse.etrice.doc/help/CreateMrPingandMrPongActors.html b/plugins/org.eclipse.etrice.doc/help/CreateMrPingandMrPongActors.html index e0b253b59..8a8e89b54 100644 --- a/plugins/org.eclipse.etrice.doc/help/CreateMrPingandMrPongActors.html +++ b/plugins/org.eclipse.etrice.doc/help/CreateMrPingandMrPongActors.html @@ -1,101 +1,101 @@ - - - -Create MrPing and MrPong Actors - - - - - - - - -

Create MrPing and MrPong Actors

-
-
-
-
-

-Create MrPing and MrPong Actors

-
-
-
-

With the help of - [Content Assist] create two new actor classes and name them - [MrPing] and - [MrPong]. The resulting model should look like this: -

-
-

-RoomModel SendingData {
- -
- LogicalSystem SendingData_LogSystem {
- SubSystemRef SendingDataAppl: SendingData_SubSystem
- }
- -
- SubSystemClass SendingData_SubSystem {
- ActorRef SendigDataTopRef: SendingDataTop
- }
- -
- ActorClass SendingDataTop { }
- -
- DataClass DemoData {
- Attribute int32Val: int32 = "4711"
- Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}"
- Attribute float64Val: float64 = "0.0"
- Attribute stringVal: string = "\"empty\""
- }
- -
- ProtocolClass PingPongProtocol {
- incoming {
- Message ping(data: DemoData)
- Message pingSimple(data: int32)
- }
- outgoing {
- Message pong(data: DemoData)
- Message pongSimple(data: int32)
- }
- }
- -
- ActorClass MrPing {
- Interface { }
- Structure { }
- Behavior { }
- }
- -
- ActorClass MrPong {
- Interface { }
- Structure { }
- Behavior { }
- }
-} 
- -
- -
-

-
-
-
-

-
-
-

The outline view should look like this:

-

- -

-
-
-

- -

-
- - + + + +Create MrPing and MrPong Actors + + + + + + + + +

Create MrPing and MrPong Actors

+
+
+
+
+

+Create MrPing and MrPong Actors

+
+
+
+

With the help of + [Content Assist] create two new actor classes and name them + [MrPing] and + [MrPong]. The resulting model should look like this: +

+
+

+RoomModel SendingData {
+ +
+ LogicalSystem SendingData_LogSystem {
+ SubSystemRef SendingDataAppl: SendingData_SubSystem
+ }
+ +
+ SubSystemClass SendingData_SubSystem {
+ ActorRef SendigDataTopRef: SendingDataTop
+ }
+ +
+ ActorClass SendingDataTop { }
+ +
+ DataClass DemoData {
+ Attribute int32Val: int32 = "4711"
+ Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}"
+ Attribute float64Val: float64 = "0.0"
+ Attribute stringVal: string = "\"empty\""
+ }
+ +
+ ProtocolClass PingPongProtocol {
+ incoming {
+ Message ping(data: DemoData)
+ Message pingSimple(data: int32)
+ }
+ outgoing {
+ Message pong(data: DemoData)
+ Message pongSimple(data: int32)
+ }
+ }
+ +
+ ActorClass MrPing {
+ Interface { }
+ Structure { }
+ Behavior { }
+ }
+ +
+ ActorClass MrPong {
+ Interface { }
+ Structure { }
+ Behavior { }
+ }
+} 
+ +
+ +
+

+
+
+
+

+
+
+

The outline view should look like this:

+

+ +

+
+
+

+ +

+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/Createanewmodelfromscratch.html b/plugins/org.eclipse.etrice.doc/help/Createanewmodelfromscratch.html index c1afd0400..76f50dc29 100644 --- a/plugins/org.eclipse.etrice.doc/help/Createanewmodelfromscratch.html +++ b/plugins/org.eclipse.etrice.doc/help/Createanewmodelfromscratch.html @@ -108,9 +108,9 @@ [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 build of. It is a good idea to define a top level actor that can be used as reference within the subsystem. + [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.

-

Mention that a outline view was created that represents all currently existing model elements in a graphical way.

+

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

diff --git a/plugins/org.eclipse.etrice.doc/help/Createanewmodelfromscratch3.html b/plugins/org.eclipse.etrice.doc/help/Createanewmodelfromscratch3.html index 15a5a52e8..d9f127ec6 100644 --- a/plugins/org.eclipse.etrice.doc/help/Createanewmodelfromscratch3.html +++ b/plugins/org.eclipse.etrice.doc/help/Createanewmodelfromscratch3.html @@ -1,53 +1,53 @@ - - - -Create a new model from scratch - - - - - - - - -

Create a new model from scratch

-
-
-
-
-

-Create a new model from scratch

-
-
-
-

Remember exercise - [HelloWorld]. - Create a new eTrice project and name it - [SendingData] - Open the - [SendingData.room] file and copy the following code into the file or use content assist to create the model. -

-
-

-RoomModel SendingData {
- LogicalSystem SendingData_LogSystem {
- SubSystemRef SendingDataAppl:SendingData_SubSystem 
- }
- SubSystemClass SendingData_SubSystem {
- ActorRef SendigDataTopRef:SendingDataTop 
- }
- ActorClass SendingDataTop {
- }
- }
- -
-

-
-
-
-

-
-
-
- - + + + +Create a new model from scratch + + + + + + + + +

Create a new model from scratch

+
+
+
+
+

+Create a new model from scratch

+
+
+
+

Remember exercise + [HelloWorld]. + Create a new eTrice project and name it + [SendingData] + Open the + [SendingData.room] file and copy the following code into the file or use content assist to create the model. +

+
+

+RoomModel SendingData {
+ LogicalSystem SendingData_LogSystem {
+ SubSystemRef SendingDataAppl:SendingData_SubSystem 
+ }
+ SubSystemClass SendingData_SubSystem {
+ ActorRef SendigDataTopRef:SendingDataTop 
+ }
+ ActorClass SendingDataTop {
+ }
+ }
+ +
+

+
+
+
+

+
+
+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/Createanewprotocol.html b/plugins/org.eclipse.etrice.doc/help/Createanewprotocol.html index f603006b8..a8ec4d3db 100644 --- a/plugins/org.eclipse.etrice.doc/help/Createanewprotocol.html +++ b/plugins/org.eclipse.etrice.doc/help/Createanewprotocol.html @@ -25,7 +25,7 @@ [ProtocolClass] and name it [BlinkyControlProtocol]. Inside the brackets use the - [Content Assist] (CTRL+Space) to create two incomming messages called + [Content Assist] (CTRL+Space) to create two incoming messages called [start] and [stop].

@@ -39,7 +39,7 @@

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. + [Format] from the context menu you can format the text. Note that all elements are displayed in the outline view.

diff --git a/plugins/org.eclipse.etrice.doc/help/Createanewprotocol2.html b/plugins/org.eclipse.etrice.doc/help/Createanewprotocol2.html index 86ef1d908..14ddeb78f 100644 --- a/plugins/org.eclipse.etrice.doc/help/Createanewprotocol2.html +++ b/plugins/org.eclipse.etrice.doc/help/Createanewprotocol2.html @@ -1,51 +1,51 @@ - - - -Create a new protocol - - - - - - - - -

Create a new protocol

-
-
-
-
-

-Create a new protocol

-
-
-
-

With the help of - [Content Assist] create a - [ProtocolClass] and name it - [PingPongProtocol]. Create the following messages: -

-
-

-ProtocolClass PingPongProtocol {
- incoming {
- Message ping(data: DemoData)
- Message pingSimple(data:int32)
- }
- outgoing {
- Message pong(data: DemoData)
- Message pongSimple(data:int32)
- }
- }
- -
-

-
-
-
-

-
-
-
- - + + + +Create a new protocol + + + + + + + + +

Create a new protocol

+
+
+
+
+

+Create a new protocol

+
+
+
+

With the help of + [Content Assist] create a + [ProtocolClass] and name it + [PingPongProtocol]. Create the following messages: +

+
+

+ProtocolClass PingPongProtocol {
+ incoming {
+ Message ping(data: DemoData)
+ Message pingSimple(data:int32)
+ }
+ outgoing {
+ Message pong(data: DemoData)
+ Message pongSimple(data:int32)
+ }
+ }
+ +
+

+
+
+
+

+
+
+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/DefineActorStructureandBehavior.html b/plugins/org.eclipse.etrice.doc/help/DefineActorStructureandBehavior.html new file mode 100644 index 000000000..826ea9445 --- /dev/null +++ b/plugins/org.eclipse.etrice.doc/help/DefineActorStructureandBehavior.html @@ -0,0 +1,183 @@ + + + +Define Actor Structure and Behavior + + + + + + + + +

Define Actor Structure and Behavior

+
+
+
+
+

+Define Actor Structure and Behavior

+
+
+
+

Save the model and visit the outline view. Within the outline view, right click on the + [MrPong] actor and select + [Edit Structure]. Select an + [Interface Port] from the toolbox and add it to MrPong. Name the Port + [PingPongPort] and select the + [PingPongProtocol] +

+

+ +

+
+
+

+ +

+

Do the same with MrPing but mark the port as + [conjugated] +

+
+
+
+
+

+Define MrPongs behavior

+
+
+
+

Within the outline view, right click MrPong and select + [Edit Behavior]. Create the following state machine: +

+

+ +

+
+
+

+ +

+

The transition dialogues should look like this: + For + [ping]: +

+

+ +

+
+
+

+ +

+

For + [pingSimple]: +

+

+ +

+
+
+

+ +

+
+
+
+
+
+

+Define MrPing behavior

+
+
+
+

Within the outline view double click MrPing. Navigate the cursor to the behavior of MrPing. With the help of content assist create a new operation.

+

+ +

+
+
+

+ +

+

Name the operation + [printData] and define the DemoData as a parameter. +

+

Fill in the following code:

+
+

+Operation printData(d: DemoData) : void {
+ "System.out.printf(\"d.int32Val: %d\\n\",d.int32Val);"
+ "System.out.printf(\"d.float64Val: %f\\n\",d.float64Val);"
+ "System.out.printf(\"d.int8Array: \");"
+ "for(int i = 0; i<d.int8Array.length; i++) {"
+ "System.out.printf(\"%d \",d.int8Array[i]);}"
+ "System.out.printf(\"\\nd.stringVal: %s\\n\",d.stringVal);"
+ }
+ +
+

+
+
+
+

+
+
+

For MrPing create the following state machine:

+

+ +

+
+
+

+ +

+

The transition dialogues should look like this:

+

For + [init]: +

+

+ +

+
+
+

+ +

+

For + [wait1]: +

+

+ +

+
+
+

+ +

+

For + [next]: +

+

+ +

+
+
+

+ +

+

For + [wait2]: +

+

+ +

+
+
+

+ +

+
+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/DefinetheActorsStructureandBehavior.html b/plugins/org.eclipse.etrice.doc/help/DefinetheActorsStructureandBehavior.html deleted file mode 100644 index f551ce336..000000000 --- a/plugins/org.eclipse.etrice.doc/help/DefinetheActorsStructureandBehavior.html +++ /dev/null @@ -1,183 +0,0 @@ - - - -Define the Actors Structure and Behavior - - - - - - - - -

Define the Actors Structure and Behavior

-
-
-
-
-

-Define the Actors Structure and Behavior

-
-
-
-

Save the model and visit the outline view. Within the outline view, right click on the - [MrPong] actor and select - [Edit Structure]. Select an - [Interface Port] from the toolbox and add it to MrPong. Name the Port - [PingPongPort] and select the - [PingPongProtocol] -

-

- -

-
-
-

- -

-

Do the same with MrPing but mark the port as - [conjugated] -

-
-
-
-
-

-Define MrPongs behavior

-
-
-
-

Within the outline view, right click MrPong and select - [Edit Behavior]. Create the following state machine: -

-

- -

-
-
-

- -

-

The transition dialogues should look like this: - For - [ping]: -

-

- -

-
-
-

- -

-

For - [pingSimple]: -

-

- -

-
-
-

- -

-
-
-
-
-
-

-Define MrPing behavior

-
-
-
-

Within the outline view double click MrPing. Navigate the cursor to the behavior of MrPing. With the help of content assist create a new operation.

-

- -

-
-
-

- -

-

Name the operation - [printData] and define the DemoData as a parameter. -

-

Fill in the following code:

-
-

-Operation printData(d: DemoData) : void {
- "System.out.printf(\"d.int32Val: %d\\n\",d.int32Val);"
- "System.out.printf(\"d.float64Val: %f\\n\",d.float64Val);"
- "System.out.printf(\"d.int8Array: \");"
- "for(int i = 0; i<d.int8Array.length; i++) {"
- "System.out.printf(\"%d \",d.int8Array[i]);}"
- "System.out.printf(\"\\nd.stringVal: %s\\n\",d.stringVal);"
- }
- -
-

-
-
-
-

-
-
-

For MrPing create the following state machine:

-

- -

-
-
-

- -

-

The transition dialogues should look like this:

-

For - [init]: -

-

- -

-
-
-

- -

-

For - [wait1]: -

-

- -

-
-
-

- -

-

For - [next]: -

-

- -

-
-
-

- -

-

For - [wait2]: -

-

- -

-
-
-

- -

-
-
- - diff --git a/plugins/org.eclipse.etrice.doc/help/Definethetoplevel.html b/plugins/org.eclipse.etrice.doc/help/Definethetoplevel.html index 390b779d6..3693877f4 100644 --- a/plugins/org.eclipse.etrice.doc/help/Definethetoplevel.html +++ b/plugins/org.eclipse.etrice.doc/help/Definethetoplevel.html @@ -1,195 +1,192 @@ - - - -Define the top level - - - - - - - - -

Define the top level

-
-
-
-
-

-Define the top level

-
-
-
-

Open the Structure from SendingDataTop and add MrPing and MrPong as a reference. Connect the ports.

-

- -

-
-
-

- -

-

The model is finished now and the model file should look like this:

-
-

-
-
-

-RoomModel SendingData {
- -
- LogicalSystem SendingData_LogSystem {
- SubSystemRef SendingDataAppl: SendingData_SubSystem
- }
- -
- SubSystemClass SendingData_SubSystem {
- ActorRef SendigDataTopRef: SendingDataTop
- }
- -
- ActorClass SendingDataTop {
- Structure {
- ActorRef ref0: MrPing
- ActorRef ref1: MrPong
- Binding ref0.PingPongPort and ref1.PingPongPort
- }
- Behavior { }
- }
- -
- ActorClass MrPing {
- Interface {
- conjugated Port PingPongPort: PingPongProtocol
- }
- Structure {
- external Port PingPongPort
- }
- Behavior {
- -
- Operation printData(d: DemoData) : void {
- "System.out.printf(\"d.int32Val: %d\\n\",d.int32Val);"
- "System.out.printf(\"d.float64Val: %f\\n\",d.float64Val);"
- "System.out.printf(\"d.int8Array: \");"
- "for(int i = 0; i<d.int8Array.length; i++) {"
- "System.out.printf(\"%d \",d.int8Array[i]);}"
- "System.out.printf(\"\\nd.stringVal: %s\\n\",d.stringVal);"
- }
- -
- StateMachine {
- Transition wait2: waitForPong -> waitForPong {
- triggers {
- <pong: PingPongPort>
- }
- action {
- "printData(data);"
- }
- }
- Transition wait1: waitForPongSimple -> waitForPongSimple {
- triggers {
- <pongSimple: PingPongPort guard {
- "data < 10"
- }>
- }
- action {
- "// keep in mind that MrPong increments"
- "PingPongPort.pingSimple(data);"
- "System.out.printf(\"data: %d\\n\",data);"
- }
- }
- Transition next: waitForPongSimple -> waitForPong {
- triggers {
- <pongSimple: PingPongPort>
- }
- action {
- "System.out.printf(\"data: %d\\n\",data);"
- ""
- "DemoData d = new DemoData();"
- "// send the default values"
- "PingPongPort.ping(d);"
- "d.int32Val=815;"
- "for (int i = 0; i<d.int8Array.length;i++){"
- "\td.int8Array[i]=(byte)(i+100);"
- "\t}"
- "d.stringVal=\"some contents\";"
- "d.float64Val=3.141234;"
- "PingPongPort.ping(d);"
- }
- }
- Transition init0: initial -> waitForPongSimple {
- action {
- "PingPongPort.pingSimple(0);"
- }
- }
- State waitForPong
- State waitForPongSimple
- }
- }
- }
- -
- ActorClass MrPong {
- Interface {
- Port PingPongPort: PingPongProtocol
- }
- Structure {
- external Port PingPongPort
- }
- Behavior {
- StateMachine {
- Transition init: initial -> looping { }
- Transition tr0: looping -> looping {
- triggers {
- <ping: PingPongPort>
- }
- action {
- "PingPongPort.pong(data);"
- }
- }
- Transition tr1: looping -> looping {
- triggers {
- <pingSimple: PingPongPort>
- }
- action {
- "PingPongPort.pongSimple(data+1);"
- }
- }
- State looping
- }
- }
- }
- -
- ProtocolClass PingPongProtocol {
- incoming {
- Message ping(data: DemoData)
- Message pingSimple(data: int32)
- }
- outgoing {
- Message pong(data: DemoData)
- Message pongSimple(data: int32)
- }
- }
- -
- DataClass DemoData {
- Attribute int32Val: int32 = "4711"
- Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}"
- Attribute float64Val: float64 = "0.0"
- Attribute stringVal: string = "\"empty\""
- }
-}
- -
-

-
-
-
-

-
-
-
- - + + + +Define the top level + + + + + + + + +

Define the top level

+
+
+
+
+

+Define the top level

+
+
+
+

Open the Structure from SendingDataTop and add MrPing and MrPong as a reference. Connect the ports.

+

+ +

+
+
+

+ +

+

The model is finished now and the model file should look like this:

+
+

+RoomModel SendingData {
+ +
+ LogicalSystem SendingData_LogSystem {
+ SubSystemRef SendingDataAppl: SendingData_SubSystem
+ }
+ +
+ SubSystemClass SendingData_SubSystem {
+ ActorRef SendigDataTopRef: SendingDataTop
+ }
+ +
+ ActorClass SendingDataTop {
+ Structure {
+ ActorRef ref0: MrPing
+ ActorRef ref1: MrPong
+ Binding ref0.PingPongPort and ref1.PingPongPort
+ }
+ Behavior { }
+ }
+ +
+ ActorClass MrPing {
+ Interface {
+ conjugated Port PingPongPort: PingPongProtocol
+ }
+ Structure {
+ external Port PingPongPort
+ }
+ Behavior {
+ +
+ Operation printData(d: DemoData) : void {
+ "System.out.printf(\"d.int32Val: %d\\n\",d.int32Val);"
+ "System.out.printf(\"d.float64Val: %f\\n\",d.float64Val);"
+ "System.out.printf(\"d.int8Array: \");"
+ "for(int i = 0; i<d.int8Array.length; i++) {"
+ "System.out.printf(\"%d \",d.int8Array[i]);}"
+ "System.out.printf(\"\\nd.stringVal: %s\\n\",d.stringVal);"
+ }
+ +
+ StateMachine {
+ Transition wait2: waitForPong -> waitForPong {
+ triggers {
+ <pong: PingPongPort>
+ }
+ action {
+ "printData(data);"
+ }
+ }
+ Transition wait1: waitForPongSimple -> waitForPongSimple {
+ triggers {
+ <pongSimple: PingPongPort guard {
+ "data < 10"
+ }>
+ }
+ action {
+ "// keep in mind that MrPong increments"
+ "PingPongPort.pingSimple(data);"
+ "System.out.printf(\"data: %d\\n\",data);"
+ }
+ }
+ Transition next: waitForPongSimple -> waitForPong {
+ triggers {
+ <pongSimple: PingPongPort>
+ }
+ action {
+ "System.out.printf(\"data: %d\\n\",data);"
+ ""
+ "DemoData d = new DemoData();"
+ "// send the default values"
+ "PingPongPort.ping(d);"
+ "d.int32Val=815;"
+ "for (int i = 0; i<d.int8Array.length;i++){"
+ "\td.int8Array[i]=(byte)(i+100);"
+ "\t}"
+ "d.stringVal=\"some contents\";"
+ "d.float64Val=3.141234;"
+ "PingPongPort.ping(d);"
+ }
+ }
+ Transition init0: initial -> waitForPongSimple {
+ action {
+ "PingPongPort.pingSimple(0);"
+ }
+ }
+ State waitForPong
+ State waitForPongSimple
+ }
+ }
+ }
+ +
+ ActorClass MrPong {
+ Interface {
+ Port PingPongPort: PingPongProtocol
+ }
+ Structure {
+ external Port PingPongPort
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> looping { }
+ Transition tr0: looping -> looping {
+ triggers {
+ <ping: PingPongPort>
+ }
+ action {
+ "PingPongPort.pong(data);"
+ }
+ }
+ Transition tr1: looping -> looping {
+ triggers {
+ <pingSimple: PingPongPort>
+ }
+ action {
+ "PingPongPort.pongSimple(data+1);"
+ }
+ }
+ State looping
+ }
+ }
+ }
+ +
+ ProtocolClass PingPongProtocol {
+ incoming {
+ Message ping(data: DemoData)
+ Message pingSimple(data: int32)
+ }
+ outgoing {
+ Message pong(data: DemoData)
+ Message pongSimple(data: int32)
+ }
+ }
+ +
+ DataClass DemoData {
+ Attribute int32Val: int32 = "4711"
+ Attribute int8Array [ 10 ]: int8 = "{1,2,3,4,5,6,7,8,9,10}"
+ Attribute float64Val: float64 = "0.0"
+ Attribute stringVal: string = "\"empty\""
+ }
+}
+ +
+

+
+
+
+

+
+
+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/Finishthemodelstructure.html b/plugins/org.eclipse.etrice.doc/help/Finishthemodelstructure.html index d68aac201..638af0eb2 100644 --- a/plugins/org.eclipse.etrice.doc/help/Finishthemodelstructure.html +++ b/plugins/org.eclipse.etrice.doc/help/Finishthemodelstructure.html @@ -48,7 +48,7 @@ [stop] as incoming messages. [Blinky] receives this messages and therefore [Blinky]'s - [ControlPort] must be a base port and + [ControlPort] must be a regular port and [BlinkyController]'s [ControlPort] must be a conjugated port.

diff --git a/plugins/org.eclipse.etrice.doc/help/Generateandrunthemodel.html b/plugins/org.eclipse.etrice.doc/help/Generateandrunthemodel.html index bf0878976..c3e43e2b5 100644 --- a/plugins/org.eclipse.etrice.doc/help/Generateandrunthemodel.html +++ b/plugins/org.eclipse.etrice.doc/help/Generateandrunthemodel.html @@ -1,74 +1,84 @@ - - - -Generate and run the model - - - - - - - - -

Generate and run the model

-
-
-
-
-

-Generate and run the model

-
-
-
-

With the MWe2 workflow generate the code and run the model. - The output should look like this:

-

type ‚quit’ to exit - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 1 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 2 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 3 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 4 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 5 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 6 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 7 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 8 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 9 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 10 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - d.int32Val: 4711 - d.float64Val: 0,000000 - d.int8Array: 1 2 3 4 5 6 7 8 9 10 - d.stringVal: empty - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - d.int32Val: 815 - d.float64Val: 3,141234 - d.int8Array: 100 101 102 103 104 105 106 107 108 109 - d.stringVal: some contents - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - quit - echo: quit

-
- - + + + +Generate and run the model + + + + + + + + +

Generate and run the model

+
+
+
+
+

+Generate and run the model

+
+
+
+

With the MWe2 workflow generate the code and run the model. + The output should look like this:

+
+
+

+ type ‚quit’ to exit + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 1 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 2 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 3 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 4 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 5 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 6 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 7 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 8 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 9 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 10 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + d.int32Val: 4711 + d.float64Val: 0,000000 + d.int8Array: 1 2 3 4 5 6 7 8 9 10 + d.stringVal: empty + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + d.int32Val: 815 + d.float64Val: 3,141234 + d.int8Array: 100 101 102 103 104 105 106 107 108 109 + d.stringVal: some contents + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + quit + echo: quit

+
+
+
+
+

+
+
+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/ImplementtheBehavior.html b/plugins/org.eclipse.etrice.doc/help/ImplementtheBehavior.html index d8f0ae802..504ea672c 100644 --- a/plugins/org.eclipse.etrice.doc/help/ImplementtheBehavior.html +++ b/plugins/org.eclipse.etrice.doc/help/ImplementtheBehavior.html @@ -52,7 +52,7 @@

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 + [port.message(param);]. In this example [ControlPort.start()] sends the [start] message via the [ControlPort] to the outside world. Assuming that diff --git a/plugins/org.eclipse.etrice.doc/help/OpentheMessageSequenceChart.html b/plugins/org.eclipse.etrice.doc/help/OpentheMessageSequenceChart.html index b3721aa33..e5d7c6f07 100644 --- a/plugins/org.eclipse.etrice.doc/help/OpentheMessageSequenceChart.html +++ b/plugins/org.eclipse.etrice.doc/help/OpentheMessageSequenceChart.html @@ -20,7 +20,7 @@ -

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:

+

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:

diff --git a/plugins/org.eclipse.etrice.doc/help/ROOMConcepts.html b/plugins/org.eclipse.etrice.doc/help/ROOMConcepts.html index f0b4e564f..f70dd8583 100644 --- a/plugins/org.eclipse.etrice.doc/help/ROOMConcepts.html +++ b/plugins/org.eclipse.etrice.doc/help/ROOMConcepts.html @@ -6,7 +6,7 @@ - +

ROOM Concepts

diff --git a/plugins/org.eclipse.etrice.doc/help/Setupthemodel.html b/plugins/org.eclipse.etrice.doc/help/Setupthemodel.html new file mode 100644 index 000000000..ad035814f --- /dev/null +++ b/plugins/org.eclipse.etrice.doc/help/Setupthemodel.html @@ -0,0 +1,316 @@ + + + +Setup the model + + + + + + + + +

Setup the model

+
+
+
+
+

+Setup the model

+
+
+
+
+
    +
  • +

    Use the + [New Model Wizzard] to create a new eTrice project and name it + [PedLightsController]. +

    +
  • +
  • +

    Copy the package + [de.protos.PedLightGUI] to your + [src] directory (see blinky tutorial). +

    +
  • +
  • +

    In PedestrianLightWndNoTcp.jav uncomment line 15 (import), 36, 122 (usage) and 132-134 (registration).

    +
  • +
  • +

    Copy the following model to your model file:

    +
  • +
+
+
+

+RoomModel PedLightsController {
+ +
+ LogicalSystem LogSys_PedLights {
+ SubSystemRef application: SubSys_PedLights
+ }
+ +
+ SubSystemClass SubSys_PedLights {
+ ActorRef PedLightsTopRef: PedLightsTop
+ ActorRef timingService: room.basic.service.timing.ATimingService
+ LayerConnection ref PedLightsTopRef satisfied_by timingService.timer
+ LayerConnection ref PedLightsTopRef satisfied_by timingService.timeout
+ }
+ +
+ ActorClass PedLightsTop {
+ Structure {
+ ActorRef adapter: GuiAdapter
+ ActorRef controller: Controller
+ Binding adapter.ControlPort and controller.ControlPort
+ }
+ Behavior { }
+ }
+ +
+ ActorClass GuiAdapter {
+ Interface {
+ conjugated Port ControlPort: PedControlProtocol
+ }
+ Structure {
+ usercode1 {
+ "import PedLightGUI.*;"
+ }
+ usercode2 {
+ "private PedestrianLightWndNoTcp lights = new PedestrianLightWndNoTcp(\"Pedestrian Lights\",\"  external port connection \");"
+ "private TrafficLight3 carLights;"
+ "private TrafficLight2 pedLights;"
+ }
+ external Port ControlPort
+ }
+ Behavior {
+ Operation destroyUser() {
+ "lights.closeWindow();"
+ }
+ StateMachine {
+ Transition init: initial -> running {
+ action {
+ "carLights=lights.getCarLights();"
+ "pedLights=lights.getPedLights();"
+ "carLights.setState(TrafficLight3.OFF);"
+ "pedLights.setState(TrafficLight2.OFF);"
+ "lights.setPort(ControlPort);"
+ }
+ }
+ Transition tr0: running -> running {
+ triggers {
+ <setCarLights: ControlPort>
+ }
+ action {
+ "carLights.setState(state);"
+ }
+ }
+ Transition tr1: running -> running {
+ triggers {
+ <setPedLights: ControlPort>
+ }
+ action {
+ "pedLights.setState(state);"
+ }
+ }
+ State running
+ }
+ }
+ }
+ +
+ ActorClass Controller {
+ Interface {
+ Port ControlPort: PedControlProtocol
+ }
+ Structure {
+ usercode1 {
+ "import PedLightGUI.*;"
+ }
+ external Port ControlPort
+ SAP timer: room.basic.service.timing.PTimeout
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> off { }
+ Transition tr0: off -> carsGreen {
+ triggers {
+ <start: ControlPort>
+ }
+ action {
+ "timer.Start(700);"
+ "ControlPort.setCarLights(TrafficLight3.GREEN);"
+ "ControlPort.setPedLights(TrafficLight2.RED);"
+ }
+ }
+ Transition tr1: carsGreen -> carsYellow {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "timer.Start(700);"
+ "ControlPort.setCarLights(TrafficLight3.YELLOW);"
+ "ControlPort.setPedLights(TrafficLight2.RED);"
+ }
+ }
+ Transition tr2: carsYellow -> carsRed {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "timer.Start(1500);"
+ "ControlPort.setCarLights(TrafficLight3.RED);"
+ "ControlPort.setPedLights(TrafficLight2.GREEN);"
+ }
+ }
+ Transition tr3: carsRed -> carsYellowRed {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "timer.Start(700);"
+ "ControlPort.setCarLights(TrafficLight3.YELLOW_RED);"
+ "ControlPort.setPedLights(TrafficLight2.RED);"
+ }
+ }
+ Transition tr4: carsYellowRed -> carsGreen2 {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "timer.Start(700);"
+ "ControlPort.setCarLights(TrafficLight3.GREEN);"
+ "ControlPort.setPedLights(TrafficLight2.RED);"
+ }
+ }
+ Transition tr5: carsGreen2 -> off {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "ControlPort.setCarLights(TrafficLight3.OFF);"
+ "ControlPort.setPedLights(TrafficLight2.OFF);"
+ }
+ }
+ State off
+ State carsGreen
+ State carsYellow
+ State carsRed
+ State carsYellowRed
+ State carsGreen2
+ }
+ }
+ }
+ +
+ ProtocolClass PedControlProtocol {
+ incoming {
+ Message start()
+ }
+ outgoing {
+ Message setCarLights(state: int32)
+ Message setPedLights(state: int32)
+ }
+ }
+}
+ +
+

+
+
+
+

+
+
+
+
    +
  • +

    Arrange the Structure and the Statemachines to understand the model

    +
  • +
+
+

+ +

+
+
+

+ The + [GuiAdapter] represents the interface to the external code. It registers its + [ControlPort] by the external code. +

+

+ +

+
+
+

+ Visit the initial transition to understand the registration. The actor handles the incoming messages as usual and controls the traffic lights as known from blinky. +

+

+ +

+
+
+

+ The + [Controller] receives the + [start] message and controls the timing of the lights. Note that the + [start] message will be sent from the external code whenever the + [REQUEST] button is pressed. +

+
+
    +
  • +

    Visit the model and take a closer look to the following elements:

    +
  • +
+
+
+
    +
  1. +

    PedControlProtocol => notice that the start message is defined as usual

    +
  2. +
  3. +

    Initial transition of the + [GuiAdapter] => see the registration +

    +
  4. +
  5. +

    The + [Controller] => notice that the + [Controller] receives the external message (not the + [GuiAdapter]). The + [GuiAdapter] just provides its port and handles the incoming messages. +

    +
  6. +
  7. +

    Visit the hand written code => see the import statement of the protocol class and the usage of the port.

    +
  8. +
+
+
+
    +
  • +

    Generate and test the model

    +
  • +
  • +

    Take a look at the generated MSC => notice that the start message will shown as if the + [GuiAdapter] had sent it. +

    +
  • +
+
+

+ +

+
+
+

+ +

+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/Summary.html b/plugins/org.eclipse.etrice.doc/help/Summary.html index f0fe2ea41..5f049627b 100644 --- a/plugins/org.eclipse.etrice.doc/help/Summary.html +++ b/plugins/org.eclipse.etrice.doc/help/Summary.html @@ -21,7 +21,7 @@

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 deals with more complex state machines hierarchies in structure and behavior.

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

diff --git a/plugins/org.eclipse.etrice.doc/help/Summary2.html b/plugins/org.eclipse.etrice.doc/help/Summary2.html index 28ef397a4..691277512 100644 --- a/plugins/org.eclipse.etrice.doc/help/Summary2.html +++ b/plugins/org.eclipse.etrice.doc/help/Summary2.html @@ -20,7 +20,7 @@ -

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.

+

Run the model and take a 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/help/Summary3.html b/plugins/org.eclipse.etrice.doc/help/Summary3.html index feb52d27a..9a85aabb9 100644 --- a/plugins/org.eclipse.etrice.doc/help/Summary3.html +++ b/plugins/org.eclipse.etrice.doc/help/Summary3.html @@ -1,36 +1,36 @@ - - - -Summary - - - - - - - - -

Summary

-
-
-
-
-

-Summary

-
-
-
-

Within the first loop a integer value will be incremented from - [MrPong] and sent back to - [MrPing]. Is long as the guard is true - [MrPing] sends back the value. -

-

Within the - [next] transition, - [MrPing] creates a data class and sends the default values. Than - [MrPing] changes the values and sends the class again. At this point you should note that during the send operation, a copy of the data class will be created and sent. Otherwise it would not be possible to send the same object two times, even more it would not be possible to send a stack object at all. - In later versions of eTrice a additional mechanism to send references will be implemented. However, keep in mind that sending references takes the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. -

-
- - + + + +Summary + + + + + + + + +

Summary

+
+
+
+
+

+Summary

+
+
+
+

Within the first loop an integer value will be incremented from + [MrPong] and sent back to + [MrPing]. As long as the guard is true + [MrPing] sends back the value. +

+

Within the + [next] transition, + [MrPing] creates a data class and sends the default values. Than + [MrPing] changes the values and sends the class again. At this point you should note that during the send operation, a copy of the data class will be created and sent. Otherwise it would not be possible to send the same object two times, even more it would not be possible to send a stack object at all. + In future versions of eTrice an additional mechanism to send references will be implemented. However, keep in mind that sending references transfers the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. +

+
+ + diff --git a/plugins/org.eclipse.etrice.doc/help/TutorialBlinky.html b/plugins/org.eclipse.etrice.doc/help/TutorialBlinky.html index a80d385b4..b52ad72d1 100644 --- a/plugins/org.eclipse.etrice.doc/help/TutorialBlinky.html +++ b/plugins/org.eclipse.etrice.doc/help/TutorialBlinky.html @@ -58,12 +58,12 @@

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,... + [TimingService], how to combine a generated model with manual code and how to model 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. + [src] directory. The package contains four java classes which implement a small 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:

@@ -74,7 +74,7 @@

-

Within this tutorial we just will switching on and off the yellow light.

+

Within this tutorial we just will toggle the yellow light.

You will perform the following steps:

    diff --git a/plugins/org.eclipse.etrice.doc/help/TutorialHelloWorld.html b/plugins/org.eclipse.etrice.doc/help/TutorialHelloWorld.html index d2275bf8d..2a327b7ed 100644 --- a/plugins/org.eclipse.etrice.doc/help/TutorialHelloWorld.html +++ b/plugins/org.eclipse.etrice.doc/help/TutorialHelloWorld.html @@ -51,7 +51,7 @@
-

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:

+

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:

  1. diff --git a/plugins/org.eclipse.etrice.doc/help/TutorialPedestrianLights.html b/plugins/org.eclipse.etrice.doc/help/TutorialPedestrianLights.html new file mode 100644 index 000000000..1fdf67df3 --- /dev/null +++ b/plugins/org.eclipse.etrice.doc/help/TutorialPedestrianLights.html @@ -0,0 +1,84 @@ + + + +Tutorial Pedestrian Lights + + + + + + + + +

    Tutorial Pedestrian Lights

    +
    +
    +
    +
    +

    +Tutorial Pedestrian Lights

    +
    +
    +
    + +
    +
    +
    +
    +

    +Scope

    +
    +
    +
    +

    The scope of this tutorial is to demonstrate how to receive model messages from outside the model. Calling methods which are not part of the model is simple and you have already done this within the blinky tutorial (this is the other way round: model => external code). Receiving events from outside the model is a very common problem and a very frequently asked question. Therefore this tutorial shows how an external event (outside the model) can be received from the model.

    +

    This tutorial is not like hello world or blinky. Being familiar with the basic tool features is mandatory for this tutorial. The goal is to understand the mechanism not to learn the tool features.

    +

    The idea behind the exercise is, to control a Pedestrian crossing light. We will use the same GUI as for the blinky tutorial but now we will use the + [REQUEST] button to start a FSM, which controls the traffic lights. +

    +

    + +

    +
    +
    +

    + +

    +

    The + [REQUEST] must lead to a model message which starts the activity of the lights. +

    +

    There are several possibilities to receive external events (e.g. TCP/UDP Socket, using OS messaging mechanism), but the easiest way is, to make a port usable from outside the model. To do that a few steps are necessary:

    +
    +
      +
    1. +

      specify the messages (within a protocol) which should be sent into the model

      +
    2. +
    3. +

      model an actor with a port (which uses the specified protocol) and connect the port to the receiver

      +
    4. +
    5. +

      the external code should know the port (import of the port class)

      +
    6. +
    7. +

      the external code should provide a registration method, so that the actor is able to allow access to this port

      +
    8. +
    9. +

      the port can be used from the external code

      +
    10. +
    +
    +
    +
    + + diff --git a/plugins/org.eclipse.etrice.doc/help/TutorialSendingData.html b/plugins/org.eclipse.etrice.doc/help/TutorialSendingData.html index 6a87e64f5..c37d160b9 100644 --- a/plugins/org.eclipse.etrice.doc/help/TutorialSendingData.html +++ b/plugins/org.eclipse.etrice.doc/help/TutorialSendingData.html @@ -1,91 +1,91 @@ - - - -Tutorial Sending Data - - - - - - - - -

    Tutorial Sending Data

    -
    -
    -
    -
    -

    -Tutorial Sending Data

    -
    -
    -
    - -
    -
    -
    -
    -

    -Scope

    -
    -
    -
    -

    This tutorial shows how data will be sent in a eTrice model. Within the example you will create two actors (MrPing and MrPong). MrPong will simply loop back every data it received. - MrPing will sent data and verify the result.

    -

    You will perform the following steps:

    -
    -
      -
    1. -

      create a new model from scratch

      -
    2. -
    3. -

      create a data class

      -
    4. -
    5. -

      define a protocol with attached data

      -
    6. -
    7. -

      create an actor structure

      -
    8. -
    9. -

      create two simple state machines

      -
    10. -
    11. -

      build and run the model

      -
    12. -
    -
    -
    -
    - - + + + +Tutorial Sending Data + + + + + + + + +

    Tutorial Sending Data

    +
    +
    +
    +
    +

    +Tutorial Sending Data

    +
    +
    +
    + +
    +
    +
    +
    +

    +Scope

    +
    +
    +
    +

    This tutorial shows how data will be sent in a eTrice model. Within the example you will create two actors (MrPing and MrPong). MrPong will simply loop back every data it received. + MrPing will send data and verify the result.

    +

    You will perform the following steps:

    +
    +
      +
    1. +

      create a new model from scratch

      +
    2. +
    3. +

      create a data class

      +
    4. +
    5. +

      define a protocol with attached data

      +
    6. +
    7. +

      create an actor structure

      +
    8. +
    9. +

      create two simple state machines

      +
    10. +
    11. +

      build and run the model

      +
    12. +
    +
    +
    +
    + + diff --git a/plugins/org.eclipse.etrice.doc/help/Whydoesitworkandwhyisitsafe.html b/plugins/org.eclipse.etrice.doc/help/Whydoesitworkandwhyisitsafe.html new file mode 100644 index 000000000..cb5cf3864 --- /dev/null +++ b/plugins/org.eclipse.etrice.doc/help/Whydoesitworkandwhyisitsafe.html @@ -0,0 +1,48 @@ + + + +Why does it work and why is it safe? + + + + + + + + +

    Why does it work and why is it safe?

    +
    +
    +
    +
    +

    +Why does it work and why is it safe?

    +
    +
    +
    +

    The tutorial shows that it is generally possible to use every port from outside the model as long as the port knows its peer. This is guaranteed by describing protocol and the complete structure (especially the bindings) within the model. + The only remaining question is: Why is it safe and does not violate the „run to completion” semantic. To answer this question, take a look at the + [MessageService.java] from the runtime environment. There you will find the receive method which puts each message into the queue. +

    +
    +

    + @Override
    + public synchronized void receive(Message msg) {
    + if (msg!=null) {
    + messageQueue.push(msg);
    + notifyAll(); // wake up thread to compute message
    + }
    + }
    + +
    +

    +
    +
    +
    +

    +
    +
    +

    This method is synchronized. That means, regardless who sends the message, the queue is secured. If we later on (e.g. for performance reasons in C/C++) distinguish between internal and external senders (same thread or not), care must be taken to use the external (secure) queue.

    +
    + + diff --git a/plugins/org.eclipse.etrice.doc/help/images/025-SendigData03.png b/plugins/org.eclipse.etrice.doc/help/images/025-SendigData03.png deleted file mode 100644 index b178015e3..000000000 Binary files a/plugins/org.eclipse.etrice.doc/help/images/025-SendigData03.png and /dev/null differ diff --git a/plugins/org.eclipse.etrice.doc/help/images/030-PedLights01.png b/plugins/org.eclipse.etrice.doc/help/images/030-PedLights01.png new file mode 100644 index 000000000..bc4fc1085 Binary files /dev/null and b/plugins/org.eclipse.etrice.doc/help/images/030-PedLights01.png differ diff --git a/plugins/org.eclipse.etrice.doc/help/images/030-PedLights02.png b/plugins/org.eclipse.etrice.doc/help/images/030-PedLights02.png new file mode 100644 index 000000000..d1670a648 Binary files /dev/null and b/plugins/org.eclipse.etrice.doc/help/images/030-PedLights02.png differ diff --git a/plugins/org.eclipse.etrice.doc/help/images/030-PedLights03.png b/plugins/org.eclipse.etrice.doc/help/images/030-PedLights03.png new file mode 100644 index 000000000..bdf251429 Binary files /dev/null and b/plugins/org.eclipse.etrice.doc/help/images/030-PedLights03.png differ diff --git a/plugins/org.eclipse.etrice.doc/help/images/030-PedLights04.png b/plugins/org.eclipse.etrice.doc/help/images/030-PedLights04.png new file mode 100644 index 000000000..064bf39c5 Binary files /dev/null and b/plugins/org.eclipse.etrice.doc/help/images/030-PedLights04.png differ diff --git a/plugins/org.eclipse.etrice.doc/html/etrice.html b/plugins/org.eclipse.etrice.doc/html/etrice.html index a31da9355..6545eb3e0 100644 --- a/plugins/org.eclipse.etrice.doc/html/etrice.html +++ b/plugins/org.eclipse.etrice.doc/html/etrice.html @@ -120,7 +120,7 @@ Create MrPing and MrPong Actors
    -Define the Actors Structure and Behavior +Define Actor Structure and Behavior
    Define the top level @@ -134,7 +134,23 @@
    -6. ROOM Concepts +6. Tutorial Pedestrian Lights +
    +
    +
    +
    +Scope +
    +
    +Setup the model +
    +
    +Why does it work and why is it safe? +
    +
    +
    +
    +7. ROOM Concepts
    @@ -229,7 +245,7 @@
-

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:

+

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:

  1. @@ -347,9 +363,9 @@ [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 build of. It is a good idea to define a top level actor that can be used as reference within the subsystem. + [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.

    -

    Mention that a outline view was created that represents all currently existing model elements in a graphical way.

    +

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

    @@ -435,7 +451,7 @@

    -

    The code will be generated to the src-gen directory. The main class will be contained in +

    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.

    @@ -467,7 +483,7 @@

-

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:

+

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:

@@ -487,7 +503,7 @@

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 deals with more complex state machines hierarchies in structure and behavior.

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

@@ -509,12 +525,12 @@

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,... + [TimingService], how to combine a generated model with manual code and how to model 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. + [src] directory. The package contains four java classes which implement a small 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:

@@ -525,7 +541,7 @@

-

Within this tutorial we just will switching on and off the yellow light.

+

Within this tutorial we just will toggle the yellow light.

You will perform the following steps:

    @@ -653,7 +669,7 @@ [ProtocolClass] and name it [BlinkyControlProtocol]. Inside the brackets use the - [Content Assist] (CTRL+Space) to create two incomming messages called + [Content Assist] (CTRL+Space) to create two incoming messages called [start] and [stop].

    @@ -667,7 +683,7 @@

    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. + [Format] from the context menu you can format the text. Note that all elements are displayed in the outline view.

@@ -761,7 +777,7 @@ [stop] as incoming messages. [Blinky] receives this messages and therefore [Blinky]'s - [ControlPort] must be a base port and + [ControlPort] must be a regular port and [BlinkyController]'s [ControlPort] must be a conjugated port.

@@ -826,7 +842,7 @@

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 + [port.message(param);]. In this example [ControlPort.start()] sends the [start] message via the [ControlPort] to the outside world. Assuming that @@ -1182,7 +1198,7 @@ carLights.setState(TrafficLight3.OFF); 

-

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.

+

Run the model and take a 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.

@@ -1204,7 +1220,7 @@ carLights.setState(TrafficLight3.OFF); 

This tutorial shows how data will be sent in a eTrice model. Within the example you will create two actors (MrPing and MrPong). MrPong will simply loop back every data it received. - MrPing will sent data and verify the result.

+ MrPing will send data and verify the result.

You will perform the following steps:

    @@ -1434,12 +1450,12 @@ carLights.setState(TrafficLight3.OFF); 

-
+

-Define the Actors Structure and Behavior

+Define Actor Structure and Behavior
@@ -1622,9 +1638,6 @@ carLights.setState(TrafficLight3.OFF); 

The model is finished now and the model file should look like this:

-

-
-

RoomModel SendingData {
@@ -1793,53 +1806,63 @@ carLights.setState(TrafficLight3.OFF); 

With the MWe2 workflow generate the code and run the model. The output should look like this:

-

type ‚quit’ to exit - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 1 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 2 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 3 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 4 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 5 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 6 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 7 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 8 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 9 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - data: 10 - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping - d.int32Val: 4711 - d.float64Val: 0,000000 - d.int8Array: 1 2 3 4 5 6 7 8 9 10 - d.stringVal: empty - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - d.int32Val: 815 - d.float64Val: 3,141234 - d.int8Array: 100 101 102 103 104 105 106 107 108 109 - d.stringVal: some contents - /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong - quit - echo: quit

+
+
+

+ type ‚quit’ to exit + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 1 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 2 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 3 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 4 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 5 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 6 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 7 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 8 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 9 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPongSimple + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + data: 10 + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + /SendingData_SubSystem/SendigDataTopRef/ref1 -> looping + d.int32Val: 4711 + d.float64Val: 0,000000 + d.int8Array: 1 2 3 4 5 6 7 8 9 10 + d.stringVal: empty + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + d.int32Val: 815 + d.float64Val: 3,141234 + d.int8Array: 100 101 102 103 104 105 106 107 108 109 + d.stringVal: some contents + /SendingData_SubSystem/SendigDataTopRef/ref0 -> waitForPong + quit + echo: quit

+
+
+
+
+

+
+
@@ -1850,25 +1873,415 @@ carLights.setState(TrafficLight3.OFF); 
-

Within the first loop a integer value will be incremented from +

Within the first loop an integer value will be incremented from [MrPong] and sent back to - [MrPing]. Is long as the guard is true + [MrPing]. As long as the guard is true [MrPing] sends back the value.

Within the [next] transition, [MrPing] creates a data class and sends the default values. Than [MrPing] changes the values and sends the class again. At this point you should note that during the send operation, a copy of the data class will be created and sent. Otherwise it would not be possible to send the same object two times, even more it would not be possible to send a stack object at all. - In later versions of eTrice a additional mechanism to send references will be implemented. However, keep in mind that sending references takes the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures. + In future versions of eTrice an additional mechanism to send references will be implemented. However, keep in mind that sending references transfers the responsibility of the life cycle of the sent object to the user. It looks simple but is a very common source of failures.

-
+
+
+
+
+

+Chapter 6. Tutorial Pedestrian Lights

+
+
+
+
+
+
+
+

+Scope

+
+
+
+

The scope of this tutorial is to demonstrate how to receive model messages from outside the model. Calling methods which are not part of the model is simple and you have already done this within the blinky tutorial (this is the other way round: model => external code). Receiving events from outside the model is a very common problem and a very frequently asked question. Therefore this tutorial shows how an external event (outside the model) can be received from the model.

+

This tutorial is not like hello world or blinky. Being familiar with the basic tool features is mandatory for this tutorial. The goal is to understand the mechanism not to learn the tool features.

+

The idea behind the exercise is, to control a Pedestrian crossing light. We will use the same GUI as for the blinky tutorial but now we will use the + [REQUEST] button to start a FSM, which controls the traffic lights. +

+

+ +

+
+
+

+ +

+

The + [REQUEST] must lead to a model message which starts the activity of the lights. +

+

There are several possibilities to receive external events (e.g. TCP/UDP Socket, using OS messaging mechanism), but the easiest way is, to make a port usable from outside the model. To do that a few steps are necessary:

+
+
    +
  1. +

    specify the messages (within a protocol) which should be sent into the model

    +
  2. +
  3. +

    model an actor with a port (which uses the specified protocol) and connect the port to the receiver

    +
  4. +
  5. +

    the external code should know the port (import of the port class)

    +
  6. +
  7. +

    the external code should provide a registration method, so that the actor is able to allow access to this port

    +
  8. +
  9. +

    the port can be used from the external code

    +
  10. +
+
+
+
+
+
+
+

+Setup the model

+
+
+
+
+
    +
  • +

    Use the + [New Model Wizzard] to create a new eTrice project and name it + [PedLightsController]. +

    +
  • +
  • +

    Copy the package + [de.protos.PedLightGUI] to your + [src] directory (see blinky tutorial). +

    +
  • +
  • +

    In PedestrianLightWndNoTcp.jav uncomment line 15 (import), 36, 122 (usage) and 132-134 (registration).

    +
  • +
  • +

    Copy the following model to your model file:

    +
  • +
+
+
+

+RoomModel PedLightsController {
+ +
+ LogicalSystem LogSys_PedLights {
+ SubSystemRef application: SubSys_PedLights
+ }
+ +
+ SubSystemClass SubSys_PedLights {
+ ActorRef PedLightsTopRef: PedLightsTop
+ ActorRef timingService: room.basic.service.timing.ATimingService
+ LayerConnection ref PedLightsTopRef satisfied_by timingService.timer
+ LayerConnection ref PedLightsTopRef satisfied_by timingService.timeout
+ }
+ +
+ ActorClass PedLightsTop {
+ Structure {
+ ActorRef adapter: GuiAdapter
+ ActorRef controller: Controller
+ Binding adapter.ControlPort and controller.ControlPort
+ }
+ Behavior { }
+ }
+ +
+ ActorClass GuiAdapter {
+ Interface {
+ conjugated Port ControlPort: PedControlProtocol
+ }
+ Structure {
+ usercode1 {
+ "import PedLightGUI.*;"
+ }
+ usercode2 {
+ "private PedestrianLightWndNoTcp lights = new PedestrianLightWndNoTcp(\"Pedestrian Lights\",\"  external port connection \");"
+ "private TrafficLight3 carLights;"
+ "private TrafficLight2 pedLights;"
+ }
+ external Port ControlPort
+ }
+ Behavior {
+ Operation destroyUser() {
+ "lights.closeWindow();"
+ }
+ StateMachine {
+ Transition init: initial -> running {
+ action {
+ "carLights=lights.getCarLights();"
+ "pedLights=lights.getPedLights();"
+ "carLights.setState(TrafficLight3.OFF);"
+ "pedLights.setState(TrafficLight2.OFF);"
+ "lights.setPort(ControlPort);"
+ }
+ }
+ Transition tr0: running -> running {
+ triggers {
+ <setCarLights: ControlPort>
+ }
+ action {
+ "carLights.setState(state);"
+ }
+ }
+ Transition tr1: running -> running {
+ triggers {
+ <setPedLights: ControlPort>
+ }
+ action {
+ "pedLights.setState(state);"
+ }
+ }
+ State running
+ }
+ }
+ }
+ +
+ ActorClass Controller {
+ Interface {
+ Port ControlPort: PedControlProtocol
+ }
+ Structure {
+ usercode1 {
+ "import PedLightGUI.*;"
+ }
+ external Port ControlPort
+ SAP timer: room.basic.service.timing.PTimeout
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> off { }
+ Transition tr0: off -> carsGreen {
+ triggers {
+ <start: ControlPort>
+ }
+ action {
+ "timer.Start(700);"
+ "ControlPort.setCarLights(TrafficLight3.GREEN);"
+ "ControlPort.setPedLights(TrafficLight2.RED);"
+ }
+ }
+ Transition tr1: carsGreen -> carsYellow {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "timer.Start(700);"
+ "ControlPort.setCarLights(TrafficLight3.YELLOW);"
+ "ControlPort.setPedLights(TrafficLight2.RED);"
+ }
+ }
+ Transition tr2: carsYellow -> carsRed {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "timer.Start(1500);"
+ "ControlPort.setCarLights(TrafficLight3.RED);"
+ "ControlPort.setPedLights(TrafficLight2.GREEN);"
+ }
+ }
+ Transition tr3: carsRed -> carsYellowRed {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "timer.Start(700);"
+ "ControlPort.setCarLights(TrafficLight3.YELLOW_RED);"
+ "ControlPort.setPedLights(TrafficLight2.RED);"
+ }
+ }
+ Transition tr4: carsYellowRed -> carsGreen2 {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "timer.Start(700);"
+ "ControlPort.setCarLights(TrafficLight3.GREEN);"
+ "ControlPort.setPedLights(TrafficLight2.RED);"
+ }
+ }
+ Transition tr5: carsGreen2 -> off {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "ControlPort.setCarLights(TrafficLight3.OFF);"
+ "ControlPort.setPedLights(TrafficLight2.OFF);"
+ }
+ }
+ State off
+ State carsGreen
+ State carsYellow
+ State carsRed
+ State carsYellowRed
+ State carsGreen2
+ }
+ }
+ }
+ +
+ ProtocolClass PedControlProtocol {
+ incoming {
+ Message start()
+ }
+ outgoing {
+ Message setCarLights(state: int32)
+ Message setPedLights(state: int32)
+ }
+ }
+}
+ +
+

+
+
+
+

+
+
+
+
    +
  • +

    Arrange the Structure and the Statemachines to understand the model

    +
  • +
+
+

+ +

+
+
+

+ The + [GuiAdapter] represents the interface to the external code. It registers its + [ControlPort] by the external code. +

+

+ +

+
+
+

+ Visit the initial transition to understand the registration. The actor handles the incoming messages as usual and controls the traffic lights as known from blinky. +

+

+ +

+
+
+

+ The + [Controller] receives the + [start] message and controls the timing of the lights. Note that the + [start] message will be sent from the external code whenever the + [REQUEST] button is pressed. +

+
+
    +
  • +

    Visit the model and take a closer look to the following elements:

    +
  • +
+
+
+
    +
  1. +

    PedControlProtocol => notice that the start message is defined as usual

    +
  2. +
  3. +

    Initial transition of the + [GuiAdapter] => see the registration +

    +
  4. +
  5. +

    The + [Controller] => notice that the + [Controller] receives the external message (not the + [GuiAdapter]). The + [GuiAdapter] just provides its port and handles the incoming messages. +

    +
  6. +
  7. +

    Visit the hand written code => see the import statement of the protocol class and the usage of the port.

    +
  8. +
+
+
+
    +
  • +

    Generate and test the model

    +
  • +
  • +

    Take a look at the generated MSC => notice that the start message will shown as if the + [GuiAdapter] had sent it. +

    +
  • +
+
+

+ +

+
+
+

+ +

+
+
+
+
+
+

+Why does it work and why is it safe?

+
+
+
+

The tutorial shows that it is generally possible to use every port from outside the model as long as the port knows its peer. This is guaranteed by describing protocol and the complete structure (especially the bindings) within the model. + The only remaining question is: Why is it safe and does not violate the „run to completion” semantic. To answer this question, take a look at the + [MessageService.java] from the runtime environment. There you will find the receive method which puts each message into the queue. +

+
+

+ @Override
+ public synchronized void receive(Message msg) {
+ if (msg!=null) {
+ messageQueue.push(msg);
+ notifyAll(); // wake up thread to compute message
+ }
+ }
+ +
+

+
+
+
+

+
+
+

This method is synchronized. That means, regardless who sends the message, the queue is secured. If we later on (e.g. for performance reasons in C/C++) distinguish between internal and external senders (same thread or not), care must be taken to use the external (secure) queue.

+
+
+

-Chapter 6. ROOM Concepts

+Chapter 7. ROOM Concepts
diff --git a/plugins/org.eclipse.etrice.doc/html/images/025-SendigData03.png b/plugins/org.eclipse.etrice.doc/html/images/025-SendigData03.png deleted file mode 100644 index b178015e3..000000000 Binary files a/plugins/org.eclipse.etrice.doc/html/images/025-SendigData03.png and /dev/null differ diff --git a/plugins/org.eclipse.etrice.doc/html/images/030-PedLights01.png b/plugins/org.eclipse.etrice.doc/html/images/030-PedLights01.png new file mode 100644 index 000000000..bc4fc1085 Binary files /dev/null and b/plugins/org.eclipse.etrice.doc/html/images/030-PedLights01.png differ diff --git a/plugins/org.eclipse.etrice.doc/html/images/030-PedLights02.png b/plugins/org.eclipse.etrice.doc/html/images/030-PedLights02.png new file mode 100644 index 000000000..d1670a648 Binary files /dev/null and b/plugins/org.eclipse.etrice.doc/html/images/030-PedLights02.png differ diff --git a/plugins/org.eclipse.etrice.doc/html/images/030-PedLights03.png b/plugins/org.eclipse.etrice.doc/html/images/030-PedLights03.png new file mode 100644 index 000000000..bdf251429 Binary files /dev/null and b/plugins/org.eclipse.etrice.doc/html/images/030-PedLights03.png differ diff --git a/plugins/org.eclipse.etrice.doc/html/images/030-PedLights04.png b/plugins/org.eclipse.etrice.doc/html/images/030-PedLights04.png new file mode 100644 index 000000000..064bf39c5 Binary files /dev/null and b/plugins/org.eclipse.etrice.doc/html/images/030-PedLights04.png differ diff --git a/plugins/org.eclipse.etrice.doc/manual/etrice.pdf b/plugins/org.eclipse.etrice.doc/manual/etrice.pdf index 029584d22..527c9fadc 100644 Binary files a/plugins/org.eclipse.etrice.doc/manual/etrice.pdf and b/plugins/org.eclipse.etrice.doc/manual/etrice.pdf differ diff --git a/plugins/org.eclipse.etrice.doc/styles/fopdf.xsl b/plugins/org.eclipse.etrice.doc/styles/fopdf.xsl index 0e5962342..6b00bc5fa 100644 --- a/plugins/org.eclipse.etrice.doc/styles/fopdf.xsl +++ b/plugins/org.eclipse.etrice.doc/styles/fopdf.xsl @@ -82,7 +82,7 @@ - + diff --git a/plugins/org.eclipse.etrice.doc/styles/xmpp.xsl b/plugins/org.eclipse.etrice.doc/styles/xmpp.xsl index d73663af6..8f152e6cc 100644 --- a/plugins/org.eclipse.etrice.doc/styles/xmpp.xsl +++ b/plugins/org.eclipse.etrice.doc/styles/xmpp.xsl @@ -36,10 +36,10 @@ - Xtext + eTrice - Xtext 1.0 + eTrice 0.1 diff --git a/plugins/org.eclipse.etrice.doc/toc.xml b/plugins/org.eclipse.etrice.doc/toc.xml index 2f6939520..bc19761b6 100644 --- a/plugins/org.eclipse.etrice.doc/toc.xml +++ b/plugins/org.eclipse.etrice.doc/toc.xml @@ -30,14 +30,19 @@ - - - + + + + + + + + -- cgit v1.2.3