Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level Modified.

Similar presentations


Presentation on theme: "The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level Modified."— Presentation transcript:

1 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level Modified

2 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-2 Section 4: Advanced Event Parameters Event Hierarchy Strings Concurrency Mutexes Useful tips

3 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-3 Section 4 Advanced Level Event Parameters

4 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-4 Event Parameters Events ( and Triggered Operations ) can be passed parameters Rhapsody provides a pointer called params to access these parameters. For instance if an event evGo has a parameter n then n can be accessed using params->n

5 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-5 Project Parameters Create a new project “Parameters” and in an OMD, draw a simple class Motor with statechart as shown: Note that GEN(evGo) broadcasts the event evGo to itself.!

6 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-6 Adding a Parameter Add an argument n of type int to the event evGo. Add an attribute cycles of type int. Create a constructor to initialize cycles to 0.

7 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-7 Exercise Check that execution is as expected. Why does the output increment by 2 ?

8 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-8 Section 4 Advanced Level Event Hierarchy

9 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-9 Event Hierarchy It is possible for events to inherit from other events. In this example, evCommsError, evDivZeroError and evOutOfMemError all inherit from evError.

10 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-10 Client Generating Events The client sends one of each events to the server

11 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-11 Server Handling Events Note how each event is handled.

12 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-12 Section 4 Advanced Level Strings

13 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-13 OMString Class Rhapsody provides a string class that we have already used. This class allows operations such as: stringA = stringB stringA += stringB; length = string.GetLength(); character = string[5]; Note that the GetLength operation starts with a capital ‘G’ which is contrary to the normal style !

14 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-14 OMString Class This class reserves memory off the heap in blocks of 256 bytes and will add extra memory if needed during an operation such as stringA += stringB. The operation setDefaultBlock(n) allows the block size to be changed.

15 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-15 Section 4 Advanced Level Concurrency

16 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-16 Code Generation Per Package Generated code for each package can be directed into separate directories:

17 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-17 Concurrency We want each Sensor to run on its own thread (active class). To do so, we need each Sensor to be Reactive (class that waits for events). So we will create a Statechart for the base Sensor class as follows:

18 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-18 Active Classes With the browser, change the concurrency of the Sensor class from sequential to active.

19 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-19 Setting Priority, Stack Size,... For an active class, the stack size, priority, name, etc can be set through the following properties:

20 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-20 Section 4 Advanced Mutexes

21 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-21 Mutexes Rhapsody provides OMProtected which is a mutex (or binary semaphore) for protecting consecutive access to devices. OMProtected can be used as follows: –attribute OMProtected myMutex; –free myMutex.free(); –lock myMutex.lock();

22 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-22 Section 4 Advanced Level Useful Tips

23 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-23 Useful Tips I 4Keep statecharts simple, if they are too complex then divide the object into several smaller ones or use sub-statecharts. 4Draw states as small as possible and as close as possible to other states. This helps greatly during animating, since they are more readable, especially when there are several diagrams open at the same time. 4Don’t call many actions on a statechart, it makes the diagram very difficult to read. Instead call a new operation that calls the actions.

24 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-24 Useful Tips II 4Since there is no UNDO (coming very soon), make sure that you do periodic saves. 4Before modifying a complicated statechart, or diagram, make a copy, by selecting the class or diagram in the browser, holding the control key and moving to somewhere else. 4Don’t give the same name to several different elements of the model ex: package and class. The generated files will overwrite each other.

25 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-25 Useful Tips III 4Don’t put everything onto a single diagram, this can make reading the diagram difficult. Using a couple of diagrams, depicting different views can really help in understanding the model. 4When working with large projects, it is essential to divide up the model into domains. The interfaces between these domains should be defined. Then work can be carried out simultaneously and independently by different teams on each domain.

26 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-26 Useful Tips IV 4Use an iterative approach similar to that taken during this training, constantly model / save / generate / make / run. Don’t wait until the model is too large before animating. 4Make use of the Framework Base classes ( OMReactive, OMEvent, … ) to help de-couple classes. 4Beware of using names such as res, id, execute, start, suspend, resume, event, since OMThread & OMReactive use these operations. This can lead to problems that are very hard to track down.

27 The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-27 Useful Naming Conventions 4Start Event names with ev –ex: evStart 4Start Triggered operation with op –ex: opPress 4Start Condition operations with is –ex: isPressed() 4Start Interface classes with a I –ex: IHardware These conventions help when reading diagrams.


Download ppt "The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level Modified."

Similar presentations


Ads by Google