Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4696be669f5c8bc458db4ac2e36e24e62b5f4b90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>eTrice User Guide</title>
<link href="book.css" rel="stylesheet" type="text/css">
<meta content="DocBook XSL Stylesheets V1.75.1" name="generator">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="book" title="eTrice User Guide">
<div class="titlepage">
<div>
<div>
<h1 class="title">
<a name="N10001"></a>eTrice User Guide</h1>
</div>
</div>
<hr>
</div>
<div class="toc">
<p>
<b>Table of Contents</b>
</p>
<dl>
<dt>
<span class="chapter"><a href="#eTriceOverview">1. eTrice Overview</a></span>
</dt>
<dd>
<dl>
<dt>
<span class="section"><a href="#WhatiseTrice">What is eTrice?</a></span>
</dt>
<dt>
<span class="section"><a href="#WhoshoulduseeTrice">Who should use eTrice?</a></span>
</dt>
<dt>
<span class="section"><a href="#HowDoesItWork">How Does It Work?</a></span>
</dt>
<dt>
<span class="section"><a href="#WhoisBehindeTrice">Who is Behind eTrice?</a></span>
</dt>
</dl>
</dd>
<dt>
<span class="chapter"><a href="#IntroductiontotheROOMLanguage">2. Introduction to the ROOM Language</a></span>
</dt>
<dt>
<span class="chapter"><a href="#TutorialHelloWorld">3. Tutorial HelloWorld</a></span>
</dt>
<dd>
<dl>
<dt>
<span class="section"><a href="#Scope">Scope</a></span>
</dt>
<dt>
<span class="section"><a href="#Createanewmodelfromscratch">Create a new model from scratch</a></span>
</dt>
<dt>
<span class="section"><a href="#Createastatemachine">Create a state machine</a></span>
</dt>
<dt>
<span class="section"><a href="#Buildandrunthemodel">Build and run the model</a></span>
</dt>
<dt>
<span class="section"><a href="#OpentheMessageSequenceChart">Open the Message Sequence Chart</a></span>
</dt>
<dt>
<span class="section"><a href="#Summary">Summary</a></span>
</dt>
</dl>
</dd>
<dt>
<span class="chapter"><a href="#TutorialBlinky">4. Tutorial Blinky</a></span>
</dt>
<dd>
<dl>
<dt>
<span class="section"><a href="#Scope2">Scope</a></span>
</dt>
<dt>
<span class="section"><a href="#Createanewmodelfromscratch2">Create a new model from scratch</a></span>
</dt>
<dt>
<span class="section"><a href="#Addtwoadditionalactorclasses">Add two additional actor classes</a></span>
</dt>
<dt>
<span class="section"><a href="#Createanewprotocol">Create a new protocol</a></span>
</dt>
<dt>
<span class="section"><a href="#ImporttheTimingService">Import the Timing Service</a></span>
</dt>
<dt>
<span class="section"><a href="#Finishthemodelstructure">Finish the model structure</a></span>
</dt>
<dt>
<span class="section"><a href="#ImplementtheBehavior">Implement the Behavior</a></span>
</dt>
<dt>
<span class="section"><a href="#Summary2">Summary</a></span>
</dt>
</dl>
</dd>
<dt>
<span class="chapter"><a href="#ROOMConcepts">5. ROOM Concepts</a></span>
</dt>
<dd>
<dl>
<dt>
<span class="section"><a href="#MainConcepts">Main Concepts</a></span>
</dt>
</dl>
</dd>
</dl>
</div>
<div class="chapter" title="Chapter&nbsp;1.&nbsp;eTrice Overview">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="eTriceOverview"></a>Chapter&nbsp;1.&nbsp;eTrice Overview</h2>
</div>
</div>
</div>
<div class="section" title="What is eTrice?">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="WhatiseTrice"></a>What is eTrice?</h2>
</div>
</div>
</div>
<p>eTrice provides an implementation of the ROOM modeling language (Real Time Object Oriented Modeling) together with editors, code generators for Java, C++ and C code and exemplary target middleware.</p>
<p>The model is defined in textual form (Xtext) with graphical editors (Graphiti) for the structural and behavioral (i.e. state machine) parts.  </p>
</div>
<div class="section" title="Who should use eTrice?">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="WhoshoulduseeTrice"></a>Who should use eTrice?</h2>
</div>
</div>
</div>
<p>Basically everyone who develops eventdriven realtime or embedded systems. </p>
<p>If you have other ideas how to use it, tell us!</p>
</div>
<div class="section" title="How Does It Work?">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="HowDoesItWork"></a>How Does It Work?</h2>
</div>
</div>
</div>
<p>TODO</p>
</div>
<div class="section" title="Who is Behind eTrice?">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="WhoisBehindeTrice"></a>Who is Behind eTrice?</h2>
</div>
</div>
</div>
<p>TODO</p>
</div>
</div>
<div class="chapter" title="Chapter&nbsp;2.&nbsp;Introduction to the ROOM Language">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="IntroductiontotheROOMLanguage"></a>Chapter&nbsp;2.&nbsp;Introduction to the ROOM Language</h2>
</div>
</div>
</div>
</div>
<div class="chapter" title="Chapter&nbsp;3.&nbsp;Tutorial HelloWorld">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="TutorialHelloWorld"></a>Chapter&nbsp;3.&nbsp;Tutorial HelloWorld</h2>
</div>
</div>
</div>
<div class="section" title="Scope">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Scope"></a>Scope</h2>
</div>
</div>
</div>
<p>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:</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>create a new model from scratch</p>
</li>
<li class="listitem">
<p>add a very simple state machine to an actor</p>
</li>
<li class="listitem">
<p>generate the source code</p>
</li>
<li class="listitem">
<p>run the model</p>
</li>
<li class="listitem">
<p>open the message sequence chart</p>
</li>
</ol>
</div>
</div>
<div class="section" title="Create a new model from scratch">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Createanewmodelfromscratch"></a>Create a new model from scratch</h2>
</div>
</div>
</div>
<p>The easiest way to create a new eTrice Project is to use the eclipse project wizard. From the eclipse file menu select 
				[<span class="citation">File-&gt;New-&gt;Project</span>] and create a new eTrice project and name it 
				[<span class="citation">HelloWorld</span>]
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld10.PNG"></div>
<p>
			
</p>
<p>The wizard creates everything that is needed to create, build and run a eTrice model. The resulting project should look like this:</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld11.PNG"></div>
<p>
			
</p>
<p>Within the model directory the model file 
				[<span class="citation">HelloWorld.room</span>] was created. Open the 
				[<span class="citation">HelloWorld.room</span>] file and position the cursor at the very beginning of the file. Open the content assist with Ctrl+Space and select 
				[<span class="citation">model skeleton</span>].
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld12.PNG"></div>
<p>   
			
</p>
<p>Edit the template variables and remove the artefacts from the wizard. </p>
<p>The resulting model code should look like this:</p>
<div class="literallayout">
<p>
<code class="code">RoomModel&nbsp;HelloWorld&nbsp;{<br>

<br>
	LogicalSystem&nbsp;System_HelloWorld&nbsp;{<br>
		SubSystemRef&nbsp;subsystem&nbsp;:&nbsp;SubSystem_HelloWorld<br>
	}<br>

<br>
	SubSystemClass&nbsp;SubSystem_HelloWorld&nbsp;{<br>
		ActorRef&nbsp;application&nbsp;:&nbsp;HelloWorldTop<br>
	}<br>

<br>
	ActorClass&nbsp;HelloWorldTop&nbsp;{<br>
	}<br>
}&nbsp;<br>

</code>
</p>
</div>
<div class="blockquote">
<blockquote class="blockquote">
<p></p>
</blockquote>
</div>
<p>The goal of eTrice is to describe distributed systems on a logical level. In the current version not all elements will be supported. But as prerequisite for further versions the following elements are mandatory for an eTrice model:</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>the 
						[<span class="citation">LogicalSystem</span>] 
					</p>
</li>
<li class="listitem">
<p>at least one 
						[<span class="citation">SubSystemClass</span>]
					</p>
</li>
<li class="listitem">
<p>at least one 
						[<span class="citation">ActorClass</span>]
					</p>
</li>
</ul>
</div>
<p>The 
				[<span class="citation">LogicalSystem</span>] represents the complete distributed system and contains at least one 
				[<span class="citation">SubSystemRef</span>]. The 
				[<span class="citation">SubSystemClass</span>] represents an address space and contains at least one 
				[<span class="citation">ActorRef</span>]. The 
				[<span class="citation">ActorClass</span>] 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.
			</p>
<p>Mention that a outline view was created that represents all currently existing model elements in a graphical way.</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld02.PNG"></div>
<p>
			
</p>
</div>
<div class="section" title="Create a state machine">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Createastatemachine"></a>Create a state machine</h2>
</div>
</div>
</div>
<p>We will implement the Hello World code on the initial transition of the 
				[<span class="citation">HelloWorldTop</span>] actor. Therefore open the state machine editor by right clicking the 
				[<span class="citation">HelloWorldTop</span>] actor in the outline view and select 
				[<span class="citation">Edit Behavior</span>].
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld03.PNG"></div>
<p>
			
</p>
<p>The state machine editor will be opened. Drag and drop an 
				[<span class="citation">Initial Point</span>] from the tool box to the diagram into the top level state. Drag and drop a 
				[<span class="citation">State</span>] from the tool box to the diagram. Confirm the dialogue with 
				[<span class="citation">ok</span>]. Select the 
				[<span class="citation">Transition</span>] in the tool box and draw the transition from the 
				[<span class="citation">Initial Point</span>] to the State. Open the transition dialogue by double clicking the caption of the transition and fill in the action code.
			</p>
<div class="literallayout">
<p>
<code class="code">System.out.println("Hello&nbsp;World&nbsp;!");<br>

</code>
</p>
</div>
<p>The result should look like this:</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld04.PNG"></div>
<p>
			
</p>
<p>Save the diagram and inspect the model file. Note that the textual representation was created after saving the diagram.</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld05.PNG"></div>
<p>
			
</p>
</div>
<div class="section" title="Build and run the model">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Buildandrunthemodel"></a>Build and run the model</h2>
</div>
</div>
</div>
<p>Now the model is finished and source code can be generated. The project wizard has created a workflow that is responsible to generate the source code. From 
				[<span class="citation">HelloWorld/src/workflow</span>] right click 
				[<span class="citation">HelloWorld.mwe2</span>] and run it as MWE2Workflow. All model files in the model directory will be generated.
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld06.PNG"></div>
<p>
			
</p>
<p>The code will be generated to the src-gen directory. The main class will be contained in 
				[<span class="citation">SubSystem_HelloWorldRunner.java</span>]. Select this file and run it as Java application.
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld07.PNG"></div>
<p>
			
</p>
<p>The Hello World application starts and the string will be printed on the console window. To stop the application the user must type 
				[<span class="citation">quit</span>] in the console window.
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld08.PNG"></div>
<p>
			
</p>
</div>
<div class="section" title="Open the Message Sequence Chart">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="OpentheMessageSequenceChart"></a>Open the Message Sequence Chart</h2>
</div>
</div>
</div>
<p>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:</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/015-HelloWorld09.PNG"></div>
<p>
			
</p>
</div>
<div class="section" title="Summary">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Summary"></a>Summary</h2>
</div>
</div>
</div>
<p>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.</p>
</div>
</div>
<div class="chapter" title="Chapter&nbsp;4.&nbsp;Tutorial Blinky">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="TutorialBlinky"></a>Chapter&nbsp;4.&nbsp;Tutorial Blinky</h2>
</div>
</div>
</div>
<div class="section" title="Scope">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Scope2"></a>Scope</h2>
</div>
</div>
</div>
<p>This tutorial describes how to use the 
				[<span class="citation">TimingService</span>], combine a generated model with manual code and how to modeling a hierarchical state machine. The idea of the tutorial is, to switch a LED on and off. The behavior of the LED should be: blinking in a one second interval for 5 seconds, stop blinking for 5 seconds, blinking, stop,...  
				For this exercise we will use a little GUI class that will be used in more sophisticated tutorials too. The GUI simulates a pedestrian traffic crossing. For now, just a simple LED simulation will be used from the GUI. 
			</p>
<p>To use the GUI please copy the package 
				[<span class="citation">de.protos.PedLightGUI</span>] to your 
				[<span class="citation">src</span>] 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.
			</p>
<p>The GUI looks like this:</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky08.PNG"></div>
<p>
			
</p>
<p>Within this tutorial we just will switching on and off the yellow light.</p>
<p>You will perform the following steps:</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>create a new model from scratch</p>
</li>
<li class="listitem">
<p>define a protocol</p>
</li>
<li class="listitem">
<p>create an actor structure</p>
</li>
<li class="listitem">
<p>create a hierarchical state machine</p>
</li>
<li class="listitem">
<p>use the predefined 
						[<span class="citation">TimingService</span>]
					</p>
</li>
<li class="listitem">
<p>combine manual code with generated code</p>
</li>
<li class="listitem">
<p>build and run the model</p>
</li>
<li class="listitem">
<p>open the message sequence chart</p>
</li>
</ol>
</div>
</div>
<div class="section" title="Create a new model from scratch">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Createanewmodelfromscratch2"></a>Create a new model from scratch</h2>
</div>
</div>
</div>
<p>Remember exercise 
				[<span class="citation">HelloWorld</span>].
				Create a new eTrice project and name it 
				[<span class="citation">Blinky</span>]
				Open the 
				[<span class="citation">Blinky.room</span>] file and copy the following code into the file or use content assist to create the model.
			</p>
<div class="literallayout">
<p>
<code class="code">RoomModel&nbsp;Blinky&nbsp;{<br>

<br>
	LogicalSystem&nbsp;System_Blinky&nbsp;{<br>
		SubSystemRef&nbsp;subsystem&nbsp;:&nbsp;SubSystem_Blinky<br>
	}<br>

<br>
	SubSystemClass&nbsp;SubSystem_Blinky&nbsp;{<br>
		ActorRef&nbsp;application&nbsp;:&nbsp;BlinkyTop<br>
	}<br>

<br>
	ActorClass&nbsp;BlinkyTop&nbsp;{<br>
	}<br>
}<br>

</code>
</p>
</div>
<div class="blockquote">
<blockquote class="blockquote">
<p></p>
</blockquote>
</div>
</div>
<div class="section" title="Add two additional actor classes">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Addtwoadditionalactorclasses"></a>Add two additional actor classes</h2>
</div>
</div>
</div>
<p>Position the cursor outside any class definition and right click the mouse within the editor window. From the context menu select 
				[<span class="citation">Content Assist</span>]  
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky02.png"></div>
<p>
			
</p>
<p>Select 
				[<span class="citation">ActorClass &ndash; actor class skeleton</span>] and name it 
				[<span class="citation">Blinky</span>].
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky01.PNG"></div>
<p> 
			
</p>
<p>Repeat the described procedure and name the new actor 
				[<span class="citation">BlinkyController</span>].
			</p>
<p>Save the model and visit the outline view.</p>
</div>
<div class="section" title="Create a new protocol">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Createanewprotocol"></a>Create a new protocol</h2>
</div>
</div>
</div>
<p>With the help of 
				[<span class="citation">Content Assist</span>] create a 
				[<span class="citation">ProtocolClass</span>] and name it 
				[<span class="citation">BlinkyControlProtocol</span>].
				Inside the brackets use the 
				[<span class="citation">Content Assist</span>] (CTRL+Space) to create two incomming messages called 
				[<span class="citation">start</span>] and 
				[<span class="citation">stop</span>].
			</p>
<p>The resulting code should look like this:</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky03.PNG"></div>
<p> 
			
</p>
<p>With Ctrl-Shift+F or selecting 
				[<span class="citation">Format</span>] from the context menu you can format the text. Mention that all elements are displayed in the outline view.
			</p>
</div>
<div class="section" title="Import the Timing Service">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="ImporttheTimingService"></a>Import the Timing Service</h2>
</div>
</div>
</div>
<p>Switching on and off the LED is timing controlled. Therefore a timing service is needed. To import the timing service in the outline view right click to 
				[<span class="citation">SubSystem_Blinky</span>]. Select 
				[<span class="citation">Edit Structure</span>]. Drag and Drop an 
				[<span class="citation">ActorRef</span>] to the 
				[<span class="citation">SubSystem_Blinky</span>] and name it 
				[<span class="citation">application</span>]. From the actor class drop down list select 
				[<span class="citation">BlinkyTop</span>]. Do the same clicks for the timing service. Name it 
				[<span class="citation">timingService</span>] and from the drop down list select 
				[<span class="citation">room.basic.service.timing.ATimingService</span>]. Draw a 
				[<span class="citation">LayerConnection</span>] from 
				[<span class="citation">application</span>] to each service provision point (SPP) of the 
				[<span class="citation">timingService</span>]. The resulting structure should look like this:
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky06.PNG"></div>
<p> 
			
</p>
<p>The current version of eTrice does not provide a graphical element for a service access point (SAP). Therefore the SAPs to access the timing service must be added in the .room file. Open the 
				[<span class="citation">Blinky.room</span>] file and navigate to the 
				[<span class="citation">Blinky</span>] actor. Add the following line to the structure of the actor:
			</p>
<div class="literallayout">
<p>
<code class="code">SAP&nbsp;timer:&nbsp;room.basic.service.timing.PTimeout<br>

</code>
</p>
</div>
<p>Do the same thing for 
				[<span class="citation">BlinkyController</span>].
			</p>
<p>The resulting code should look like this:</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky07.PNG"></div>
<p>
			
</p>
</div>
<div class="section" title="Finish the model structure">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Finishthemodelstructure"></a>Finish the model structure</h2>
</div>
</div>
</div>
<p>From the outline view right click to 
				[<span class="citation">Blinky</span>] and select 
				[<span class="citation">Edit Structure</span>]. Drag and Drop an 
				[<span class="citation">Interface Port</span>] to the boarder of the 
				[<span class="citation">Blinky</span>] actor. Note that an interface port is not possible inside the the actor. Name the port 
				[<span class="citation">ControlPort</span>] and select 
				[<span class="citation">BlinkyControlProtocol</span>] from the drop down list. Uncheck 
				[<span class="citation">Conjugated</span>] and 
				[<span class="citation">Is Relay Port</span>]. Klick 
				[<span class="citation">ok</span>]. The resulting structure should look like this:
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky04.PNG"></div>
<p>
			
</p>
<p>Repeat the above steps for the 
				[<span class="citation">BlinkyController</span>]. Make the port 
				[<span class="citation">Conjugated</span>]
			</p>
<p>Keep in mind that the protocol defines 
				[<span class="citation">start</span>] and 
				[<span class="citation">stop</span>] as incoming messages. 
				[<span class="citation">Blinky</span>] receives this messages and therefore 
				[<span class="citation">Blinky</span>]'s 
				[<span class="citation">ControlPort</span>] must be a base port and 
				[<span class="citation">BlinkyController</span>]'s 
				[<span class="citation">ControlPort</span>] must be a conjugated port.
			</p>
<p>From the outline view right click 
				[<span class="citation">BlinkyTop</span>] and select 
				[<span class="citation">Edit Structure</span>].
			</p>
<p>Drag and Drop an 
				[<span class="citation">ActorRef</span>] inside the 
				[<span class="citation">BlinkyTop</span>] actor. Name it 
				[<span class="citation">blinky</span>]. From the actor class drop down list select 
				[<span class="citation">Blinky</span>]. Do the same for 
				[<span class="citation">controller</span>]. Connect the ports via the binding tool. The resulting structure should look like this:
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky05.PNG"></div>
<p>
			
</p>
</div>
<div class="section" title="Implement the Behavior">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="ImplementtheBehavior"></a>Implement the Behavior</h2>
</div>
</div>
</div>
<p>The application should switch on and off the LED for 5 seconds in a 1 second interval, than stop blinking for 5 seconds and start again. To implement this behavior we will implement two FSMs. One for the 1 second interval and one for the 5 second interval. The 1 second blinking should be implemented in 
				[<span class="citation">Blinky</span>]. The 5 second interval should be implemented in 
				[<span class="citation">BlinkyController</span>]. First implement the Controller.
			</p>
<p>Right click to 
				[<span class="citation">BlinkyController</span>] and select 
				[<span class="citation">Edit Behavior</span>].
				Drag and Drop the 
				[<span class="citation">Initial Point</span>] and two 
				[<span class="citation">States</span>] into the top state. Name the states 
				[<span class="citation">on</span>] and 
				[<span class="citation">off</span>]. 
				Use the 
				[<span class="citation">Transition</span>] tool to draw transitions from 
				[<span class="citation">init</span>] to 
				[<span class="citation">off</span>] from 
				[<span class="citation">on</span>] to 
				[<span class="citation">off</span>] and from 
				[<span class="citation">off</span>] to 
				[<span class="citation">on</span>].
			</p>
<p>Open the transition dialog by double click the arrow to specify the trigger event and the action code of each transition. Note that the initial transition does not have a trigger event.</p>
<p>The dialog should look like this:</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky09.PNG"></div>
<p> 
			
</p>
<p>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 
				[<span class="citation">port.message(p1,p2);</span>]. In this example 
				[<span class="citation">ControlPort.start()</span>] sends the 
				[<span class="citation">start</span>] message via the 
				[<span class="citation">ControlPort</span>] to the outside world. Assuming that 
				[<span class="citation">Blinky</span>] is connected to this port, the message will start the one second blinking FSM. It is the same thing with the 
				[<span class="citation">timer</span>]. The SAP is also a port and follows the same rules. So it is clear that 
				[<span class="citation">timer.Start(5000);</span>] will send the 
				[<span class="citation">Start</span>] message to the timing service. The timing service will send a 
				[<span class="citation">timeoutTick</span>] message back after 5000ms.
			</p>
<p>Within each transition the timer will be restarted and the appropriate message will be sent via the 
				[<span class="citation">ControlPort</span>]. 
			</p>
<p>The resulting state machine should look like this:</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky10.PNG"></div>
<p>
			
</p>
<p>Save the diagram and inspect the 
				[<span class="citation">Blinky.room</span>] file. The 
				[<span class="citation">BlinkyController</span>] should look like this:
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky11.PNG"></div>
<p> 
			
</p>
<p>Now we will implement 
				[<span class="citation">Blinky</span>]. Due to the fact that 
				[<span class="citation">Blinky</span>] interacts with the GUI class a view things must to be done in the model file.
			</p>
<p>Double click 
				[<span class="citation">Blinky</span>] in the outline view to navigate to 
				[<span class="citation">Blinky</span>] within the model file.
				Add the following code:
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky12.PNG"></div>
<p> 
			
</p>
<p>
				[<span class="citation">usercode1</span>] will be generated at the beginning of the file, outside the class definition. 
				[<span class="citation">usercode2</span>] will be generated within the class definition. The code imports the GUI class and instantiates the window class. Attributes for the carLights and pedLights will be declared to easily access the lights in the state machine.
				The Operation 
				[<span class="citation">destroyUser()</span>] is a predefined operation that will be called during shutdown of the application. Within this operation, cleanup of manual coded classes can be done.
			</p>
<p>Now design the FSM of 
				[<span class="citation">Blinky</span>]. Open the behavior diagram of 
				[<span class="citation">Blinky</span>] by right clicking the 
				[<span class="citation">Blinky</span>] actor in the outline view. Create two states named 
				[<span class="citation">blinking</span>] and 
				[<span class="citation">off</span>]. Right click to 
				[<span class="citation">blinking</span>] and create a subgraph.
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky13.PNG"></div>
<p>
			
</p>
<p>Create the following state machine. The trigger events between 
				[<span class="citation">on</span>] and 
				[<span class="citation">off</span>] are the 
				[<span class="citation">timeoutTick</span>] from the 
				[<span class="citation">timer</span>] port. 
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky14.PNG"></div>
<p>
			
</p>
<p>Create entry code for both states by right clicking the state and select 
				[<span class="citation">Edit State...</span>]
			</p>
<p>Entry code of 
				[<span class="citation">on</span>] is:
			</p>
<div class="literallayout">
<p>
<code class="code">timer.Start(1000);<br>
carLights.setState(TrafficLight3.YELLOW);&nbsp;<br>

</code>
</p>
</div>
<div class="blockquote">
<blockquote class="blockquote">
<p></p>
</blockquote>
</div>
<p>Entry code  of 
				[<span class="citation">off</span>] is:
			</p>
<div class="literallayout">
<p>
<code class="code">timer.Start(1000);<br>
carLights.setState(TrafficLight3.OFF);<br>

</code>
</p>
</div>
<div class="blockquote">
<blockquote class="blockquote">
<p></p>
</blockquote>
</div>
<p>Navigate to the Top level state by double clicking the 
				[<span class="citation">/blinking</span>] state. Create the following state machine:
			</p>
<p>
				
</p>
<div class="mediaobject">
<img src="images/020-Blinky15.PNG"></div>
<p>
			
</p>
<p>The trigger event from 
				[<span class="citation">off</span>] to 
				[<span class="citation">blinking</span>] is the 
				[<span class="citation">start</span>] event from the 
				[<span class="citation">ControlPort</span>].The trigger event from 
				[<span class="citation">blinking</span>] to 
				[<span class="citation">off</span>] is the 
				[<span class="citation">stop</span>] event from the 
				[<span class="citation">ControlPort</span>].
			</p>
<p>Action code of the init transition is:</p>
<div class="literallayout">
<p>
<code class="code">carLights&nbsp;=&nbsp;light.getCarLights();<br>
pedLights&nbsp;=&nbsp;light.getPedLights();<br>
carLights.setState(TrafficLight3.OFF);<br>
pedLights.setState(TrafficLight2.OFF);<br>

</code>
</p>
</div>
<div class="blockquote">
<blockquote class="blockquote">
<p></p>
</blockquote>
</div>
<p>Action code from 
				[<span class="citation">blinking</span>] to 
				[<span class="citation">off</span>] is:
			</p>
<div class="literallayout">
<p>
<code class="code">timer.Kill();<br>
carLights.setState(TrafficLight3.OFF);&nbsp;<br>

</code>
</p>
</div>
<div class="blockquote">
<blockquote class="blockquote">
<p></p>
</blockquote>
</div>
<p>The complete resulting model looks like this:</p>
<div class="literallayout">
<p>
<code class="code">RoomModel&nbsp;Blinky&nbsp;{<br>

<br>
	LogicalSystem&nbsp;System_Blinky&nbsp;{<br>
		SubSystemRef&nbsp;subsystem:&nbsp;SubSystem_Blinky<br>
	}<br>

<br>
	SubSystemClass&nbsp;SubSystem_Blinky&nbsp;{<br>
		ActorRef&nbsp;application:&nbsp;BlinkyTop<br>
		ActorRef&nbsp;timingService:&nbsp;room.basic.service.timing.ATimingService<br>
		LayerConnection&nbsp;ref&nbsp;application&nbsp;satisfied_by&nbsp;timingService.timer<br>
		LayerConnection&nbsp;ref&nbsp;application&nbsp;satisfied_by&nbsp;timingService.timeout<br>
	}<br>

<br>
	ActorClass&nbsp;BlinkyTop&nbsp;{<br>
		Structure&nbsp;{<br>
			ActorRef&nbsp;blinky:&nbsp;Blinky<br>
			ActorRef&nbsp;controller:&nbsp;BlinkyController<br>
			Binding&nbsp;blinky.ControlPort&nbsp;and&nbsp;controller.ControlPort<br>
		}<br>
		Behavior&nbsp;{&nbsp;}<br>
	}<br>

<br>
	ActorClass&nbsp;Blinky&nbsp;{<br>
		Interface&nbsp;{<br>
			Port&nbsp;ControlPort:&nbsp;BlinkyControlProtocoll<br>
		}<br>
		Structure&nbsp;{<br>
			usercode1{<br>
				"import&nbsp;de.protos.PedLightGUI.*;"<br>
			}<br>
			usercode2&nbsp;{<br>
				"private&nbsp;PedestrianLightWndNoTcp&nbsp;light&nbsp;=&nbsp;new&nbsp;PedestrianLightWndNoTcp();"<br>
				"private&nbsp;TrafficLight3&nbsp;carLights;"<br>
				"private&nbsp;TrafficLight2&nbsp;pedLights;"<br>
				
<br>
			}<br>
			external&nbsp;Port&nbsp;ControlPort<br>
			SAP&nbsp;timer:&nbsp;room.basic.service.timing.PTimeout<br>
		}<br>
		Behavior&nbsp;{<br>
			Operation&nbsp;destroyUser(){<br>
				"light.closeWindow();"<br>
			}<br>
			StateMachine&nbsp;{<br>
				Transition&nbsp;init:&nbsp;initial&nbsp;-&gt;&nbsp;off&nbsp;{<br>
					action&nbsp;{<br>
						"carLights&nbsp;=&nbsp;light.getCarLights();"<br>
						"pedLights&nbsp;=&nbsp;light.getPedLights();"<br>
						"carLights.setState(TrafficLight3.OFF);"<br>
						"pedLights.setState(TrafficLight2.OFF);"<br>
					}<br>
				}<br>
				Transition&nbsp;tr0:&nbsp;off&nbsp;-&gt;&nbsp;tp0&nbsp;of&nbsp;blinking&nbsp;{<br>
					triggers&nbsp;{<br>
						&lt;start:&nbsp;ControlPort&gt;<br>
					}<br>
				}<br>
				Transition&nbsp;tr1:&nbsp;blinking&nbsp;-&gt;&nbsp;off&nbsp;{<br>
					triggers&nbsp;{<br>
						&lt;stop:&nbsp;ControlPort&gt;<br>
					}<br>
					action&nbsp;{<br>
						"timer.Kill();"<br>
						"carLights.setState(TrafficLight3.OFF);"<br>
					}<br>
				}<br>
				State&nbsp;off<br>
				State&nbsp;blinking&nbsp;{<br>
					subgraph&nbsp;{<br>
						Transition&nbsp;tr0:&nbsp;my&nbsp;tp0&nbsp;-&gt;&nbsp;on<br>
						Transition&nbsp;tr1:&nbsp;on&nbsp;-&gt;&nbsp;off&nbsp;{<br>
							triggers&nbsp;{<br>
								&lt;timeoutTick:&nbsp;timer&gt;<br>
							}<br>
						}<br>
						Transition&nbsp;tr2:&nbsp;off&nbsp;-&gt;&nbsp;on&nbsp;{<br>
							triggers&nbsp;{<br>
								&lt;timeoutTick:&nbsp;timer&gt;<br>
							}<br>
						}<br>
						Transition&nbsp;init:&nbsp;initial&nbsp;-&gt;&nbsp;on&nbsp;{&nbsp;}<br>
						EntryPoint&nbsp;tp0<br>
						State&nbsp;on&nbsp;{<br>
							entry&nbsp;{<br>
								"timer.Start(1000);"<br>
								"carLights.setState(TrafficLight3.YELLOW);"<br>
							}<br>
						}<br>
						State&nbsp;off&nbsp;{<br>
							entry&nbsp;{<br>
								"timer.Start(1000);"<br>
								"carLights.setState(TrafficLight3.OFF);"<br>
							}<br>
						}<br>
					}<br>
				}<br>
			}<br>
		}<br>
	}<br>

<br>
	ActorClass&nbsp;BlinkyController&nbsp;{<br>
		Interface&nbsp;{<br>
			conjugated&nbsp;Port&nbsp;ControlPort:&nbsp;BlinkyControlProtocoll<br>
		}<br>
		Structure&nbsp;{<br>
			external&nbsp;Port&nbsp;ControlPort<br>
			SAP&nbsp;timer:&nbsp;room.basic.service.timing.PTimeout<br>
		}<br>
		Behavior&nbsp;{<br>
			StateMachine&nbsp;{<br>
				Transition&nbsp;init:&nbsp;initial&nbsp;-&gt;&nbsp;on&nbsp;{<br>
					action&nbsp;{<br>
						"timer.Start(5000);"<br>
						"ControlPort.start();"<br>
					}<br>
				}<br>
				Transition&nbsp;goOff:&nbsp;on&nbsp;-&gt;&nbsp;off&nbsp;{<br>
					triggers&nbsp;{<br>
						&lt;timeoutTick:&nbsp;timer&gt;<br>
					}<br>
					action&nbsp;{<br>
						"ControlPort.stop();"<br>
						"timer.Start(5000);"<br>
					}<br>
				}<br>
				Transition&nbsp;goOn:&nbsp;off&nbsp;-&gt;&nbsp;on&nbsp;{<br>
					triggers&nbsp;{<br>
						&lt;timeoutTick:&nbsp;timer|timeoutTick:&nbsp;timer&gt;<br>
					}<br>
					action&nbsp;{<br>
						"ControlPort.start();"<br>
						"timer.Start(5000);"<br>
					}<br>
				}<br>
				State&nbsp;on<br>
				State&nbsp;off<br>
			}<br>
		}<br>
	}<br>

<br>
	ProtocolClass&nbsp;BlinkyControlProtocoll&nbsp;{<br>
		incoming&nbsp;{<br>
			Message&nbsp;start()<br>
			Message&nbsp;stop()<br>
		}<br>
		outgoing&nbsp;{&nbsp;}<br>
	}<br>

<br>
}<br>

</code>
</p>
</div>
<div class="blockquote">
<blockquote class="blockquote">
<p></p>
</blockquote>
</div>
<p>The model is complete now. You can run and debug the model as described in getting started. Have fun.</p>
</div>
<div class="section" title="Summary">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Summary2"></a>Summary</h2>
</div>
</div>
</div>
<p>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.</p>
</div>
</div>
<div class="chapter" title="Chapter&nbsp;5.&nbsp;ROOM Concepts">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="ROOMConcepts"></a>Chapter&nbsp;5.&nbsp;ROOM Concepts</h2>
</div>
</div>
</div>
<div class="section" title="Main Concepts">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="MainConcepts"></a>Main Concepts</h2>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

Back to the top