You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CCS-COMM_BOARD/MODBUSRTU/ModbusRTUCRC.h

59 lines
1014 B
C

/*
* ModbusRTUCRC.h
*
* Author: Aleksey Gerasimenko
* gerasimenko.aleksey.n@gmail.com
*/
#include <math.h>
#include <stdint.h>
#ifndef MODBUSRTU_MODBUSRTUCRC_H_
#define MODBUSRTU_MODBUSRTUCRC_H_
struct Uint16ByteField
{
uint16_t low: 8;
uint16_t high: 8;
};//Uint16ByteField
union Uint16Register
{
uint16_t all;
Uint16ByteField byte;
Uint16Register():
all(0)
{}
};//
namespace MODBUSRTU
{
class ModbusRTUCRC
{
private:
static const uint16_t m_table[256];
private:
Uint16Register m_crc_calculate;
uint16_t m_table_crc_index;
Uint16Register m_table_crc_value;
uint16_t *m_start;
uint16_t *m_end;
public:
ModbusRTUCRC();
public:
uint16_t calculate(uint16_t *start, uint16_t length);
uint16_t calculate(uint16_t *start, uint16_t *end);
uint16_t calculate(uint16_t databyte, uint16_t crc);
private:
inline void _while_cycle();
};
} /* namespace MODBUSRTU */
#endif /* MODBUSRTU_MODBUSRTUCRC_H_ */