Hey Guys,
I've been asked to write a technical document describing a protocol. Although I wrote most of it, the underlying structure ie header, and checksum was already in existence. In the technical documentation, I would like to describe the type of checksum used but from the code, I can't determine what it is. It looks like it might be a variant of Fletcher-16 using a modulus of 255, but I'm not sure.
Any ideas? The code is below and the processor is big-endian.
Thanks!
unsigned short calc_checksum(void *data, int count) {
unsigned char *checksum_ptr; unsigned short tx_sum1 = 0; unsigned short tx_sum2 = 0; unsigned char csum1; unsigned char csum2;
for (checksum_ptr = data; checksum_ptr < data + count; checksum_ptr++) { tx_sum1 += *checksum_ptr; if (tx_sum1 >= 255) { tx_sum1 -= 255; } tx_sum2 += tx_sum1; }
tx_sum2 %= 255; csum1 = (255 - ((tx_sum1 + tx_sum2) % 255)); csum2 = (255 - ((tx_sum1 + csum1) % 255)); return (unsigned short)csum1