semf
semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR > Class Template Reference

Template class for CRC generation in software. More...

#include <crcsoftware.h>

Inheritance diagram for semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >:
Inheritance graph
Collaboration diagram for semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >:
Collaboration graph

Public Member Functions

 CrcSoftware (T polynomial=DEFAULT_POLYNOMIAL, T initValue=DEFAULT_INITVALUE, T finalXor=DEFAULT_FINALXOR)
 Constructor. More...
 
virtual ~CrcSoftware ()=default
 
void reset ()
 Resets internal values to their initial values. More...
 
const uint8_t * accumulate (const uint8_t data[], size_t dataSize) override
 Computes the CRC of the input data using a combination of the previous CRC value and the new one. More...
 
const uint8_t * calculate (const uint8_t data[], size_t dataSize) override
 Calculates the CRC of the input data. More...
 
bool isEqual (const uint8_t data[]) override
 Checks if previously calculated CRC is equal to the input value. More...
 
size_t bitSize () const override
 Returns the size of the CRC in bits. More...
 
size_t byteSize () const override
 Returns the size of the CRC in bytes. More...
 
- Public Member Functions inherited from semf::app::Crc
virtual ~Crc ()=default
 
virtual void reset ()=0
 Resets internal values to their initial values. More...
 
virtual const uint8_t * accumulate (const uint8_t data[], size_t size)=0
 Computes the CRC of the input data using a combination of the previous CRC value and the new one. More...
 
virtual const uint8_t * calculate (const uint8_t data[], size_t size)=0
 Calculates the CRC of the input data. More...
 
virtual bool isEqual (const uint8_t data[])=0
 Checks if previously calculated CRC is equal to the input value. More...
 
virtual size_t bitSize () const =0
 Returns the size of the CRC in bits. More...
 
virtual size_t byteSize () const =0
 Returns the size of the CRC in bytes. More...
 

Detailed Description

template<typename T, T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
class semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >

Template class for CRC generation in software.

Parameters
TCRC data type
DEFAULT_POLYNOMIALCRC default polynomial.
DEFAULT_INITVALUECRC default init value.
DEFAULT_FINALXORCRC default final xor.

Definition at line 29 of file crcsoftware.h.

Constructor & Destructor Documentation

◆ CrcSoftware()

template<typename T , T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >::CrcSoftware ( polynomial = DEFAULT_POLYNOMIAL,
initValue = DEFAULT_INITVALUE,
finalXor = DEFAULT_FINALXOR 
)
explicit

Constructor.

Parameters
polynomialUses this polynomial instead of the default polynomial.
initValueUses this initValue instead of the default initValue.
finalXorUses this final xor value instead of the default final xor value.

Definition at line 66 of file crcsoftware.h.

◆ ~CrcSoftware()

template<typename T , T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
virtual semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >::~CrcSoftware ( )
virtualdefault

Member Function Documentation

◆ accumulate()

template<typename T , T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
const uint8_t * semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >::accumulate ( const uint8_t  data[],
size_t  size 
)
overridevirtual

Computes the CRC of the input data using a combination of the previous CRC value and the new one.

Note
This function is helpful if the data is not completely stored in the memory and is called up piece by piece from another memory.
Parameters
dataData over which a CRC value will be computed.
sizeSize of the input data.
Returns
Pointer to the calculated CRC value.
See also
reset().

Implements semf::app::Crc.

Definition at line 82 of file crcsoftware.h.

◆ bitSize()

template<typename T , T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
size_t semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >::bitSize ( ) const
overridevirtual

Returns the size of the CRC in bits.

Returns
Number of bits of the CRC value.

Implements semf::app::Crc.

Definition at line 123 of file crcsoftware.h.

◆ byteSize()

template<typename T , T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
size_t semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >::byteSize ( ) const
overridevirtual

Returns the size of the CRC in bytes.

Returns
Number of bytes of the CRC value.

Implements semf::app::Crc.

Definition at line 129 of file crcsoftware.h.

◆ calculate()

template<typename T , T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
const uint8_t * semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >::calculate ( const uint8_t  data[],
size_t  size 
)
overridevirtual

Calculates the CRC of the input data.

Note
This function is helpful if the data is completely stored in the memory, unlike in accumulate() function.
Parameters
dataData over which a CRC value will be computed.
sizeSize of the input data.
Returns
Pointer to the calculated CRC value.

Implements semf::app::Crc.

Definition at line 101 of file crcsoftware.h.

◆ isEqual()

template<typename T , T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
bool semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >::isEqual ( const uint8_t  data[])
overridevirtual

Checks if previously calculated CRC is equal to the input value.

Parameters
dataCRC value to compare with calculated CRC value.
Returns
true for CRCs are equal, otherwise false.

Implements semf::app::Crc.

Definition at line 110 of file crcsoftware.h.

◆ reset()

template<typename T , T DEFAULT_POLYNOMIAL, T DEFAULT_INITVALUE, T DEFAULT_FINALXOR>
void semf::CrcSoftware< T, DEFAULT_POLYNOMIAL, DEFAULT_INITVALUE, DEFAULT_FINALXOR >::reset ( )
virtual

Resets internal values to their initial values.

See also
accumulate().

Implements semf::app::Crc.

Definition at line 75 of file crcsoftware.h.