FW Profile - C1 Implementation
FwDaHwDev.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 "FwDaHwDev.h"
16 
22 static float tempMeasurement = 0;
23 
30 static float curMeasurement = 0;
31 
32 /* --------------------------------------------------------------------- */
38 static void OnEntry(FwSmDesc_t smDesc) {
39  fprintf(stdout, "\nHW Device switched on");
40 }
41 
42 /* --------------------------------------------------------------------- */
48 static void OffEntry(FwSmDesc_t smDesc) {
49  fprintf(stdout, "\nHW Device switched off");
50 }
51 
52 /* --------------------------------------------------------------------- */
58 static void SbyEntry(FwSmDesc_t smDesc) {
59  fprintf(stdout, "\nHW Device in STANDBY");
60 }
61 
62 /* --------------------------------------------------------------------- */
68 static void OperEntry(FwSmDesc_t smDesc) {
69  fprintf(stdout, "\nHW Device operational");
70 }
71 
72 /* --------------------------------------------------------------------- */
86 static void CollectMeasurements(FwSmDesc_t smDesc) {
87  tempMeasurement = (rand()%1000)*HW_DEV_TEMP_MAX/1000.0;
88  curMeasurement = (rand()%1000)*HW_DEV_CUR_MAX/1000.0;
89 }
90 
91 /* --------------------------------------------------------------------- */
93  static FwSmDesc_t hwDevSm = NULL; /* HW Device SM */
94  static FwSmDesc_t esmDesc; /* SM embedded in state ON of HW Device SM */
95 
96  if (hwDevSm != NULL) /* SM has already been created and configured */
97  return hwDevSm;
98 
99  /* Create the SM embedded in state ON */
100  esmDesc = FwSmCreate(2, 0, 3, 2, 0);
101 
102  /* Configure the SM embedded in state ON */
103  FwSmAddState(esmDesc, HW_DEV_SBY, 1, &SbyEntry, NULL, NULL, NULL);
104  FwSmAddState(esmDesc, HW_DEV_OPER, 1, &OperEntry, NULL, NULL, NULL);
105  FwSmAddTransIpsToSta(esmDesc, HW_DEV_SBY, NULL);
108 
109  /* Create the HW Device State Machine */
110  hwDevSm = FwSmCreate(2, 0, 3, 3, 0);
111 
112  /* Configure the HW Device State Machine */
113  FwSmSetData(hwDevSm, NULL); /* NB: There are no data attached to this SM */
114  FwSmAddState(hwDevSm, HW_DEV_ON, 1, &OnEntry, NULL, &CollectMeasurements, esmDesc);
115  FwSmAddState(hwDevSm, HW_DEV_OFF, 1, &OffEntry, NULL, NULL, NULL);
116  FwSmAddTransIpsToSta(hwDevSm, HW_DEV_OFF, NULL);
117  FwSmAddTransStaToSta(hwDevSm, TR_HW_DEV_ON, HW_DEV_OFF, HW_DEV_ON, NULL, NULL);
118  FwSmAddTransStaToSta(hwDevSm, TR_HW_DEV_OFF, HW_DEV_ON, HW_DEV_OFF, NULL, NULL);
119 
120  return hwDevSm;
121 }
122 
123 /* --------------------------------------------------------------------- */
124 float GetHwDevTemp() {
125  return tempMeasurement;
126 }
127 
128 /* --------------------------------------------------------------------- */
129 float GetHwDevCur() {
130  return curMeasurement;
131 }
132 
#define HW_DEV_OPER
Name of the OPERATIONAL state in the HW Device State Machine.
Definition: FwDaHwDev.h:35
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
Declaration of the dynamical creation interface for a FW State Machine.
float GetHwDevTemp()
This function returns the temperature of the Hardware Device.
Definition: FwDaHwDev.c:124
#define HW_DEV_ON
Name of the ON state in the HW Device State Machine.
Definition: FwDaHwDev.h:29
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
#define HW_DEV_CUR_MAX
The maximum value of the current absorbed by the Hardware Device.
Definition: FwDaHwDev.h:50
Definition of the interface to access the Hardware Device.
#define HW_DEV_SBY
Name of the STANDBY state in the HW Device State Machine.
Definition: FwDaHwDev.h:33
#define TR_HW_DEV_SBY
Name of the transition from OPERATIONAL to STANDBY in the HW Device State Machine.
Definition: FwDaHwDev.h:44
#define HW_DEV_OFF
Name of the OFF state in the HW Device State Machine.
Definition: FwDaHwDev.h:31
#define TR_HW_DEV_OPER
Name of the transition from STANDBY to OPERATIONAL in the HW Device State Machine.
Definition: FwDaHwDev.h:42
#define TR_HW_DEV_OFF
Name of the transition from ON to OFF in the HW Device State Machine.
Definition: FwDaHwDev.h:40
float GetHwDevCur()
This function returns the current absorbed by the Hardware Device.
Definition: FwDaHwDev.c:129
Structure representing a state machine descriptor.
Definition: FwSmPrivate.h:303
#define TR_HW_DEV_ON
Name of the transition from OFF to ON in the HW Device State Machine.
Definition: FwDaHwDev.h:38
void FwSmSetData(FwSmDesc_t smDesc, void *smData)
Set the pointer to the state machine data in the state machine descriptor.
Definition: FwSmConfig.c:83
#define HW_DEV_TEMP_MAX
The maximum value of the temperature of the Hardware Device.
Definition: FwDaHwDev.h:47
FwSmDesc_t GetHwDevSm()
Retrieve the descriptor of the Hardware Device State Machine.
Definition: FwDaHwDev.c:92
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
Declaration of the auxiliary interface for a FW State Machine.
P&P Software GmbH, Copyright 2011, All Rights Reserved