Technical topic: OpenGEODE - Design pattern: How to emulate the SAVE symbol
Contents
Introduction
When modelling with SDL it is common to use the SAVE symbol. The SAVE symbol allows to postpone the reception of a message until a given state is reached.
In the above example (picture taken from http://www.sdl-forum.org/sdl88tutorial/) the signal C is "saved" while state is S. This means that it is ignored but not lost; It may be actually consumed in state T.
The SAVE symbol is not supported in OpenGEODE because it implies the management of a non-bounded queue to store the saved messages until a state accepts them. At code level this requires to use dynamic memory allocation, and this is usually forbidden in embedded systems.
Mimic the behaviour of the SAVE symbol
SDL offers possibilities to reproduce the behaviour of the SAVE symbol by letting the user specify and manage his own (bounded) queue. The release of the messages from the queue in the appropriate state can be done using a Continuous signal.
In the Opengeode/tests/regression/test-save folder an example shows how to save a signal.
You need to create a data type to store the number of parameters you want to save:
Here we want to be able to save up to 10 messages of type boolean using the type SeqOf.
System example
In this system we want to save the content of the message named "saved_signal" when we are in state "Wait" and we want to consume it in state Running.
We need very few things:
- declare the buffer of type SeqOf
- call the "SAVE" procedure upon (explicit) reception of the "saved_signal" message.
- use a continuous signal that tests the size of our buffer in the Running state and call the "GET" procedure
Procedure SAVE
We need to provide the content of the SAVE procedure for the Boolean type. It is simply appending the received parameter to the buffer (and checking for overflow).
Procedure GET
And the procedure Get puts into the Param variable the first value of the buffer ; then it removes it.