2023-11-21 20:28:23 +08:00
|
|
|
#ifndef CRC_H
|
|
|
|
#define CRC_H
|
|
|
|
#include <QObject>
|
|
|
|
#include "stdint-gcc.h"
|
|
|
|
#include "QString"
|
|
|
|
#include "QByteArray"
|
|
|
|
|
|
|
|
#define DECODE 0
|
|
|
|
#define ENCODE 1
|
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
int32_t l_data;
|
|
|
|
uint32_t ul_data;
|
|
|
|
uint8_t uc_databuf[4];
|
|
|
|
char c_databuf[4];
|
|
|
|
uint16_t us_databuf[2];
|
|
|
|
int16_t s_databuf[2];
|
2023-11-21 20:28:23 +08:00
|
|
|
} ConverBuf;
|
|
|
|
|
|
|
|
class crc
|
|
|
|
{
|
|
|
|
public:
|
2023-11-27 14:31:00 +08:00
|
|
|
crc();
|
|
|
|
static int8_t CheckSumCode(uint8_t CODEMODE, uint8_t *pBuffer, uint16_t Len, uint16_t offset, uint8_t *CHKA, uint8_t *CHKB);
|
|
|
|
static int CheckSumCode(uint8_t CODEMODE, QByteArray pBuffer, uint16_t Len, uint16_t offset, uint8_t *CHKA, uint8_t *CHKB);
|
2023-11-21 20:28:23 +08:00
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
static QString byte_array_to_string(QByteArray data);
|
|
|
|
static QString byte_array_to_int_string(QByteArray data);
|
|
|
|
static QString uint8_array_to_string(uint8_t *buf, int len);
|
2023-11-21 20:28:23 +08:00
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
static uint8_t crc8(uint8_t *Ptr, uint8_t num);
|
|
|
|
static void crc16(uint8_t *data, int offset, int len, uint8_t *lb, uint8_t *hb);
|
|
|
|
static uint32_t crc32(const QByteArray &data_buf);
|
2023-11-21 20:28:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CRC_H
|