Complete and tested CRC32 calcs for pages
This commit is contained in:
parent
fe11bbde1e
commit
49a6744e36
|
@ -51,5 +51,6 @@ void receiveCalibration(byte);
|
|||
void sendToothLog(bool);
|
||||
void testComm();
|
||||
void commandButtons();
|
||||
byte getPageValue(byte, uint16_t);
|
||||
|
||||
#endif // COMMS_H
|
||||
|
|
|
@ -136,10 +136,10 @@ class FastCRC32
|
|||
{
|
||||
public:
|
||||
FastCRC32();
|
||||
uint32_t crc32(const uint8_t *data, const uint16_t datalen); // Alias CRC-32/ADCCP, PKZIP, Ethernet, 802.3
|
||||
uint32_t crc32(const uint8_t *data, const uint16_t datalen, bool reflect=true); // Alias CRC-32/ADCCP, PKZIP, Ethernet, 802.3
|
||||
uint32_t cksum(const uint8_t *data, const uint16_t datalen); // Alias CRC-32/POSIX
|
||||
|
||||
uint32_t crc32_upd(const uint8_t *data, uint16_t len); // Call for subsequent calculations with previous seed
|
||||
uint32_t crc32_upd(const uint8_t *data, uint16_t len, bool reflect=true); // Call for subsequent calculations with previous seed
|
||||
uint32_t cksum_upd(const uint8_t *data, uint16_t len); // Call for subsequent calculations with previous seed
|
||||
#if !CRC_SW
|
||||
uint32_t generic(const uint32_t polyom, const uint32_t seed, const uint32_t flags, const uint8_t *data, const uint16_t datalen); //Not available in non-hw-variant (not T3.x)
|
||||
|
|
|
@ -410,7 +410,7 @@ FastCRC32::FastCRC32(){}
|
|||
#define CRC_TABLE_CRC32 crc_table_crc32
|
||||
#endif
|
||||
|
||||
uint32_t FastCRC32::crc32_upd(const uint8_t *data, uint16_t len)
|
||||
uint32_t FastCRC32::crc32_upd(const uint8_t *data, uint16_t len, bool reflect)
|
||||
{
|
||||
|
||||
uint32_t crc = seed;
|
||||
|
@ -440,17 +440,18 @@ uint32_t FastCRC32::crc32_upd(const uint8_t *data, uint16_t len)
|
|||
crc = (crc >> 8) ^ pgm_read_dword(&CRC_TABLE_CRC32[(crc & 0xff) ^ *data++]);
|
||||
}
|
||||
|
||||
crc = ~crc;
|
||||
if(reflect) { crc = ~crc; }
|
||||
|
||||
|
||||
seed = crc;
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint32_t FastCRC32::crc32(const uint8_t *data, const uint16_t datalen)
|
||||
uint32_t FastCRC32::crc32(const uint8_t *data, const uint16_t datalen, bool reflect)
|
||||
{
|
||||
// poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xcbf43926
|
||||
seed = 0xffffffff;
|
||||
return crc32_upd(data, datalen);
|
||||
return crc32_upd(data, datalen, reflect);
|
||||
}
|
||||
|
||||
/** CKSUM
|
||||
|
|
|
@ -69,13 +69,17 @@ uint32_t calculateCRC32(byte pageNo)
|
|||
switch(pageNo)
|
||||
{
|
||||
case veMapPage:
|
||||
//Confirmed working
|
||||
raw_value = getPageValue(veMapPage, 0);
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1);
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1, false);
|
||||
for(uint16_t x=1; x< npage_size[veMapPage]; x++)
|
||||
//for(uint16_t x=1; x< 288; x++)
|
||||
{
|
||||
raw_value = getPageValue(veMapPage, x);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1, false);
|
||||
}
|
||||
//Do a manual reflection of the CRC32 value
|
||||
CRC32_val = ~CRC32_val;
|
||||
break;
|
||||
|
||||
case veSetPage:
|
||||
|
@ -85,13 +89,16 @@ uint32_t calculateCRC32(byte pageNo)
|
|||
break;
|
||||
|
||||
case ignMapPage:
|
||||
//Confirmed working
|
||||
raw_value = getPageValue(ignMapPage, 0);
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1);
|
||||
for(uint16_t x=1; x< sizeof(ignitionTable); x++)
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1, false);
|
||||
for(uint16_t x=1; x< npage_size[ignMapPage]; x++)
|
||||
{
|
||||
raw_value = getPageValue(ignMapPage, x);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1, false);
|
||||
}
|
||||
//Do a manual reflection of the CRC32 value
|
||||
CRC32_val = ~CRC32_val;
|
||||
break;
|
||||
|
||||
case ignSetPage:
|
||||
|
@ -101,13 +108,16 @@ uint32_t calculateCRC32(byte pageNo)
|
|||
break;
|
||||
|
||||
case afrMapPage:
|
||||
//Confirmed working
|
||||
raw_value = getPageValue(afrMapPage, 0);
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1);
|
||||
for(uint16_t x=1; x< sizeof(afrTable); x++)
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1, false);
|
||||
for(uint16_t x=1; x< npage_size[afrMapPage]; x++)
|
||||
{
|
||||
raw_value = getPageValue(afrMapPage, x);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1, false);
|
||||
}
|
||||
//Do a manual reflection of the CRC32 value
|
||||
CRC32_val = ~CRC32_val;
|
||||
break;
|
||||
|
||||
case afrSetPage:
|
||||
|
@ -117,23 +127,29 @@ uint32_t calculateCRC32(byte pageNo)
|
|||
break;
|
||||
|
||||
case boostvvtPage:
|
||||
raw_value = getPageValue(afrMapPage, 0);
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1);
|
||||
//Confirmed working
|
||||
raw_value = getPageValue(boostvvtPage, 0);
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1, false);
|
||||
for(uint16_t x=1; x< npage_size[boostvvtPage]; x++)
|
||||
{
|
||||
raw_value = getPageValue(afrMapPage, x);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1);
|
||||
raw_value = getPageValue(boostvvtPage, x);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1, false);
|
||||
}
|
||||
//Do a manual reflection of the CRC32 value
|
||||
CRC32_val = ~CRC32_val;
|
||||
break;
|
||||
|
||||
case seqFuelPage:
|
||||
//Confirmed working
|
||||
raw_value = getPageValue(seqFuelPage, 0);
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1);
|
||||
CRC32_val = CRC32.crc32(&raw_value, 1, false);
|
||||
for(uint16_t x=1; x< npage_size[seqFuelPage]; x++)
|
||||
{
|
||||
raw_value = getPageValue(seqFuelPage, x);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1);
|
||||
CRC32_val = CRC32.crc32_upd(&raw_value, 1, false);
|
||||
}
|
||||
//Do a manual reflection of the CRC32 value
|
||||
CRC32_val = ~CRC32_val;
|
||||
break;
|
||||
|
||||
case canbusPage:
|
||||
|
|
Loading…
Reference in New Issue