[CRC] Reworked for non-standard CRC lengths
This commit is contained in:
parent
8062a322c6
commit
acf683b91b
1 changed files with 13 additions and 14 deletions
|
@ -6,17 +6,16 @@ RadioLibCRC::RadioLibCRC() {
|
|||
|
||||
uint32_t RadioLibCRC::checksum(uint8_t* buff, size_t len) {
|
||||
uint32_t crc = this->init;
|
||||
for(size_t i = 0; i < len; i+=this->size/8) {
|
||||
uint32_t window = 0;
|
||||
for(uint8_t j = 0; j < this->size/8; j++) {
|
||||
uint8_t inByte = buff[i + j];
|
||||
size_t pos = 0;
|
||||
for(size_t i = 0; i < 8*len; i++) {
|
||||
if(i % 8 == 0) {
|
||||
uint32_t in = buff[pos++];
|
||||
if(this->refIn) {
|
||||
inByte = Module::reflect(inByte, 8);
|
||||
in = Module::reflect(in, 8);
|
||||
}
|
||||
window |= (inByte << ((this->size - 8) - 8*j));
|
||||
crc ^= (in << (this->size - 8));
|
||||
}
|
||||
crc ^= window;
|
||||
for(size_t k = 0; k < this->size; k++) {
|
||||
|
||||
if(crc & ((uint32_t)1 << (this->size - 1))) {
|
||||
crc <<= (uint32_t)1;
|
||||
crc ^= this->poly;
|
||||
|
@ -24,7 +23,7 @@ uint32_t RadioLibCRC::checksum(uint8_t* buff, size_t len) {
|
|||
crc <<= (uint32_t)1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= this->out;
|
||||
if(this->refOut) {
|
||||
crc = Module::reflect(crc, this->size);
|
||||
|
|
Loading…
Add table
Reference in a new issue