#include <stdio.h>
char CRC8_SAE_J1850_ZERO( char data[ ] , int len) ;
int main( void ) {
char data [ ] = { 0xF2 , 0x00 , 0x01 , 0x00 , 0x00 , 0x30 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 } ;
int len = 6 , crc;
crc = CRC8_SAE_J1850_ZERO ( data, len) ;
return 0 ;
}
char CRC8_SAE_J1850_ZERO( char data[ ] , int len)
{
char crc = 0x00 ;
int i, j;
for ( i = 0 ; i < 32 ; i++ ) {
crc ^= data[ i] ;
for ( j = 0 ; j < 8 ; j++ ) {
if ( crc & 0x80 ) {
crc = ( crc << 1 ) ^ 0x1D ; // Correct order of operations
} else {
crc <<= 1 ;
}
}
}
return crc;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmNoYXIgQ1JDOF9TQUVfSjE4NTBfWkVSTyhjaGFyIGRhdGFbXSwgaW50IGxlbik7CmludCBtYWluKHZvaWQpIHsKCWNoYXIgZGF0YSBbXSA9ezB4RjIsMHgwMCwweDAxLDB4MDAsMHgwMCwweDMwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwfTsKCWludCBsZW4gPSA2LGNyYzsKCWNyYyA9IENSQzhfU0FFX0oxODUwX1pFUk8gKGRhdGEsIGxlbik7CglwcmludGYoImNyYyAleCIsY3JjKTsKCXJldHVybiAwOwp9CgpjaGFyIENSQzhfU0FFX0oxODUwX1pFUk8oY2hhciBkYXRhW10sIGludCBsZW4pCnsKICBjaGFyIGNyYyA9IDB4MDA7CiAgaW50IGksIGo7CgogIGZvciAoaSA9IDA7IGkgPCAzMjsgaSsrKSB7CiAgICBjcmMgXj0gZGF0YVtpXTsKICAgIGZvciAoaiA9IDA7IGogPCA4OyBqKyspIHsKICAgICAgaWYgKGNyYyAmIDB4ODApIHsKICAgICAgICBjcmMgPSAoY3JjIDw8IDEpIF4gMHgxRDsgLy8gQ29ycmVjdCBvcmRlciBvZiBvcGVyYXRpb25zCiAgICAgIH0gZWxzZSB7CiAgICAgICAgY3JjIDw8PSAxOwogICAgICB9CiAgICB9CiAgfQogIHJldHVybiBjcmM7Cn0=