Table of Contents Previous Chapter 4 Tutorial: An SDL-92 Example
Version 3 will add a clock function and add / redefine properties.
The OOA analysis indicates that a new class Clock is needed. This class will keep track of the current time and spontaneously, each minute, send the current time to the display. Furthermore the system must be updated so that it will be possible to set and adjust the clock from the panel.
The time will be displayed in the format "HH:MM", and the time can be set from the panel by first entering "#" followed by the time in the format "HHMM".
From the SDL-92 point of view this means that we should make a specialization of the system by adding the new process type Clock and adding a new signal DisplayTime.
Making a specialization in SDL-92 means inherit the properties from a supertype and then adding new properties. The simplest way to accomplish this in our AccessControl system is to make a system type of the basic system and store this type in a package (the SDL term for a library). The system TimeAccessControl can now inherit all the properties from the basic system and add the Clock type.
The OOA analysis showed that the new class Clock is most related to the class LocalPanel, for that reason we will put the type definition inside the block type Controller. For this version, for reasons of clarity, we will also move all the process type definitions to the block types were they are used.
We will use the SDL-92 concept VIRTUAL and declare the block type LocalPanel as a VIRTUAL type.
A VIRTUAL type may be REDEFINED which means that we can add new properties (add signals, data types, processes etc.) without creating a new type (this is one major difference between the specialization and virtual concepts, a specialization will always result in a new type).
A virtual type can contain other VIRTUAL types, that can be redefined in a redefinition of the outer type.
To sum up the actions, this is what we have to do to add the Clock function:
- Create a package diagram.
- Make a system type of the existing system diagram and store it in the package diagram.
- Move the process types to the block types where they are used.
- Declare the block type LocalPanel as VIRTUAL.
- Declare the process type Controller as VIRTUAL.
- Declare the process type Display as VIRTUAL.
- Make a system type of the specialized AccessControlOOA where the virtual block type LocalPanel is declared as redefined and a new signal DisplayTime is introduced.
- Store the specialized system in the package.
- Redefine block type LocalPanel by adding process Clock and declaring the process types Controller and Display as REDEFINED.
- Redefine process type Display by handling the new signal DisplayTime.
- Redefine process type Controller by handling the new signal DisplayTime and reading the new key sequence for setting the time.
- Create a new procedure ReadTime to read the key sequence for setting the time.
- Define new operators to convert an SDL time variable to a charstring and a charstring to an SDL time. We need these operators because the Clock function is implemented with an SDL timer. When the timer expires, the variable CurrentTime is updated with the TimeOut time. CurrentTime must be converted to a charstring before it can be displayed. Input from the keypad is always interpreted as characters and the variable TimeString must be converted to an SDL time before CurrentTime can be assigned its new value.
To be able to instantiate a system type it must be placed in a library (package diagram). The instance uses a USE clause to make a type from a package visible, see Figure 184.
Figure\x11 184 : Using a Package.
-----
(fig)
-----
- You can create a Package diagram from the Organizer with the command New from the File menu, see Figure 185.
Figure\x11 185 : Creating a Package.
-----
(fig)
-----
- Open the package diagram by double-clicking on it. In the next section, when you convert a system diagram to a system type diagram, you can directly insert the type diagram in the package diagram.
- Save the system file for the package and open the system file AccessControlOOAVer3.sdt
- Again, set the Source Directory, save, close and open the system file.
- Double-click on the system diagram in the Organizer. Change the declaration in the diagram heading to system type BaseAccessControl, see Figure 186.
Figure\x11 186 : Having Converted to a System Type.
-----
(fig)
-----
You must save the diagram in a new file with extension .sst (system type). The best way is to use the command: Save As from the SDL Editor's File menu.
Open your system file for the package SystemTypes and create the package diagram. Place a System Type symbol and name it BaseAccessControl, see Figure 187.
Figure\x11 187 : System Type Symbol.
-----
(fig)
-----
Now we must connect the symbol and expand the structure. The best way to do this is to use a search list when we connect and expand the diagram.
- First we must create a search list. Open the Search List Manager from the Tools menu and create a new search list, see Figure 188.
Figure\x11 188 : The Search List Manager.
-----
(fig)
-----
- Save the search list on file as sdt.ssl in the VERSION3 directory.
- Connect the diagram from the Organizer and specify the search list in the dialog, see Figure 189.
Figure\x11 189 : Expanding Diagrams Using a Search List
-----
(fig)
-----
- Open the page InteractionPage in the system type.
- Remove the process type symbols on this page.
- Open the block type LocalPanel and place the four process types Controller, CardReader, Display and KeyPad here instead.
When you are ready, your block type LocalPanel should look like Figure 190.
Figure\x11 190 : The Resulting Block Type.
-----
(fig)
-----
Now do the same for the rest of the process types, i.e.
- Put Door and DoorLock inside the block type Doors.
- Put RegisteredCard inside block type RegisteredCard.
- Connect the symbols to their files by connecting them from the Organizer. See the following table for the names of the existing files.
------------------------------------
Process Type File Name
------------------------------------
Controller controller.spt
CardReader cardreader.spt
Display display.spt
KeyPad keypad.spt
Door door.spt
DoorLock doorlock.spt
RegisteredCard registeredcardcp.spt
------------------------------------
Next step is to declare the block type LocalPanel as a VIRTUAL block type.
- The best way to do this is to put the keyword VIRTUAL immediately preceding the name in the reference symbol, see Figure 191.
Figure\x11 191 : Changing a Reference Symbol to VIRTUAL.
-----
(fig)
-----
- The diagram heading must also be updated with the keyword VIRTUAL and a qualifier. The qualifier specifies where in the system structure this diagram is defined, see Figure 192.
Figure\x11 192 : Virtual Diagram Heading With Qualifier.
-----
(fig)
-----
The two process types: Controller and Display should also be declared as VIRTUAL.
- You do this in the same way as you did for the block type, i.e. put in the keyword VIRTUAL in front of the name in the reference symbols and in the heading.
- Don't forget do add the qualifiers in the headings in the same way as for the block type.
The system type is now prepared for specializations, the system diagram is converted to a system type and the blocks and process types, involved in the forthcoming specialization, are declared as VIRTUAL.
A specialization will only show added and/or changed properties of the supertype.
- In our case the block type LocalPanel is REDEFINED. A new signal DisplayTime is introduced and sent on a new channel LpEnvOut2 from the existing block Lp (an instance of LocalPanel). A dashed symbol in a specialization always represents an existing object from the supertype, see Figure 193.
Figure\x11 193 : The System Type TimeAccessControl.
-----
(fig)
-----
It is best to create a new package and define the new system type TimeAccessControl there. This is mainly because of the way SDT handles the package concept.
---------------------------------------------------------------------
Note:
Whenever you refer to a package with a USE clause, everything in
that package will be analyzed and generated code for even if you are
only using one diagram from the package. This can cause consider
able overhead. To avoid this use several packages. A package can
make USE on other packages.
---------------------------------------------------------------------
- Create and open a new package SystemTypeWithTime. This package should make USE of the first package: SystemTypes. See Figure 194.
Figure\x11 194 : Package SystemTypeWithTime.
-----
(fig)
-----
- You should now create a new system type diagram named TimeAccessControl. Edit the diagram according to Figure 193.
----------------------------------------------------------------
Hint:
A dashed symbol (the block Instance symbol and the gate symbol)
is accomplished by selecting the symbol and invoking the Dash
command from the Edit menu (this command toggles between Dash
and Undash).
----------------------------------------------------------------
- Double-click on the REDEFINED block type (LocalPanel). A new diagram will be created and you should now edit it according to Figure 195.
Figure\x11 195 : Redefined Block Type LocalPanel.
-----
(fig)
-----
- As you can see the two process types Display and Controller are declared REDEFINED and a new process Clock is introduced. The process Clock is not defined as a process type, instead as an "ordinary" process definition (it is always permitted to use SDL-88 constructs together with SDL-92 concepts, because new concepts are always defined as "pure" additions to the language).
-----------------------------------------------------------------------
Note:
New signals between existing objects (blocks or processes) must be
sent on new channels and signal routes. Another rule states that it is
allowed to add new signals to existing gates. These rules are applied
to our example (e.g. the new signal route ClDl2 carries the new sig
nal DisplayTime and is connected to the existing gates E and A).
-----------------------------------------------------------------------
- Save the new redefined block type before you continue. Use the Save As command and give the file the name localpanel.sbt
Redefining the process type Display is very simple. One new transition and one new variable are needed, see Figure 196.
Figure\x11 196 : Redefined Process Type Display.
-----
(fig)
-----
- Double-click on the REDEFINED process type (Display) and edit it according to Figure 196.
- Save the diagram in the same way as you did with the redefined block type diagram.
For the redefined process type Controller we need first of all a new transition to every state, that will receive signal DisplayTime and send it on to the process Display (via gate E). Secondly we need a new transition, in state Idle, to receive the signal ReadCode. In state Idle this signal will start the activity of setting the time, see Figure 197.
Figure\x11 197 : Process Type Controller.
-----
(fig)
-----
- Double-click on the REDEFINED process type Controller and edit it according to Figure 197.
- After you have edit the diagram, save in the usual way.
The procedure ReadCode reads four character, typed from the keypad and stores them in an array. Reading a new time when setting time will also read four characters, but it is more convenient to store them in a charstring. For that reason we need two different procedures.
This procedure is already present in the tutorial directory. The filename is readtime.spd.
The procedure Clock is also provided, the filename is clock.spr. See Figure 198.
Figure\x11 198 : The Process Clock, Page 2.
-----
(fig)
-----
So far we have created two system types and placed them in two different packages. What we have left to do is to create a system instance that will be an instance of the TimeAccessControl type.
- Create a new system file with a new system diagram as root. Name the diagram TimeAccessControl.
- Edit the system diagram according to Figure 199.
Figure\x11 199 : System Instance.
-----
(fig)
-----
---------------------------
Note:
This is the entire diagram!
---------------------------
- Save the diagram and exit the editor.
- To expand all diagram references (from the referenced packages) use the Import Diagrams command in the Organizer. You can select No Save in the dialog that follows, see Figure 200.
Figure\x11 200 : Save Before Import Dialog.
-----
(fig)
-----
- In the next dialog you should specify your system diagram and expand from source directory; see Figure 201.
Figure\x11 201 : Expand From Source Directory.
-----
(fig)
-----
If you have followed the instructions, the entire system should now be expanded. You should see three sections in the Organizer:
Before we analyze and simulate, let us have a look at the Type Viewer.
- First you must generate a Type Viewer diagram. You will find the command under the Tools menu in the Organizer.
- After a few seconds two windows will pop up: the Type Viewer and the Type Trees.
- It is in the Type Trees viewer you can see how new (or redefined) types are related to existing types and where they are instantiated in the structure; see Figure 203.
Figure\x11 203 : The Type Tree.
-----
(fig)
-----
You can now analyze and simulate your system in the same way as you did for the two first versions.
Table of Contents Next Chapter