MySensors Library & Examples  2.3.2-62-ge298769
PJON_CRC8.h
1 
2 #pragma once
3 
4 /* Compute CRC8 with a table-less implementation:
5  Copyright Giovanni Blu Mitolo [email protected] 2018
6 
7  CRC8 C2, source Baicheva98 (implicit + 1 notation)
8  0x97 = (x + 1)(x^7 + x^6 + x^5 + x^2 + 1)^2
9  Chosen because it has the largest possible length (119 bit) at which
10  HD=4 can be achieved with 8-bit CRC. */
11 
12 struct PJON_crc8 {
13 
14  static inline uint8_t roll(uint8_t input_byte, uint8_t crc)
15  {
16  for(uint8_t i = 8; i; i--, input_byte >>= 1) {
17  uint8_t result = (crc ^ input_byte) & 0x01;
18  crc >>= 1;
19  if(result) {
20  crc ^= 0x97;
21  }
22  }
23  return crc;
24  };
25 
26 
27  static inline uint8_t compute(const uint8_t *input_byte, uint16_t length)
28  {
29  uint8_t crc = 0;
30  for(uint16_t b = 0; b < length; b++) {
31  crc = roll(input_byte[b], crc);
32  }
33  return crc;
34  };
35 
36 };
PJON_crc8
Definition: PJON_CRC8.h:12