CORDET Framework - C2 Implementation
|
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... | |
CrFwTypeCnt_t | CrFwPcktGetTypeCnt (CrFwPckt_t pckt) |
Return the type counter of the command or report encapsulated in a packet. More... | |
void | CrFwPcktSetTypeCnt (CrFwPckt_t pckt, CrFwTypeCnt_t typeCnt) |
Set the type 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. | |
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 | offsetTypeCnt = 56 |
Offset of the type counter in a packet. | |
static const CrFwPcktLength_t | offsetGroup = 60 |
Offset of the group in a packet. | |
static const CrFwPcktLength_t | offsetPar = 64 |
Offset of the parameter area in a packet. | |
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.
ICM-18: Operation to Access Attributes of an InCommand
ILD-10: Operation to Get Packet Destination
ILD-13: Operation to Get Packet Type
IRP-11: Operation to Access Attributes of an InReport
OCM-10: Acknowledge Level Attribute of OutComponent
OCM-19: Operation to Access Attributes of an OutComponent
IST-07: Operation to Get Packet Source from Incoming Packet
IST-08: Operation to Get Packet Sequence Counter from Incoming Packet
IST-13: Operation to get Group to which Incoming Packet belongs
OLD-09: Operation to set Set Time-Stamp in Outgoing Packets
OST-09: Operation to set Sequence Counter in Outgoing Packets
OST-10: Operation to set Type Counter in Outgoing Packets
OST-14: Operation to get Group to which Out-Going Packet belongs
OST-13: Operation to Compute and Set a Packet's CRC
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.
#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 77 of file CrFwPckt.c.
CrFwCrc_t CrFwPcktComputeCrc | ( | CrFwPckt_t | pckt | ) |
Compute the CRC in the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 277 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.
pckt | the packet. |
Definition at line 369 of file CrFwPckt.c.
CrFwCmdRepType_t CrFwPcktGetCmdRepType | ( | CrFwPckt_t | pckt | ) |
Return the type of a packet (either a command packet or a report packet).
pckt | the packet |
Definition at line 229 of file CrFwPckt.c.
CrFwCrc_t CrFwPcktGetCrc | ( | CrFwPckt_t | pckt | ) |
Return the CRC of the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 293 of file CrFwPckt.c.
CrFwDestSrc_t CrFwPcktGetDest | ( | CrFwPckt_t | pckt | ) |
Return the destination of the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 345 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.
pckt | the packet. |
Definition at line 303 of file CrFwPckt.c.
CrFwGroup_t CrFwPcktGetGroup | ( | CrFwPckt_t | pckt | ) |
Return the group of the command/report encapsulated in a packet.
pckt | the packet. |
Definition at line 428 of file CrFwPckt.c.
CrFwPcktLength_t CrFwPcktGetLength | ( | CrFwPckt_t | pckt | ) |
Return the length (in number of bytes) of a packet.
pckt | the packet. |
Definition at line 224 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.
Definition at line 219 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
.
Definition at line 214 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
.
pckt | a packet encapsulating a command or a report. |
Definition at line 417 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
.
pckt | a packet encapsulating a command or a report. |
Definition at line 412 of file CrFwPckt.c.
CrFwSeqCnt_t CrFwPcktGetSeqCnt | ( | CrFwPckt_t | pckt | ) |
Return the sequence counter of the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 241 of file CrFwPckt.c.
CrFwServSubType_t CrFwPcktGetServSubType | ( | CrFwPckt_t | pckt | ) |
Return the service sub-type of the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 333 of file CrFwPckt.c.
CrFwServType_t CrFwPcktGetServType | ( | CrFwPckt_t | pckt | ) |
Return the service type of the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 321 of file CrFwPckt.c.
CrFwDestSrc_t CrFwPcktGetSrc | ( | CrFwPckt_t | pckt | ) |
Return the source of the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 357 of file CrFwPckt.c.
CrFwTimeStamp_t CrFwPcktGetTimeStamp | ( | CrFwPckt_t | pckt | ) |
Return the time stamp of the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 265 of file CrFwPckt.c.
CrFwTypeCnt_t CrFwPcktGetTypeCnt | ( | CrFwPckt_t | pckt | ) |
Return the type counter of the command or report encapsulated in a packet.
pckt | the packet. |
Definition at line 253 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.
pckt | a packet encapsulating a command. |
Definition at line 388 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.
pcktLength | the length of the packet in bytes (a positive integer) |
Definition at line 194 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.
pckt | a packet encapsulating a command. |
Definition at line 400 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.
pckt | a packet encapsulating a command. |
Definition at line 394 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.
pckt | a packet encapsulating a command. |
Definition at line 406 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
.
pcktLength | the length of the packet in bytes (a positive integer) |
Definition at line 147 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
.
pckt | the packet to be released |
Definition at line 174 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.
pckt | the packet. |
accept | 1 if acknowledge of command acceptance is desired, 0 otherwise. |
start | 1 if acknowledge of command start is desired, 0 otherwise. |
progress | 1 if acknowledge of command progress is desired, 0 otherwise. |
term | 1 if acknowledge of command acceptance termination is desired, 0 otherwise. |
Definition at line 375 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.
pckt | the packet. |
id | the command or report identifier. |
Definition at line 363 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).
pckt | the packet |
type | the type of the entity (a command or a report) encapsulated by the packet. |
Definition at line 235 of file CrFwPckt.c.
void CrFwPcktSetCrc | ( | CrFwPckt_t | pckt, |
CrFwCrc_t | crc | ||
) |
Set the CRC in the command or report encapsulated in a packet.
pckt | the packet. |
crc | the command or report CRC. |
Definition at line 283 of file CrFwPckt.c.
void CrFwPcktSetDest | ( | CrFwPckt_t | pckt, |
CrFwDestSrc_t | dest | ||
) |
Set the destination of the command or report encapsulated in a packet.
pckt | the packet. |
dest | the destination of the packet. |
Definition at line 339 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.
pckt | the packet. |
discriminant | the discriminant. |
Definition at line 309 of file CrFwPckt.c.
void CrFwPcktSetGroup | ( | CrFwPckt_t | pckt, |
CrFwGroup_t | group | ||
) |
Set the group of the command/report encapsulated in a packet.
pckt | the packet. |
group | the destination or source group of the packet. |
Definition at line 422 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.
pckt | the packet. |
seqCnt | the sequence counter. |
Definition at line 247 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.
pckt | the packet. |
servSubType | the service sub-type. |
Definition at line 327 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.
pckt | the packet. |
servType | the service type. |
Definition at line 315 of file CrFwPckt.c.
void CrFwPcktSetSrc | ( | CrFwPckt_t | pckt, |
CrFwDestSrc_t | src | ||
) |
Set the source of the command or report encapsulated in a packet.
pckt | the packet. |
src | the source of the packet. |
Definition at line 351 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.
pckt | the packet. |
timeStamp | the time stamp. |
Definition at line 271 of file CrFwPckt.c.
void CrFwPcktSetTypeCnt | ( | CrFwPckt_t | pckt, |
CrFwTypeCnt_t | typeCnt | ||
) |
Set the type counter of the command or report encapsulated in a packet.
pckt | the packet. |
typeCnt | the type counter. |
Definition at line 259 of file CrFwPckt.c.
|
static |
The array holding the packets.
Packets are stored in this array in blocks of size CR_FW_MAX_PCKT_LENGTH.
Definition at line 83 of file CrFwPckt.c.
|
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 90 of file CrFwPckt.c.