Book a Demo

Author Topic: Generating Code from StateMachine diagrams  (Read 3523 times)

Blueprint

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Generating Code from StateMachine diagrams
« on: May 17, 2011, 02:49:52 am »
I have a state Machine with concurrent states.



State3:



I generated the following code (.h) C++
Code: [Select]
///////////////////////////////////////////////////////////
//  RwKsz.h
//  Implementation of the Class BelsoClass
//  Created on:      16-máj.-2011 14:53:11
//  Original author:
///////////////////////////////////////////////////////////

#if !defined(EA_45DC22E9_D093_47ea_A247_DB648E053D23__INCLUDED_)
#define EA_45DC22E9_D093_47ea_A247_DB648E053D23__INCLUDED_

class BelsoClass
{

public:
      BelsoClass();
      virtual ~BelsoClass();
      BelsoClass(const BelsoClass& theBelsoClass);

      void Belsofunct1(int fuctnumero);
      void Belsofunct2();

private:
      int att1mod;
      int att2;

      /* Begin - EA generated code for StateMachine */


      enum StateType
      {
            SMBelsoClass_SBC1,
            SMBelsoClass_SBC1_ST2,
            SMBelsoClass_SBC1_ST1,
            SMBelsoClass_SBC2,
            ST_NOSTATE
      };
      enum TransitionType
      {
            TT_NOTRANSITION
      };
      enum CommandType
      {
            Do,
            Entry,
            Exit
      };
private:
      StateType currState;
      StateType nextState;
      TransitionType currTransition;
      bool transcend;
      StateType SMBelsoClass_history;
      StateType SMBelsoClass_SBC1_history;
      void sMBelsoClass_SBC1(CommandType command);
      void sMBelsoClass_SBC1_ST2(CommandType command);

      void sMBelsoClass_SBC1_ST1(CommandType command);

      void sMBelsoClass_SBC2(CommandType command);
      void StatesProc(StateType currState, CommandType command);
      void TransitionsProc(TransitionType transition);
      void initializeStateMachine();
      void runStateMachine();


      /* End - EA generated code for StateMachine */

};
#endif // !defined(EA_45DC22E9_D093_47ea_A247_DB648E053D23__INCLUDED_)

and .ccp C++
Code: [Select]
///////////////////////////////////////////////////////////
//  RwKsz.cpp
//  Implementation of the Class BelsoClass
//  Created on:      16-máj.-2011 14:53:13
//  Original author:
///////////////////////////////////////////////////////////

#include "RwKsz.h"


BelsoClass::BelsoClass(){

}



BelsoClass::~BelsoClass(){

}



BelsoClass::BelsoClass(const BelsoClass& theBelsoClass){

}





void BelsoClass::Belsofunct1(int fuctnumero){

}


void BelsoClass::Belsofunct2(){

}


/* Begin - EA generated code for StateMachine */



void BelsoClass::sMBelsoClass_SBC1(CommandType command)
{
      switch(command)
      {
            case Do:
            {
                  // Do Behaviors..
                  
                  // State's Transitions
                  nextState = SMBelsoClass_SBC2;
                  
                  break;
            }
            default:
            {
                  break;
            }
      }
}

void BelsoClass::sMBelsoClass_SBC1_ST2(CommandType command)
{
      switch(command)
      {
            case Do:
            {
                  // Do Behaviors..
                  
                  // State's Transitions
                  nextState = SMBelsoClass_SBC1_ST1;
                  
                  break;
            }
            default:
            {
                  break;
            }
      }
}

void BelsoClass::sMBelsoClass_SBC1_ST1(CommandType command)
{
      switch(command)
      {
            case Do:
            {
                  // Do Behaviors..
                  
                  // State's Transitions
                  nextState = SMBelsoClass_SBC1_ST2;
                  
                  break;
            }
            default:
            {
                  break;
            }
      }
}

void BelsoClass::sMBelsoClass_SBC2(CommandType command)
{
      switch(command)
      {
            case Do:
            {
                  // Do Behaviors..
                  
                  // State's Transitions
                  nextState = SMBelsoClass_SBC1_ST1;
                  transcend = true;
                  SMBelsoClass_history = currState;
                  
                  break;
            }
            default:
            {
                  break;
            }
      }
}
void BelsoClass::StatesProc(StateType currState, CommandType command)
{
      switch(currState)
      {
            case SMBelsoClass_SBC1:
            {
                  sMBelsoClass_SBC1(command);
                  break;
            }

            case SMBelsoClass_SBC1_ST2:
            {
                  sMBelsoClass_SBC1_ST2(command);
                  break;
            }

            case SMBelsoClass_SBC1_ST1:
            {
                  sMBelsoClass_SBC1_ST1(command);
                  break;
            }

            case SMBelsoClass_SBC2:
            {
                  sMBelsoClass_SBC2(command);
                  break;
            }
            default:
                  break;
      }
}
void BelsoClass::TransitionsProc(TransitionType transition)
{
}
void BelsoClass::initializeStateMachine()
{
      currState = SMBelsoClass_SBC1_ST1;
      nextState = ST_NOSTATE;
      currTransition = TT_NOTRANSITION;
}


void BelsoClass::runStateMachine()
{
      while(true)
      {
            if ( currState == ST_NOSTATE )
            {
                  break ;
            }
            
            currTransition = TT_NOTRANSITION;
            StatesProc(currState, Do);
            // and then check if there is any valid transition assigned after the do behavior
            if ( nextState == ST_NOSTATE)
            {
                  break;
            }
            
            if ( currTransition != TT_NOTRANSITION )
            {
                  TransitionsProc( currTransition );
            }
            if ( currState != nextState)
            {
                  StatesProc(currState, Exit);
                  StatesProc(nextState, Entry);
                  currState = nextState ;
            }
      }
}


/* End - EA generated code for StateMachine */



I seems, that it can not handle the concurrent states!!!

It also not capable of handling the entry to compound states.

The code is wrong and not usable!

Please advise!
« Last Edit: May 17, 2011, 02:57:21 am by blueprint »

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Generating Code from StateMachine diagrams
« Reply #1 on: May 19, 2011, 06:30:52 pm »
I never used the built in code generation from state machines, so I cannot really help you there.

Anyway, in my experience concurrent state regions are not being handled decently in EA. When I export a state machine model to XMI 2.1, there is not information as to which state belongs to which region. The only link between states and regions is contained within the positions of the state elelements in a diagram (i.e the regions are not treated as model elements). So the fact that EA ignores regions on code generation does not surprise me in the least.

Blueprint

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Generating Code from StateMachine diagrams
« Reply #2 on: May 21, 2011, 08:07:44 pm »
That is I was afraid of...

Thanks.

Daniel Siegl

  • EA User
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: Generating Code from StateMachine diagrams
« Reply #3 on: May 23, 2011, 11:40:53 pm »

Hello,
Our AMUSE handles this!
http://www.lieberlieber.com/unser-angebot/amuse.html

but we need substatemachines after the fork join.

Generally speaking I have the feeling that the behaviour code generation needs to be tailored to your needs to be usable for production code generation.

BR
Daniel
« Last Edit: May 23, 2011, 11:43:22 pm by daniels »