Download presentation
Presentation is loading. Please wait.
1
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-1 Exercise 3 : Dishwasher
2
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-2 Exercise 3 : Dishwasher
3
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-3 Dishwasher Create a new project “Dishwasher”, make sure that it is created in its own folder. Draw a single class Dishwasher
4
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-4 Attributes Add the following attributes all of which are of type int and with initial value of 0
5
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-5 Operations Add the following operations, with appropriate return types and implementations:
6
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-6 Types In the implementation for the operation isInNeedOfService() we used a constant called MAX_CYCLES. Select the Default package, right-click and select “Add New -> Type” Enter MAX_CYCLES as name and declaration: const int %s = 3; %s is a shortcut for the name of the type
7
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-7 Creating a Component As in the previous exercise, rename the DefaultComponent to Test and the DefaultConfig to Debug Select “Animation” and create an initial instance of Dishwasher
8
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-8 Save / Generate / Make Before adding a statechart, let’s make sure that we haven’t made any errors by doing a build. Save Generate / Make
9
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-9 Creating a Statechart Add a Statechart to the Dishwasher class We are going to be drawing a complex diagram, it is highly recommended to maximise the Statechart window and close all other windows. Draw a single state as large as possible called active
10
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-10 Creating Concurrent States Use the and-line icon to create concurrent states To draw the AND line, either: click and drag the line or click to start the line then double-click to end it Draw this line first This box with “active”inside will appear when the and-lines are drawn Note the only way to move an AND-line, is to delete it and redraw it. Concurrent States
11
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-11 Naming the Concurrent States Name the concurrent states using the icon to running, service and mode.
12
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-12 Adding Nested States Add the following states: To change the size of an outer state, without the inner states changing, hold down the “Alt” key when changing the size
13
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-13 Adding History and Diagram Connectors Add a History connector to the on state Add two identical Diagram connectors named DONE
14
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-14 Adding Default Transitions Add the following four default transitions
15
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-15 Adding the Transitions Add the following transitions and actions
16
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-16 Action on Entry Finally in the normal state, add an “Action on entry” to set cycles=0; Once an action has been set, the symbol “>” is shown.
17
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-17 Start Behavior צור/י configuration הנקראת trace עם Instrumentation מסוג Tracer. מה מתבצע ב- Start Behavior? מכאן ולהבא תשתמש/' ב configuration הנקראת debug
18
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-18 Save / Generate / Make / Run Save / Generate / Make / Run Do “Go step” to create a Dishwasher instance הסביר/י את ההודעות ב Call Stack. לחצ/י על “Go Step” כמה פעמים עד ש “Executable Idle” מופיע ב- “Output Window”. הסביר/י את ההודעות ב Call Stack If there is no instance created, then it is probable that an initial instance of Dishwasher was not selected in the configuration.
19
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-19 Animated Statechart Check that there are three concurrent animated states 1 2 3
20
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-20 Injecting Events The Dishwasher is in an idle state waiting for some events Generate the event evStart by right-clicking anywhere on the animated statechart and selecting “Generate Event” The event evStart should appear in the event queue Events can also be generated via the Command prompt or via the Event Generator
21
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-21 Design Level Debugging Do “Go” and watch the animation Does your Dishwasher work as expected? What happens if you open the door when it’s on, does it remember what state it was in? Why does the Dishwasher become faulty after four cycles? Can you get the Dishwasher back to the normal state? עד כאן תרגיל 3!
22
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-22 Intense / Quick Modify the setup operation so that the timings are different in the quick and intense modes. Save / Generate / Make / Run It should now be quicker to get the Dishwasher into the “faulty” state. IS_IN is a macro that tests to see if the object is in a particular state.
23
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-23 Extended Exercise Using the IS_IN macro and a guard, prevent the Dishwasher from being started if it is faulty.
24
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-24 Breakpoints Setting breakpoints can be done in a similar way to injecting events by right-clicking on a state in the animated statechart Breakpoints can be added/removed via the breakpoint icon on the animation toolbar.
25
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-25 Using the Simulated Time Model השכלה כללית בלבד At the moment, we are using the System tick for all our timeouts and so a timeout of 1000ms takes 1000ms, which means that all simulations can be long. There is an alternative time model that we can use that is the “Simulated” time model. When we use this, all the timeouts are executed in the appropriate order, but rather than waiting, the shortest timeout immediately times out. This means that we can test models such as this one much quicker. Make a copy of the Debug configuration, rename it to Sim and set the “Time Model” to Simulated
26
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-26 The Command Prompt Events and breakpoints can also be generated through the command prompt For example, we could inject the evStart by typing “Dishwasher->GEN(evStart)” in the command window More useful perhaps is that we can use the command window to invoke scripts GEN is a macro that will create the event before sending it to the object. GEN(evStart) ≈ gen( new evStart )
27
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-27 Creating a Test Script One way of testing our Dishwasher is by running a script We can create this script inside Rhapsody in the following way: In the Test Component, select “Add New File” Name the file TestScript.cfg
28
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-28 TestScript.cfg Set the Path to “..\..” Set the File Type to “Other” The script we’re about to create, will be contained inside the model and will now be generated every time that code is generated
29
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-29 Script Contents Select “Add text”, enter “script contents” as the name And then press to start the text editor
30
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-30 The Script Enter the following: Don’t leave any blank lines or any leading spaces! This script logs everything that happens including timing information to a file called TestScript.log For more information on the scripting language, search for example “timestamp” in the user reference manual
31
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-31 Running the Script Save / Generate / Make / Run Use the command prompt to run the script Once the script has run and terminated, stop the animation The script should have created a file called TestScript.log, we can edit this file from within Rhapsody by adding another file called TestScript.log of type Other and Path..\.. If the script is called “OMAnimator.cfg” then on starting the animation, the script will be automatically run. This script must be located in the project directory.
32
www.ilogix.com © I-Logix 1999-2004 Rhapsody C++ V5.0.1 17/01/2004 E1-32 Reading TestScript.log Select the TestScript.log file in the browser, right-click and select “Edit File” Elapsed Time
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.