I am using Rhapsody 8.2.1 - and just learning some of the basics.
I have it compiling (with MSVC 2012), generating code and running. To begin with I had a class counter
with one attribute int m_count
with a constructor that print "hello" and a state chart with one state start
with a default transition going to it - the default transaction sets m_count = 3
. start::stateEntry()
action which does printf("start - stateEntry m_count = %d\r\n", m_count);
.
So, next I added a timer event going from state start --> start
every second. Which does m_count -= 1
So... as you might expect, when I run this I get:
start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
start - stateEntry m_count = -1
etc...
Now I when m_count == 0
I want to transition to a new state done
. So to achieve this I add a new state and join the two states with a state transition going from start --> done
. I name the state transition evTrigger
(as I saw in a tutorial) and press ctrl+enter. This has the effect of adding:
- A new event called
evTrigger
- A new triggered operation called
counter::evTrigger()
(a member of class counter).
When I open the transition the "Trigger" says evTrigger in Default
- so I guess it is referring to the event, not the triggered operation.
Now I try to use it, I add the following code into the entry action of state start
:
if (m_count <= 0)
{
GEN(evTrigger());
}
And in the entry of state done
I put the code: printf("stateEntry - Done!\r\n");
Ok, so this works - I get:
start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
stateEntry - done!
But I can't use the triggered operation that was made for me called evTrigger()
. Why not?
If I call evTrigger() instead of GEN(evTrigger()); it compiles but the event transition does not trigger (it keeps counting down below zero). Why?
I then make two new items to test events and triggered operation separately, and I use each in a new transition from start
to done
so there are 3 transition with different triggers:
- new event evTriggerEvent
- new triggered operation trTriggerOperation
So the state diagram looks like:
*
| /m_count = 3;
|
| +---------+ evTrigger +---------+
+-----> | start |---------------------------->| done |
|---------| |---------|
| | | |
| | trTriggerOperation | |
| |---------------------------->| |
| | | |
| | | |
| | evTriggerEvent | |
| |---------------------------->| |
+---------+ +---------+
| ^
| | tm(1000)/m_count -=1;
+-----+
And the start entry action looks like this:
if (m_count <= 0)
{
//GEN(evTrigger()); <----- works
//trTriggerOperation(); <----- appears to do nothing
//GEN(evTriggerEvent()); <----- works
}
I then un-comment one at a time (ensuring the other two are commented out) and test them, I get the following results (results also commented above):
GEN(evTrigger()) - Works:
start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
stateEntry - done!
trTriggerOperation() - Does not trigger the transaction...
start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
start - stateEntry m_count = -1
start - stateEntry m_count = -2
etc...
GEN(evTriggerEvent()) - Works:
start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
stateEntry - done!
So my questions are:
- Why does ctrl+enter generation both an event and a triggered operation - when simply and event would do the same job?
- What is the purpose of the triggered action (it does not do what intuitively it should)?
- What is the correct way to use a triggered action (if I am doing it wrong)?
Update
I just noticed - I can create an event on its own. But when I use the event in a transition trigger a triggered operation is automatically created in the class operations... I can't delete it because it is being used - now I am even more confused :(
The main issue is that the documentation/examples on Rhapsody is very poor... most forums are tumbleweeds, so this brings up a further question: is this a dead / dying product or what?!