Lab 1: FSMs
- Due 5 Apr 2022 by 15:00
- Points 1
This assignment requires you to design and simulate an FSM model using PtolemyII's Virgil. For a detailed description of how FSM modeling works in PtolemyII please consult the Using PtolemyII book Download Using PtolemyII book, Chapter 6.
Task
Design and simulate an FSM able to parse the network packages formed according to the description below. The packages arrive as sequences of values to a unique input and your FSM has to identify the contents and output other values as requested by the packages. The FSM should also keep track of a "routing table" storing information received via packages as described below. You should handle the following sequences:
- 0, D - is a request for the routing table contents at index D
- 1, 0, D - update the routing table at index 0 with data D
- 1, 1, 0, D - update the routing table at index 1 with data D
- 1, 1, 1, D - update the routing table at index 2 with data D
The routing table should be initialized with -1 on all positions. Note that D may be any integer in most cases.
As an example, your FSM should be able to process the following sequence:
1, 1, 0, 5, 1, 0, 3, 0, 1, 1, 0, 4, 0, 2, 0, 0
by identifying cases III, II, I, II, I, I and producing outputs 5, -1, 4
You may use, for instance, a Sequence actor (Actor/Sources/SequenceSources) to generate inputs and a Display (Actor/Sinks/GenericSinks) to show the outputs.
Extend the sequence to cover the last case, and other combinations capturing all the transitions in your FSM.
Estimated required time, including (fast) reading about FSM modeling: 4h
Hints:
- to check for the presence of an input S in your guards, use S_isPresent, see page 196.
- if you are using the SDF Director to run your FSM as a ModalModel, make sure you give it enough iterations in the parameters to produce all the numbers in your sequence.
- have a look at arrays in PtolemyII Download PtolemyII book, section 13.3.1, especially update function on page 465. You can use these internally to store your routing table.