CORDET Framework - C2 Implementation
cordetfw/tests/config/CrFwPckt.c
Go to the documentation of this file.
1 
51 #include <stdlib.h>
52 #include "CrFwConstants.h"
54 #include "Pckt/CrFwPckt.h"
55 #include "BaseCmp/CrFwBaseCmp.h"
56 
62 #define CR_FW_MAX_PCKT_LENGTH 100
63 
69 
76 
79 
81 static const CrFwPcktLength_t offsetLength = 0;
82 
85 
88 
90 static const CrFwPcktLength_t offsetServType = 12;
91 
94 
96 static const CrFwPcktLength_t offsetDest = 20;
97 
99 static const CrFwPcktLength_t offsetSrc = 24;
100 
103 
105 static const CrFwPcktLength_t offsetSeqCnt = 32;
106 
109 
112 
115 
118 
121 
123 static const CrFwPcktLength_t offsetGroup = 56;
124 
126 static const CrFwPcktLength_t offsetPar = 60;
127 
128 /*-----------------------------------------------------------------------------------------*/
130  CrFwCounterU2_t i;
131 
132  if (pcktLength > CR_FW_MAX_PCKT_LENGTH) {
134  return NULL;
135  }
136 
137  if (pcktLength < 1) {
139  return NULL;
140  }
141 
142  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
143  if (pcktInUse[i] == 0) {
144  pcktInUse[i] = 1;
145  pcktArray[i*CR_FW_MAX_PCKT_LENGTH] = (char)pcktLength;
147  return (&pcktArray[i*CR_FW_MAX_PCKT_LENGTH]);
148  }
149  }
150 
152  return NULL;
153 }
154 
155 /*-----------------------------------------------------------------------------------------*/
157  CrFwCounterU2_t i;
158 
159  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
160  if (pckt == &pcktArray[i*CR_FW_MAX_PCKT_LENGTH]) {
161  if (pcktInUse[i] == 0) {
163  } else {
165  pcktInUse[i] = 0;
166  }
167  return;
168  }
169  }
170 
172  return;
173 }
174 
175 /*-----------------------------------------------------------------------------------------*/
177  CrFwCounterU2_t i;
178 
179  if (pcktLength > CR_FW_MAX_PCKT_LENGTH)
180  return 0;
181 
182  if (pcktLength < 1)
183  return 0;
184 
185  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
186  if (pcktInUse[i] == 0)
187  return 1;
188  }
189 
190  return 0;
191 }
192 
193 
194 
195 /*-----------------------------------------------------------------------------------------*/
197  return nOfAllocatedPckts;
198 }
199 
200 /*-----------------------------------------------------------------------------------------*/
202  return CR_FW_MAX_PCKT_LENGTH;
203 }
204 
205 /*-----------------------------------------------------------------------------------------*/
207  return (CrFwPcktLength_t)pckt[offsetLength];
208 }
209 
210 /*-----------------------------------------------------------------------------------------*/
212  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetCmdRepType);
213  return (*loc);
214 }
215 
216 /*-----------------------------------------------------------------------------------------*/
218  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetCmdRepType);
219  (*loc) = type;
220 }
221 
222 /*-----------------------------------------------------------------------------------------*/
224  CrFwSeqCnt_t* loc = (CrFwSeqCnt_t*)(pckt+offsetSeqCnt);
225  return (*loc);
226 }
227 
228 /*-----------------------------------------------------------------------------------------*/
230  CrFwSeqCnt_t* loc = (CrFwSeqCnt_t*)(pckt+offsetSeqCnt);
231  (*loc) = seqCnt;
232 }
233 
234 /*-----------------------------------------------------------------------------------------*/
237  return (*loc);
238 }
239 
240 /*-----------------------------------------------------------------------------------------*/
243  (*loc) = timeStamp;
244 }
245 
246 /*-----------------------------------------------------------------------------------------*/
248  (void)pckt;
249  return 0xFFFF;
250 }
251 
252 /*-----------------------------------------------------------------------------------------*/
254  CrFwPcktLength_t len;
255  CrFwCrc_t* loc;
256 
257  len = CrFwPcktGetLength(pckt);
258  loc = (CrFwCrc_t*)(pckt+len-sizeof(CrFwCrc_t));
259  (*loc) = crc;
260 }
261 
262 /*-----------------------------------------------------------------------------------------*/
264  CrFwPcktLength_t len;
265  CrFwCrc_t* loc;
266 
267  len = CrFwPcktGetLength(pckt);
268  loc = (CrFwCrc_t*)(pckt+len-sizeof(CrFwCrc_t));
269  return (*loc);
270 }
271 
272 /*-----------------------------------------------------------------------------------------*/
275  return (*loc);
276 }
277 
278 /*-----------------------------------------------------------------------------------------*/
281  (*loc) = discriminant;
282 }
283 
284 /*-----------------------------------------------------------------------------------------*/
287  (*loc) = servType;
288 }
289 
290 /*-----------------------------------------------------------------------------------------*/
293  return (*loc);
294 }
295 
296 /*-----------------------------------------------------------------------------------------*/
299  (*loc) = servSubType;
300 }
301 
302 /*-----------------------------------------------------------------------------------------*/
305  return (*loc);
306 }
307 
308 /*-----------------------------------------------------------------------------------------*/
310  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetDest);
311  (*loc) = dest;
312 }
313 
314 /*-----------------------------------------------------------------------------------------*/
316  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetDest);
317  return (*loc);
318 }
319 
320 /*-----------------------------------------------------------------------------------------*/
322  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetSrc);
323  (*loc) = src;
324 }
325 
326 /*-----------------------------------------------------------------------------------------*/
328  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetSrc);
329  return (*loc);
330 }
331 
332 /*-----------------------------------------------------------------------------------------*/
335  (*loc) = id;
336 }
337 
338 /*-----------------------------------------------------------------------------------------*/
341  return (*loc);
342 }
343 
344 /*-----------------------------------------------------------------------------------------*/
346  CrFwBool_t progress, CrFwBool_t term) {
347  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetAcceptAckLev);
348  (*loc) = accept;
349  loc = (CrFwBool_t*)(pckt+offsetStartAckLev);
350  (*loc) = start;
351  loc = (CrFwBool_t*)(pckt+offsetProgressAckLev);
352  (*loc) = progress;
353  loc = (CrFwBool_t*)(pckt+offsetTermAckLev);
354  (*loc) = term;
355 }
356 
357 /*-----------------------------------------------------------------------------------------*/
359  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetAcceptAckLev);
360  return (*loc);
361 }
362 
363 /*-----------------------------------------------------------------------------------------*/
365  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetStartAckLev);
366  return (*loc);
367 }
368 
369 /*-----------------------------------------------------------------------------------------*/
372  return (*loc);
373 }
374 
375 /*-----------------------------------------------------------------------------------------*/
377  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetTermAckLev);
378  return (*loc);
379 }
380 
381 /*-----------------------------------------------------------------------------------------*/
383  return (CrFwPckt_t)(pckt+offsetPar);
384 }
385 
386 /*-----------------------------------------------------------------------------------------*/
389 }
390 
391 /*-----------------------------------------------------------------------------------------*/
393  CrFwGroup_t* loc = (CrFwGroup_t*)(pckt+offsetGroup);
394  (*loc) = group;
395 }
396 
397 /*-----------------------------------------------------------------------------------------*/
399  CrFwGroup_t* loc = (CrFwGroup_t*)(pckt+offsetGroup);
400  return (*loc);
401 }
static const CrFwPcktLength_t offsetLength
Offset of the length field in a packet.
static const CrFwPcktLength_t offsetServSubType
Offset of the service sub-type field in a packet.
A packet allocation request has failed (see CrFwPcktMake).
CrFwPckt_t * pckt
The list of packets in the PQ.
void CrFwPcktSetSrc(CrFwPckt_t pckt, CrFwDestSrc_t src)
Set the source of the command or report encapsulated in a packet.
unsigned char CrFwServSubType_t
Type used for the command or report sub-type.
static const CrFwPcktLength_t offsetCmdRepId
Offset of the command or report identifier in a packet.
void CrFwSetAppErrCode(CrFwAppErrCode_t errCode)
Set the value of the application error code (see CrFwGetAppErrCode).
unsigned char CrFwGroup_t
Type used for the destination or source group of a packet.
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
Definition: CrFwConstants.h:38
#define CR_FW_MAX_NOF_PCKTS
The maximum number of packets which can be created with the default packet implementation.
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
void CrFwPcktSetCrc(CrFwPckt_t pckt, CrFwCrc_t crc)
Set the CRC in the command or report encapsulated in a packet.
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
static const CrFwPcktLength_t offsetGroup
Offset of the group in a packet.
unsigned char CrFwDestSrc_t
Type used for the command or report destination and source.
CrFwCmdRepType_t
Enumerated type for command and reports.
Definition: CrFwConstants.h:41
CrFwServSubType_t CrFwPcktGetServSubType(CrFwPckt_t pckt)
Return the service sub-type of the command or report encapsulated in a packet.
CrFwServType_t CrFwPcktGetServType(CrFwPckt_t pckt)
Return the service type of the command or report encapsulated in a packet.
Interface for creating and accessing a report or command packet.
CrFwBool_t CrFwPcktIsProgressAck(CrFwPckt_t pckt)
Return the acknowledge level for command progress for the command encapsulated in the packet...
void CrFwPcktSetCmdRepType(CrFwPckt_t pckt, CrFwCmdRepType_t type)
Set the type of a packet (either a command packet or a report packet).
CrFwCmdRepType_t CrFwPcktGetCmdRepType(CrFwPckt_t pckt)
Return the type of a packet (either a command packet or a report packet).
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
Definition: CrFwConstants.h:32
static CrFwServSubType_t servSubType
Service sub-type.
unsigned char CrFwServType_t
Type used for the service type of a command or report.
void CrFwPcktSetDest(CrFwPckt_t pckt, CrFwDestSrc_t dest)
Set the destination of the command or report encapsulated in a packet.
Header file to define all invariant publicly available constants and types for the CORDET Framework...
static const CrFwPcktLength_t offsetProgressAckLev
Offset of the progress acknowledge level field in a packet.
CrFwCrc_t CrFwPcktGetCrc(CrFwPckt_t pckt)
Return the CRC of the command or report encapsulated in a packet.
static const CrFwPcktLength_t offsetAcceptAckLev
Offset of the acceptance acknowledge level field in a packet.
void CrFwPcktSetCmdRepId(CrFwPckt_t pckt, CrFwInstanceId_t id)
Set the command or report identifier in the command or report encapsulated in a packet.
static const CrFwPcktLength_t offsetServType
Offset of the service type field in a packet.
CrFwDestSrc_t CrFwPcktGetSrc(CrFwPckt_t pckt)
Return the source of the command or report encapsulated in a packet.
static const CrFwPcktLength_t offsetPar
Offset of the parameter area in a packet.
static const CrFwPcktLength_t offsetCmdRepType
Offset of the flag defining the type of packet (1 for a command, 2 for a report)
static const CrFwPcktLength_t offsetSeqCnt
Offset of the sequence counter field in a packet.
CrFwTimeStamp_t CrFwPcktGetTimeStamp(CrFwPckt_t pckt)
Return the time stamp of the command or report encapsulated in a packet.
CrFwPcktLength_t CrFwPcktGetMaxLength()
Return the maximum length of a packet in number of bytes.
CrFwPcktLength_t CrFwPcktGetLength(CrFwPckt_t pckt)
Return the length (in number of bytes) of a packet.
unsigned short int CrFwPcktLength_t
Type for the packet length.
void CrFwPcktSetServSubType(CrFwPckt_t pckt, CrFwServSubType_t servSubType)
Set the service sub-type of the command or report encapsulated in a packet.
static CrFwBool_t pcktInUse[CR_FW_MAX_NOF_PCKTS]
The array holding the "in use" status of the packets.
void CrFwPcktSetDiscriminant(CrFwPckt_t pckt, CrFwDiscriminant_t discriminant)
Set the discriminant of the command or report encapsulated in a packet.
CrFwBool_t CrFwPcktIsAcceptAck(CrFwPckt_t pckt)
Return the acknowledge level for command acceptance for the command encapsulated in the packet...
CrFwInstanceId_t CrFwPcktGetCmdRepId(CrFwPckt_t pckt)
Return the command or report identifier of the command or report encapsulated in a packet...
static const CrFwPcktLength_t offsetStartAckLev
Offset of the start acknowledge level field in a packet.
CrFwPckt_t CrFwPcktGetParStart(CrFwPckt_t pckt)
Return the start address of the packet&#39;s parameter area.
Definition of the utility functions for the CORDET Framework.
static const CrFwPcktLength_t offsetTermAckLev
Offset of the termination acknowledge level field in a packet.
void CrFwPcktRelease(CrFwPckt_t pckt)
Release function for command or report packets.
CrFwSeqCnt_t CrFwPcktGetSeqCnt(CrFwPckt_t pckt)
Return the sequence counter of the command or report encapsulated in a packet.
unsigned short CrFwDiscriminant_t
Type used for the discriminant of a command or report.
CrFwBool_t CrFwPcktIsAvail(CrFwPcktLength_t pcktLength)
Check whether a packet of a specified length is available.
CrFwBool_t CrFwPcktIsTermAck(CrFwPckt_t pckt)
Return the acknowledge level for command termination for the command encapsulated in the packet...
CrFwPcktLength_t CrFwPcktGetParLength(CrFwPckt_t pckt)
Return the length in bytes of the packet&#39;s parameter area.
void CrFwPcktSetGroup(CrFwPckt_t pckt, CrFwGroup_t group)
Set the group of the command/report encapsulated in a packet.
Definition of Base Component.
static CrFwServType_t servType
The InCommand type as computed in the Validity Check.
static const CrFwPcktLength_t offsetDiscriminant
Offset of the discriminant field in a packet.
static CrFwDestSrc_t dest
Destination.
void CrFwPcktSetServType(CrFwPckt_t pckt, CrFwServType_t servType)
Set the service type of the command or report encapsulated in a packet.
unsigned short CrFwCrc_t
Type used for the CRC field in a packet.
static const CrFwPcktLength_t offsetSrc
Offset of the source field in a packet.
CrFwBool_t CrFwPcktIsStartAck(CrFwPckt_t pckt)
Return the acknowledge level for command start for the command encapsulated in the packet...
static const CrFwPcktLength_t offsetTimeStamp
Offset of the time stamp field in a packet.
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.
CrFwCounterU2_t CrFwPcktGetNOfAllocated()
Return the number of packets which are currently allocated.
CrFwDestSrc_t CrFwPcktGetDest(CrFwPckt_t pckt)
Return the destination of the command or report encapsulated in a packet.
A packet release request has encountered an error (see CrFwPcktRelease).
static unsigned char pcktArray[CR_FW_MAX_NOF_PCKTS *CR_FW_MAX_PCKT_LENGTH]
The array holding the packets.
CrFwGroup_t CrFwPcktGetGroup(CrFwPckt_t pckt)
Return the group of the command/report encapsulated in a packet.
CrFwDiscriminant_t CrFwPcktGetDiscriminant(CrFwPckt_t pckt)
Return the discriminant of the command or report encapsulated in a packet.
void CrFwPcktSetTimeStamp(CrFwPckt_t pckt, CrFwTimeStamp_t timeStamp)
Set the time stamp of the command or report encapsulated in a packet.
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
void CrFwPcktSetSeqCnt(CrFwPckt_t pckt, CrFwSeqCnt_t seqCnt)
Set the sequence counter of the command or report encapsulated in a packet.
CrFwCrc_t CrFwPcktComputeCrc(CrFwPckt_t pckt)
Compute the CRC in the command or report encapsulated in a packet.
unsigned int CrFwSeqCnt_t
Type used for the sequence counter of commands or reports.
#define CR_FW_MAX_PCKT_LENGTH
Maximum length of a packet expressed in number of bytes (see CrFwPacket.h).
static const CrFwPcktLength_t offsetDest
Offset of the destination field in a packet.
static CrFwCounterU2_t nOfAllocatedPckts
The number of currently allocated packets.
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