CORDET Framework - C2 Implementation
CrFwPckt.c File Reference

Default implementation of the packet interface of CrFwPckt.h. More...

Go to the source code of this file.

Macros

#define CR_FW_MAX_PCKT_LENGTH   100
 Maximum length of a packet expressed in number of bytes (see CrFwPacket.h). More...
 

Functions

CrFwPckt_t CrFwPcktMake (CrFwPcktLength_t pcktLength)
 Make function for command or report packets. More...
 
void CrFwPcktRelease (CrFwPckt_t pckt)
 Release function for command or report packets. More...
 
CrFwBool_t CrFwPcktIsAvail (CrFwPcktLength_t pcktLength)
 Check whether a packet of a specified length is available. More...
 
CrFwCounterU2_t CrFwPcktGetNOfAllocated ()
 Return the number of packets which are currently allocated. More...
 
CrFwPcktLength_t CrFwPcktGetMaxLength ()
 Return the maximum length of a packet in number of bytes. More...
 
CrFwPcktLength_t CrFwPcktGetLength (CrFwPckt_t pckt)
 Return the length (in number of bytes) of a packet. More...
 
CrFwCmdRepType_t CrFwPcktGetCmdRepType (CrFwPckt_t pckt)
 Return the type of a packet (either a command packet or a report packet). More...
 
void CrFwPcktSetCmdRepType (CrFwPckt_t pckt, CrFwCmdRepType_t type)
 Set the type of a packet (either a command packet or a report packet). More...
 
CrFwSeqCnt_t CrFwPcktGetSeqCnt (CrFwPckt_t pckt)
 Return the sequence counter of the command or report encapsulated in a packet. More...
 
void CrFwPcktSetSeqCnt (CrFwPckt_t pckt, CrFwSeqCnt_t seqCnt)
 Set the sequence counter of the command or report encapsulated in a packet. More...
 
CrFwTimeStamp_t CrFwPcktGetTimeStamp (CrFwPckt_t pckt)
 Return the time stamp of the command or report encapsulated in a packet. More...
 
void CrFwPcktSetTimeStamp (CrFwPckt_t pckt, CrFwTimeStamp_t timeStamp)
 Set the time stamp of the command or report encapsulated in a packet. More...
 
CrFwCrc_t CrFwPcktComputeCrc (CrFwPckt_t pckt)
 Compute the CRC in the command or report encapsulated in a packet. More...
 
void CrFwPcktSetCrc (CrFwPckt_t pckt, CrFwCrc_t crc)
 Set the CRC in the command or report encapsulated in a packet. More...
 
CrFwCrc_t CrFwPcktGetCrc (CrFwPckt_t pckt)
 Return the CRC of the command or report encapsulated in a packet. More...
 
CrFwDiscriminant_t CrFwPcktGetDiscriminant (CrFwPckt_t pckt)
 Return the discriminant of the command or report encapsulated in a packet. More...
 
void CrFwPcktSetDiscriminant (CrFwPckt_t pckt, CrFwDiscriminant_t discriminant)
 Set the discriminant of the command or report encapsulated in a packet. More...
 
void CrFwPcktSetServType (CrFwPckt_t pckt, CrFwServType_t servType)
 Set the service type of the command or report encapsulated in a packet. More...
 
CrFwServType_t CrFwPcktGetServType (CrFwPckt_t pckt)
 Return the service type of the command or report encapsulated in a packet. More...
 
void CrFwPcktSetServSubType (CrFwPckt_t pckt, CrFwServSubType_t servSubType)
 Set the service sub-type of the command or report encapsulated in a packet. More...
 
CrFwServSubType_t CrFwPcktGetServSubType (CrFwPckt_t pckt)
 Return the service sub-type of the command or report encapsulated in a packet. More...
 
void CrFwPcktSetDest (CrFwPckt_t pckt, CrFwDestSrc_t dest)
 Set the destination of the command or report encapsulated in a packet. More...
 
CrFwDestSrc_t CrFwPcktGetDest (CrFwPckt_t pckt)
 Return the destination of the command or report encapsulated in a packet. More...
 
void CrFwPcktSetSrc (CrFwPckt_t pckt, CrFwDestSrc_t src)
 Set the source of the command or report encapsulated in a packet. More...
 
CrFwDestSrc_t CrFwPcktGetSrc (CrFwPckt_t pckt)
 Return the source of the command or report encapsulated in a packet. More...
 
void CrFwPcktSetCmdRepId (CrFwPckt_t pckt, CrFwInstanceId_t id)
 Set the command or report identifier in the command or report encapsulated in a packet. More...
 
CrFwInstanceId_t CrFwPcktGetCmdRepId (CrFwPckt_t pckt)
 Return the command or report identifier of the command or report encapsulated in a packet. More...
 
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. More...
 
CrFwBool_t CrFwPcktIsAcceptAck (CrFwPckt_t pckt)
 Return the acknowledge level for command acceptance for the command encapsulated in the packet. More...
 
CrFwBool_t CrFwPcktIsStartAck (CrFwPckt_t pckt)
 Return the acknowledge level for command start for the command encapsulated in the packet. More...
 
CrFwBool_t CrFwPcktIsProgressAck (CrFwPckt_t pckt)
 Return the acknowledge level for command progress for the command encapsulated in the packet. More...
 
CrFwBool_t CrFwPcktIsTermAck (CrFwPckt_t pckt)
 Return the acknowledge level for command termination for the command encapsulated in the packet. More...
 
CrFwPckt_t CrFwPcktGetParStart (CrFwPckt_t pckt)
 Return the start address of the packet's parameter area. More...
 
CrFwPcktLength_t CrFwPcktGetParLength (CrFwPckt_t pckt)
 Return the length in bytes of the packet's parameter area. More...
 
void CrFwPcktSetGroup (CrFwPckt_t pckt, CrFwGroup_t group)
 Set the group of the command/report encapsulated in a packet. More...
 
CrFwGroup_t CrFwPcktGetGroup (CrFwPckt_t pckt)
 Return the group of the command/report encapsulated in a packet. More...
 

Variables

static unsigned char pcktArray [CR_FW_MAX_NOF_PCKTS *CR_FW_MAX_PCKT_LENGTH]
 The array holding the packets. More...
 
static CrFwBool_t pcktInUse [CR_FW_MAX_NOF_PCKTS] = {0}
 The array holding the "in use" status of the packets. More...
 
static CrFwCounterU2_t nOfAllocatedPckts = 0
 The number of currently allocated packets. More...
 
static const CrFwPcktLength_t offsetLength = 0
 Offset of the length field in a packet.
 
static const CrFwPcktLength_t offsetCmdRepType = 4
 Offset of the flag defining the type of packet (1 for a command, 2 for a report)
 
static const CrFwPcktLength_t offsetTimeStamp = 8
 Offset of the time stamp field in a packet.
 
static const CrFwPcktLength_t offsetServType = 12
 Offset of the service type field in a packet.
 
static const CrFwPcktLength_t offsetServSubType = 16
 Offset of the service sub-type field in a packet.
 
static const CrFwPcktLength_t offsetDest = 20
 Offset of the destination field in a packet.
 
static const CrFwPcktLength_t offsetSrc = 24
 Offset of the source field in a packet.
 
static const CrFwPcktLength_t offsetDiscriminant = 28
 Offset of the discriminant field in a packet.
 
static const CrFwPcktLength_t offsetSeqCnt = 32
 Offset of the sequence counter field in a packet.
 
static const CrFwPcktLength_t offsetCmdRepId = 36
 Offset of the command or report identifier in a packet.
 
static const CrFwPcktLength_t offsetAcceptAckLev = 40
 Offset of the acceptance acknowledge level field in a packet.
 
static const CrFwPcktLength_t offsetStartAckLev = 44
 Offset of the start acknowledge level field in a packet.
 
static const CrFwPcktLength_t offsetProgressAckLev = 48
 Offset of the progress acknowledge level field in a packet.
 
static const CrFwPcktLength_t offsetTermAckLev = 52
 Offset of the termination acknowledge level field in a packet.
 
static const CrFwPcktLength_t offsetGroup = 56
 Offset of the group in a packet.
 
static const CrFwPcktLength_t offsetPar = 60
 Offset of the parameter area in a packet.
 

Detailed Description

Default implementation of the packet interface of CrFwPckt.h.

The implementation of this interface is one of the adaptation points of the CORDET Framework. This file provides a default implementation which is primarily intended to support testing. It is expected that applications will provide their own implementation. Application will therefore normally replace this file with their own file providing their application-specific implementation.

This implementation pre-allocates the memory for a predefined number of packets of fixed size. Packets can be either "in use" or "not in use". A packet is in use if it has been requested through a call to CrFwPcktMake and has not yet been released through a call to CrFwPcktRelease.

The implementation provided in this file uses global data structures to hold the pool of pre-allocated packets.

A packet encapsulates a command or a report and it holds all the attributes of the command or report. The layout of a packet is defined by the value of the offsetYyy constants which defines the offset within a packet at which attribute "Yyy" is stored. The exception is the CRC attribute which is placed at the end of the packet. The CRC is arbitrarily set equal to 0xFFFF.

The setter functions for the packet attributes assume that the packet length is adequate to hold the attributes. Compliance with this constraint is not checked by the setter functions. Its violation may result in memory corruption.

The CRC-related functions assume the CRC to be at the end of the packet and always compute a dummy value of 0xFFFF for the CRC of a packet.

Author
Vaclav Cechticky vacla.nosp@m.v.ce.nosp@m.chtic.nosp@m.ky@p.nosp@m.np-so.nosp@m.ftwa.nosp@m.re.co.nosp@m.m
Alessandro Pasetti paset.nosp@m.ti@p.nosp@m.np-so.nosp@m.ftwa.nosp@m.re.co.nosp@m.m

This file is part of the CORDET Framework.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

For information on alternative licensing, please contact P&P Software GmbH.

Definition in file CrFwPckt.c.

Macro Definition Documentation

#define CR_FW_MAX_PCKT_LENGTH   100

Maximum length of a packet expressed in number of bytes (see CrFwPacket.h).

The value of this constant must be smaller than the range of the CrFwPcktLength_t integer type.

Definition at line 62 of file CrFwPckt.c.

Function Documentation

CrFwCrc_t CrFwPcktComputeCrc ( CrFwPckt_t  pckt)

Compute the CRC in the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the command or report CRC.

Definition at line 247 of file CrFwPckt.c.

CrFwInstanceId_t CrFwPcktGetCmdRepId ( CrFwPckt_t  pckt)

Return the command or report identifier of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the command or report identifier.

Definition at line 339 of file CrFwPckt.c.

CrFwCmdRepType_t CrFwPcktGetCmdRepType ( CrFwPckt_t  pckt)

Return the type of a packet (either a command packet or a report packet).

Parameters
pcktthe packet
Returns
the type of the entity (a command or a report) encapsulated by the packet.

Definition at line 211 of file CrFwPckt.c.

CrFwCrc_t CrFwPcktGetCrc ( CrFwPckt_t  pckt)

Return the CRC of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the command or report CRC.

Definition at line 263 of file CrFwPckt.c.

CrFwDestSrc_t CrFwPcktGetDest ( CrFwPckt_t  pckt)

Return the destination of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the destination of the packet.

Definition at line 315 of file CrFwPckt.c.

CrFwDiscriminant_t CrFwPcktGetDiscriminant ( CrFwPckt_t  pckt)

Return the discriminant of the command or report encapsulated in a packet.

Not all commands and reports have a discriminant field. If the argument packet holds a command or report which does not have a discriminant field, the behaviour of this function is undefined.

Parameters
pcktthe packet.
Returns
the discriminant.

Definition at line 273 of file CrFwPckt.c.

CrFwGroup_t CrFwPcktGetGroup ( CrFwPckt_t  pckt)

Return the group of the command/report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the destination or source group of the packet.

Definition at line 398 of file CrFwPckt.c.

CrFwPcktLength_t CrFwPcktGetLength ( CrFwPckt_t  pckt)

Return the length (in number of bytes) of a packet.

Parameters
pcktthe packet.
Returns
the length (in number of bytes) of the packet.

Definition at line 206 of file CrFwPckt.c.

CrFwPcktLength_t CrFwPcktGetMaxLength ( )

Return the maximum length of a packet in number of bytes.

Some implementation may restrict the maximum length of a packet. This function allows this maximum length to be retrieved. If the function returns a value of zero, then no restriction on the length of a packet is defined by the implementation.

Returns
the maximum length of a packet in number of bytes or zero if no restriction on the packet length exists.

Definition at line 201 of file CrFwPckt.c.

CrFwCounterU2_t CrFwPcktGetNOfAllocated ( )

Return the number of packets which are currently allocated.

This function returns the number of packets which have been successfully allocated through calls to CrFwPcktMake and have not yet been released through calls to CrFwPcktRelease.

Returns
the number of packets which are currently allocated.

Definition at line 196 of file CrFwPckt.c.

CrFwPcktLength_t CrFwPcktGetParLength ( CrFwPckt_t  pckt)

Return the length in bytes of the packet's parameter area.

The parameter area is the part of a packet which is reserved to the storage of the parameters of the command or report encapsulated by the packet. The parameter area consists of an uninterrupted sequence of bytes. The start address of the parameter area is returned by function CrFwPcktGetParStart.

Parameters
pckta packet encapsulating a command or a report.
Returns
the length in bytes of the packet's parameter area.

Definition at line 387 of file CrFwPckt.c.

CrFwPckt_t CrFwPcktGetParStart ( CrFwPckt_t  pckt)

Return the start address of the packet's parameter area.

The parameter area is the part of a packet which is reserved to the storage of the parameters of the command or report encapsulated by the packet. The parameter area consists of an uninterrupted sequence of bytes. The size of the parameter area is returned by function CrFwPcktGetParLength.

Parameters
pckta packet encapsulating a command or a report.
Returns
the start address of the packet's parameter area.

Definition at line 382 of file CrFwPckt.c.

CrFwSeqCnt_t CrFwPcktGetSeqCnt ( CrFwPckt_t  pckt)

Return the sequence counter of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the sequence counter.

Definition at line 223 of file CrFwPckt.c.

CrFwServSubType_t CrFwPcktGetServSubType ( CrFwPckt_t  pckt)

Return the service sub-type of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the service sub-type.

Definition at line 303 of file CrFwPckt.c.

CrFwServType_t CrFwPcktGetServType ( CrFwPckt_t  pckt)

Return the service type of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the service type.

Definition at line 291 of file CrFwPckt.c.

CrFwDestSrc_t CrFwPcktGetSrc ( CrFwPckt_t  pckt)

Return the source of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the source of the packet.

Definition at line 327 of file CrFwPckt.c.

CrFwTimeStamp_t CrFwPcktGetTimeStamp ( CrFwPckt_t  pckt)

Return the time stamp of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
Returns
the time stamp.

Definition at line 235 of file CrFwPckt.c.

CrFwBool_t CrFwPcktIsAcceptAck ( CrFwPckt_t  pckt)

Return the acknowledge level for command acceptance for the command encapsulated in the packet.

If the packet does not hold a command, the behaviour of the function is undefined.

Parameters
pckta packet encapsulating a command.
Returns
1 if command acceptance is to be acknowledged, 0 otherwise.

Definition at line 358 of file CrFwPckt.c.

CrFwBool_t CrFwPcktIsAvail ( CrFwPcktLength_t  pcktLength)

Check whether a packet of a specified length is available.

A packet of length L is available if a call to function CrFwPcktMake with argument L would return a non-NULL value. Applications typically implement the CrFwPckt.h interface to manage a pool of pre-allocated memory from which packets are allocated using function CrFwPcktMake and are released using function CrFwPcktRelease. This function does not change the state of the pool from which the packets are allocated. It only verifies whether the allocation of a packet of a given length would be possible at the time the function is called.

The packet length must be a positive integer. If a negative or a zero value is used, the function returns false.

Parameters
pcktLengththe length of the packet in bytes (a positive integer)
Returns
true if a packet of the specified length is available, false otherwise of if the length is not a positive integer

Definition at line 176 of file CrFwPckt.c.

CrFwBool_t CrFwPcktIsProgressAck ( CrFwPckt_t  pckt)

Return the acknowledge level for command progress for the command encapsulated in the packet.

If the packet does not hold a command, the behaviour of the function is undefined.

Parameters
pckta packet encapsulating a command.
Returns
1 if command progress is to be acknowledged, 0 otherwise.

Definition at line 370 of file CrFwPckt.c.

CrFwBool_t CrFwPcktIsStartAck ( CrFwPckt_t  pckt)

Return the acknowledge level for command start for the command encapsulated in the packet.

If the packet does not hold a command, the behaviour of the function is undefined.

Parameters
pckta packet encapsulating a command.
Returns
1 if command start is to be acknowledged, 0 otherwise.

Definition at line 364 of file CrFwPckt.c.

CrFwBool_t CrFwPcktIsTermAck ( CrFwPckt_t  pckt)

Return the acknowledge level for command termination for the command encapsulated in the packet.

If the packet does not hold a command, the behaviour of the function is undefined.

Parameters
pckta packet encapsulating a command.
Returns
1 if command termination is to be acknowledged, 0 otherwise.

Definition at line 376 of file CrFwPckt.c.

CrFwPckt_t CrFwPcktMake ( CrFwPcktLength_t  pcktLength)

Make function for command or report packets.

This function returns an unconfigured packet of the specified length. An unconfigured packet of length L consists of a sequence of L bytes. The function allocates the memory for the packet and returns a pointer to the allocated memory.

The memory allocated to the packet remains reserved to the packet until the packet is released through a call to function CrFwPcktRelease. The content of the packet returned by this function is undefined. The way the memory is allocated and released is implementation-specific.

If the allocation of the memory for the new packet failed, the function returns NULL. Depending on the implementation, allocation memory failure may result in the application error code being set to crPcktAllocationFail.

The packet length must be a positive integer. If a negative or a zero value is used, the function returns NULL. Depending on the implementation, this may also result in the application error code being set to crPcktAllocationFail.

Parameters
pcktLengththe length of the packet in bytes (a positive integer)
Returns
a new packet or NULL if it was not possible to allocate the memory for the packet or if the packet length was not a positive integer

Definition at line 129 of file CrFwPckt.c.

void CrFwPcktRelease ( CrFwPckt_t  pckt)

Release function for command or report packets.

The argument of this function must be a packet which was created using function CrFwPcktMake. This function releases the memory which was allocated to the argument packet. After this function is called, the argument packet cannot be used.

An attempt to release a packet which had already been released, or to release a non-existent packet results in the application error code being set to: crPcktRelErr.

Parameters
pcktthe packet to be released

Definition at line 156 of file CrFwPckt.c.

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.

If the packet on which this function is called does not encapsulate a command, nothing is done.

Parameters
pcktthe packet.
accept1 if acknowledge of command acceptance is desired, 0 otherwise.
start1 if acknowledge of command start is desired, 0 otherwise.
progress1 if acknowledge of command progress is desired, 0 otherwise.
term1 if acknowledge of command acceptance termination is desired, 0 otherwise.

Definition at line 345 of file CrFwPckt.c.

void CrFwPcktSetCmdRepId ( CrFwPckt_t  pckt,
CrFwInstanceId_t  id 
)

Set the command or report identifier in the command or report encapsulated in a packet.

Parameters
pcktthe packet.
idthe command or report identifier.

Definition at line 333 of file CrFwPckt.c.

void CrFwPcktSetCmdRepType ( CrFwPckt_t  pckt,
CrFwCmdRepType_t  type 
)

Set the type of a packet (either a command packet or a report packet).

Parameters
pcktthe packet
typethe type of the entity (a command or a report) encapsulated by the packet.

Definition at line 217 of file CrFwPckt.c.

void CrFwPcktSetCrc ( CrFwPckt_t  pckt,
CrFwCrc_t  crc 
)

Set the CRC in the command or report encapsulated in a packet.

Parameters
pcktthe packet.
crcthe command or report CRC.

Definition at line 253 of file CrFwPckt.c.

void CrFwPcktSetDest ( CrFwPckt_t  pckt,
CrFwDestSrc_t  dest 
)

Set the destination of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
destthe destination of the packet.

Definition at line 309 of file CrFwPckt.c.

void CrFwPcktSetDiscriminant ( CrFwPckt_t  pckt,
CrFwDiscriminant_t  discriminant 
)

Set the discriminant of the command or report encapsulated in a packet.

Not all commands and reports have a discriminant field. If the argument packet holds a command or report which does not have a discriminant field, the behaviour of this function is undefined.

Parameters
pcktthe packet.
discriminantthe discriminant.

Definition at line 279 of file CrFwPckt.c.

void CrFwPcktSetGroup ( CrFwPckt_t  pckt,
CrFwGroup_t  group 
)

Set the group of the command/report encapsulated in a packet.

Parameters
pcktthe packet.
groupthe destination or source group of the packet.

Definition at line 392 of file CrFwPckt.c.

void CrFwPcktSetSeqCnt ( CrFwPckt_t  pckt,
CrFwSeqCnt_t  seqCnt 
)

Set the sequence counter of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
seqCntthe sequence counter.

Definition at line 229 of file CrFwPckt.c.

void CrFwPcktSetServSubType ( CrFwPckt_t  pckt,
CrFwServSubType_t  servSubType 
)

Set the service sub-type of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
servSubTypethe service sub-type.

Definition at line 297 of file CrFwPckt.c.

void CrFwPcktSetServType ( CrFwPckt_t  pckt,
CrFwServType_t  servType 
)

Set the service type of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
servTypethe service type.

Definition at line 285 of file CrFwPckt.c.

void CrFwPcktSetSrc ( CrFwPckt_t  pckt,
CrFwDestSrc_t  src 
)

Set the source of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
srcthe source of the packet.

Definition at line 321 of file CrFwPckt.c.

void CrFwPcktSetTimeStamp ( CrFwPckt_t  pckt,
CrFwTimeStamp_t  timeStamp 
)

Set the time stamp of the command or report encapsulated in a packet.

Parameters
pcktthe packet.
timeStampthe time stamp.

Definition at line 241 of file CrFwPckt.c.

Variable Documentation

CrFwCounterU2_t nOfAllocatedPckts = 0
static

The number of currently allocated packets.

Definition at line 78 of file CrFwPckt.c.

unsigned char pcktArray[CR_FW_MAX_NOF_PCKTS *CR_FW_MAX_PCKT_LENGTH]
static

The array holding the packets.

Packets are stored in this array in blocks of size CR_FW_MAX_PCKT_LENGTH.

Definition at line 68 of file CrFwPckt.c.

CrFwBool_t pcktInUse[CR_FW_MAX_NOF_PCKTS] = {0}
static

The array holding the "in use" status of the packets.

A packet is in use if it has been requested through a call to the "make" function and has not yet been released through a call to the "release" function.

Definition at line 75 of file CrFwPckt.c.

P&P Software GmbH, Copyright 2012-2013, All Rights Reserved