akshada
Member level 3
hello all,
i am trying to calculate crc32 of a binary file in chunks of 500 bytes. I'll give you a general idea what my system is doing.
I am trying to send the binary packets from server to my controller and i've written a crc32 code in php and the same crc32 algorithm is being implemented in microcontroller(STM32F100xx) for first few 500 bytes, it gives correct result but later on it is mismatched
PHP crc32 gives: 331516C0
microcontroller CRC32 : 331516C
the controller is not showing the last 0.
for your reference i am pasting my crc32 algorithm
PHP crc32:
thanks for your suggestion
i am trying to calculate crc32 of a binary file in chunks of 500 bytes. I'll give you a general idea what my system is doing.
I am trying to send the binary packets from server to my controller and i've written a crc32 code in php and the same crc32 algorithm is being implemented in microcontroller(STM32F100xx) for first few 500 bytes, it gives correct result but later on it is mismatched
PHP crc32 gives: 331516C0
microcontroller CRC32 : 331516C
the controller is not showing the last 0.
for your reference i am pasting my crc32 algorithm
Code:
uint32_t crc32_gen(unsigned char *block, unsigned int bytelength)
{
register unsigned long crc;
unsigned long i;
crc = 0xFFFFFFFF;
for (i = 0; i < bytelength; i++)
{
crc = ( (crc >> 8) & 0x00FFFFFF ) ^ crc32_tab[(crc & 0xFF) ^ *block++ ];
}
return (crc ^ 0xFFFFFFFF);
}
PHP crc32:
Code:
function crc32gen(&$buffer,$bytelength)
{
$crc_table = $GLOBALS['crc_table'];
$crc = 0xFFFFFFFF;
for($i=0;$i < $bytelength;$i++)
{
$crc = (($crc >> 8) & 0x00FFFFFF) ^ $crc_table [($crc & 0xFF) ^ ord($buffer[$i])];
}
return($crc ^ 0xFFFFFFFF);
}
thanks for your suggestion
Last edited: