CORDET Framework - C2 Implementation
CrPsHkRep.c
Go to the documentation of this file.
1 
22 #include "CrPsHkRep.h"
23 
24 /* CrFramework includes */
25 #include "OutCmp/CrFwOutCmp.h"
26 #include "CrFwCmpData.h"
27 #include "Pckt/CrFwPckt.h"
28 
29 /* FwProfile includes */
30 #include "FwPrConfig.h"
31 #include "FwPrCore.h"
32 #include "FwSmConfig.h"
33 
34 #include <CrPsUserConstants.h>
35 #include <CrPsUtilitiesServHk.h>
36 #include <DataPool/CrPsDp.h>
37 #include <DataPool/CrPsDpServHk.h>
42 
43 #include <stdlib.h>
44 
45 #define HK_MAX_DP_MULT_SIZE 100
46 
47 uint32_t SampleBuffer[HK_MAX_REP][HK_MAX_N_REP][HK_MAX_N_GR][HK_N_SAMP_BUF];
48 
49 
50 CrFwBool_t CrPsHkRepEnableCheck(FwSmDesc_t smDesc)
51 {
52  CrPsSid_t sid, rdlSid, rdlSlot;
53 
54  CrFwCmpData_t *cmpData;
55  CrFwOutCmpData_t *cmpSpecificData;
56  CrFwPckt_t pckt;
58 
59  /* The report is enabled if its SID is defined in the RDL */
60 
61  cmpData = (CrFwCmpData_t *) FwSmGetData(smDesc);
62  cmpSpecificData = (CrFwOutCmpData_t *) cmpData->cmpSpecificData;
63  pckt = cmpSpecificData->pckt;
64  disc = CrFwPcktGetDiscriminant(pckt);
65 
66  /* Get the SID: discriminant for HK is the SID */
67  sid = (CrPsSid_t) disc;
68 
69  /* look for the slot */
70  for (rdlSlot = 0; rdlSlot < HK_N_REP_DEF; rdlSlot++)
71  {
72  rdlSid = getDpsidItem(rdlSlot);
73 
74  if (sid == rdlSid)
75  break;
76  }
77 
78  /* sid not defined in list */
79  if (rdlSlot == HK_N_REP_DEF)
80  {
81  return 0;
82  }
83 
84  return 1;
85 }
86 
87 CrFwBool_t CrPsHkRepReadyCheck(FwSmDesc_t smDesc)
88 {
89  CrFwCmpData_t *cmpData;
90  CrFwOutCmpData_t *cmpSpecificData;
91  CrFwPckt_t pckt;
94  CrPsSid_t sid, rdlSid, rdlSlot;
95 
96  /* Run the procedure Ready Check of HkRep Report of figure 9.5 */
97 
98  cmpData = (CrFwCmpData_t *) FwSmGetData(smDesc);
99  cmpSpecificData = (CrFwOutCmpData_t *) cmpData->cmpSpecificData;
100  pckt = cmpSpecificData->pckt;
101  disc = CrFwPcktGetDiscriminant(pckt);
102 
103  /* Get the SID: discriminant for HK is the SID */
104  sid = (CrPsSid_t) disc;
105 
106  /* look for the slot */
107  for (rdlSlot = 0; rdlSlot < HK_N_REP_DEF; rdlSlot++)
108  {
109  rdlSid = getDpsidItem(rdlSlot);
110 
111  if (sid == rdlSid)
112  break;
113  }
114 
115  /* Set prData of procedure */
116  /* initial setting of prData */
117  prData.smDesc = smDesc;
118  prData.rdlSlot = rdlSlot;
119  FwPrSetData(getPrDescHkRepReadyCheck(), &prData);
120 
121  FwPrStart(getPrDescHkRepReadyCheck());
122  FwPrExecute(getPrDescHkRepReadyCheck());
123 
124  cmpData = (CrFwCmpData_t *) FwSmGetData(smDesc);
125 
126  return cmpData->outcome;
127 }
128 
129 void CrPsHkRepUpdateAction(FwSmDesc_t smDesc)
130 {
131  CrPsSid_t sid, rdlSid, rdlSlot;
132 
133  CrFwCmpData_t *cmpData;
134  CrFwOutCmpData_t *cmpSpecificData;
135  CrFwPckt_t pckt;
137 
138  unsigned int i, j, k, s;
139 
140  CrFwCounterU4_t N1, NFA, N2;
141  CrPsParamId_t N1ParamId;
142  CrPsRepNum_t SCSampleRepNum;
143  CrPsParamId_t N2ParamId;
144  size_t size;
145  uint8_t N1ParamCharValue, N2ParamCharValue; /* TODO Types ??*/
146  uint16_t N1ParamShortValue, N2ParamShortValue;
147  uint32_t N1ParamIntValue, N2ParamIntValue;
148  uint32_t pos_data;
149  unsigned int offset;
150  unsigned char N1ParamValue[HK_MAX_DP_MULT_SIZE];
151 
152  /* Load the value of the simply-commutated data items from the data pool
153  * and that of the super-commutated data items from the Sampling Buffer
154  * associated to the report’s SID according to the Report Definition. */
155 
156  /* Get packet and discriminant */
157  cmpData = (CrFwCmpData_t *) FwSmGetData(smDesc);
158  cmpSpecificData = (CrFwOutCmpData_t *) cmpData->cmpSpecificData;
159  pckt = cmpSpecificData->pckt;
160  disc = CrFwPcktGetDiscriminant(pckt);
161 
162  /* Set SID equal to discriminant */
163  sid = (CrPsSid_t) disc;
164 
165  /* look for the slot */
166  for (rdlSlot = 0; rdlSlot < HK_N_REP_DEF; rdlSlot++)
167  {
168  rdlSid = getDpsidItem(rdlSlot);
169 
170  if (sid == rdlSid)
171  break;
172  }
173 
174  /* Set initial offset for first data value in packet */
175  pos_data = sizeof(TmHeader_t) + 1; /* SID = disc (uchar) is just taken in data field */
176 
177  /* Get N1 (nSimple) from data pool, the number of simple commutated data items */
178  N1 = getDpnSimpleItem(rdlSlot);
179 
180  if (N1!=0)
181  {
182 
183  /* Get N1 parameter IDs and put the corresponding values in the out-going packet */
184  for (i=0; i<N1; i++)
185  {
186  /* Get value for N1ParamId from data pool */
187  N1ParamId = getDplstIdItem(rdlSlot*HK_MAX_N_ITEMS + i);
188 
189  /* Set value in out-going packet */
190  size = getDpSize(N1ParamId);
191  switch (size)
192  {
193  case 1: /*TODO (01.02.2018) never reached in Testsuite */
194  getDpValue(N1ParamId, &N1ParamCharValue);
195  setPcktChar(pckt, pos_data, N1ParamCharValue);
196  pos_data += 1;
197  break;
198  case 2: /*TODO (01.02.2018) never reached in Testsuite */
199  getDpValue(N1ParamId, &N1ParamShortValue);
200  setPcktShort(pckt, pos_data, N1ParamShortValue);
201  pos_data += 2;
202  break;
203  case 4:
204  getDpValue(N1ParamId, &N1ParamIntValue);
205  setPcktInt(pckt, pos_data, N1ParamIntValue);
206  pos_data += 4;
207  break;
208  default:
209  getDpValue(N1ParamId, N1ParamValue);
210  if (size<=HK_MAX_DP_MULT_SIZE)
211  {
212  for (s=0; s<size; s++)
213  {
214  setPcktChar(pckt, pos_data, N1ParamValue[s]);
215  pos_data += 1;
216  }
217  }
218  break;
219  }
220  }
221 
222  }
223 
224  NFA = getNFA(rdlSlot);
225 
226  if (NFA!=0)
227  {
228  offset = 0;
229 
230  for (k=0; k<NFA; k++)
231  {
232  /* Get sample repetition number (rep[1..nGroup]) */
233  SCSampleRepNum = getDplstSampleRepItem(rdlSlot*HK_MAX_N_GR + k);
234 
235  /* Get N2 (nRep[1..nGroup]) */
236  N2 = getDplstNSampRepItem(rdlSlot*HK_MAX_N_GR + k);
237 
238  for (i=0; i<SCSampleRepNum; i++)
239  {
240  for (j=0; j<N2; j++)
241  {
242  N2ParamId = getDplstIdItem(rdlSlot*HK_MAX_N_ITEMS + N1 + offset + j);
243 
244  /* Set value in out-going packet */
245  size = getDpSize(N2ParamId);
246  switch (size)
247  {
248  case 1:/*TODO (01.02.2018) never reached in Testsuite */
249  /* Retrieve the i-th value of the j-th data item in the k-th group in the sampling buffer of ID l */
250  N2ParamCharValue = (uint8_t)getDpBufferElement(i, j, k, (uint32_t)getDpsampleBufIdItem(rdlSlot));
251  setPcktChar(pckt, pos_data, N2ParamCharValue);
252  pos_data += 1;
253  break;
254  case 2:/*TODO (01.02.2018) never reached in Testsuite */
255  /* Retrieve the i-th value of the j-th data item in the k-th group in the sampling buffer of ID l */
256  N2ParamShortValue = (uint16_t)getDpBufferElement(i, j, k, (uint32_t)getDpsampleBufIdItem(rdlSlot));
257  setPcktShort(pckt, pos_data, N2ParamShortValue);
258  pos_data += 2;
259  break;
260  case 4:
261  /* Retrieve the i-th value of the j-th data item in the k-th group in the sampling buffer of ID l */
262  N2ParamIntValue = (uint32_t)getDpBufferElement(i, j, k, (uint32_t)getDpsampleBufIdItem(rdlSlot));
263  setPcktInt(pckt, pos_data, N2ParamIntValue);
264  pos_data += 4;
265  break;
266  default:
267  break;
268  }
269  }
270  }
271 
272  /* update offset */
273  offset += N2;
274  }
275 
276  }
277 
278  cmpData->outcome = 1;
279 
280  return;
281 }
Type for the Framework Component Data (FCD).
uint32_t CrPsRepNum_t
Type used for the Repetition Number of a packet.
CrFwOutcome_t outcome
The outcome of an action or check executed by a state machine or by one of its procedures.
CrFwCounterU4_t i
CrPsCmd5EidStart function definitions.
CrFwDiscriminant_t CrFwPcktGetDiscriminant(CrFwPckt_t pckt)
Return the discriminant of the command or report encapsulated in a packet.
Interface through which applications can initialize and execute framework PUS extension components...
Header file to define all user-configurable constants and types for the IASW Application.
uint16_t CrPsParamId_t
Type used for the Parameter ID of a packet.
void CrPsHkRepUpdateAction(FwSmDesc_t smDesc)
Update action of the Periodic Housekeeping Report (3,25) out-going report packet. ...
Definition: CrPsHkRep.c:129
Interface for accessing data pool items.
Type for the data describing an OutComponent.
Header file to define all service and packet identifiers.
size_t getDpSize(ParameterId_t id)
Get the size of a datapool item by identifier.
Definition: CrPsDp.c:250
CrFwPckt_t pckt
Packet to which the out-going command or report is serialized.
Interface for creating and accessing a report or command packet.
void setPcktShort(void *p, uint32_t pos, uint16_t t)
Generic Setter for Short Values from a Packet.
Definition: CrPsPktUtil.c:80
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:30
#define HK_MAX_N_REP
Maximum number of data items in a super-commutated groups in a housekeeping/diagnostic report...
size_t getDpValue(ParameterId_t id, void *dest)
Get the value of a datapool item by identifier.
Definition: CrPsDp.c:191
static uint32_t getDpBufferElement(uint32_t i, uint32_t j, uint32_t k, uint32_t l)
Gets a Datapool Buffer Element.
Definition: CrPsDpServHk.h:118
static CrPsSid_t getDpsidItem(int i)
Gets the value of the i-th element in the datapool array sid.
Definition: CrPsDpServHk.h:289
CrFwBool_t CrPsHkRepEnableCheck(FwSmDesc_t smDesc)
Enable check of the Periodic Housekeeping Report (3,25) out-going report packet.
Definition: CrPsHkRep.c:50
auxiliary Interface for accessing fields in packets of service "ServHk".
void setPcktInt(void *p, uint32_t pos, uint32_t t)
Generic Setter for Int Values from a Packet.
Definition: CrPsPktUtil.c:68
static CrFwDiscriminant_t disc
Discriminant.
static CrFwCounterU4_t getNFA(int i)
Gets the number of super-commutated groups (NFA) from number of sample repetition numbers (rep[]) ...
Definition: CrPsDpServHk.h:140
void setPcktChar(void *p, uint32_t pos, uint8_t t)
Generic Setter for Character Values from a Packet.
Definition: CrPsPktUtil.c:92
#define HK_MAX_REP
Maximum value of the repetition number of a super- commutated group in a housekeeping/diagnostic repo...
generic Interface for accessing fields in packets.
FwPrDesc_t getPrDescHkRepReadyCheck()
Getter for HkRepReadyCheck procedure descriptor.
void * cmpSpecificData
Derived data which are specific to each type of framework component.
Declaration of the Periodic Housekeeping Report (3,25) or Periodic Diagnostic Report (3...
CrFwBool_t CrPsHkRepReadyCheck(FwSmDesc_t smDesc)
Ready check of the Periodic Housekeeping Report (3,25) out-going report packet.
Definition: CrPsHkRep.c:87
static CrPsNumberU2_t getDplstNSampRepItem(int i)
Gets the value of the i-th element in the datapool array lstNSampRep.
Definition: CrPsDpServHk.h:409
unsigned short CrFwDiscriminant_t
Type used for the discriminant of a command or report.
#define HK_N_REP_DEF
Number of Report Definitions in the Report Definition List (maximum number of housekeeping/diagnostic...
uint8_t CrPsSid_t
Type used for the Parameter Report Structure ID of a packet.
static CrPsParamId_t getDpsampleBufIdItem(int i)
Gets the value of the i-th element in the datapool array sampleBufId.
Definition: CrPsDpServHk.h:499
char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:36
#define HK_MAX_N_GR
Maximum number of super-commutated groups in a house- keeping/diagnostic report.
Definition of the OutComponent Component of the framework.
static uint16_t getDplstSampleRepItem(int i)
Gets the value of the i-th element in the datapool array lstSampleRep.
Definition: CrPsDpServHk.h:439
Interface for accessing fields in packets of service "ServHk".
static CrPsParamId_t getDplstIdItem(int i)
Gets the value of the i-th element in the datapool array lstId.
Definition: CrPsDpServHk.h:379
#define HK_N_SAMP_BUF
Number of service 3 Sampling Buffers.
Interface for accessing data pool items.
static CrPsNumberU2_t getDpnSimpleItem(int i)
Gets the value of the i-th element in the datapool array nSimple.
Definition: CrPsDpServHk.h:469
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved