How do you interpret this phrase?
Checksum
This is the value to make zero on the addition of the lower 8 bits from the header to the checksum.
With this protocol description:
Protocol
Consist of header (1 byte) + data length (1 byte) +
command data (13 bytes) + check sum (1 bytes) + connection ID (1
byte).
(I literally copied this protocol description, so I’dont know why there is 1 bytes (in plural). But I can tell you it is only one byte)
Here are some sample TCP packets of this protocol:
HE:DL:------------Command Data -------------:CS:ID
02:0d:be:ef:03:06:00:19:d3:02:00:00:60:00:00:ed:01
02:0d:be:ef:03:06:00:cd:d2:02:00:00:20:00:00:7a:01
02:0d:be:ef:03:06:00:10:f6:02:00:ba:30:00:00:49:01
02:0d:be:ef:03:06:00:c8:d8:02:00:20:30:00:00:49:01
// Requested Packets
02:0d:be:ef:03:06:00:13:d3:01:00:02:30:01:00:21:01
02:0d:be:ef:03:06:00:c2:ff:02:00:90:10:00:00:d8:01
Where
HEis the HEader (which is fixed to0x02)DLis the DataLength (which is always0x0d, because the packets are all the same length)CSis the CheckSum (which is my question about)IDis the connection ID (seems to be always 01 in my tests)
I can’t figure out how the checksum is computed. I hope I gave enough info.
Thanks in advance.
I think there’s just an error in the description. It looks like they are summing all the bytes between the header and the checksum. And the checksum is just a number that clears the lower 8 bits. So, for the first example, the sum of all bytes between the header and the checksum is 0x0313. Or
When it’s lined up like that, you can clearly see you’ll be zeroing out the lower 8 bits and returning:
You didn’t specify a language, but you could also quickly calculate your own checksum by doing (0 XOR calculatedSum) + 1.