blob: 150e1249528d687eee4b3b32ecd166a350c80ccb [file] [log] [blame]
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head><title>HelloWorld for Java</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<!-- xhtml,3,next,html -->
<meta name="src" content="etrice-doc.tex" />
<meta name="date" content="2015-08-27 23:56:00" />
<link rel="stylesheet" type="text/css" href="etrice-doc.css" />
</head><body
>
<!--l. 1--><div class="crosslinks"><p class="noindent">[<a
href="etrice-docse6.html" >next</a>] [<a
href="etrice-docse4.html" >prev</a>] [<a
href="etrice-docse4.html#tailetrice-docse4.html" >prev-tail</a>] [<a
href="#tailetrice-docse5.html">tail</a>] [<a
href="etrice-docch2.html#etrice-docse5.html" >up</a>] </p></div>
<h3 class="sectionHead"><span class="titlemark">2.3 </span> <a
id="x9-280003"></a>HelloWorld for Java</h3>
<!--l. 3--><p class="noindent" >In this tutorial you will get a first look at a very simple eTrice model. The goal is to learn the work flow of eTrice and to
understand a few basic features of ROOM.
</p><!--l. 5--><p class="noindent" ><span
class="ec-lmssbx-10">Preconditions</span>: </p>
<ul class="itemize1">
<li class="itemize">Installed JDT Eclipse
</li>
<li class="itemize">Activated <span
class="ec-lmsso-10">Build Automatically </span>option in Eclipse: <span
class="ec-lmsso-10">Project -&#x003E; Build Automatically</span>
</li>
<li class="itemize">Recommended: Activate automatic resource refresh in Eclipse: <span
class="ec-lmsso-10">Window -&#x003E; Preferences -&#x003E; General -&#x003E;</span>
<span
class="ec-lmsso-10">Workspace</span>
<ul class="itemize2">
<li class="itemize"><span
class="ec-lmsso-10">Refresh using native hooks or polling</span>
</li>
<li class="itemize"><span
class="ec-lmsso-10">Refresh on access</span></li></ul>
</li>
<li class="itemize">Optional: Install <a
href="http://trace2uml.stage.tigris.org/" >Trace2UML</a>, a Open Source MSC viewer
<ul class="itemize2">
<li class="itemize"><a
href="http://trace2uml.tigris.org/servlets/ProjectDocumentList?folderID=6208" >Windows download site</a>
</li>
<li class="itemize"><a
href="http://apt.astade.de/" >Linux package</a></li></ul>
</li></ul>
<a
id="x9-28001r43"></a>
<h4 class="subsectionHead"><span class="titlemark">2.3.1 </span> <a
id="x9-290001"></a>Create template project</h4>
<!--l. 23--><p class="noindent" >After installation of eTricein Eclipse, we can use the wizard to create the template project, which is good starting point for
new ROOM applications. Select the menu <span
class="ec-lmsso-10">File -&#x003E; New -&#x003E; Other </span>(Ctrl+N) and choose <span
class="ec-lmsso-10">eTrice Java Template Project</span>.
Name the project <span
class="ec-lmsso-10">TemplateModel </span>and press <span
class="ec-lmsso-10">Next</span>. On the next page select <span
class="ec-lmsso-10">use Eclipse JDT build </span>and press
<span
class="ec-lmsso-10">Finish</span>.
</p><!--l. 25--><p class="noindent" ><img
src="images/014-wizard.png" alt="PIC"
/>
</p><!--l. 27--><p class="noindent" >This will add three projects into your workspace, the library projects <span
class="ec-lmsso-10">runtime.java </span>and <span
class="ec-lmsso-10">modellib.java </span>and our application
project <span
class="ec-lmsso-10">TemplateModel</span>. Now open the <span
class="ec-lmsso-10">TemplateModel.room </span>in the model folder of our project.
</p><!--l. 29--><p class="noindent" ><img
src="images/014-after-wizard.png" alt="PIC"
/>
</p><!--l. 31--><p class="noindent" >The model contains an ActorClass <span
class="ec-lmsso-10">TopActor</span>, which is currently the only active actor. TopActor has a state machine that is
intended to output a simple HelloWorld statement. To inspect its behavior graphically, we can open the behavior diagram by
right click on <span
class="ec-lmsso-10">Outline View -&#x003E; TopActor -&#x003E; Edit Behavior</span>. Alternatively we can place the cursor within the textual notation
and press Alt+B.
</p><!--l. 33--><p class="noindent" ><img
src="images/014-open-hello-fsm.png" alt="PIC"
/>
</p><!--l. 35--><p class="noindent" >The state machine has an initial transition that leads to <span
class="ec-lmsso-10">helloState</span>. The state defines an entry code, which is executed during
the transition. We can view the details by hovering over the state and edit the code with a double-click or right click and <span
class="ec-lmsso-10">Edit</span>
<span
class="ec-lmsso-10">State</span>.
</p><!--l. 37--><p class="noindent" ><img
src="images/014-hello-fsm.png" alt="PIC"
/>
<a
id="x9-29001r45"></a>
</p>
<h4 class="subsectionHead"><span class="titlemark">2.3.2 </span> <a
id="x9-300002"></a>Generate and run application</h4>
<!--l. 41--><p class="noindent" >Now we are ready to translate the model into an executable application. The first step is to generate source files from the
model. Therefore we run the eTrice model generator by right click on file
</p><div class="quote">
<!--l. 42--><p class="noindent" ><span
class="ec-lmsso-10">generate_TemplateModel.launch -&#x003E; Run As -&#x003E; generate_TemplateModel</span>.</p></div>
<!--l. 44--><p class="noindent" >After that we can build and run the application by right click on file
</p><div class="quote">
<!--l. 46--><p class="noindent" ><span
class="ec-lmsso-10">run_TemplateModel.launch -&#x003E; Run As -&#x003E; run_TemplateModel</span></p></div>
<!--l. 47--><p class="noindent" >. This will trigger the build process, carried out by JDT Eclipse and then subsequently start our application.
</p>
<div class="tabular"> <table id="TBL-3" class="tabular"
cellspacing="0" cellpadding="0"
><colgroup id="TBL-3-1g"><col
id="TBL-3-1" /><col
id="TBL-3-2" /></colgroup><tr
style="vertical-align:baseline;" id="TBL-3-1-"><td style="white-space:nowrap; text-align:center;" id="TBL-3-1-1"
class="td11"> <img
src="images/014-generate.png" alt="PIC"
/> </td><td style="white-space:nowrap; text-align:center;" id="TBL-3-1-2"
class="td11"> <img
src="images/014-build_run.png" alt="PIC"
/> </td>
</tr><tr
style="vertical-align:baseline;" id="TBL-3-2-"><td style="white-space:nowrap; text-align:center;" id="TBL-3-2-1"
class="td11"> 1. Invoke generator </td><td style="white-space:nowrap; text-align:center;" id="TBL-3-2-2"
class="td11"> 2. Build and run application </td>
</tr></table>
</div>
<!--l. 56--><p class="noindent" >The output of our application is logged in the Console View and it shows the "Hello World". By typing "quit", as prompt, and
pressing enter, the application terminates regularly.
</p><!--l. 58--><p class="noindent" ><img
src="images/014-quit-hello-msc.png" alt="PIC"
/>
<a
id="x9-30001r46"></a>
</p>
<h4 class="subsectionHead"><span class="titlemark">2.3.3 </span> <a
id="x9-310003"></a>Open the Message Sequence Chart</h4>
<!--l. 3--><p class="noindent" >After termination, we can inspect the behavior of our application. It is recorded in the form of a MSC (Message Sequence
Chart) and can now be used for debugging or documentation purpose. Open <span
class="ec-lmsso-10">msc.seq </span>or <span
class="ec-lmsso-10">subSystemRef_Async.seq </span>in the
folder <span
class="ec-lmsso-10">log </span>using the tool Trace2UML.
</p><div class="quote">
<!--l. 6--><p class="noindent" >If Trace2UML (Open Source tool) is not already installed, it can be obtained here: <a
href="http://trace2uml.tigris.org/servlets/ProjectDocumentList?folderID=6208" >Windows download
site</a> or <a
href="http://apt.astade.de/" >Linux package of the Astade UML tool containing Trace2UML</a></p></div>
<!--l. 10--><p class="noindent" >Yet the MSC is nearly empty having not recorded any interaction between actors. It shows that <span
class="ec-lmsso-10">topActor </span>(full
instance path <span
class="ec-lmsso-10">/LogSys/subSystemRef/topActor</span>) has taken <span
class="ec-lmsso-10">helloState</span>. In the next PingPong tutorial we are
going to create a more sophisticated and vivid eTriceapplication introducing actor building blocks and message
protocols.
</p><!--l. 62--><p class="noindent" ><img
src="images/014-hello-msc.png" alt="PIC"
/>
</p>
<!--l. 1--><div class="crosslinks"><p class="noindent">[<a
href="etrice-docse6.html" >next</a>] [<a
href="etrice-docse4.html" >prev</a>] [<a
href="etrice-docse4.html#tailetrice-docse4.html" >prev-tail</a>] [<a
href="etrice-docse5.html" >front</a>] [<a
href="etrice-docch2.html#etrice-docse5.html" >up</a>] </p></div>
<!--l. 1--><p class="noindent" ><a
id="tailetrice-docse5.html"></a></p>
</body></html>