CORDET Framework - C2 Implementation
CrFwPckt.c
Go to the documentation of this file.
1 
66 #include <stdlib.h>
67 #include "CrFwConstants.h"
69 #include "Pckt/CrFwPckt.h"
70 #include "BaseCmp/CrFwBaseCmp.h"
71 
77 #define CR_FW_MAX_PCKT_LENGTH 100
78 
84 
91 
94 
96 static const CrFwPcktLength_t offsetLength = 0;
97 
100 
103 
106 
109 
111 static const CrFwPcktLength_t offsetDest = 20;
112 
114 static const CrFwPcktLength_t offsetSrc = 24;
115 
118 
120 static const CrFwPcktLength_t offsetSeqCnt = 32;
121 
124 
127 
130 
133 
136 
138 static const CrFwPcktLength_t offsetTypeCnt = 56;
139 
141 static const CrFwPcktLength_t offsetGroup = 60;
142 
144 static const CrFwPcktLength_t offsetPar = 64;
145 
146 /*-----------------------------------------------------------------------------------------*/
148  CrFwCounterU2_t i;
149 
150  if (pcktLength > CR_FW_MAX_PCKT_LENGTH) {
152  return NULL;
153  }
154 
155  if (pcktLength < 1) {
157  return NULL;
158  }
159 
160  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
161  if (pcktInUse[i] == 0) {
162  pcktInUse[i] = 1;
163  pcktArray[i*CR_FW_MAX_PCKT_LENGTH] = (char)pcktLength;
165  return (&pcktArray[i*CR_FW_MAX_PCKT_LENGTH]);
166  }
167  }
168 
170  return NULL;
171 }
172 
173 /*-----------------------------------------------------------------------------------------*/
175  CrFwCounterU2_t i;
176 
177  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
178  if (pckt == &pcktArray[i*CR_FW_MAX_PCKT_LENGTH]) {
179  if (pcktInUse[i] == 0) {
181  } else {
183  pcktInUse[i] = 0;
184  }
185  return;
186  }
187  }
188 
190  return;
191 }
192 
193 /*-----------------------------------------------------------------------------------------*/
195  CrFwCounterU2_t i;
196 
197  if (pcktLength > CR_FW_MAX_PCKT_LENGTH)
198  return 0;
199 
200  if (pcktLength < 1)
201  return 0;
202 
203  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
204  if (pcktInUse[i] == 0)
205  return 1;
206  }
207 
208  return 0;
209 }
210 
211 
212 
213 /*-----------------------------------------------------------------------------------------*/
215  return nOfAllocatedPckts;
216 }
217 
218 /*-----------------------------------------------------------------------------------------*/
220  return CR_FW_MAX_PCKT_LENGTH;
221 }
222 
223 /*-----------------------------------------------------------------------------------------*/
225  return (CrFwPcktLength_t)pckt[offsetLength];
226 }
227 
228 /*-----------------------------------------------------------------------------------------*/
230  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetCmdRepType);
231  return (*loc);
232 }
233 
234 /*-----------------------------------------------------------------------------------------*/
236  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetCmdRepType);
237  (*loc) = type;
238 }
239 
240 /*-----------------------------------------------------------------------------------------*/
242  CrFwSeqCnt_t* loc = (CrFwSeqCnt_t*)(pckt+offsetSeqCnt);
243  return (*loc);
244 }
245 
246 /*-----------------------------------------------------------------------------------------*/
248  CrFwSeqCnt_t* loc = (CrFwSeqCnt_t*)(pckt+offsetSeqCnt);
249  (*loc) = seqCnt;
250 }
251 
252 /*-----------------------------------------------------------------------------------------*/
254  CrFwTypeCnt_t* loc = (CrFwTypeCnt_t*)(pckt+offsetTypeCnt);
255  return (*loc);
256 }
257 
258 /*-----------------------------------------------------------------------------------------*/
260  CrFwTypeCnt_t* loc = (CrFwTypeCnt_t*)(pckt+offsetTypeCnt);
261  (*loc) = typeCnt;
262 }
263 
264 /*-----------------------------------------------------------------------------------------*/
267  return (*loc);
268 }
269 
270 /*-----------------------------------------------------------------------------------------*/
273  (*loc) = timeStamp;
274 }
275 
276 /*-----------------------------------------------------------------------------------------*/
278  (void)pckt;
279  return 0xFFFF;
280 }
281 
282 /*-----------------------------------------------------------------------------------------*/
284  CrFwPcktLength_t len;
285  CrFwCrc_t* loc;
286 
287  len = CrFwPcktGetLength(pckt);
288  loc = (CrFwCrc_t*)(pckt+len-sizeof(CrFwCrc_t));
289  (*loc) = crc;
290 }
291 
292 /*-----------------------------------------------------------------------------------------*/
294  CrFwPcktLength_t len;
295  CrFwCrc_t* loc;
296 
297  len = CrFwPcktGetLength(pckt);
298  loc = (CrFwCrc_t*)(pckt+len-sizeof(CrFwCrc_t));
299  return (*loc);
300 }
301 
302 /*-----------------------------------------------------------------------------------------*/
305  return (*loc);
306 }
307 
308 /*-----------------------------------------------------------------------------------------*/
311  (*loc) = discriminant;
312 }
313 
314 /*-----------------------------------------------------------------------------------------*/
317  (*loc) = servType;
318 }
319 
320 /*-----------------------------------------------------------------------------------------*/
323  return (*loc);
324 }
325 
326 /*-----------------------------------------------------------------------------------------*/
329  (*loc) = servSubType;
330 }
331 
332 /*-----------------------------------------------------------------------------------------*/
335  return (*loc);
336 }
337 
338 /*-----------------------------------------------------------------------------------------*/
340  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetDest);
341  (*loc) = dest;
342 }
343 
344 /*-----------------------------------------------------------------------------------------*/
346  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetDest);
347  return (*loc);
348 }
349 
350 /*-----------------------------------------------------------------------------------------*/
352  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetSrc);
353  (*loc) = src;
354 }
355 
356 /*-----------------------------------------------------------------------------------------*/
358  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetSrc);
359  return (*loc);
360 }
361 
362 /*-----------------------------------------------------------------------------------------*/
365  (*loc) = id;
366 }
367 
368 /*-----------------------------------------------------------------------------------------*/
371  return (*loc);
372 }
373 
374 /*-----------------------------------------------------------------------------------------*/
376  CrFwBool_t progress, CrFwBool_t term) {
377  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetAcceptAckLev);
378  (*loc) = accept;
379  loc = (CrFwBool_t*)(pckt+offsetStartAckLev);
380  (*loc) = start;
381  loc = (CrFwBool_t*)(pckt+offsetProgressAckLev);
382  (*loc) = progress;
383  loc = (CrFwBool_t*)(pckt+offsetTermAckLev);
384  (*loc) = term;
385 }
386 
387 /*-----------------------------------------------------------------------------------------*/
389  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetAcceptAckLev);
390  return (*loc);
391 }
392 
393 /*-----------------------------------------------------------------------------------------*/
395  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetStartAckLev);
396  return (*loc);
397 }
398 
399 /*-----------------------------------------------------------------------------------------*/
402  return (*loc);
403 }
404 
405 /*-----------------------------------------------------------------------------------------*/
407  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetTermAckLev);
408  return (*loc);
409 }
410 
411 /*-----------------------------------------------------------------------------------------*/
413  return (CrFwPckt_t)(pckt+offsetPar);
414 }
415 
416 /*-----------------------------------------------------------------------------------------*/
419 }
420 
421 /*-----------------------------------------------------------------------------------------*/
423  CrFwGroup_t* loc = (CrFwGroup_t*)(pckt+offsetGroup);
424  (*loc) = group;
425 }
426 
427 /*-----------------------------------------------------------------------------------------*/
429  CrFwGroup_t* loc = (CrFwGroup_t*)(pckt+offsetGroup);
430  return (*loc);
431 }
Definition of Base Component.
Header file to define all invariant publicly available constants and types for the CORDET Framework.
CrFwCmdRepType_t
Enumerated type for command and reports.
Definition: CrFwConstants.h:41
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:38
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
static CrFwServType_t servType
The InCommand type as computed in the Validity Check.
static CrFwDestSrc_t dest
Destination.
static CrFwServSubType_t servSubType
Service sub-type.
static CrFwTypeCnt_t typeCnt[CR_FW_OUTSTREAM_STUB_MEM_LEN]
Type counters of most recently received packets.
static CrFwSeqCnt_t seqCnt[CR_FW_OUTSTREAM_STUB_MEM_LEN]
Sequence counters of most recently received packets.
CrFwBool_t CrFwPcktIsAvail(CrFwPcktLength_t pcktLength)
Check whether a packet of a specified length is available.
Definition: CrFwPckt.c:194
void CrFwPcktSetServSubType(CrFwPckt_t pckt, CrFwServSubType_t servSubType)
Set the service sub-type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:327
CrFwPckt_t CrFwPcktGetParStart(CrFwPckt_t pckt)
Return the start address of the packet's parameter area.
Definition: CrFwPckt.c:412
void CrFwPcktSetCmdRepId(CrFwPckt_t pckt, CrFwInstanceId_t id)
Set the command or report identifier in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:363
CrFwTypeCnt_t CrFwPcktGetTypeCnt(CrFwPckt_t pckt)
Return the type counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:253
static const CrFwPcktLength_t offsetProgressAckLev
Offset of the progress acknowledge level field in a packet.
Definition: CrFwPckt.c:132
void CrFwPcktSetSeqCnt(CrFwPckt_t pckt, CrFwSeqCnt_t seqCnt)
Set the sequence counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:247
CrFwSeqCnt_t CrFwPcktGetSeqCnt(CrFwPckt_t pckt)
Return the sequence counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:241
void CrFwPcktSetCmdRepType(CrFwPckt_t pckt, CrFwCmdRepType_t type)
Set the type of a packet (either a command packet or a report packet).
Definition: CrFwPckt.c:235
static const CrFwPcktLength_t offsetServSubType
Offset of the service sub-type field in a packet.
Definition: CrFwPckt.c:108
CrFwBool_t CrFwPcktIsProgressAck(CrFwPckt_t pckt)
Return the acknowledge level for command progress for the command encapsulated in the packet.
Definition: CrFwPckt.c:400
static const CrFwPcktLength_t offsetPar
Offset of the parameter area in a packet.
Definition: CrFwPckt.c:144
CrFwBool_t CrFwPcktIsTermAck(CrFwPckt_t pckt)
Return the acknowledge level for command termination for the command encapsulated in the packet.
Definition: CrFwPckt.c:406
static const CrFwPcktLength_t offsetCmdRepId
Offset of the command or report identifier in a packet.
Definition: CrFwPckt.c:123
static const CrFwPcktLength_t offsetLength
Offset of the length field in a packet.
Definition: CrFwPckt.c:96
static CrFwBool_t pcktInUse[CR_FW_MAX_NOF_PCKTS]
The array holding the "in use" status of the packets.
Definition: CrFwPckt.c:90
#define CR_FW_MAX_PCKT_LENGTH
Maximum length of a packet expressed in number of bytes (see CrFwPacket.h).
Definition: CrFwPckt.c:77
CrFwCmdRepType_t CrFwPcktGetCmdRepType(CrFwPckt_t pckt)
Return the type of a packet (either a command packet or a report packet).
Definition: CrFwPckt.c:229
CrFwCrc_t CrFwPcktComputeCrc(CrFwPckt_t pckt)
Compute the CRC in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:277
void CrFwPcktSetDiscriminant(CrFwPckt_t pckt, CrFwDiscriminant_t discriminant)
Set the discriminant of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:309
void CrFwPcktSetTimeStamp(CrFwPckt_t pckt, CrFwTimeStamp_t timeStamp)
Set the time stamp of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:271
static const CrFwPcktLength_t offsetAcceptAckLev
Offset of the acceptance acknowledge level field in a packet.
Definition: CrFwPckt.c:126
CrFwPcktLength_t CrFwPcktGetParLength(CrFwPckt_t pckt)
Return the length in bytes of the packet's parameter area.
Definition: CrFwPckt.c:417
static const CrFwPcktLength_t offsetStartAckLev
Offset of the start acknowledge level field in a packet.
Definition: CrFwPckt.c:129
static const CrFwPcktLength_t offsetSeqCnt
Offset of the sequence counter field in a packet.
Definition: CrFwPckt.c:120
static const CrFwPcktLength_t offsetServType
Offset of the service type field in a packet.
Definition: CrFwPckt.c:105
void CrFwPcktSetServType(CrFwPckt_t pckt, CrFwServType_t servType)
Set the service type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:315
CrFwCounterU2_t CrFwPcktGetNOfAllocated()
Return the number of packets which are currently allocated.
Definition: CrFwPckt.c:214
CrFwDestSrc_t CrFwPcktGetSrc(CrFwPckt_t pckt)
Return the source of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:357
static const CrFwPcktLength_t offsetTimeStamp
Offset of the time stamp field in a packet.
Definition: CrFwPckt.c:102
static const CrFwPcktLength_t offsetSrc
Offset of the source field in a packet.
Definition: CrFwPckt.c:114
CrFwServSubType_t CrFwPcktGetServSubType(CrFwPckt_t pckt)
Return the service sub-type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:333
static const CrFwPcktLength_t offsetCmdRepType
Offset of the flag defining the type of packet (1 for a command, 2 for a report)
Definition: CrFwPckt.c:99
CrFwDestSrc_t CrFwPcktGetDest(CrFwPckt_t pckt)
Return the destination of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:345
CrFwInstanceId_t CrFwPcktGetCmdRepId(CrFwPckt_t pckt)
Return the command or report identifier of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:369
CrFwBool_t CrFwPcktIsAcceptAck(CrFwPckt_t pckt)
Return the acknowledge level for command acceptance for the command encapsulated in the packet.
Definition: CrFwPckt.c:388
CrFwTimeStamp_t CrFwPcktGetTimeStamp(CrFwPckt_t pckt)
Return the time stamp of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:265
static const CrFwPcktLength_t offsetTypeCnt
Offset of the type counter in a packet.
Definition: CrFwPckt.c:138
void CrFwPcktSetAckLevel(CrFwPckt_t pckt, CrFwBool_t accept, CrFwBool_t start, CrFwBool_t progress, CrFwBool_t term)
Set the acknowledge level for the command encapsulated in a packet.
Definition: CrFwPckt.c:375
void CrFwPcktSetCrc(CrFwPckt_t pckt, CrFwCrc_t crc)
Set the CRC in the command or report encapsulated in a packet.
Definition: CrFwPckt.c:283
static CrFwCounterU2_t nOfAllocatedPckts
The number of currently allocated packets.
Definition: CrFwPckt.c:93
void CrFwPcktRelease(CrFwPckt_t pckt)
Release function for command or report packets.
Definition: CrFwPckt.c:174
CrFwGroup_t CrFwPcktGetGroup(CrFwPckt_t pckt)
Return the group of the command/report encapsulated in a packet.
Definition: CrFwPckt.c:428
static unsigned char pcktArray[CR_FW_MAX_NOF_PCKTS *CR_FW_MAX_PCKT_LENGTH]
The array holding the packets.
Definition: CrFwPckt.c:83
CrFwPcktLength_t CrFwPcktGetMaxLength()
Return the maximum length of a packet in number of bytes.
Definition: CrFwPckt.c:219
static const CrFwPcktLength_t offsetDest
Offset of the destination field in a packet.
Definition: CrFwPckt.c:111
static const CrFwPcktLength_t offsetDiscriminant
Offset of the discriminant field in a packet.
Definition: CrFwPckt.c:117
CrFwPcktLength_t CrFwPcktGetLength(CrFwPckt_t pckt)
Return the length (in number of bytes) of a packet.
Definition: CrFwPckt.c:224
CrFwBool_t CrFwPcktIsStartAck(CrFwPckt_t pckt)
Return the acknowledge level for command start for the command encapsulated in the packet.
Definition: CrFwPckt.c:394
CrFwCrc_t CrFwPcktGetCrc(CrFwPckt_t pckt)
Return the CRC of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:293
void CrFwPcktSetSrc(CrFwPckt_t pckt, CrFwDestSrc_t src)
Set the source of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:351
void CrFwPcktSetDest(CrFwPckt_t pckt, CrFwDestSrc_t dest)
Set the destination of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:339
void CrFwPcktSetGroup(CrFwPckt_t pckt, CrFwGroup_t group)
Set the group of the command/report encapsulated in a packet.
Definition: CrFwPckt.c:422
CrFwDiscriminant_t CrFwPcktGetDiscriminant(CrFwPckt_t pckt)
Return the discriminant of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:303
static const CrFwPcktLength_t offsetTermAckLev
Offset of the termination acknowledge level field in a packet.
Definition: CrFwPckt.c:135
CrFwServType_t CrFwPcktGetServType(CrFwPckt_t pckt)
Return the service type of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:321
void CrFwPcktSetTypeCnt(CrFwPckt_t pckt, CrFwTypeCnt_t typeCnt)
Set the type counter of the command or report encapsulated in a packet.
Definition: CrFwPckt.c:259
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
Definition: CrFwPckt.c:147
static const CrFwPcktLength_t offsetGroup
Offset of the group in a packet.
Definition: CrFwPckt.c:141
Interface for creating and accessing a report or command packet.
unsigned int CrFwTimeStamp_t
Type used for the time stamp of a command or report.
unsigned int CrFwSeqCnt_t
Type used for the sequence counter of commands or reports.
unsigned char CrFwServType_t
Type used for the service type of a command or report.
unsigned char CrFwDestSrc_t
Type used for the command or report destination and source.
#define CR_FW_MAX_NOF_PCKTS
The maximum number of packets which can be created with the default implementation of the packet acce...
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
unsigned short CrFwDiscriminant_t
Type used for the discriminant of a command or report.
unsigned short int CrFwPcktLength_t
Type for the packet length.
unsigned int CrFwTypeCnt_t
Type used for the type counter of commands or reports.
unsigned char CrFwGroup_t
Type used for the destination or source group of a packet.
unsigned short CrFwCrc_t
Type used for the CRC field in a packet.
@ crPcktAllocationFail
A packet allocation request has failed (see CrFwPcktMake).
@ crPcktRelErr
A packet release request has encountered an error (see CrFwPcktRelease).
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
unsigned char CrFwServSubType_t
Type used for the command or report sub-type.
void CrFwSetAppErrCode(CrFwAppErrCode_t errCode)
Set the value of the application error code (see CrFwGetAppErrCode).
Definition of the utility functions for the CORDET Framework.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved