crc8.h
Go to the documentation of this file.
1 //
2 // Created by armadillo2 on 26/12/17.
3 //
4 
5 #ifndef RIC_INTERFACE_CRC8_H
6 #define RIC_INTERFACE_CRC8_H
7 
8 #include <stdio.h>
9 #include <iostream>
10 
11 typedef uint8_t byte;
12 
13 class Crc8
14 {
15 
16 private:
17  const byte CRC7_POLY_ = 0x91;
19 
20 
22  {
23  byte j;
24 
25  for (j = 0; j < 8; j++)
26  {
27  if (val & 1)
28  val ^= CRC7_POLY_;
29  val >>= 1;
30  }
31  return val;
32  }
33 
34  /* build crc table */
35  void init()
36  {
37  int i;
38  // fill an array with CRC values of all 256 possible bytes
39  for (i = 0; i < 256; i++)
40  crc_table_[i] = get_byte_crc(i);
41  }
42 
43 public:
44 
45  byte get_crc(byte message[], size_t size)
46  {
47  init();
48  byte i, crc = 0;
49  for (i = 0; i < size; i++)
50  crc = crc_table_[crc ^ message[i]];
51  return crc;
52  }
53 };
54 
55 #endif //RIC_INTERFACE_CRC8_H
byte get_byte_crc(byte val)
Definition: crc8.h:21
void init()
Definition: crc8.h:35
Definition: crc8.h:13
uint8_t byte
Definition: crc8.h:11
byte get_crc(byte message[], size_t size)
Definition: crc8.h:45
byte crc_table_[256]
Definition: crc8.h:18
const byte CRC7_POLY_
Definition: crc8.h:17


ric_interface
Author(s):
autogenerated on Wed Jan 3 2018 03:48:20