I am communicating with a machine over serial. Part of the protocol communication spec states that the control sum is an "arithmetic sum of bytes from <'PS'> (included), <'data'> to <'CS'>"
The packet messages are structured as follows:
<'PS'><'data'><'CS'>, where:
<'PS'> - Packet Size
Length: 1
Value: 0x02 to 0x63
Max packet length is 99 bytes
<'data'> - Data
Length: 1...90 bytes
Value: 0x00 - 0xFF
The length of the data part depends on the command.
<'CS'> - Check Sum
Length - 1 byte
Value: 0x00 - 0xFF
Example:
ACK Packet: 0x02 0x01 0x03 where 0x03 is the checksum.
So how do I compute the checksum for these bytes in C++?