Topic
  • 3 replies
  • Latest Post - ‏2013-02-14T11:10:08Z by shanz9903
SystemAdmin
SystemAdmin
1305 Posts

Pinned topic Code for default: in a statechart

‏2013-02-11T16:33:20Z |
Hello

I am using Rhapsody in C 7.6.1

When I generate code for a statechart, i see that the statechart is implemented using switch case. This is absolutely fine.

At the end of switch case, there is a "default:" case, for which no code is generated.

Where should i mention the code in statechart so that it is generated in the "default:" case of the generated code?
Updated on 2013-02-14T11:10:08Z at 2013-02-14T11:10:08Z by shanz9903
  • Yevo
    Yevo
    280 Posts

    Re: Code for default: in a statechart

    ‏2013-02-12T11:43:11Z  
    You should not. The default case is used to meet coding standards like MISRA. Also, if ,e.g., statechart receives an event, which it doesn't process, then the defaut case is used to ignore it. Probably, more situations are possible, when Default (empty) case is needed.
  • SystemAdmin
    SystemAdmin
    1305 Posts

    Re: Code for default: in a statechart

    ‏2013-02-13T08:42:38Z  
    • Yevo
    • ‏2013-02-12T11:43:11Z
    You should not. The default case is used to meet coding standards like MISRA. Also, if ,e.g., statechart receives an event, which it doesn't process, then the defaut case is used to ignore it. Probably, more situations are possible, when Default (empty) case is needed.
    hi

    ok but consider this scenario.

    Say I have a statechart with say 5 states named state_1, state_2, ... ,state_5.

    Depending on a certain input i go to one of these states. Now if I get an invalid input, then I want my system to go to say state_2.

    This can only be done by default: case right? How else can i do it? So i need to generate code for default:
  • shanz9903
    shanz9903
    274 Posts

    Re: Code for default: in a statechart

    ‏2013-02-14T11:10:08Z  
    hi

    ok but consider this scenario.

    Say I have a statechart with say 5 states named state_1, state_2, ... ,state_5.

    Depending on a certain input i go to one of these states. Now if I get an invalid input, then I want my system to go to say state_2.

    This can only be done by default: case right? How else can i do it? So i need to generate code for default:
    You could have a superstate (sixth state) that encompasses all the other 5 states.
    Then the event can trigger a transition into state_2 from the superstate - ie: irrespective of the status in the inner states.