38 lines
		
	
	
		
			981 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			981 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #ifndef CRC_H
 | |
| #define CRC_H
 | |
| #include <QObject>
 | |
| #include "stdint-gcc.h"
 | |
| #include "QString"
 | |
| #include "QByteArray"
 | |
| 
 | |
| #define DECODE 0
 | |
| #define ENCODE 1
 | |
| 
 | |
| 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];
 | |
| } ConverBuf;
 | |
| 
 | |
| class crc
 | |
| {
 | |
| public:
 | |
|   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);
 | |
| 
 | |
|   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);
 | |
| 
 | |
|   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);
 | |
| };
 | |
| 
 | |
| #endif // CRC_H
 | 
