Initial commit
This commit is contained in:
26
src/crc8.cpp
Normal file
26
src/crc8.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "tinycrc.h"
|
||||
|
||||
/*
|
||||
CRC8 (from https://devcoons.com/crc8/)
|
||||
*/
|
||||
|
||||
uint8_t tinycrc_crc8(const uint8_t* data, uint16_t length)
|
||||
{
|
||||
char crc = 0x00;
|
||||
char extract;
|
||||
char sum;
|
||||
for(int i=0;i<length;i++)
|
||||
{
|
||||
extract = *data;
|
||||
for (char tempI = 8; tempI; tempI--)
|
||||
{
|
||||
sum = (crc ^ extract) & 0x01;
|
||||
crc >>= 1;
|
||||
if (sum)
|
||||
crc ^= 0x8C;
|
||||
extract >>= 1;
|
||||
}
|
||||
data++;
|
||||
}
|
||||
return crc;
|
||||
}
|
Reference in New Issue
Block a user