#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 = 32 , 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 < len; i++ ) {
crc ^= data[ i] ;
for ( j = 0 ; j < 8 ; j++ ) {
if ( crc & 0x80 ) {
crc = ( crc << 1 ) ^ 0x1D ;
} else {
crc <<= 1 ;
}
}
}
return crc;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmNoYXIgQ1JDOF9TQUVfSjE4NTBfWkVSTyhjaGFyIGRhdGFbXSwgaW50IGxlbik7CmludCBtYWluKHZvaWQpIHsKCWNoYXIgZGF0YSBbXSA9ezB4RjIsMHgwMCwweDAxLDB4MDAsMHgwMCwweDMwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwfTsKCWludCBsZW4gPSAzMixjcmM7CgljcmMgPSBDUkM4X1NBRV9KMTg1MF9aRVJPIChkYXRhLCBsZW4pOwoJcHJpbnRmKCJjcmMgJXgiLGNyYyk7CglyZXR1cm4gMDsKfQoKY2hhciBDUkM4X1NBRV9KMTg1MF9aRVJPKGNoYXIgZGF0YVtdLCBpbnQgbGVuKQp7CiAgY2hhciBjcmMgPSAweDAwOwogIGludCBpLCBqOwoKICBmb3IgKGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgIGNyYyBePSBkYXRhW2ldOwogICAgZm9yIChqID0gMDsgaiA8IDg7IGorKykgewogICAgICBpZiAoY3JjICYgMHg4MCkgewogICAgICAgIGNyYyA9IChjcmMgPDwgMSkgXiAweDFEOwogICAgICB9IGVsc2UgewogICAgICAgIGNyYyA8PD0gMTsKICAgICAgfQogICAgfQogIH0KICByZXR1cm4gY3JjOwp9