CORDET Framework - C2 Implementation
CrPsCmd3s1StartFunc.c
Go to the documentation of this file.
1 
25 #include "CrPsCmd3s1StartCreate.h"
26 
27 /* CrFramework includes */
28 #include "Pckt/CrFwPckt.h"
30 #include "OutCmp/CrFwOutCmp.h"
32 #include "CrFwCmpData.h"
33 
35 #include "FwSmConstants.h"
36 #include "FwSmConfig.h"
37 #include "FwSmCore.h"
38 #include "FwPrDCreate.h"
39 #include "FwPrConfig.h"
40 #include "FwPrCore.h"
41 #include "FwPrConstants.h"
42 
43 #include <CrPsRepErr.h>
44 #include <CrPsUserConstants.h>
46 #include <DataPool/CrPsDpServHk.h>
50 
51 #include <stdlib.h>
52 #include <time.h>
53 
54 static FwSmDesc_t rep;
55 static CrPsSid_t rdlSlot;
56 
57 
58 /* ----------------------------------------------------------------------------------------------------------------- */
59 
61 void CrPsCmd3s1StartN1(FwPrDesc_t prDesc)
62 {
63  CrFwCmpData_t *cmpData;
64  FwSmDesc_t smDesc;
65 
66  /* Set action outcome to 'failure' with failure code VER_FULL_RDL */
67 
68  /* Get smDesc from OutCmp */
69  smDesc = FwPrGetData(prDesc);
70 
71  /* Set outcome in InCmd prData to 'failure' */
72  cmpData = (CrFwCmpData_t*) FwSmGetData(smDesc);
73  cmpData->outcome = (unsigned char)VER_FULL_RDL;
74  FwSmSetData(smDesc, cmpData);
75 
76  return;
77 }
78 
80 void CrPsCmd3s1StartN2(FwPrDesc_t prDesc)
81 {
82  CrFwCmpData_t *cmpData;
83  CrFwInCmdData_t *cmpSpecificData;
84  CrFwPckt_t pckt;
85  FwSmDesc_t smDesc;
86  CrFwServSubType_t tcServSubType;
87  CrPsSid_t sid;
88 
89  /* Retrieve a report of type (3,25) or (3,26) from the OutFactory */
90 
91  /* Get smDesc from prData */
92  smDesc = FwPrGetData(prDesc);
93 
94  /* Get inPckt */
95  cmpData = (CrFwCmpData_t*)FwSmGetData(smDesc);
96  cmpSpecificData = (CrFwInCmdData_t *) cmpData->cmpSpecificData;
97  pckt = cmpSpecificData->pckt;
98 
99  /* Get SubType */
100  tcServSubType = CrFwPcktGetServSubType(pckt);
101 
102  /* Get SID */
103  sid = getHkCreateCmdRepStrucId(pckt);
104 
105  /* Generate report of type (3,25) or (3,26) according to TC(3,1) or TC(3,2) */
106  if (tcServSubType == CRPS_HK_CREATE_HKSTRUCT_CMD)
107  {
108  rep = CrFwOutFactoryMakeOutCmp(CRPS_HK, CRPS_HK_HKPARAM_REP, sid, getHkRepSizeFromPckt(pckt)); /* arguments: type, subType, discriminant/evtId, length */
109  }
110  else if (tcServSubType == CRPS_HK_CREATE_DIAGSTRUCT_CMD)
111  {
112  rep = CrFwOutFactoryMakeOutCmp(CRPS_HK, CRPS_HK_DIAGPARAM_REP, sid, getHkRepSizeFromPckt(pckt)); /* arguments: type, subType, discriminant/evtId, length */
113  }
114 
115  return;
116 }
117 
119 void CrPsCmd3s1StartN3(FwPrDesc_t prDesc)
120 {
121  CrPsRepErrCode_t errCode;
122  CRFW_UNUSED(prDesc);
123 
124  /* Generate error report OUTFACTORY_FAIL */
125 
126  errCode = crOutfactoryFail;
128 
129  return;
130 }
131 
133 void CrPsCmd3s1StartN4(FwPrDesc_t prDesc)
134 {
135  CrFwCmpData_t *cmpData;
136  CrFwInCmdData_t *cmpSpecificData;
137  CrFwPckt_t pckt;
138  FwSmDesc_t smDesc;
140 
141  /* Load the report in the OutLoader */
142 
143  smDesc = FwPrGetData(prDesc);
144 
145  /* Get inPckt */
146  cmpData = (CrFwCmpData_t*) FwSmGetData(smDesc);
147  cmpSpecificData = (CrFwInCmdData_t *) cmpData->cmpSpecificData;
148  pckt = cmpSpecificData->pckt;
149 
150  dest = CrFwPcktGetSrc(pckt);
151  CrFwOutCmpSetDest(rep, dest);
152 
154 
155  return;
156 }
157 
159 void CrPsCmd3s1StartN6(FwPrDesc_t prDesc)
160 {
161  CrFwCmpData_t *cmpData;
162  FwSmDesc_t smDesc;
163 
164  /* Set action outcome to 'success' */
165 
166  /* Get smDesc from OutCmp */
167  smDesc = FwPrGetData(prDesc);
168 
169  /* Set outcome in InCmd prData to 'success' */
170  cmpData = (CrFwCmpData_t*) FwSmGetData(smDesc);
171  cmpData->outcome = 1;
172  FwSmSetData(smDesc, cmpData);
173 
174  return;
175 }
176 
178 void CrPsCmd3s1StartN7(FwPrDesc_t prDesc)
179 {
180  CrFwCmpData_t *cmpData;
181  CrFwInCmdData_t *cmpSpecificData;
182  CrFwPckt_t pckt;
183  FwSmDesc_t smDesc;
184  CrPsSid_t sid;
185 
186  /* Set action outcome to 'failure' with code VER_SID_IN_USE and load SID in verFailData data pool item */
187 
188  /* Get smDesc from OutCmp */
189  smDesc = FwPrGetData(prDesc);
190 
191  /* Set outcome in InCmd prData to 'failure' */
192  cmpData = (CrFwCmpData_t*) FwSmGetData(smDesc);
193  cmpData->outcome = (unsigned char)VER_SID_IN_USE;
194  FwSmSetData(smDesc, cmpData);
195 
196  /* Get inPckt */
197  cmpSpecificData = (CrFwInCmdData_t *) cmpData->cmpSpecificData;
198  pckt = cmpSpecificData->pckt;
199 
200  /* Get SID from inPckt */
201  sid = getHkCreateCmdRepStrucId(pckt);
202 
203  /* Load SID in verFailData data pool item */
204  setDpverFailData((uint32_t)sid);
205 
206  return;
207 }
208 
210 void CrPsCmd3s1StartN8(FwPrDesc_t prDesc)
211 {
212  CrFwCmpData_t *cmpData;
213  FwSmDesc_t smDesc;
214 
215  /* Set action outcome to 'failure' with failure code VER_RDL_CONSTR and load identifier of constraint in verFailData */
216 
217  /* Get smDesc from OutCmp */
218  smDesc = FwPrGetData(prDesc);
219 
220  /* Set outcome in InCmd prData to 'failure' */
221  cmpData = (CrFwCmpData_t*) FwSmGetData(smDesc);
222  cmpData->outcome = (unsigned char)VER_RDL_CONSTR;
223  FwSmSetData(smDesc, cmpData);
224 
225  /* Load identifier of constraint in verFailData */
226  setDpverFailData((CrFwCounterU4_t)VER_RDL_CONSTR);
227 
228  return;
229 }
230 
232 void CrPsCmd3s1StartN9(FwPrDesc_t prDesc)
233 {
234  CrFwCmpData_t *cmpData;
235  FwSmDesc_t smDesc;
236 
237  /* Set action outcome to 'failure' with code VER_DUPL_DI and load identifier of duplicated DI in verFailData */
238 
239  /* Get smDesc from OutCmp */
240  smDesc = FwPrGetData(prDesc);
241 
242  /* Set outcome in InCmd prData to 'failure' */
243  cmpData = (CrFwCmpData_t*) FwSmGetData(smDesc);
244  cmpData->outcome = (unsigned char)VER_DUPL_DI;
245  FwSmSetData(smDesc, cmpData);
246 
247  /* Load identifier of duplicated DI in verFailData */
248  setDpverFailData((CrPsFailData_t)VER_DUPL_DI);
249 
250  return;
251 }
252 
254 void CrPsCmd3s1StartN10(FwPrDesc_t prDesc)
255 {
256  CrFwCmpData_t *cmpData;
257  FwSmDesc_t smDesc;
258 
259  /* Set action outcome to 'failure' with failure code VER_REP_CR_FD */
260 
261  /* Get smDesc from OutCmp */
262  smDesc = FwPrGetData(prDesc);
263 
264  /* Set outcome in InCmd prData to 'failure' */
265  cmpData = (CrFwCmpData_t*) FwSmGetData(smDesc);
266  cmpData->outcome = (unsigned char)VER_REP_CR_FD;
267  FwSmSetData(smDesc, cmpData);
268 
269  return;
270 }
271  /* TODO (01.02.2018): cannot be reached due to Guard always returns 1 */
273 void CrPsCmd3s1StartN11(FwPrDesc_t prDesc)
274 {
275  CrFwCmpData_t *cmpData;
276  FwSmDesc_t smDesc;
277 
278  /* Set action outcome to 'failure' with falure code VER_OUTLOADER_FD */
279 
280  /* Get smDesc from OutCmp */
281  smDesc = FwPrGetData(prDesc);
282 
283  /* Set outcome in InCmd prData to 'failure' */
284  cmpData = (CrFwCmpData_t*) FwSmGetData(smDesc);
285  cmpData->outcome = (unsigned char)VER_OUTLOADER_FD;
286  FwSmSetData(smDesc, cmpData);
287 
288  return;
289 }
290 
291 /**************/
292 /*** GUARDS ***/
293 /**************/
294 
296 FwPrBool_t CrPsCmd3s1StartG1(FwPrDesc_t prDesc)
297 {
298  CrPsSid_t rdlSid;
299 
300  CRFW_UNUSED(prDesc);
301  /* There is no free slot in the RDL */
302 
303  /* look for a free slot */
304  for (rdlSlot = 0; rdlSlot < HK_N_REP_DEF; rdlSlot++)
305  {
306  rdlSid = getDpsidItem(rdlSlot);
307 
308  if (rdlSid == 0)
309  break;
310  }
311 
312  if (rdlSlot == HK_N_REP_DEF)
313  {
314  return 1;
315  }
316  else
317  {
318  return 0;
319  }
320 }
321 
323 FwPrBool_t CrPsCmd3s1StartG2(FwPrDesc_t prDesc)
324 {
325  CrFwCmpData_t *cmpData;
326  CrFwInCmdData_t *cmpSpecificData;
327  CrFwPckt_t pckt;
328  FwSmDesc_t smDesc;
329  CrPsSid_t sid;
330  CrFwCounterU4_t N1;
331 
332  /* One or more constraints listed in table 9.1 are not satisfied */
333 
334  /* Get smDesc from prData */
335  smDesc = FwPrGetData(prDesc);
336 
337  /* Get in data */
338  cmpData = (CrFwCmpData_t*)FwSmGetData(smDesc);
339  cmpSpecificData = (CrFwInCmdData_t *) cmpData->cmpSpecificData;
340  pckt = cmpSpecificData->pckt;
341 
342  /* Get sid and check: Integer in range: 1..HK_MAX_SID */
343  sid = getHkCreateCmdRepStrucId(pckt);
344  if ((sid == 0) || (sid > HK_MAX_SID))
345  return 1;
346 
347  /* Get nSimple and check: Integer in range: 1..HK_MAX_N_SIMPLE */
348  N1 = getHkCreateCmdN1(pckt);
349  if ((N1 == 0) || (N1 > HK_MAX_N_SIMPLE))
350  return 1;
351 
352  return 0;
353 }
354 
356 FwPrBool_t CrPsCmd3s1StartG3(FwPrDesc_t prDesc)
357 {
358  CrFwCmpData_t *cmpData;
359  CrFwInCmdData_t *cmpSpecificData;
360  CrFwPckt_t pckt;
361  FwSmDesc_t smDesc;
362  CrPsSid_t rdlSid, sid;
363 
364  /* The SID in the command is already in use */
365 
366  /* Get smDesc from prData */
367  smDesc = FwPrGetData(prDesc);
368 
369  /* Get in data */
370  cmpData = (CrFwCmpData_t*)FwSmGetData(smDesc);
371  cmpSpecificData = (CrFwInCmdData_t *) cmpData->cmpSpecificData;
372  pckt = cmpSpecificData->pckt;
373 
374  /* Get sid */
375  sid = getHkCreateCmdRepStrucId(pckt);
376 
377  /* look for the same sid in RDL */
378  for (rdlSlot = 0; rdlSlot < HK_N_REP_DEF; rdlSlot++)
379  {
380  rdlSid = getDpsidItem(rdlSlot);
381 
382  if (rdlSid == sid)
383  break;
384  }
385 
386  if (rdlSlot == HK_N_REP_DEF)
387  {
388  return 0;
389  }
390  else
391  {
392  return 1;
393  }
394 }
395 
397 FwPrBool_t CrPsCmd3s1StartG4(FwPrDesc_t prDesc)
398 {
399  CrFwCmpData_t *cmpData;
400  CrFwInCmdData_t *cmpSpecificData;
401  CrFwPckt_t pckt;
402  FwSmDesc_t smDesc;
403  uint16_t currentDataItem, checkDataItem;
404  CrFwCounterU4_t i, k, m, a=0;
405  CrFwCounterU4_t N1, NFA, N2[10], LSTNMB; /* TODO: set maximum as constant */
406  unsigned short dataItemArray[100]; /* TODO: set maximum as constant */
407 
408  /* The same data item identifier appears twice in the definition of the new report */
409 
410  /* Get smDesc from prData */
411  smDesc = FwPrGetData(prDesc);
412 
413  /* Get in data */
414  cmpData = (CrFwCmpData_t*)FwSmGetData(smDesc);
415  cmpSpecificData = (CrFwInCmdData_t *) cmpData->cmpSpecificData;
416  pckt = cmpSpecificData->pckt;
417 
418  /* Get N1 and NFA */
419  N1 = getHkCreateCmdN1(pckt); /* nSimple */
420  NFA = getHkCreateCmdNFA(pckt); /* number of groups */
421 
422  /* Calculate number of data items: only nSimple items ... */
423  LSTNMB = N1;
424 
425  /* Get N2 NFA times; NFA is number of groups (nGroup) */
426  for (i=0; i<NFA; i++)
427  {
428  N2[i] = getHkCreateCmdN2(pckt, i+1); /* nRep[GroupX] */
429  /* ... add super-cummutated group items */
430  LSTNMB += N2[i];
431  }
432 
433  /* Collect all data items in an array */
434  for (k=0; k<N1; k++)
435  {
436  dataItemArray[k] = getHkCreateCmdN1ParamIdItem(pckt, k+1);
437  }
438 
439  for (k=0; k<NFA; k++)
440  {
441  for (m=0; m<N2[k]; m++)
442  {
443  dataItemArray[N1+a] = getHkCreateCmdN2ParamIdItem(pckt, k+1, m+1);
444  a+=1;
445  }
446  }
447 
448  /* Go through all data item identifiers */
449  for (i=0; i<LSTNMB; i++)
450  {
451  /* Get next data item */
452  checkDataItem = dataItemArray[i];
453 
454  for(k=0;k<LSTNMB-i-1;k++)
455  {
456  /* Get next data item identifiers coming afterwards */
457  currentDataItem = dataItemArray[i+k+1];
458 
459  /* Compare with data item identifiers */
460  if (checkDataItem == currentDataItem)
461  return 1;
462  }
463  }
464 
465  return 0;
466 }
467 
469 FwPrBool_t CrPsCmd3s1StartG5(FwPrDesc_t prDesc)
470 {
471  CRFW_UNUSED(prDesc);
472 
473  /* Factory fails to return the report */
474 
475  if (rep == NULL)
476  {
477  return 1;
478  }
479  else
480  {
481  return 0;
482  }
483 }
484 
486 FwPrBool_t CrPsCmd3s1StartG6(FwPrDesc_t prDesc)
487 {
488  CRFW_UNUSED(prDesc);
489 
490  /* Load Operation is successful */
491  /* TBV: could this be done with checking the numberOfPendingOutCmp */
492  /* make a Ticket!! ??? application Error ??? */
493 
494  return 1;
495 }
496 
497 /* ----------------------------------------------------------------------------------------------------------------- */
498 
Type for the Framework Component Data (FCD).
CrFwOutcome_t outcome
The outcome of an action or check executed by a state machine or by one of its procedures.
CrFwDestSrc_t CrFwPcktGetSrc(CrFwPckt_t pckt)
Return the source of the command or report encapsulated in a packet.
CrFwCounterU4_t i
CrPsCmd5EidStart function definitions.
#define CRPS_REQVERIF_PROG_FAIL
Subtype identifier of the Request Verification Progress Failed out-going report packet.
#define CRFW_UNUSED(x)
A macro that can be used to specify that a function parameter is not used.
Definition: CrFwConstants.h:27
unsigned char CrFwServSubType_t
Type used for the command or report sub-type.
FwPrBool_t CrPsCmd3s1StartG1(FwPrDesc_t prDesc)
Guard on the Control Flow from DECISION1 to N1.
Header file to define all user-configurable constants and types for the IASW Application.
void CrPsCmd3s1StartN6(FwPrDesc_t prDesc)
Action for node N6.
#define CRPS_HK_CREATE_DIAGSTRUCT_CMD
Subtype identifier of the Housekeeping Create a Diagnostic Parameter Report Structure command packet...
FwPrBool_t CrPsCmd3s1StartG6(FwPrDesc_t prDesc)
Guard on the Control Flow from DECISION6 to N6.
Interface for accessing data pool items.
FwPrBool_t CrPsCmd3s1StartG5(FwPrDesc_t prDesc)
Guard on the Control Flow from DECISION5 to N3.
Definition of the OutFactory component.
CrFwPckt_t pckt
Packet holding the InCommand.
unsigned char CrFwDestSrc_t
Type used for the command or report destination and source.
#define HK_MAX_N_SIMPLE
Maximum number of simply-commutated parameters in a housekeeping/diagnostic report.
Header file to define all service and packet identifiers.
#define HK_MAX_SID
Maximum value of a service 3 Structure Identifier (SID)
Interface for creating and accessing a report or command packet.
static void setDpverFailData(CrPsFailData_t verFailData)
Sets the value of the datapool item verFailData.
static FwSmDesc_t rep
CrPsCmd3s1Start function definitions.
void CrPsCmd3s1StartN2(FwPrDesc_t prDesc)
Action for node N2.
size_t getHkRepSizeFromPckt(void *p)
Get the size of a HkRep Housekeeping packet.
void CrPsCmd3s1StartN8(FwPrDesc_t prDesc)
Action for node N8.
FwPrBool_t CrPsCmd3s1StartG2(FwPrDesc_t prDesc)
Guard on the Control Flow from DECISION2 to N8.
#define CRPS_HK_HKPARAM_REP
Subtype identifier of the Housekeeping Housekeeping Parameter Report out-going report packet...
static CrPsSid_t getDpsidItem(int i)
Gets the value of the i-th element in the datapool array sid.
Definition: CrPsDpServHk.h:289
void CrFwOutLoaderLoad(FwSmDesc_t outCmp)
Load an OutComponent into its OutManager.
auxiliary Interface for accessing fields in packets of service "ServHk".
void CrPsCmd3s1StartN9(FwPrDesc_t prDesc)
Action for node N9.
The Outfactory failed to make the component (see CrPsRepErr.h)
CrFwCounterU4_t getHkCreateCmdN2(void *p, CrFwCounterU4_t NFA)
Get "N2" from "HkCreateCmd" packet.
Interface for accessing data pool items.
CrPsRepErrCode_t
Identifier for the errors reported through the error reporting interface of CrFwRepErr.h.
#define CRPS_HK_DIAGPARAM_REP
Subtype identifier of the Housekeeping Diagnostic Parameter Report out-going report packet...
void CrPsCmd3s1StartN7(FwPrDesc_t prDesc)
Action for node N7.
void CrPsCmd3s1StartN10(FwPrDesc_t prDesc)
Action for node N10.
uint32_t CrPsFailData_t
Type used for the Failure Data of a packet.
void * cmpSpecificData
Derived data which are specific to each type of framework component.
void CrPsCmd3s1StartN3(FwPrDesc_t prDesc)
Action for node N3.
void CrPsCmd3s1StartN4(FwPrDesc_t prDesc)
Action for node N4.
Create one instance of the CrPsCmd3s1Start procedure.
FwPrBool_t CrPsCmd3s1StartG4(FwPrDesc_t prDesc)
Guard on the Control Flow from DECISION4 to N9.
void CrPsCmd3s1StartN11(FwPrDesc_t prDesc)
Action for node N11.
CrFwServSubType_t CrFwPcktGetServSubType(CrFwPckt_t pckt)
Return the service sub-type of the command or report encapsulated in a packet.
static CrPsSid_t getHkCreateCmdRepStrucId(void *p)
Get "RepStrucId" from "HkCreateCmd" packet.
static CrFwDestSrc_t dest
Destination.
void CrPsRepErr(CrPsRepErrCode_t errCode, CrFwServType_t repType, CrFwServSubType_t repSubType, CrFwDiscriminant_t repDiscriminant)
Report an error which has no parameters attached to it.
Definition: CrPsRepErr.c:37
#define CRPS_HK
Type identifier of the Housekeeping Data Report out-going report packet.
#define CRPS_HK_CREATE_HKSTRUCT_CMD
Subtype identifier of the Housekeeping Create a Housekeeping Parameter Report Structure command packe...
Interface for reporting an error detected by a PUS Extension component.
#define HK_N_REP_DEF
Number of Report Definitions in the Report Definition List (maximum number of housekeeping/diagnostic...
CrPsParamId_t getHkCreateCmdN2ParamIdItem(void *p, CrFwCounterU4_t NFA, CrFwCounterU4_t N2)
Get "N2ParamID" from "HkCreateCmd" packet.
uint8_t CrPsSid_t
Type used for the Parameter Report Structure ID of a packet.
char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:36
Definition of the OutComponent Component of the framework.
void CrFwOutCmpSetDest(FwSmDesc_t smDesc, CrFwDestSrc_t dest)
Set the destination of the OutComponent.
Definition: CrFwOutCmp.c:192
Interface for accessing fields in packets of service "ServHk".
Type for the data describing an InCommand.
#define VER_FULL_RDL
Outcome Failure Codes for Service 3 (Housekeeping)
CrFwCounterU4_t getHkCreateCmdNFA(void *p)
Get "NFA" from "HkCreateCmd" packet.
void CrPsCmd3s1StartN1(FwPrDesc_t prDesc)
Action for node N1.
FwPrBool_t CrPsCmd3s1StartG3(FwPrDesc_t prDesc)
Guard on the Control Flow from DECISION3 to N7.
CrPsParamId_t getHkCreateCmdN1ParamIdItem(void *p, CrFwCounterU4_t N)
Get "N1ParamId" arrayItem from "HkCreateCmd" packet.
Definition of the OutLoader component.
static CrFwCounterU4_t getHkCreateCmdN1(void *p)
Get "N1" from "HkCreateCmd" packet.
FwSmDesc_t CrFwOutFactoryMakeOutCmp(CrFwServType_t type, CrFwServSubType_t subType, CrFwDiscriminant_t discriminant, CrFwPcktLength_t length)
Make function for an OutComponent.
#define CRPS_REQVERIF
Type identifier of the Request Verification Service.
Definition: CrPsConstants.h:80
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved