beautypg.com

Serauxpac and getaux – Pioneer 2 / PeopleBot User Manual

Page 47

background image

ActivMedia Robotics

Send the CONFIG command #18 with or without an argument to have P2OS send back a
special server information packet containing the robot's operational parameters. The
CONFIGpac

SIP packet type is 32 (0x20). The next chapter gives details about the

configuration packet data.

/* Send commands and retrieve responses via the P2OS AUX serial port */

#define SERAUXpac 0xB0
int serbytes, inbufptr;
char inbuf[200];
...
/* Replace Saphira's default packet processor with
our own that can detect and parse SERAUXpac packets */
void myStartupFn(void)
{
sfInitProcess(myPackets,

"GetAuxPkt");

sfRemoveTask("packets");

/* default packet processing */

...
}

/* SERAUXpac packet processor */
void myPackets(void)
{
char

packet_type;

if

(sfIsConnected)

{
while(sfHaveClientPacket())
{
packet_type

=

sfReadClientByte();

if (packet_type == SERAUXpac)
{
/* get aux serbytes into inbuf */
while

(inbufptr++

<

serbytes)

inbuf[inbufptr]

=

sfReadClientByte();

}
/* If not SERAUXpac, send along to default */
else
sfProcessClientPacket(packet_type);
}
}

void main(int argc, char **argv)
{
/* Initialize client and connect with robot */
...
sfRobotComInt(43,0);

/* flush the aux buffer */

sfRobotComStrn(42,"fictitious command",18); /* send command to AUX device */
inbufptr = 0;
serbytes = 10; /* number of response bytes to retrieve */
sfRobotComInt(43,serbytes); /* Expect a 10 byte response */
...
}

SERAUXpac and GETAUX

P2OS 1.4 implemented two-way communications through the AUX serial port on the

microcontroller. And with those earlier versions of P2OS, you are able to send a string of
data (a command or otherwise) from the Host port-connected client to an AUX port-
connected serial device (TTY2 command number 42), but you could not get data back
from that device.

Now P2OS maintains a circular buffer for incoming serial data from the AUX port and
sends successive portions of the buffer to your client via the Host port depending on the

41