CORDET Framework - C2 Implementation
CrPsLptFunc.c
Go to the documentation of this file.
1 
25 #include "CrPsLptCreate.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 <CrPsUtilitiesServLpt.h>
44 #include <DataPool/CrPsDpServLpt.h>
46 #include <CrPsRepErr.h>
47 
48 #include <time.h>
49 #include <stdlib.h>
50 
51 CrFwBool_t FirstPartFlag, SecondPartFlag, LastPartFlag;
52 uint32_t LptBufferId;
53 
54 
55 /* ----------------------------------------------------------------------------------------------------------------- */
56 
58 void CrPsLptDownTransferEntryAction(FwSmDesc_t smDesc)
59 {
60  CRFW_UNUSED(smDesc);
61 
62 
63  LptBufferId = DownTransferLptBufferId;
64 
65  /* nOfDownLinks++ */
67 
68  /* partSeqNmb = 1 */
69  setDppartSeqNmbItem(LptBufferId, 1);
70 
71  /* lptRemSize = lptSize */
72  setDplptRemSizeItem(LptBufferId, getDplptSizeItem(LptBufferId));
73 
74  /* Set Flag_2, Flag_3 and Flag_4 to True */
75  FirstPartFlag = 1;
76  SecondPartFlag = 1;
77  LastPartFlag = 1;
78 
79  return;
80 }
81 
83 void CrPsLptDownTransferExitAction(FwSmDesc_t smDesc)
84 {
85  CRFW_UNUSED(smDesc);
86 
87  LptBufferId = DownTransferLptBufferId;
88 
89  /* Increment largeMsgTransId by LPT\_N\_BUF; */
90  setDplargeMsgTransIdItem(LptBufferId, getDplargeMsgTransIdItem(LptBufferId) + LPT_N_BUF);
91 
92  /* nOfDownLinks-- */
94 
95  return;
96 }
97 
99 void CrPsLptDownTransferDoAction(FwSmDesc_t smDesc)
100 {
101  FwSmDesc_t rep;
102 
103  CRFW_UNUSED(smDesc);
104 
105  LptBufferId = DownTransferLptBufferId;
106 
107  /* if (partSeqNmb==1 && Flag_2) {
108  Load (13,1) report with lptDest as destination;
109  Flag_2 = False; } */
110  if ((getDppartSeqNmbItem(LptBufferId) == 1) && FirstPartFlag)
111  {
113  if (rep == NULL)
114  {
116  }
117  else
118  {
119  CrFwOutCmpSetDest(rep, getDplptSrcItem(LptBufferId));
120  CrFwOutLoaderLoad(rep);
121  FirstPartFlag = 0;
122  }
123  }
124  /* elseif ((partSeqNmb==2 && lptRemSize > partSize && Flag_3) {
125  Load (13,2) report with lptDest as destination;
126  Flag_3 = False; } */
127  else if ((getDppartSeqNmbItem(LptBufferId) == 2) && (getDplptRemSizeItem(LptBufferId) > CR_FW_MAX_PCKT_LENGTH - (sizeof(TmHeader_t) + sizeof(CrPsTid_t) + sizeof(CrPsNumberU4_t) + CRC_LENGTH)) && SecondPartFlag)
128  {
130  if (rep == NULL)
131  {
133  }
134  else
135  {
136  CrFwOutCmpSetDest(rep, getDplptSrcItem(LptBufferId));
137  CrFwOutLoaderLoad(rep);
138  SecondPartFlag = 0;
139  }
140  }
141  /* elseif (lptRemSize <= partSize && Flag_4) {
142  Load (13,3) report with lptDest as destination;
143  Flag_4 = False; } */
144  else if ((getDplptRemSizeItem(LptBufferId) <= CR_FW_MAX_PCKT_LENGTH - (sizeof(TmHeader_t) + sizeof(CrPsTid_t) + sizeof(CrPsNumberU4_t) + CRC_LENGTH)) && LastPartFlag)
145  {
146  rep = (FwSmDesc_t) CrFwOutFactoryMakeOutCmp(CRPS_LPT, CRPS_LPT_DOWNLAST_REP, 0, sizeof(TmHeader_t) + sizeof(CrPsTid_t) + sizeof(CrPsNumberU4_t) + CRC_LENGTH + getDplptRemSizeItem(LptBufferId));
147  if (rep == NULL)
148  {
150  }
151  else
152  {
153  CrFwOutCmpSetDest(rep, getDplptSrcItem(LptBufferId));
154  CrFwOutLoaderLoad(rep);
155  LastPartFlag = 0;
156  }
157  }
158 
159  return;
160 }
161 
163 void CrPsLptUpTransferEntryAction(FwSmDesc_t smDesc)
164 {
165  CRFW_UNUSED(smDesc);
166 
167  LptBufferId = UpTransferLptBufferId;
168 
169  /* nOfUpLinks++ */
171 
172  /* lptFailCode = NO_FAIL */
173  setDplptFailCodeItem(LptBufferId, LPT_FAILCODE_NO_FAIL);
174 
175  return;
176 }
177 
179 void CrPsLptUpTransferDoAction(FwSmDesc_t smDesc)
180 {
181  CrPsTimeOut_t timeOut;
182  CrFwTimeStamp_t ts;
183  time_t coarse_prev, coarse_now;
184  uint16_t fine_prev, fine_now;
185 
186  CRFW_UNUSED(smDesc);
187 
188  LptBufferId = UpTransferLptBufferId;
189 
190  /* if (Flag_1) lptFailCode = TIME_OUT */
191  /* Flag_1 is true if the time since the last up-transfer
192  command (as given by lptTime) is larger than lptTimeOut */
193 
194  timeOut = getDplptTimeOutItem(LptBufferId);
195 
196  ts = getDplptTimeItem(LptBufferId);
197  coarse_prev = (ts.t[0] << 24) | (ts.t[1] << 16) | (ts.t[2] << 8) | ts.t[3];
198  fine_prev = (ts.t[4] << 7) | (ts.t[5] & 0xfe);
199 
201  coarse_now = (ts.t[0] << 24) | (ts.t[1] << 16) | (ts.t[2] << 8) | ts.t[3];
202  fine_now = (ts.t[4] << 7) | (ts.t[5] & 0xfe);
203 
204  if ((int)(coarse_now - coarse_prev) > (int)timeOut)
205  {
206  /* lptFailCode = TIME_OUT */
207  setDplptFailCodeItem(LptBufferId, LPT_FAILCODE_TIME_OUT);
208  }
209 
210  CRFW_UNUSED(fine_prev);
211  CRFW_UNUSED(fine_now);
212  return;
213 }
214 
216 void CrPsLptUpTransferExitAction(FwSmDesc_t smDesc)
217 {
218  CRFW_UNUSED(smDesc);
219 
220  /* nOfUpLinks-- */
222 
223  return;
224 }
225 
227 void CrPsLptGenerateAbortEvent(FwSmDesc_t smDesc)
228 {
229  CRFW_UNUSED(smDesc);
230 
231  /* Generate event EVT_DOWN_ABORT */
232  CrPsRepErr(EVT_DOWN_ABORT, 13, 0, 0);
233 
234  return;
235 }
236 
238 FwSmBool_t CrPsLptIsTransferFinished(FwSmDesc_t smDesc)
239 {
240  CRFW_UNUSED(smDesc);
241 
242  /* [ Transfer is finished ] */
243 
244  LptBufferId = DownTransferLptBufferId;
245 
246  if (getDplptRemSizeItem(LptBufferId) == 0)
247  {
248  return 1;
249  }
250  else
251  {
252  return 0;
253  }
254 }
255 
257 void CrPsLptLoadReport(FwSmDesc_t smDesc)
258 {
259  FwSmDesc_t rep;
260 
261  CRFW_UNUSED(smDesc);
262 
263  /* Load (13,16) report */
264 
265  rep = (FwSmDesc_t) CrFwOutFactoryMakeOutCmp(CRPS_LPT, CRPS_LPT_UPABORT_REP, 0, sizeof(TmHeader_t) + sizeof(CrPsTid_t) + sizeof(CrPsNumberU4_t));
266  if (rep == NULL)
267  {
268  /* TM(13,16) OUTFACTORY_FAIL */
270  }
271  else
272  {
273  CrFwOutCmpSetDest(rep, 1);
274  CrFwOutLoaderLoad(rep);
275  }
276 
277  return;
278 }
279 
281 FwSmBool_t CrPsLptIsFailed(FwSmDesc_t smDesc)
282 {
283  CRFW_UNUSED(smDesc);
284 
285  LptBufferId = UpTransferLptBufferId;
286 
287  /* [ lptFailCode != NO_FAIL ] */
288  if (getDplptFailCodeItem(LptBufferId) != LPT_FAILCODE_NO_FAIL)
289  return 1;
290  else
291  return 0;
292 }
293 
295 void CrPsLptInitialization(FwSmDesc_t smDesc)
296 {
297  uint32_t i;
298 
299  CRFW_UNUSED(smDesc);
300 
301  /* Initialize largeMsgTransId */
302  for (i=0; i<LPT_N_BUF; i++)
303  {
305  }
306 
307  return;
308 }
309 
310 /* ----------------------------------------------------------------------------------------------------------------- */
311 
static void setDpnOfDownlinks(CrFwCounterU4_t nOfDownlinks)
Sets the value of the datapool item nOfDownlinks.
CrFwCounterU4_t i
CrPsCmd5EidStart function definitions.
void CrPsLptUpTransferExitAction(FwSmDesc_t smDesc)
Exit Action for the state UP_TRANSFER.
Definition: CrPsLptFunc.c:216
static CrFwCounterU4_t getDpnOfUplinks()
Gets the value of the datapool item nOfUplinks.
#define CR_FW_MAX_PCKT_LENGTH
The maximum size in number of bytes of a packet.
#define CRFW_UNUSED(x)
A macro that can be used to specify that a function parameter is not used.
Definition: CrFwConstants.h:27
static CrPsSize_t getDplptRemSizeItem(int i)
Gets the value of the i-th element in the datapool array lptRemSize.
static void setDplargeMsgTransIdItem(int i, CrPsTid_t largeMsgTransId)
Sets the value of the i-th element in the datapool array largeMsgTransId.
#define CRC_LENGTH
The length of CRC.
#define CRPS_LPT_DOWNFIRST_REP
Subtype identifier of the Large Packet Transfer First Downlink Part out-going report packet...
static void setDplptFailCodeItem(int i, CrPsFailCode_t lptFailCode)
Sets the value of the i-th element in the datapool array lptFailCode.
Interface for accessing data pool items.
static CrPsTimeOut_t getDplptTimeOutItem(int i)
Gets the value of the i-th element in the datapool array lptTimeOut.
FwSmDesc_t rep
CrPsCmd3s9Prgr function definitions.
Definition of the OutFactory component.
Header file to define all service and packet identifiers.
Interface for creating and accessing a report or command packet.
Interface through which applications can initialize and execute framework PUS extension components...
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:30
void CrPsLptLoadReport(FwSmDesc_t smDesc)
Action on the transition from UP_TRANSFER to INACTIVE.
Definition: CrPsLptFunc.c:257
void CrPsLptGenerateAbortEvent(FwSmDesc_t smDesc)
Action on the transition from DOWN_TRANSFER to INACTIVE.
Definition: CrPsLptFunc.c:227
void CrPsLptUpTransferDoAction(FwSmDesc_t smDesc)
Do Action for the state UP_TRANSFER.
Definition: CrPsLptFunc.c:179
Create one instance of the CrPsLpt state machine.
static void setDpnOfUplinks(CrFwCounterU4_t nOfUplinks)
Sets the value of the datapool item nOfUplinks.
static CrPsFailCode_t getDplptFailCodeItem(int i)
Gets the value of the i-th element in the datapool array lptFailCode.
static void setDplptRemSizeItem(int i, CrPsSize_t lptRemSize)
Sets the value of the i-th element in the datapool array lptRemSize.
static CrFwCounterU4_t getDpnOfDownlinks()
Gets the value of the datapool item nOfDownlinks.
void CrPsLptDownTransferDoAction(FwSmDesc_t smDesc)
Do Action for the state DOWN_TRANSFER.
Definition: CrPsLptFunc.c:99
static CrPsTid_t getDplargeMsgTransIdItem(int i)
Gets the value of the i-th element in the datapool array largeMsgTransId.
void CrFwOutLoaderLoad(FwSmDesc_t outCmp)
Load an OutComponent into its OutManager.
#define CRPS_LPT_UPABORT_REP
Subtype identifier of the Large Packet Transfer Abort Uplink out-going report packet.
The Outfactory failed to make the component (see CrPsRepErr.h)
void CrPsLptUpTransferEntryAction(FwSmDesc_t smDesc)
Entry Action for the state UP_TRANSFER.
Definition: CrPsLptFunc.c:163
#define CRPS_LPT_DOWNINTER_REP
Subtype identifier of the Large Packet Transfer Intermediate Downlink Part out-going report packet...
#define CRPS_LPT_DOWNLAST_REP
Subtype identifier of the Large Packet Transfer Last Downlink Part out-going report packet...
static CrPsSize_t getDplptSizeItem(int i)
Gets the value of the i-th element in the datapool array lptSize.
CrFwBool_t FirstPartFlag
CrPsLpt function definitions.
Definition: CrPsLptFunc.c:51
FwSmBool_t CrPsLptIsTransferFinished(FwSmDesc_t smDesc)
Guard on the transition from DOWN_TRANSFER to INACTIVE.
Definition: CrPsLptFunc.c:238
#define CRPS_LPT
Type identifier of the Large Packet Transfer Service.
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
static CrPsDestSrc_t getDplptSrcItem(int i)
Gets the value of the i-th element in the datapool array lptSrc.
FwSmBool_t CrPsLptIsFailed(FwSmDesc_t smDesc)
Guard on the transition from UP_TRANSFER to INACTIVE.
Definition: CrPsLptFunc.c:281
Interface for reporting an error detected by a PUS Extension component.
Definition of the OutComponent Component of the framework.
static CrFwCounterU4_t getDppartSeqNmbItem(int i)
Gets the value of the i-th element in the datapool array partSeqNmb.
static CrFwTimeStamp_t getDplptTimeItem(int i)
Gets the value of the i-th element in the datapool array lptTime.
void CrPsLptDownTransferExitAction(FwSmDesc_t smDesc)
Exit Action for the state DOWN_TRANSFER.
Definition: CrPsLptFunc.c:83
void CrPsLptDownTransferEntryAction(FwSmDesc_t smDesc)
Entry Action for the state DOWN_TRANSFER.
Definition: CrPsLptFunc.c:58
void CrFwOutCmpSetDest(FwSmDesc_t smDesc, CrFwDestSrc_t dest)
Set the destination of the OutComponent.
Definition: CrFwOutCmp.c:192
uint32_t CrPsTimeOut_t
Type used for the Timeout for packets.
static void setDppartSeqNmbItem(int i, CrFwCounterU4_t partSeqNmb)
Sets the value of the i-th element in the datapool array partSeqNmb.
void CrPsLptInitialization(FwSmDesc_t smDesc)
Action on the transition from Initial State to INACTIVE.
Definition: CrPsLptFunc.c:295
Definition of the OutLoader component.
CrFwTimeStamp_t CrFwGetCurrentTimeServer()
Provide the current time.
FwSmDesc_t CrFwOutFactoryMakeOutCmp(CrFwServType_t type, CrFwServSubType_t subType, CrFwDiscriminant_t discriminant, CrFwPcktLength_t length)
Make function for an OutComponent.
unsigned int CrFwTimeStamp_t
Type used for the time stamp of a command or report.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved