CORDET Framework - C2 Implementation
cordetfw-examples/src/CrConfigDemoMaster/CrFwPckt.c
Go to the documentation of this file.
1 
46 #include <stdlib.h>
47 #include "CrFwConstants.h"
49 #include "Pckt/CrFwPckt.h"
50 #include "BaseCmp/CrFwBaseCmp.h"
51 
57 #define CR_FW_MAX_PACKET_LENGTH 100
58 
60 #define CR_FW_MAX_PCKT_LENGTH 100
61 
67 
74 
77 
79 static const CrFwPcktLength_t offsetLength = 0;
80 
83 
86 
88 static const CrFwPcktLength_t offsetServType = 12;
89 
92 
94 static const CrFwPcktLength_t offsetDest = 20;
95 
97 static const CrFwPcktLength_t offsetSrc = 24;
98 
101 
103 static const CrFwPcktLength_t offsetSeqCnt = 32;
104 
107 
110 
113 
116 
119 
121 static const CrFwPcktLength_t offsetGroup = 56;
122 
124 static const CrFwPcktLength_t offsetPar = 60;
125 
126 /*-----------------------------------------------------------------------------------------*/
128  CrFwCounterU2_t i;
129 
130  if (pcktLength > CR_FW_MAX_PCKT_LENGTH) {
132  return NULL;
133  }
134 
135  if (pcktLength < 1) {
137  return NULL;
138  }
139 
140  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
141  if (pcktInUse[i] == 0) {
142  pcktInUse[i] = 1;
143  pcktArray[i*CR_FW_MAX_PCKT_LENGTH] = (char)pcktLength;
145  return (&pcktArray[i*CR_FW_MAX_PCKT_LENGTH]);
146  }
147  }
148 
150  return NULL;
151 }
152 
153 /*-----------------------------------------------------------------------------------------*/
155  CrFwCounterU2_t i;
156 
157  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
158  if (pckt == &pcktArray[i*CR_FW_MAX_PCKT_LENGTH]) {
159  if (pcktInUse[i] == 0) {
161  } else {
163  pcktInUse[i] = 0;
164  }
165  return;
166  }
167  }
168 
170  return;
171 }
172 
173 /*-----------------------------------------------------------------------------------------*/
175  CrFwCounterU2_t i;
176 
177  if (pcktLength > CR_FW_MAX_PCKT_LENGTH)
178  return 0;
179 
180  if (pcktLength < 1)
181  return 0;
182 
183  for (i=0; i<CR_FW_MAX_NOF_PCKTS; i++) {
184  if (pcktInUse[i] == 0)
185  return 1;
186  }
187 
188  return 0;
189 }
190 
191 
192 
193 /*-----------------------------------------------------------------------------------------*/
195  return nOfAllocatedPckts;
196 }
197 
198 /*-----------------------------------------------------------------------------------------*/
200  return CR_FW_MAX_PCKT_LENGTH;
201 }
202 
203 /*-----------------------------------------------------------------------------------------*/
205  return (CrFwPcktLength_t)pckt[offsetLength];
206 }
207 
208 /*-----------------------------------------------------------------------------------------*/
210  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetCmdRepType);
211  return (*loc);
212 }
213 
214 /*-----------------------------------------------------------------------------------------*/
216  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetCmdRepType);
217  (*loc) = type;
218 }
219 
220 /*-----------------------------------------------------------------------------------------*/
222  CrFwSeqCnt_t* loc = (CrFwSeqCnt_t*)(pckt+offsetSeqCnt);
223  return (*loc);
224 }
225 
226 /*-----------------------------------------------------------------------------------------*/
228  CrFwSeqCnt_t* loc = (CrFwSeqCnt_t*)(pckt+offsetSeqCnt);
229  (*loc) = seqCnt;
230 }
231 
232 /*-----------------------------------------------------------------------------------------*/
235  return (*loc);
236 }
237 
238 /*-----------------------------------------------------------------------------------------*/
241  (*loc) = timeStamp;
242 }
243 
244 /*-----------------------------------------------------------------------------------------*/
247  return (*loc);
248 }
249 
250 /*-----------------------------------------------------------------------------------------*/
253  (*loc) = discriminant;
254 }
255 
256 /*-----------------------------------------------------------------------------------------*/
259  (*loc) = servType;
260 }
261 
262 /*-----------------------------------------------------------------------------------------*/
265  return (*loc);
266 }
267 
268 /*-----------------------------------------------------------------------------------------*/
271  (*loc) = servSubType;
272 }
273 
274 /*-----------------------------------------------------------------------------------------*/
277  return (*loc);
278 }
279 
280 /*-----------------------------------------------------------------------------------------*/
282  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetDest);
283  (*loc) = dest;
284 }
285 
286 /*-----------------------------------------------------------------------------------------*/
288  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetDest);
289  return (*loc);
290 }
291 
292 /*-----------------------------------------------------------------------------------------*/
294  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetSrc);
295  (*loc) = src;
296 }
297 
298 /*-----------------------------------------------------------------------------------------*/
300  CrFwDestSrc_t* loc = (CrFwDestSrc_t*)(pckt+offsetSrc);
301  return (*loc);
302 }
303 
304 /*-----------------------------------------------------------------------------------------*/
307  (*loc) = id;
308 }
309 
310 /*-----------------------------------------------------------------------------------------*/
313  return (*loc);
314 }
315 
316 /*-----------------------------------------------------------------------------------------*/
318  CrFwBool_t progress, CrFwBool_t term) {
319  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetAcceptAckLev);
320  (*loc) = accept;
321  loc = (CrFwBool_t*)(pckt+offsetStartAckLev);
322  (*loc) = start;
323  loc = (CrFwBool_t*)(pckt+offsetProgressAckLev);
324  (*loc) = progress;
325  loc = (CrFwBool_t*)(pckt+offsetTermAckLev);
326  (*loc) = term;
327 }
328 
329 /*-----------------------------------------------------------------------------------------*/
331  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetAcceptAckLev);
332  return (*loc);
333 }
334 
335 /*-----------------------------------------------------------------------------------------*/
337  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetStartAckLev);
338  return (*loc);
339 }
340 
341 /*-----------------------------------------------------------------------------------------*/
344  return (*loc);
345 }
346 
347 /*-----------------------------------------------------------------------------------------*/
349  CrFwBool_t* loc = (CrFwBool_t*)(pckt+offsetTermAckLev);
350  return (*loc);
351 }
352 
353 /*-----------------------------------------------------------------------------------------*/
355  return (char*)(pckt+offsetPar);
356 }
357 
358 /*-----------------------------------------------------------------------------------------*/
361 }
362 
363 /*-----------------------------------------------------------------------------------------*/
365  CrFwGroup_t* loc = (CrFwGroup_t*)(pckt+offsetGroup);
366  (*loc) = group;
367 }
368 
369 /*-----------------------------------------------------------------------------------------*/
371  CrFwGroup_t* loc = (CrFwGroup_t*)(pckt+offsetGroup);
372  return (*loc);
373 }
CrFwBool_t CrFwPcktIsAvail(CrFwPcktLength_t pcktLength)
Check whether a packet of a specified length is available.
static const CrFwPcktLength_t offsetServSubType
Offset of the service sub-type field in a packet.
CrFwDestSrc_t CrFwPcktGetSrc(CrFwPckt_t pckt)
Return the source of the command or report encapsulated in a packet.
CrFwTimeStamp_t CrFwPcktGetTimeStamp(CrFwPckt_t pckt)
Return the time stamp of the command or report encapsulated in a packet.
A packet allocation request has failed (see CrFwPcktMake).
CrFwServType_t CrFwPcktGetServType(CrFwPckt_t pckt)
Return the service type of the command or report encapsulated in a packet.
void CrFwPcktRelease(CrFwPckt_t pckt)
Release function for command or report packets.
CrFwDiscriminant_t CrFwPcktGetDiscriminant(CrFwPckt_t pckt)
Return the discriminant of the command or report encapsulated in a packet.
CrFwPckt_t * pckt
The list of packets in the PQ.
static const CrFwPcktLength_t offsetAcceptAckLev
Offset of the acceptance acknowledge level field in a packet.
CrFwInstanceId_t CrFwPcktGetCmdRepId(CrFwPckt_t pckt)
Return the command or report identifier of the command or report encapsulated in a packet...
#define CR_FW_MAX_PCKT_LENGTH
The maximum size in number of bytes of a packet.
void CrFwPcktSetServType(CrFwPckt_t pckt, CrFwServType_t servType)
Set the service type of the command or report encapsulated in a packet.
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).
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
CrFwCmdRepType_t CrFwPcktGetCmdRepType(CrFwPckt_t pckt)
Return the type of a packet (either a command packet or a report packet).
CrFwBool_t CrFwPcktIsTermAck(CrFwPckt_t pckt)
Return the acknowledge level for command termination for the command encapsulated in the packet...
void CrFwPcktSetSrc(CrFwPckt_t pckt, CrFwDestSrc_t src)
Set the source of the command or report encapsulated in a packet.
#define CR_FW_MAX_NOF_PCKTS
The maximum number of packets which can be created with the default packet implementation.
unsigned short CrFwInstanceId_t
Type used for instance identifiers.
static const CrFwPcktLength_t offsetStartAckLev
Offset of the start acknowledge level field 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
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
void CrFwPcktSetCmdRepId(CrFwPckt_t pckt, CrFwInstanceId_t id)
Set the command or report identifier in the command or report encapsulated in a packet.
Interface for creating and accessing a report or command packet.
static const CrFwPcktLength_t offsetTermAckLev
Offset of the termination acknowledge level field in a 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.
static const CrFwPcktLength_t offsetServType
Offset of the service type field in a packet.
void CrFwPcktSetCmdRepType(CrFwPckt_t pckt, CrFwCmdRepType_t type)
Set the type of a packet (either a command packet or a report packet).
Header file to define all invariant publicly available constants and types for the CORDET Framework...
CrFwSeqCnt_t CrFwPcktGetSeqCnt(CrFwPckt_t pckt)
Return the sequence counter of the command or report encapsulated in a packet.
void CrFwPcktSetSeqCnt(CrFwPckt_t pckt, CrFwSeqCnt_t seqCnt)
Set the sequence counter of the command or report encapsulated in a packet.
static const CrFwPcktLength_t offsetSrc
Offset of the source field 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)
CrFwDestSrc_t CrFwPcktGetDest(CrFwPckt_t pckt)
Return the destination of the command or report encapsulated in a packet.
CrFwPcktLength_t CrFwPcktGetLength(CrFwPckt_t pckt)
Return the length (in number of bytes) of a packet.
void CrFwPcktSetGroup(CrFwPckt_t pckt, CrFwGroup_t group)
Set the group of the command/report encapsulated in a packet.
static const CrFwPcktLength_t offsetPar
Offset of the parameter area in a packet.
unsigned short int CrFwPcktLength_t
Type for the packet length.
CrFwBool_t CrFwPcktIsProgressAck(CrFwPckt_t pckt)
Return the acknowledge level for command progress for the command encapsulated in the packet...
static const CrFwPcktLength_t offsetGroup
Offset of the group in a packet.
static CrFwCounterU2_t nOfAllocatedPckts
The number of currently allocated packets.
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.
CrFwPcktLength_t CrFwPcktGetMaxLength()
Return the maximum length of a packet in number of bytes.
char * CrFwPcktGetParStart(CrFwPckt_t pckt)
Return the start address of the packet&#39;s parameter area.
Definition of the utility functions for the CORDET Framework.
void CrFwPcktSetServSubType(CrFwPckt_t pckt, CrFwServSubType_t servSubType)
Set the service sub-type of the command or report encapsulated in a packet.
static const CrFwPcktLength_t offsetProgressAckLev
Offset of the progress acknowledge level field in a packet.
static char pcktArray[CR_FW_MAX_NOF_PCKTS *CR_FW_MAX_PCKT_LENGTH]
The array holding the packets.
static const CrFwPcktLength_t offsetLength
Offset of the length field in a packet.
static const CrFwPcktLength_t offsetCmdRepId
Offset of the command or report identifier in a packet.
unsigned short CrFwDiscriminant_t
Type used for the discriminant of a command or report.
static CrFwBool_t pcktInUse[CR_FW_MAX_NOF_PCKTS]
The array holding the "in use" status of the packets.
CrFwServSubType_t CrFwPcktGetServSubType(CrFwPckt_t pckt)
Return the service sub-type of the command or report encapsulated in a packet.
CrFwGroup_t CrFwPcktGetGroup(CrFwPckt_t pckt)
Return the group of the command/report encapsulated in a packet.
CrFwCounterU2_t CrFwPcktGetNOfAllocated()
Return the number of packets which are currently allocated.
void CrFwPcktSetDest(CrFwPckt_t pckt, CrFwDestSrc_t dest)
Set the destination of the command or report encapsulated in a packet.
Definition of Base Component.
static CrFwServType_t servType
The InCommand type as computed in the Validity Check.
static CrFwDestSrc_t dest
Destination.
static const CrFwPcktLength_t offsetDiscriminant
Offset of the discriminant field in a packet.
CrFwPcktLength_t CrFwPcktGetParLength(CrFwPckt_t pckt)
Return the length in bytes of the packet&#39;s parameter area.
CrFwBool_t CrFwPcktIsAcceptAck(CrFwPckt_t pckt)
Return the acknowledge level for command acceptance for the command encapsulated in the packet...
void CrFwPcktSetTimeStamp(CrFwPckt_t pckt, CrFwTimeStamp_t timeStamp)
Set the time stamp of the command or report encapsulated in a packet.
static const CrFwPcktLength_t offsetSeqCnt
Offset of the sequence counter field in a packet.
A packet release request has encountered an error (see CrFwPcktRelease).
CrFwBool_t CrFwPcktIsStartAck(CrFwPckt_t pckt)
Return the acknowledge level for command start for the command encapsulated in the packet...
unsigned short CrFwCounterU2_t
Type used for unsigned integers with a "medium" range.
unsigned int CrFwSeqCnt_t
Type used for the sequence counter of commands or reports.
void CrFwPcktSetDiscriminant(CrFwPckt_t pckt, CrFwDiscriminant_t discriminant)
Set the discriminant of the command or report encapsulated in a packet.
static const CrFwPcktLength_t offsetTimeStamp
Offset of the time stamp field in a packet.
unsigned int CrFwTimeStamp_t
Type used for the time stamp of a command or report.
static const CrFwPcktLength_t offsetDest
Offset of the destination field in a packet.
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved