FW Profile - C1 Implementation
FwDaFDCheck.c
Go to the documentation of this file.
1 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "FwSmConfig.h"
13 #include "FwSmDCreate.h"
14 #include "FwSmAux.h"
15 #include "FwSmConstants.h"
16 #include "FwDaFDCheck.h"
17 
18 /* --------------------------------------------------------------------- */
24 static void ResetCounter(FwSmDesc_t smDesc) {
25  FDCheckData_t* fdcData = GetFDCheckData(smDesc);
26  fdcData->counter = 0;
27  return;
28 }
29 
30 /* --------------------------------------------------------------------- */
36 static void IncrCounter(FwSmDesc_t smDesc) {
37  FDCheckData_t* fdcData = GetFDCheckData(smDesc);
38  fdcData->counter = fdcData->counter + 1;
39  return;
40 }
41 
42 /* --------------------------------------------------------------------- */
49 static FwSmBool_t IsAnomalyDetected(FwSmDesc_t smDesc) {
50  FDCheckData_t* fdcData = GetFDCheckData(smDesc);
51  return (fdcData->detectionCheckOutcome == anomalyDetected);
52 }
53 
54 /* --------------------------------------------------------------------- */
61 static FwSmBool_t IsNoAnomalyDetected(FwSmDesc_t smDesc) {
62  FDCheckData_t* fdcData = GetFDCheckData(smDesc);
63  return (fdcData->detectionCheckOutcome == noAnomalyDetected);
64 }
65 
66 /* --------------------------------------------------------------------- */
73 static FwSmBool_t HasFailed(FwSmDesc_t smDesc) {
74  FDCheckData_t* fdcData = GetFDCheckData(smDesc);
75  return ((fdcData->detectionCheckOutcome == anomalyDetected) &&
76  (fdcData->counter == fdcData->cntLimit));
77 }
78 
79 /* --------------------------------------------------------------------- */
89 static char* PrintFDCheckId(FDCheckId_t id) {
90  switch (id) {
91  case curFDCheckId: return "Curr. FD Check";
92  case tempFDCheckId: return "Temp. FD Check";
93  case deltaFDCheckId: return "Delta FD Check";
94  }
95 
96  return NULL;
97 }
98 
99 /* --------------------------------------------------------------------- */
123 static void TransAction(FwSmDesc_t smDesc) {
124  FDCheckData_t* fdcData = GetFDCheckData(smDesc);
125 
126  if (FwSmGetCurState(smDesc) == FD_CHECK_HEALTHY) {
127  printf(", %s --> SUSPECTED", PrintFDCheckId(fdcData->fdCheckId));
128  return;
129  }
130 
131  if ((FwSmGetCurState(smDesc) == FD_CHECK_SUSPECTED) &&
132  (fdcData->detectionCheckOutcome == anomalyDetected)) {
133  printf(", %s --> FAILED", PrintFDCheckId(fdcData->fdCheckId));
134  return;
135  }
136 
137  if ((FwSmGetCurState(smDesc) == FD_CHECK_SUSPECTED) &&
139  printf(", %s --> HEALTHY", PrintFDCheckId(fdcData->fdCheckId));
140  return;
141  }
142 }
143 
144 /* --------------------------------------------------------------------- */
151 static FwSmBool_t RemainSuspected(FwSmDesc_t smDesc) {
152  FDCheckData_t* fdcData = GetFDCheckData(smDesc);
153  return ((fdcData->detectionCheckOutcome == anomalyDetected) &&
154  (fdcData->counter < fdcData->cntLimit));
155 }
156 
157 
158 /* --------------------------------------------------------------------- */
160  return (FDCheckData_t*)FwSmGetData(smDesc);
161 }
162 
163 /* --------------------------------------------------------------------- */
165  FDCheckData_t* fdcData = GetFDCheckData(smDesc);
167  return;
168 }
169 
170 /* --------------------------------------------------------------------- */
172  return;
173 }
174 
175 /* --------------------------------------------------------------------- */
177  static FwSmDesc_t esmDesc; /* Descriptor of SM embedded in ENABLED */
178  static FwSmDesc_t fdCheckSm = NULL; /* FD Check SM Descriptor */
179  const int CPS1 = 1; /* Identifier of first Choice Pseudo-State */
180  const int CPS2 = 2; /* Identifier of second Choice Pseudo-State */
181 
182  if (fdCheckSm != NULL) /* FD Check SM has already been created */
183  return fdCheckSm;
184 
185  /* Create the SM embedded in state ENABLED */
186  esmDesc = FwSmCreate(3,2,9,4,4);
187 
188  /* Configure the SM embedded in state ENABLED */
189  FwSmAddState(esmDesc, FD_CHECK_HEALTHY, 1, &ResetCounter, NULL, NULL, NULL);
190  FwSmAddState(esmDesc, FD_CHECK_SUSPECTED, 2, &IncrCounter, NULL, NULL, NULL);
191  FwSmAddState(esmDesc, FD_CHECK_FAILED, 1, &DefRecoveryAction, NULL, NULL, NULL);
192  FwSmAddChoicePseudoState(esmDesc, CPS1, 3);
193  FwSmAddChoicePseudoState(esmDesc, CPS2, 1);
194  FwSmAddTransIpsToSta(esmDesc, FD_CHECK_HEALTHY, NULL);
195  FwSmAddTransStaToSta(esmDesc, FW_TR_EXECUTE, FD_CHECK_HEALTHY, FD_CHECK_SUSPECTED, &TransAction, &IsAnomalyDetected);
196  FwSmAddTransStaToCps(esmDesc, FW_TR_EXECUTE, FD_CHECK_SUSPECTED, CPS1, NULL, NULL);
197  FwSmAddTransCpsToSta(esmDesc, CPS1, FD_CHECK_HEALTHY, &TransAction, &IsNoAnomalyDetected);
198  FwSmAddTransCpsToSta(esmDesc, CPS1, FD_CHECK_SUSPECTED, NULL, &RemainSuspected);
199  FwSmAddTransCpsToSta(esmDesc, CPS1, FD_CHECK_FAILED, &TransAction, &HasFailed);
200  FwSmAddTransStaToCps(esmDesc, TR_FD_CHECK_RESET, FD_CHECK_SUSPECTED, CPS2, NULL, NULL);
201  FwSmAddTransStaToCps(esmDesc, TR_FD_CHECK_RESET, FD_CHECK_FAILED, CPS2, NULL, NULL);
202  FwSmAddTransCpsToSta(esmDesc, CPS2, FD_CHECK_HEALTHY, NULL, NULL);
203 
204  /* Create the FD Check SM */
205  fdCheckSm = FwSmCreate(2,0,3,1,0);
206 
207  /* Configure the FD Check SM */
208  FwSmAddState(fdCheckSm, FD_CHECK_DISABLED, 1, NULL, NULL, NULL, NULL);
209  FwSmAddState(fdCheckSm, FD_CHECK_ENABLED, 1, NULL, NULL, &DefAnomalyDetCheck, esmDesc);
210  FwSmAddTransIpsToSta(fdCheckSm, FD_CHECK_DISABLED, NULL);
213 
214  return fdCheckSm;
215 }
#define TR_FD_CHECK_ENABLE
Name of the transition to enable a FD Check.
Definition: FwDaFDCheck.h:75
FDCheckOutcome_t detectionCheckOutcome
The outcome of the last call to the Anomaly Detection Check.
Definition: FwDaFDCheck.h:126
void FwSmAddTransStaToSta(FwSmDesc_t smDesc, FwSmCounterU2_t transId, FwSmCounterS1_t srcId, FwSmCounterS1_t destId, FwSmAction_t trAction, FwSmGuard_t trGuard)
Create a transition from a proper state to a proper state and add it to a state machine.
Definition: FwSmConfig.c:191
#define FW_TR_EXECUTE
Identifier of "Execute" transition in a state machine.
void * FwSmGetData(FwSmDesc_t smDesc)
Get the pointer to the state machine data in the state machine descriptor.
Definition: FwSmConfig.c:87
FwSmDesc_t GetFailDetCheckSm()
Retrieve the descriptor of the FD Check State Machine.
Definition: FwDaFDCheck.c:176
Outcome generated when the Anomaly Detection Check detects an anomaly.
Definition: FwDaFDCheck.h:96
#define FD_CHECK_ENABLED
Name of the ENABLED state in the FD Check State Machine.
Definition: FwDaFDCheck.h:66
Declaration of the dynamical creation interface for a FW State Machine.
#define FD_CHECK_DISABLED
Name of the DISABLED state in the FD Check State Machine.
Definition: FwDaFDCheck.h:64
#define CPS2
A choice pseudo-state identifier.
Definition: FwSmMakeTest.h:46
void DefRecoveryAction(FwSmDesc_t smDesc)
Default implementation of the Recovery Action.
Definition: FwDaFDCheck.c:171
Identifier of the Delta FD Check (see FwDaDeltaCheck.h)
Definition: FwDaFDCheck.h:88
#define TR_FD_CHECK_RESET
Name of the transition to reset a FD Check.
Definition: FwDaFDCheck.h:79
void DefAnomalyDetCheck(FwSmDesc_t smDesc)
Default implementation of the Anomaly Detection Check.
Definition: FwDaFDCheck.c:164
Outcome generated when the Anomaly Detection Check detects no anomaly.
Definition: FwDaFDCheck.h:94
Declaration of the configuration interface for a FW State Machine.
FwSmDesc_t FwSmCreate(FwSmCounterS1_t nOfStates, FwSmCounterS1_t nOfChoicePseudoStates, FwSmCounterS1_t nOfTrans, FwSmCounterS1_t nOfActions, FwSmCounterS1_t nOfGuards)
Create a new state machine descriptor.
Definition: FwSmDCreate.c:23
void FwSmAddTransStaToCps(FwSmDesc_t smDesc, FwSmCounterU2_t transId, FwSmCounterS1_t srcId, FwSmCounterS1_t destId, FwSmAction_t trAction, FwSmGuard_t trGuard)
Create a transition from a proper state to a choice pseudo-state and add it to a state machine...
Definition: FwSmConfig.c:197
int cntLimit
The number of consecutive anomalies which must be detected in order for the FD Check to enter state F...
Definition: FwDaFDCheck.h:122
#define FD_CHECK_FAILED
Name of the FAILED state in the FD Check State Machine.
Definition: FwDaFDCheck.h:72
#define TR_FD_CHECK_DISABLE
Name of the transition to disable a FD Check.
Definition: FwDaFDCheck.h:77
FDCheckId_t
Type for the identifiers of the FD Checks.
Definition: FwDaFDCheck.h:82
#define FD_CHECK_SUSPECTED
Name of the SUSPECTED state in the FD Check State Machine.
Definition: FwDaFDCheck.h:70
FDCheckId_t fdCheckId
Identity of the FD Check to which this data structure is attached.
Definition: FwDaFDCheck.h:112
void FwSmAddChoicePseudoState(FwSmDesc_t smDesc, FwSmCounterS1_t choiceId, FwSmCounterS1_t nOfOutTrans)
Create a choice pseudo-state with the given characteristics and add it to a state machine...
Definition: FwSmConfig.c:140
Header file to define all constants and types for the state machine module of the FW Profile...
int FwSmBool_t
Type used for booleans (0 is "false" and 1 is "true").
Definition: FwSmConstants.h:49
#define FD_CHECK_HEALTHY
Name of the HEALTHY sub-state in the FD Check State Machine.
Definition: FwDaFDCheck.h:68
Type for the data of an FD Check State Machine.
Definition: FwDaFDCheck.h:108
int counter
The number of consecutive anomalies which have been detected by the Anomaly Detection Check...
Definition: FwDaFDCheck.h:117
#define CPS1
A choice pseudo-state identifier.
Definition: FwSmMakeTest.h:44
Structure representing a state machine descriptor.
Definition: FwSmPrivate.h:303
Identifier of the Temperature FD Check (see FwDaTempCheck.h)
Definition: FwDaFDCheck.h:86
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
Definition of the Failure Detection (FD) Check State Machine.
void FwSmAddState(FwSmDesc_t smDesc, FwSmCounterS1_t stateId, FwSmCounterS1_t nOfOutTrans, FwSmAction_t entryAction, FwSmAction_t exitAction, FwSmAction_t doAction, FwSmDesc_t esmDesc)
Create a state with the given characteristics and add it to a state machine.
Definition: FwSmConfig.c:92
void FwSmAddTransIpsToSta(FwSmDesc_t smDesc, FwSmCounterS1_t destId, FwSmAction_t trAction)
Create a transition from the initial pseudo-state to a proper state and add it to a state machine...
Definition: FwSmConfig.c:181
void FwSmAddTransCpsToSta(FwSmDesc_t smDesc, FwSmCounterS1_t srcId, FwSmCounterS1_t destId, FwSmAction_t trAction, FwSmGuard_t trGuard)
Create a transition from a choice pseudo-state to a proper state and add it to a state machine...
Definition: FwSmConfig.c:203
Declaration of the auxiliary interface for a FW State Machine.
FDCheckData_t * GetFDCheckData(FwSmDesc_t smDesc)
Get the pointer to the state machine data of an FD Check State Machine.
Definition: FwDaFDCheck.c:159
Identifier of the Current FD Check (see FwDaCurCheck.h)
Definition: FwDaFDCheck.h:84
P&P Software GmbH, Copyright 2011, All Rights Reserved