ARCOS
24
Packet Checksum
Calculate the client-server packet checksum by successively adding data byte pairs (high byte first) to a running
checksum (initially zero), disregarding sign and overflow. If there are an odd number of data bytes, the last byte is
XORed to the low-order byte of the checksum.
NOTE:
NOTE:
NOTE:
NOTE: The checksum integer is placed at the end of the packet, with its bytes in the reverse order of that used for data;
that is, b
0
is the high byte and b
1
is the low byte.
Packet Errors
ARCOS ignores a client command packet whose byte count exceeds 204 (total packet size of 207 bytes) or has an
erroneous checksum. The client should similarly ignore erroneous SIPs.
Table 4. Client command packet protocol
C
OMPONENT
B
YTES
V
ALUE
D
ESCRIPTION
header
2
0xFA, 0xFB
Packet header; same for client and server
byte count
1
N
Number
of
command/argument
bytes
plus
Checksum’s two bytes, but not including Byte
Count itself or the header bytes. Maximum
of 249.
command
number
1
0 - 255
Client command number; see
Table 6
.
argument
type
1
0x3B or
0x1B or
0x2B
Required data type of command argument:
positive
integer,
negative
or
absolute
integer, or string
argument
n
data
Command argument; always 2-byte integer or
string containing length prefix
checksum
2
computed
Packet integrity checksum
AREXPORT ArTypes::Byte2 ArRobotPacket::calcCheckSum(void)
{
int i;
unsigned char n;
int c = 0;
i = 3;
n = myBuf[2] - 2;
while (n > 1) {
c += ((unsigned char)myBuf[i]<<8) | (unsigned char)myBuf[i+1];
c = c & 0xffff;
n -= 2;
i += 2;
}
if (n > 0)
c = c ^ (int)((unsigned char) myBuf[i]);
return c;
}
(from MobileRobots ARIA ArRobotPacket.cpp)