Pioneer 2 User Manual

Page 33

Advertising
background image

Pioneer Mobile Robots

27

Table 6-1. Main elements of PSOS communication packet protocol

Packet Data Types

Packetized client commands and server information blocks use several data types, as defined below in
Table 6-2. There is no convention for sign; each packet type is interpreted idiosyncratically by the receiver.
Negative integers are sign-extended.

Table 6-2. P2OS Communication Packet Data Types

Packet Checksum

Calculate the communication packet checksum by successively adding data byte pairs (high byte first) to
the running checksum (initially zero), disregarding sign and overflow. If there is an odd number of data
bytes, the last byte is XORed to the low-order byte of the checksum.

NOTE: The checksum word is placed at the end of the packet, with its bytes in the reverse order of
that used for arguments and data; that is, b

0

is the high byte, and b

1

is the low byte.

Use the following C-code fragment in your client applications to compute a checksum:

int
calc_chksum(unsigned char *ptr) /* ptr is array of bytes, first is data count
*/
{
int n;
int c = 0;
n = *(ptr++);
n -= 2;

/* don't use chksum word */

while (n > 1) {
c += (*(ptr)<<8) | *(ptr+1);
c = c & 0xffff;
n -= 2;
ptr += 2;
}
if (n > 0) c = c ^ (int)*(ptr++);
return(c);
}

Packet Errors

Currently, P2OS ignores a client command packet whose byte count exceeds 200 or has an erroneous
checksum. The client should similarly ignore erroneous server information packets.

Component

Bytes

Value

Description

Header

2

0xFA, 0xFB

Packet header; same for client and server

Byte Count

1

N + 2

Number of subsequent data bytes, including
checksum word, but not Byte Count.
Maximum 200 total bytes.

Data

N

command

or SIB

Client command or server information block
(SIB; discussed in subsequent sections)

Checksum

2

computed

Packet integrity checksum

Data Type

Bytes

Order

integer

2

b

0

low byte; b

1

high byte

word

4

b

0

low byte; b

3

high byte

string

up to ~200,

length-prefixed

b

0

length of string;

b

1

first byte of string

Advertising