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?
This topic has been locked.
3 replies Latest Post - 2013-02-14T11:10:08Z by shanz9903
Pinned topic Code for default: in a statechart
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2013-02-14T11:10:08Z at 2013-02-14T11:10:08Z by shanz9903
Yevo 270002F6T8278 PostsACCEPTED ANSWER
Re: Code for default: in a statechart2013-02-12T11:43:11Z in response to SystemAdminYou 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 110000D4XK1305 PostsACCEPTED ANSWER
Re: Code for default: in a statechart2013-02-13T08:42:38Z in response to Yevohi
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 270003S6R4268 PostsACCEPTED ANSWER
Re: Code for default: in a statechart2013-02-14T11:10:08Z in response to SystemAdminYou 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.