Can't figure out this checksum

0

I've got some hardware I'm working with that gets strings sent over RS232. The first part of the string needs a checksum that's built into the rest of the string.

The manufacturer refuses to give me direct answers to my questions, so I'm hoping someone here might recognize what's going on here because I can't. The check sums are in hex.

For example, one of the checksums adds up to 0x6F0 and from that they extrapolate 4 hex characters (0x30 0x36 0x3F 0x30). If they checksum is longer than 4 digits you're supposed to just grab the last 4.

Some that example comes out like this:

0x02 + 0x05 + 0x75 + 0x32 .... + 0x39
== 0x6F0
=== > 0x30 0x36 0x3F 0x30

The 0x30 0x36 0x3F 0x30 are the checksum which I think concatenate to the rest of the string and send it out.

This is a loop they sent me that supposedly calculates the checksum:

    for(i=0,ChkSum=0 ; i < ip ; i++)
        ChkSum = (ChkSum + value[i]) & 0xFFFF;
        value[ip++]=( ChkSum >> 12) + 0x30;
        value[ip++]=( (ChkSum & 0x00000F00) >> 8) + 0x30;
        value[ip++]=( (ChkSum & 0x000000F0) >> 4) + 0x30;
        value[ip++]=( ChkSum & 0x0000000F)  + 0x30;
checksum
asked on Stack Overflow Feb 15, 2018 by dstana

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0