56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
#ifndef CRC32_H
|
|
#define CRC32_H
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <QtGlobal>
|
|
#include <QByteArray>
|
|
|
|
/*
|
|
* #define CRC_POLY_xxxx
|
|
*
|
|
* The constants of the form CRC_POLY_xxxx define the polynomials for some well
|
|
* known CRC calculations.
|
|
*/
|
|
|
|
#define CRC_POLY_16 0xA001
|
|
#define CRC_POLY_32 0xEDB88320L
|
|
#define CRC_POLY_CCITT 0x1021
|
|
#define CRC_POLY_DNP 0xA6BC
|
|
#define CRC_POLY_KERMIT 0x8408
|
|
#define CRC_POLY_SICK 0x8005
|
|
|
|
/*
|
|
* #define CRC_START_xxxx
|
|
*
|
|
* The constants of the form CRC_START_xxxx define the values that are used for
|
|
* initialization of a CRC value for common used calculation methods.
|
|
*/
|
|
|
|
#define CRC_START_8 0x00
|
|
#define CRC_START_16 0x0000
|
|
#define CRC_START_MODBUS 0xFFFF
|
|
#define CRC_START_XMODEM 0x0000
|
|
#define CRC_START_CCITT_1D0F 0x1D0F
|
|
#define CRC_START_CCITT_FFFF 0xFFFF
|
|
#define CRC_START_KERMIT 0x0000
|
|
#define CRC_START_SICK 0x0000
|
|
#define CRC_START_DNP 0x0000
|
|
#define CRC_START_32 0xFFFFFFFFL
|
|
|
|
|
|
class CCRC32
|
|
{
|
|
public:
|
|
CCRC32();
|
|
|
|
void InitTable();
|
|
quint32 ComputeCRC32( const unsigned char *input_str, qulonglong num_bytes );
|
|
quint32 ComputeCRC32( QByteArray Buffer);
|
|
quint32 UpdateCRC32( quint32 crc, unsigned char c );
|
|
|
|
private:
|
|
quint32 mCRC32Table[256];
|
|
};
|
|
|
|
#endif // CRC32_H
|