FW Profile - C1 Implementation
FwSmAux.c
Go to the documentation of this file.
1 
18 #include "FwSmAux.h"
19 #include "FwSmConfig.h"
20 #include "FwSmPrivate.h"
21 
22 /* ------------------------------------------------------------------------------- */
23 void FwSmPrintConfig(FwSmDesc_t smDesc, FILE* stream) {
24  char prefix[1] = "";
25  FwSmCounterS1_t actNOfPStates = 0;
26  FwSmCounterS1_t actNOfCStates = 0;
27  FwSmCounterS1_t actNOfTrans = 0;
28  FwSmCounterS1_t actNOfEsm = 0;
29  FwSmCounterS1_t actNOfActions = 0;
30  FwSmCounterS1_t actNOfGuards = 0;
31  FwSmCounterS1_t i, j, baseLoc;
32  SmTrans_t trans;
33 
34  if (smDesc == NULL) {
35  fprintf(stream, "%sThe argument state machine descriptor is NULL\n", prefix);
36  return;
37  }
38 
39  for (i = 0; i < smDesc->smBase->nOfPStates; i++) {
40  if (smDesc->smBase->pStates[i].outTransIndex != 0) {
41  actNOfPStates++;
42  }
43  }
44 
45  for (i = 0; i < smDesc->smBase->nOfCStates; i++) {
46  if (smDesc->smBase->cStates[i].outTransIndex != 0) {
47  actNOfCStates++;
48  }
49  }
50 
51  for (i = 0; i < smDesc->smBase->nOfTrans; i++) {
52  if (smDesc->smBase->trans[i].iTrAction != -1) {
53  actNOfTrans++;
54  }
55  }
56 
57  for (i = 0; i < smDesc->smBase->nOfPStates; i++) {
58  if (smDesc->esmDesc[i] != NULL) {
59  actNOfEsm++;
60  }
61  }
62 
63  for (i = 0; i < smDesc->nOfActions; i++) {
64  if (smDesc->smActions[i] != NULL) {
65  actNOfActions++;
66  }
67  }
68 
69  for (i = 0; i < smDesc->nOfGuards; i++) {
70  if (smDesc->smGuards[i] != NULL) {
71  actNOfGuards++;
72  }
73  }
74 
75  fprintf(stream, "\n");
76  fprintf(stream, "%sSTATE MACHINE SIZE\n", prefix);
77  fprintf(stream, "%s------------------\n", prefix);
78  fprintf(stream, "%sDeclared number of states : %d\n", prefix, smDesc->smBase->nOfPStates);
79  fprintf(stream, "%sDeclared number of choice pseudo-states: %d\n", prefix, smDesc->smBase->nOfCStates);
80  fprintf(stream, "%sDeclared number of transitions : %d\n", prefix, smDesc->smBase->nOfTrans);
81  fprintf(stream, "%sDeclared number of actions : %d\n", prefix, smDesc->nOfActions - 1);
82  fprintf(stream, "%sDeclared number of guards : %d\n", prefix, smDesc->nOfGuards - 1);
83  fprintf(stream, "\n");
84 
85  fprintf(stream, "%sSTATE MACHINE CONFIGURATION\n", prefix);
86  fprintf(stream, "%s---------------------------\n", prefix);
87  fprintf(stream, "%sThe error code is : %s\n", prefix, FwSmPrintErrCode(smDesc->errCode));
88  fprintf(stream, "%sThe SM Execution Counter is : %u\n", prefix, smDesc->smExecCnt);
89  fprintf(stream, "%sThe State Execution Counter is : %u\n", prefix, smDesc->stateExecCnt);
90  fprintf(stream, "%sThe outcome of the configuration check is: %s\n", prefix, FwSmPrintErrCode(FwSmCheck(smDesc)));
91  fprintf(stream, "%sNumber of configured states : %d\n", prefix, actNOfPStates);
92  fprintf(stream, "%sNumber of configured choice pseudo-states: %d\n", prefix, actNOfCStates);
93  fprintf(stream, "%sNumber of configured transitions : %d\n", prefix, actNOfTrans);
94  fprintf(stream, "%sNumber of configured actions : %d\n", prefix, actNOfActions - 1);
95  fprintf(stream, "%sNumber of configured guards : %d\n", prefix, actNOfGuards - 1);
96  fprintf(stream, "%sNumber of embedded state machines : %d\n", prefix, actNOfEsm);
97  if (FwSmIsStarted(smDesc) == 0) {
98  fprintf(stream, "%sCurrent state machine state is : STOPPED\n", prefix);
99  }
100  else {
101  fprintf(stream, "%sState machine is STARTED and is in state : %d\n", prefix, FwSmGetCurState(smDesc));
102  }
103  fprintf(stream, "\n");
104 
105  fprintf(stream, "%sCONFIGURATION OF INITIAL PSEUDO STATE\n", prefix);
106  fprintf(stream, "%s-------------------------------------\n", prefix);
107 
108  if (smDesc->smBase->trans[0].iTrAction == -1) {
109  fprintf(stream, "%sThe transition from the initial pseudo-state is not defined\n", prefix);
110  }
111  else {
112  if (smDesc->smBase->trans[0].dest > 0) {
113  fprintf(stream, "%sThe transition from the initial pseudo state is to state n. %d\n", prefix,
114  smDesc->smBase->trans[0].dest);
115  }
116  else if (smDesc->smBase->trans[0].dest < 0) {
117  fprintf(stream, "%sThe transition from the initial pseudo state is to choice pseudo-state n. %d\n", prefix,
118  -smDesc->smBase->trans[0].dest);
119  }
120  else {
121  fprintf(stream, "%sThe transition from the initial pseudo state is to the final pseudo-state.\n", prefix);
122  }
123 
124  if (smDesc->smBase->trans[0].iTrAction != 0) {
125  fprintf(stream, "\tTransition Action is action n. %d\n", smDesc->smBase->trans[0].iTrAction);
126  }
127  else {
128  fprintf(stream, "\tNo Transition Action\n");
129  }
130 
131  fprintf(stream, "\tNo Transition Guard\n");
132  }
133  fprintf(stream, "\n");
134 
135  if (smDesc->smBase->nOfPStates > 0) {
136  fprintf(stream, "%sCONFIGURATION OF STATES\n", prefix);
137  fprintf(stream, "%s-----------------------\n", prefix);
138  }
139 
140  for (i = 0; i < smDesc->smBase->nOfPStates; i++) {
141  if (smDesc->smBase->pStates[i].outTransIndex == 0) {
142  fprintf(stream, "%sState %d is not defined\n", prefix, i + 1);
143  }
144  else {
145  fprintf(stream, "%sState %d:\n", prefix, i + 1);
146 
147  if (smDesc->smBase->pStates[i].iEntryAction != 0) {
148  fprintf(stream, "\tEntry Action: action n. %d\n", smDesc->smBase->pStates[i].iEntryAction);
149  }
150  else {
151  fprintf(stream, "\tNo entry action\n");
152  }
153 
154  if (smDesc->smBase->pStates[i].iDoAction != 0) {
155  fprintf(stream, "\tDo-Action: action n. %d\n", smDesc->smBase->pStates[i].iDoAction);
156  }
157  else {
158  fprintf(stream, "\tNo do-action\n");
159  }
160 
161  if (smDesc->smBase->pStates[i].iExitAction != 0) {
162  fprintf(stream, "\tExit Action: action n. %d\n", smDesc->smBase->pStates[i].iExitAction);
163  }
164  else {
165  fprintf(stream, "\tNo exit action\n");
166  }
167 
168  if (smDesc->esmDesc[i] == NULL) {
169  fprintf(stream, "\tNo state machine is embedded in this state\n");
170  }
171  else {
172  fprintf(stream, "\tA state machine is embedded in this state\n");
173  }
174 
175  baseLoc = smDesc->smBase->pStates[i].outTransIndex;
176  for (j = baseLoc; j < (baseLoc + smDesc->smBase->pStates[i].nOfOutTrans); j++) {
177  trans = smDesc->smBase->trans[j];
178  if (trans.id == FW_TR_EXECUTE) {
179  if (trans.dest > 0) {
180  fprintf(stream, "\t'Execute' transition to state %d\n", trans.dest);
181  }
182  else if (trans.dest < 0) {
183  fprintf(stream, "\t'Execute' transition to choice pseudo-state %d\n", -trans.dest);
184  }
185  else {
186  fprintf(stream, "\t'Execute' transition to final pseudo-state\n");
187  }
188  }
189  else {
190  if (trans.dest > 0) {
191  fprintf(stream, "\tTransition %d to state %d\n", trans.id, trans.dest);
192  }
193  else if (trans.dest < 0) {
194  fprintf(stream, "\tTransition %d to choice pseudo-state %d\n", trans.id, -trans.dest);
195  }
196  else {
197  fprintf(stream, "\tTransition %d to final pseudo-state\n", trans.id);
198  }
199  }
200 
201  if (trans.iTrAction != 0) {
202  fprintf(stream, "\t\tTransition Action is action n. %d\n", trans.iTrAction);
203  }
204  else {
205  fprintf(stream, "\t\tNo Transition Action\n");
206  }
207 
208  if (trans.iTrGuard != 0) {
209  fprintf(stream, "\t\tTransition Guard is guard n. %d\n", trans.iTrGuard);
210  }
211  else {
212  fprintf(stream, "\t\tNo Transition Guard\n");
213  }
214  }
215  }
216  }
217  fprintf(stream, "\n");
218 
219  if (smDesc->smBase->nOfCStates > 0) {
220  fprintf(stream, "%sCONFIGURATION OF CHOICE PSEUDO-STATES\n", prefix);
221  fprintf(stream, "%s-------------------------------------\n", prefix);
222  }
223 
224  for (i = 0; i < smDesc->smBase->nOfCStates; i++) {
225  if (smDesc->smBase->cStates[i].outTransIndex == 0) {
226  fprintf(stream, "%sChoice Pseudo-State %d is not defined\n", prefix, i + 1);
227  }
228  else {
229  fprintf(stream, "%sChoice Pseudo-State %d:\n", prefix, i + 1);
230 
231  baseLoc = smDesc->smBase->cStates[i].outTransIndex;
232  for (j = baseLoc; j < (baseLoc + smDesc->smBase->cStates[i].nOfOutTrans); j++) {
233  if (smDesc->smBase->trans[j].dest > 0) {
234  fprintf(stream, "\tTransition to state %d\n", smDesc->smBase->trans[j].dest);
235  }
236  else if (smDesc->smBase->trans[j].dest < 0) {
237  fprintf(stream, "\tTransition to choice pseudo-state %d (this is an illegal transition)\n",
238  -smDesc->smBase->trans[j].dest);
239  }
240  else {
241  fprintf(stream, "\tTransition to final pseudo-state\n");
242  }
243 
244  if (smDesc->smBase->trans[j].iTrAction != 0) {
245  fprintf(stream, "\t\tTransition Action: action n. %d\n", smDesc->smBase->trans[j].iTrAction);
246  }
247  else {
248  fprintf(stream, "\t\tNo Transition Action\n");
249  }
250 
251  if (smDesc->smBase->trans[j].iTrGuard != 0) {
252  fprintf(stream, "\t\tTransition Guard: guard n. %d\n", smDesc->smBase->trans[j].iTrGuard);
253  }
254  else {
255  fprintf(stream, "\t\tNo Transition Guard\n");
256  }
257  }
258  }
259  }
260 }
261 
262 /* ------------------------------------------------------------------------------- */
263 void FwSmPrintConfigRec(FwSmDesc_t smDesc, FILE* stream) {
264  FwSmCounterS1_t i;
265  FwSmDesc_t embDesc;
266 
267  FwSmPrintConfig(smDesc, stream);
268 
269  for (i = 1; i <= smDesc->smBase->nOfPStates; ++i) {
270  embDesc = FwSmGetEmbSm(smDesc, i);
271  if (NULL != embDesc) {
272  FwSmPrintConfigRec(embDesc, stream);
273  }
274  }
275 }
276 
277 /* ------------------------------------------------------------------------------- */
279  switch (errCode) {
280  case smSuccess:
281  return "success";
282  case smOutOfMemory:
283  return "smOutOfMemory";
284  case smNullPState:
285  return "smNullPState";
286  case smNullCState:
287  return "smNullCState";
288  case smNullTrans:
289  return "smNullTrans";
290  case smConfigErr:
291  return "smConfigErr";
292  case smIllStateId:
293  return "smIllStateId";
294  case smIllChoiceId:
295  return "smIllChoiceId";
296  case smStateIdInUse:
297  return "smStateIdInUse";
298  case smChoiceIdInUse:
299  return "smChoiceIdInUse";
300  case smUndefinedTransSrc:
301  return "smUndefinedTransSrc";
302  case smIllegalPDest:
303  return "smIllegalPDest";
304  case smIllegalCDest:
305  return "smIllegalCDest";
306  case smIllNOfOutTrans:
307  return "smIllNOfOutTrans";
308  case smIllTransSrc:
309  return "smIllTransSrc";
310  case smTransErr:
311  return "smTransErr";
312  case smTooManyTrans:
313  return "smTooManyTrans";
314  case smTooManyOutTrans:
315  return "smTooManyOutTrans";
316  case smTooManyActions:
317  return "smTooManyActions";
318  case smTooManyGuards:
319  return "smTooManyGuards";
320  case smTooFewActions:
321  return "smTooFewActions";
322  case smTooFewGuards:
323  return "smTooFewGuards";
324  case smNegOutTrans:
325  return "smNegOutTrans";
326  case smUndefAction:
327  return "smUndefAction";
328  case smUndefGuard:
329  return "smUndefGuard";
330  case smNotDerivedSM:
331  return "smNotDerivedSM";
332  case smEsmDefined:
333  return "smEsmDefined";
334  case smWrongNOfActions:
335  return "smWrongNOfActions";
336  case smWrongNOfGuards:
337  return "smWrongNOfGuards";
338  default:
339  return "invalid error code";
340  }
341 }
A choice pseudo-state is added to a state machine with an illegal (out-of-range) identifier.
FwSmCounterS1_t outTransIndex
index of first out-going transition in transition array of SmBaseDesc_t
Definition: FwSmPrivate.h:151
#define FW_TR_EXECUTE
Identifier of "Execute" transition in a state machine.
FwSmCounterS1_t dest
the index of the destination of the transition
Definition: FwSmPrivate.h:197
FwSmCounterS1_t nOfOutTrans
number of outgoing transitions from the choice pseudo-state
Definition: FwSmPrivate.h:153
FwSmCounterS1_t iTrGuard
the index of the guard associated to the transition
Definition: FwSmPrivate.h:203
A transition from a certain source (either a state or a choice pseudo-state) is added to a state mach...
FwSmErrCode_t
Error codes and function return codes for the state machine functions.
Definition: FwSmConstants.h:82
FwSmBool_t FwSmIsStarted(FwSmDesc_t smDesc)
Check whether the state machine is started.
Definition: FwSmCore.c:240
There is an undefined transition in a state machine.
There is an undefined state in a state machine.
Definition: FwSmConstants.h:94
There is an undefined choice pseudo-state in a state machine.
Definition: FwSmConstants.h:98
FwSmCounterS1_t nOfActions
the number of actions (state actions + transition actions) in the state machine
Definition: FwSmPrivate.h:313
A configuration error has been detected during the state machine configuration process.
FwSmAction_t * smActions
the state machine actions (state and transition actions)
Definition: FwSmPrivate.h:307
FwSmCounterS1_t iDoAction
the do action for the state
Definition: FwSmPrivate.h:129
An error was encountered while executing a transition in a state machine (see FwSmMakeTrans).
The number of actions added to the state machine is smaller than the number of actions declared when ...
Declaration of the configuration interface for a FW State Machine.
FwSmCounterS1_t nOfPStates
the number of states in the state machine
Definition: FwSmPrivate.h:243
A choice pseudo-state is added to a state machine with less than 1 out-going transitions.
A transition is added to a state machine with a source (either a state or a choice pseudo-state) whic...
SmCState_t * cStates
array holding the choice pseudo-states in the state machine
Definition: FwSmPrivate.h:239
The number of guards added to the state machine exceeds the number of guards declared when the state ...
The number of guards in the base state machine is not the same as in the derived state machine...
The number of actions added to the state machine exceeds the number of actions declared when the stat...
FwSmCounterU2_t id
the identifier (the "name") of the transition
Definition: FwSmPrivate.h:199
FwSmErrCode_t errCode
either &#39;success&#39; or the code of the last error encountered by the state machine
Definition: FwSmPrivate.h:325
The state machine where an action or a guard is overridden or a state machine is embedded is not a de...
FwSmCounterS1_t outTransIndex
index of first out-going transition in the transition array of SmBaseDesc_t
Definition: FwSmPrivate.h:123
struct FwSmDesc ** esmDesc
the state machines embedded in the state machine
Definition: FwSmPrivate.h:311
A transition is added to a state machine with an illegal (out-of-range) choice pseudo-state destinati...
FwSmCounterS1_t nOfCStates
the number of choice pseudo-states in the state machine
Definition: FwSmPrivate.h:245
FwSmCounterU3_t smExecCnt
the state machine execution counter
Definition: FwSmPrivate.h:321
FwSmCounterS1_t nOfOutTrans
number of outgoing transitions
Definition: FwSmPrivate.h:125
A state is added with a negative number of outgoing transitions.
FwSmDesc_t FwSmGetEmbSm(FwSmDesc_t smDesc, FwSmCounterS1_t i)
Return the state machine embedded in the i-th state of the argument state machine.
Definition: FwSmCore.c:217
The overridden guard in a derived state machine does not exist.
void FwSmPrintConfigRec(FwSmDesc_t smDesc, FILE *stream)
Print the configuration of the state machine and its embedded state machines to an output stream...
Definition: FwSmAux.c:263
FwSmCounterS1_t nOfTrans
the number of transitions in SM
Definition: FwSmPrivate.h:247
Structure representing a transition.
Definition: FwSmPrivate.h:195
Structure representing a state machine descriptor.
Definition: FwSmPrivate.h:303
A choice pseudo-state is added twice to the same state machine.
FwSmCounterS1_t FwSmGetCurState(FwSmDesc_t smDesc)
Return the identifier of the current state in a state machine (or zero if the state machine is stoppe...
Definition: FwSmCore.c:222
A transition is added to a state machine with an illegal (out-of-range) state destination.
FwSmCounterU3_t stateExecCnt
the state execution counter
Definition: FwSmPrivate.h:323
FwSmErrCode_t FwSmCheck(FwSmDesc_t smDesc)
Check the correctness and completeness of the configuration of a state machine descriptor.
Definition: FwSmConfig.c:350
FwSmCounterS1_t iExitAction
the exit action for the state
Definition: FwSmPrivate.h:131
void FwSmPrintConfig(FwSmDesc_t smDesc, FILE *stream)
Print the configuration of the state machine to an output stream.
Definition: FwSmAux.c:23
FwSmCounterS1_t iTrAction
the index of the action associated to the transition
Definition: FwSmPrivate.h:201
FwSmCounterS1_t nOfGuards
the number of guards in the state machine
Definition: FwSmPrivate.h:315
FwSmGuard_t * smGuards
the transition guards in the state machine
Definition: FwSmPrivate.h:309
A state is added twice to the same state machine.
A call to malloc has failed (it has returned a NULL pointer).
Definition: FwSmConstants.h:90
SmPState_t * pStates
array holding the proper states in the state machine
Definition: FwSmPrivate.h:237
char * FwSmPrintErrCode(FwSmErrCode_t errCode)
Print the name of a state machine error code.
Definition: FwSmAux.c:278
SmBaseDesc_t * smBase
pointer to the base descriptor
Definition: FwSmPrivate.h:305
A transition is added to a state machine with a source which has an illegal identifier.
The number of guards added to the state machine is smaller than the number of guards declared when th...
The overridden action in a derived state machine does not exist.
Return codes of a function which has completed execution without errors.
Definition: FwSmConstants.h:86
Declaration of the auxiliary interface for a FW State Machine.
The state in a derived state machine to which an embedded state machine is added already holds an emb...
signed char FwSmCounterS1_t
Type used for signed counters with a "short" range.
Definition: FwSmConstants.h:79
A state or choice pseudo-state is added to a state machine which has more out-going transitions than ...
The number of actions in the base state machine is not the same as in the derived state machine...
FwSmCounterS1_t iEntryAction
the entry action for the state
Definition: FwSmPrivate.h:127
Declaration of the internal data structures of the FW State Machine Module.
SmTrans_t * trans
array holding the transitions in the state machine
Definition: FwSmPrivate.h:241
A state is added to a state machine with an illegal (out-of-range) identifier.
P&P Software GmbH, Copyright 2011, All Rights Reserved