CORDET Framework - C2 Implementation
CrFwInLoader.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 /* Include configuration files */
21 #include "CrFwInLoaderUserPar.h"
22 #include "CrFwCmpData.h"
23 /* Include framework files */
24 #include "CrFwConstants.h"
25 #include "CrFwRepErr.h"
26 #include "CrFwTime.h"
27 #include "CrFwInLoader.h"
28 #include "CrFwRepInCmdOutcome.h"
29 #include "BaseCmp/CrFwBaseCmp.h"
30 #include "BaseCmp/CrFwInitProc.h"
31 #include "BaseCmp/CrFwResetProc.h"
33 #include "Pckt/CrFwPckt.h"
34 #include "Pckt/CrFwPcktQueue.h"
37 #include "InStream/CrFwInStream.h"
39 #include "InCmd/CrFwInCmd.h"
42 /* Include FW Profile files */
43 #include "FwSmConstants.h"
44 #include "FwSmDCreate.h"
45 #include "FwSmConfig.h"
46 #include "FwSmCore.h"
47 #include "FwPrConstants.h"
48 #include "FwPrDCreate.h"
49 #include "FwPrConfig.h"
50 #include "FwPrCore.h"
51 
53 static FwSmDesc_t inLoader = NULL;
54 
57 
60 
63 
66 
74 static void InLoaderExecAction(FwPrDesc_t execPr);
75 
83 static void InLoaderLoadCmdRep(CrFwPckt_t pckt);
84 
85 /*-----------------------------------------------------------------------------------------*/
86 FwSmDesc_t CrFwInLoaderMake() {
87  FwPrDesc_t resetPr, execPr, initPr;
88 
89  if (inLoader != NULL) {
90  return inLoader; /* The requested SM has already been created */
91  }
92 
93  /* Create the requested SM as an extension of the base component SM */
94  inLoader = FwSmCreateDer(CrFwBaseCmpMake());
95 
96  /* Create the Reset Procedure for the InLoader Component */
97  resetPr = FwPrCreateDer(CrFwCmpGetResetProc());
98 
99  /* Create the Initialization Procedure for the InLoader Component */
100  initPr = FwPrCreateDer(CrFwCmpGetInitProc());
101 
102  /* Create the Execution Procedure for the InLoader Component */
103  execPr = FwPrCreateDer(CrFwBaseCmpGetDummyExecProc());
104  FwPrOverrideAction(execPr, &CwFwBaseCmpDummyExecAction, &InLoaderExecAction);
105 
106  /* Initialize the data for the requested SM */
107  inLoaderData.outcome = 1;
108  inLoaderData.initProc = initPr;
109  inLoaderData.resetProc = resetPr;
110  inLoaderData.execProc = execPr;
111  inLoaderData.instanceId = 0;
112  inLoaderData.typeId = CR_FW_INLOADER_TYPE;
114 
115  /* Attach the data to the InLoader state machine and to its procedures. */
116  FwSmSetData(inLoader, &inLoaderData);
117  FwPrSetData(inLoaderData.initProc, &inLoaderData);
118  FwPrSetData(inLoaderData.resetProc, &inLoaderData);
119  FwPrSetData(inLoaderData.execProc, &inLoaderData);
120 
121  /* Start the InLoader */
122  FwSmStart(inLoader);
123 
124  return inLoader;
125 }
126 
127 /*-----------------------------------------------------------------------------------------*/
128 void CrFwInLoaderSetInStream(FwSmDesc_t inStream) {
129  inLoaderCmpSpecificData.inStream = inStream;
130 }
131 
132 /*-----------------------------------------------------------------------------------------*/
133 static void InLoaderExecAction(FwPrDesc_t prDesc) {
134  CrFwPckt_t pckt;
135  CrFwDestSrc_t pcktDest, reroutingDest;
136  FwSmDesc_t outStream;
137  CRFW_UNUSED(prDesc);
138 
139  /* Retrieve packet from InStream */
140  pckt = CrFwInStreamGetPckt(inLoaderCmpSpecificData.inStream);
141  if (pckt == NULL)
142  return;
143 
144  /* Get packet destination and check whether it is the host application */
145  pcktDest = CrFwPcktGetDest(pckt);
146  if (pcktDest == CR_FW_HOST_APP_ID) {
147  InLoaderLoadCmdRep(pckt);
148  return;
149  }
150 
151  /* Check whether packet should be re-routed to another destination */
152  reroutingDest = getReroutingDest(pcktDest);
153  if (reroutingDest == 0) { /* destination is invalid */
155  CrFwPcktGetCmdRepId(pckt), pcktDest, pckt);
156  CrFwPcktRelease(pckt);
157  return;
158  }
159 
160  /* Re-route packet and then release it */
161  outStream = CrFwOutStreamGet(reroutingDest);
162  CrFwOutStreamSend(outStream, pckt);
163  CrFwPcktRelease(pckt);
164  return;
165 }
166 
167 /*-----------------------------------------------------------------------------------------*/
168 static void InLoaderLoadCmdRep(CrFwPckt_t pckt) {
169  FwSmDesc_t inCmp;
170  CrFwInstanceId_t instanceId = CrFwPcktGetCmdRepId(pckt);
174  CrFwCmdRepType_t cmdRepFlag = CrFwPcktGetCmdRepType(pckt);
175  CrFwCmpData_t* inCmpData;
176  CrFwInstanceId_t inManagerInstanceId;
177  CrFwBool_t inManagerLoadOutcome;
178 
179  if (CrFwPcktGetCmdRepType(pckt) == crCmdType) {
180  inCmp = CrFwInFactoryMakeInCmd(pckt);
181  if (inCmp == NULL) { /* InCmd had invalid type or no more resources are available */
183  CrFwPcktRelease(pckt);
184  return;
185  }
186  } else {
187  inCmp = CrFwInFactoryMakeInRep(pckt);
188  if (inCmp == NULL) { /* InRep had invalid type or no more resources are available */
189  CrFwRepErrPckt(crInLoaderCreFail, inLoaderData.typeId,inLoaderData.instanceId, pckt);
190  CrFwPcktRelease(pckt);
191  return;
192  }
193  }
194 
195  if (FwSmGetCurState(inCmp) != CR_FW_BASE_STATE_CONFIGURED) { /* InRep/InCmd has failed its validity check */
196  inCmpData = FwSmGetData(inCmp);
197  if (cmdRepFlag == crRepType) {
198  CrFwRepErrRep(crInLoaderAccFail, inLoaderData.typeId,inLoaderData.instanceId, inCmp);
200  return;
201  } else {
202  CrFwRepInCmdOutcome(crCmdAckAccFail, instanceId, servType, servSubType, disc, inCmpData->outcome, inCmp);
204  return;
205  }
206  }
207 
208  /* Select InManager */
209  inManagerInstanceId = getInManager(servType, servSubType, disc, cmdRepFlag);
210 
211  /* Load InReport/InCommand in selected InManager */
212  inManagerLoadOutcome = CrFwInManagerLoad(CrFwInManagerMake(inManagerInstanceId), inCmp);
213  if (inManagerLoadOutcome == 0) { /* Load operation has failed */
214  if (cmdRepFlag == crRepType) {
215  CrFwRepErrRep(crInLoaderLdFail, inLoaderData.typeId,inLoaderData.instanceId,inCmp);
217  return;
218  } else {
219  CrFwRepInCmdOutcome(crCmdAckLdFail, instanceId, servType, servSubType, disc, 0, inCmp);
221  return;
222  }
223  } else /* Load operation was successful */
224  if (cmdRepFlag == crCmdType)
225  if (CrFwInCmdIsAcceptAck(inCmp) == 1)
226  CrFwRepInCmdOutcome(crCmdAckAccSucc, instanceId, servType, servSubType, disc, 0, inCmp);
227 }
228 
229 /*-----------------------------------------------------------------------------------------*/
231  return pcktDest;
232 }
233 
234 /*-----------------------------------------------------------------------------------------*/
236  CRFW_UNUSED(pcktDest);
237  return 0;
238 }
239 
240 /*-----------------------------------------------------------------------------------------*/
242  CrFwDiscriminant_t discriminant, CrFwCmdRepType_t cmdRepFlag) {
243  CRFW_UNUSED(servType);
244  CRFW_UNUSED(servSubType);
245  CRFW_UNUSED(discriminant);
246  if (cmdRepFlag == crCmdType)
247  return 0;
248  else
249  return 1;
250 }
Type for the Framework Component Data (FCD).
Definition: CrFwCmpData.h:79
Interface through which framework components access the current time.
CrFwInstanceId_t CrFwInLoaderDefGetInManager(CrFwServType_t servType, CrFwServSubType_t servSubType, CrFwDiscriminant_t discriminant, CrFwCmdRepType_t cmdRepFlag)
Default implementation of the function which selects the InManager to which an incoming InReport or I...
Definition: CrFwInLoader.c:241
void CrFwOutStreamSend(FwSmDesc_t smDesc, CrFwPckt_t pckt)
Send a packet to the OutStream.
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
CrFwOutcome_t outcome
The outcome of an action or check executed by a state machine or by one of its procedures.
Definition: CrFwCmpData.h:93
Definition of the InLoader component.
An InReport has failed its validity check.
FwPrDesc_t CrFwCmpGetResetProc()
Retrieve the singleton instance of the CRP.
Definition: CrFwResetProc.c:45
Report type.
Definition: CrFwConstants.h:45
Definition of the Framework Component Data (FCD) Type.
User-modifiable parameters for the InLoader components (see CrFwInLoader.h).
CrFwInstanceId_t(* CrFwInLoaderGetInManager_t)(CrFwServType_t, CrFwServSubType_t, CrFwDiscriminant_t, CrFwCmdRepType_t)
Type for a pointer to the function which selects the InManager where the InCommand or InReport must b...
Definition: CrFwInLoader.h:131
#define CRFW_UNUSED(x)
A macro that can be used to specify that a function parameter is not used.
Definition: CrFwConstants.h:29
#define CR_FW_HOST_APP_ID
The identifier of the host application.
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:38
CrFwServType_t CrFwPcktGetServType(CrFwPckt_t pckt)
Return the service type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:291
Definition of the OutStream component.
CrFwCmdRepType_t
Enumerated type for command and reports.
Definition: CrFwConstants.h:41
CrFwDestSrc_t CrFwPcktGetDest(CrFwPckt_t pckt)
Return the destination of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:315
Acceptance failure.
Interface for creating and accessing a report or command packet.
Definition of the InStream component.
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
FwPrDesc_t resetProc
The Component Reset Procedure (CRP) (see CrFwResetProc.h).
Definition: CrFwCmpData.h:97
static CrFwServSubType_t servSubType
Service sub-type.
CrFwDestSrc_t CrFwInLoaderDefNoRerouting(CrFwDestSrc_t pcktDest)
Default implementation of the function which checks the legality of a destination and returns the re-...
Definition: CrFwInLoader.c:235
Dummy Component Execution Procedure (CEP) for the Base Component.
static void InLoaderExecAction(FwPrDesc_t execPr)
Implement the logic of the InLoader Execution Procedure (see figure below).
Definition: CrFwInLoader.c:133
Header file to define all invariant publicly available constants and types for the CORDET Framework...
Creation failure.
void CrFwPcktRelease(CrFwPckt_t pckt)
Release function for command or report packets.
Definition: CrFwPckt.c:156
Definition of the InRegistry Component.
unsigned short CrFwDiscriminant_t
Type used for the discriminant of a command or report.
FwSmDesc_t inStream
InStream from which packets are to be retrieved in the next execution cycle.
unsigned char CrFwDestSrc_t
Type used for the command or report destination and source.
CrFwInstanceId_t instanceId
The instance identifier of the framework component.
Definition: CrFwCmpData.h:81
Command type.
Definition: CrFwConstants.h:43
static CrFwInLoaderGetInManager_t getInManager
Pointer to function which selects the InManager.
Definition: CrFwInLoader.c:65
Type for the data describing an InLoader.
Interface for reporting an error detected by a framework component.
static CrFwDestSrc_t reroutingDest
Return value of function CrFwInLoaderDefGetReroutingDestination.
static CrFwDiscriminant_t disc
Discriminant.
void CrFwRepInCmdOutcome(CrFwRepInCmdOutcome_t outcome, CrFwInstanceId_t instanceId, CrFwServType_t servType, CrFwServSubType_t servSubType, CrFwDiscriminant_t disc, CrFwOutcome_t failCode, FwSmDesc_t inCmd)
Report the outcome of the processing of an InCommand.
Acceptance success.
#define CR_FW_INLOADER_DET_REROUTING_DEST
The function which determines the re-routing destination of a packet.
Definition and management of packet queues.
FwSmDesc_t CrFwInLoaderMake()
Factory function to retrieve the state machine implementing the InLoader singleton component...
Definition: CrFwInLoader.c:86
FwSmDesc_t CrFwInManagerMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th InManager State Machine instance.
Definition: CrFwInManager.c:96
CrFwCmdRepType_t CrFwPcktGetCmdRepType(CrFwPckt_t pckt)
Return the type of a packet (either a command packet or a report packet).
Definition: CrFwPckt.c:211
CrFwDiscriminant_t CrFwPcktGetDiscriminant(CrFwPckt_t pckt)
Return the discriminant of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:273
void * cmpSpecificData
Derived data which are specific to each type of framework component.
Definition: CrFwCmpData.h:101
void CrFwRepErrPckt(CrFwRepErrCode_t errCode, CrFwTypeId_t typeId, CrFwInstanceId_t instanceId, CrFwPckt_t pckt)
Report an error which has one parameter attached to it representing a command or report packet...
Definition: CrFwRepErr.c:193
Definition of the InFactory component.
CrFwBool_t CrFwInCmdIsAcceptAck(FwSmDesc_t smDesc)
Return the acknowledge level for command acceptance for the command encapsulated in the InCommand...
Definition: CrFwInCmd.c:359
void CrFwRepInCmdOutcomeCreFail(CrFwRepInCmdOutcome_t outcome, CrFwOutcome_t failCode, CrFwPckt_t pckt)
Report the a "creation failure" outcome for the processing of a packet carrying an InCommand...
Definition of the utility functions for the CORDET Framework.
FwSmDesc_t CrFwOutStreamGet(CrFwDestSrc_t dest)
Getter function for the OutStream corresponding to the argument destination.
static FwSmDesc_t inLoader
The InLoader singleton.
Definition: CrFwInLoader.c:53
#define CR_FW_INLOADER_SEL_INMANAGER
The function which determines the InManager into which an InReport or InCommand must be loaded...
FwPrDesc_t execProc
The Component Execution Procedure (CEP) (see CrFwBaseCmp.h).
Definition: CrFwCmpData.h:99
CrFwBool_t CrFwInManagerLoad(FwSmDesc_t smDesc, FwSmDesc_t inCmp)
Load a new InReport or InCommand into the InManager.
FwSmDesc_t CrFwBaseCmpMake()
Retrieve the singleton instance of the Base State Machine.
Definition: CrFwBaseCmp.c:77
FwPrDesc_t CrFwBaseCmpGetDummyExecProc()
Retrieve the singleton instance of the Dummy CEP.
CrFwServSubType_t CrFwPcktGetServSubType(CrFwPckt_t pckt)
Return the service sub-type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:303
Interface for reporting the outcome of the processing of an InCommand.
An InReport could not be loaded in its InManager.
An InReport could not be created due to insufficient resources or illegal type/sub-type/discriminant...
void CrFwInFactoryReleaseInRep(FwSmDesc_t inRepInstance)
Release function for an InReport.
The InLoader has retrieved a packet with an invalid destination (see CrFwInLoader.h)
Definition of Base Component.
static CrFwServType_t servType
The InCommand type as computed in the Validity Check.
static CrFwCmpData_t inLoaderData
The data structure for the InLoader.
Definition: CrFwInLoader.c:56
void CrFwInLoaderSetInStream(FwSmDesc_t inStream)
Set the InStream from which the packets will be retrieved the next time the InLoader is executed...
Definition: CrFwInLoader.c:128
Definition of the InManager component.
void CrFwInFactoryReleaseInCmd(FwSmDesc_t inCmdInstance)
Release function for an InCommand.
CrFwInstanceId_t CrFwPcktGetCmdRepId(CrFwPckt_t pckt)
Return the command or report identifier of the command or report encapsulated in a packet...
Definition: CrFwPckt.c:339
Load failure.
Component Initialization Procedure (CIP) for the Base Component.
#define CR_FW_INLOADER_TYPE
Type identifier for the InLoader component.
FwSmDesc_t CrFwInFactoryMakeInRep(CrFwPckt_t pckt)
Make function for a component encapsulating an incoming report (InReport).
CrFwTypeId_t typeId
The type identifier of the framework component.
Definition: CrFwCmpData.h:83
CrFwDestSrc_t CrFwInLoaderDefGetReroutingDestination(CrFwDestSrc_t pcktDest)
Default implementation of the function which checks the legality of a destination and returns the re-...
Definition: CrFwInLoader.c:230
#define CR_FW_BASE_STATE_CONFIGURED
State identifier for state CONFIGURED in the Base State Machine.
CrFwPckt_t CrFwInStreamGetPckt(FwSmDesc_t smDesc)
Retrieve a packet from the InStream.
Definition: CrFwInStream.c:232
void CrFwRepErrInstanceIdAndDest(CrFwRepErrCode_t errCode, CrFwTypeId_t typeId, CrFwInstanceId_t instanceId, CrFwInstanceId_t secondaryInstanceId, CrFwDestSrc_t dest, CrFwPckt_t pckt)
Report an error which has three parameters attached to it representing the instance identifier of a c...
Definition: CrFwRepErr.c:109
void CrFwRepErrRep(CrFwRepErrCode_t errCode, CrFwTypeId_t typeId, CrFwInstanceId_t instanceId, FwSmDesc_t rep)
Report an error which has one parameter attached to it representing an report component.
Definition: CrFwRepErr.c:207
static CrFwInLoaderData_t inLoaderCmpSpecificData
The component-specific data for the InLoader.
Definition: CrFwInLoader.c:59
CrFwDestSrc_t(* CrFwInLoaderGetReroutingDest_t)(CrFwDestSrc_t)
Type for a pointer to the function which determines the re-routing destination of a packet...
Definition: CrFwInLoader.h:119
FwPrDesc_t CrFwCmpGetInitProc()
Retrieve the singleton instance of the CIP.
Definition: CrFwInitProc.c:48
unsigned char CrFwServType_t
Type used for the service type of a command or report.
FwSmDesc_t CrFwInFactoryMakeInCmd(CrFwPckt_t pckt)
Make function for a component encapsulating an incoming command (InCommand).
Component Reset Procedure (CRP) for the Base Component.
FwPrDesc_t initProc
The Component Initialization Procedure (CIP) (see CrFwInitProc.h).
Definition: CrFwCmpData.h:95
unsigned char CrFwServSubType_t
Type used for the command or report sub-type.
void CwFwBaseCmpDummyExecAction(FwPrDesc_t prDesc)
Dummy action executed in the single node of the Dummy Execution Procedure.
Definition of the InCommand Component of the framework.
static CrFwInLoaderGetReroutingDest_t getReroutingDest
Pointer to function which checks the legality of the packet destination.
Definition: CrFwInLoader.c:62
static void InLoaderLoadCmdRep(CrFwPckt_t pckt)
Load the command or report encapsulated in the argument packet into an InManager. ...
Definition: CrFwInLoader.c:168
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved