Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArBasePacket Class Reference

Base packet class. More...

#include <ArBasePacket.h>

Inheritance diagram for ArBasePacket:

ArAMPTUPacket ArDPPTUPacket ArRobotPacket ArSickPacket ArSonyPacket ArVCC4Packet List of all members.

Public Member Functions

 ArBasePacket (ArTypes::UByte2 bufferSize=0, ArTypes::UByte2 headerLength=0, char *buf=NULL, ArTypes::UByte2 footerLength=0)
 Constructor.
virtual ArTypes::Byte bufToByte (void)
 Gets a ArTypes::Byte from the buffer.
virtual ArTypes::Byte2 bufToByte2 (void)
 Gets a ArTypes::Byte2 from the buffer.
virtual ArTypes::Byte4 bufToByte4 (void)
 Gets a ArTypes::Byte4 from the buffer.
virtual void bufToData (char *data, int length)
 Gets length bytes from buffer and puts them into data.
virtual void bufToStr (char *buf, int len)
 Gets a string from the buffer.
virtual ArTypes::UByte bufToUByte (void)
 Gets a ArTypes::UByte from the buffer.
virtual ArTypes::UByte2 bufToUByte2 (void)
 Gets a ArTypes::UByte2 from the buffer.
virtual ArTypes::UByte4 bufToUByte4 (void)
 Gets a ArTypes::UByte4 from the buffer.
virtual void byte2ToBuf (ArTypes::Byte2 val)
 Puts ArTypes::Byte2 into packets buffer.
virtual void byte4ToBuf (ArTypes::Byte4 val)
 Puts ArTypes::Byte4 into packets buffer.
virtual void byteToBuf (ArTypes::Byte val)
 Puts ArTypes::Byte into packets buffer.
virtual void dataToBuf (const char *data, int length)
 Copies length bytes from data into packet buffer.
virtual void duplicatePacket (ArBasePacket *packet)
 Makes this packet a duplicate of another packet.
virtual void empty (void)
 resets the length for more data to be added
virtual void finalizePacket (void)
 MakeFinals the packet in preparation for sending, must be done.
virtual const char * getBuf (void)
 Gets a pointer to the buffer the packet uses.
virtual ArTypes::UByte2 getDataLength (void)
 Gets the length of the data in the packet.
virtual ArTypes::UByte2 getDataReadLength (void)
 Gets how far into the data of the packet that has been read.
virtual ArTypes::UByte2 getFooterLength (void)
 Gets the length of the header.
virtual ArTypes::UByte2 getHeaderLength (void)
 Gets the length of the header.
virtual ArTypes::UByte2 getLength (void)
 Gets the total length of the packet.
virtual ArTypes::UByte2 getMaxLength (void)
 Gets the maximum length packet.
virtual ArTypes::UByte2 getReadLength (void)
 Gets how far into the packet that has been read.
virtual void log (void)
 ArLogs the contents of the packet.
virtual void printHex (void)
 ArLogs the contents of the packet in hex.
virtual void resetRead (void)
 Restart the reading process.
virtual void setBuf (char *buf, ArTypes::UByte2 bufferSize)
 Sets the buffer the packet is using.
virtual bool setHeaderLength (ArTypes::UByte2 length)
 Sets the length of the header.
virtual bool setLength (ArTypes::UByte2 length)
 Sets the length of the packet.
virtual void setMaxLength (ArTypes::UByte2 bufferSize)
 Sets the maximum buffer size (if new size is <= current does nothing).
virtual void setReadLength (ArTypes::UByte2 readLength)
 Sets the read length.
virtual void strNToBuf (const char *str, int length)
 Copies length bytes from str into packet buffer.
virtual void strToBuf (const char *str)
 Puts a string into packet buffer.
virtual void strToBufPadded (const char *str, int length)
 Copies length bytes from str, if str ends before length, pads data.
virtual void uByte2ToBuf (ArTypes::UByte2 val)
 Puts ArTypes::UByte2 into packet buffer.
virtual void uByte4ToBuf (ArTypes::UByte4 val)
 Puts ArTypes::UByte 4 into packet buffer.
virtual void uByteToBuf (ArTypes::UByte val)
 Puts ArTypes::UByte into packets buffer.
virtual ~ArBasePacket ()
 Destructor.

Protected Member Functions

bool isNextGood (int bytes)

Protected Attributes

char * myBuf
ArTypes::UByte2 myFooterLength
ArTypes::UByte2 myHeaderLength
ArTypes::UByte2 myLength
ArTypes::UByte2 myMaxLength
bool myOwnMyBuf
ArTypes::UByte2 myReadLength

Detailed Description

Base packet class.

This class is a base class for all packets... most software will never need to use this class, it is there mostly to help people do more advanced client and server communications.

All of the functions are virtual so it can be completely overridden if desired... but the few most likely ones to be overridden are empty and makeFinal...

The theory of the packet works like this, the packet has a buffer, headerLength, footer length, readLength, length, and a maxLength. When the packet is initialized it is given a buffer and its maxLength. All of the functions that are somethingToBuf put data in at the current length of the packet, and advance the length. All of the functions that do bufToSomething get the data from where readLength points, and advance read length. If bufToSomething would go beyond the data length of the packet it returns a 0 (note that this includes if it goes into the footer length). resetRead sets readLength back to the header (since no one outside of the person who writes the class should touch the header). empty likewise sets the length back to the header since the header will be calculated in the finalizePacket method.

The base class and most classes of this kind will have an integer before the string, denoting the strings length... this is hidden by the function calls, but something someone may want to be aware of... it should not matter much as this same packet class should be used on both sides.

Uses of this class that don't get newed and deleted a lot can just go ahead and use the constructor with buf = NULL, as this will have the packet manage its own memory, making life easier.

Definition at line 69 of file ArBasePacket.h.


Constructor & Destructor Documentation

ArBasePacket::ArBasePacket ArTypes::UByte2  bufferSize = 0,
ArTypes::UByte2  headerLength = 0,
char *  buf = NULL,
ArTypes::UByte2  footerLength = 0
 

Constructor.

Parameters:
bufferSize size of the buffer
headerLength length of the header
buf buffer packet uses, if NULL, instance will allocate memory

Definition at line 37 of file ArBasePacket.cpp.


Member Function Documentation

void ArBasePacket::bufToData char *  data,
int  length
[virtual]
 

Gets length bytes from buffer and puts them into data.

copies length bytes from the buffer into data, length is passed in, not read from packet

Parameters:
data character array to copy the data into
length number of bytes to copy into data

Definition at line 384 of file ArBasePacket.cpp.

void ArBasePacket::bufToStr char *  buf,
int  len
[virtual]
 

Gets a string from the buffer.

Copy a string from the packet buffer into the given buffer, stopping when the end of the packet buffer is reached, the given length is reached, or a NUL character ('') is reached.

Parameters:
buf Destination buffer
len Maximum number of characters to copy into the destination buffer

Definition at line 356 of file ArBasePacket.cpp.

Referenced by ArRobot::asyncConnectHandler().

void ArBasePacket::dataToBuf const char *  data,
int  length
[virtual]
 

Copies length bytes from data into packet buffer.

Parameters:
data chacter array to copy into buffer
length how many bytes to copy from data into packet

Definition at line 249 of file ArBasePacket.cpp.

Referenced by ArVCC4::readPacket(), ArSickPacketReceiver::receivePacket(), and ArRobotPacketReceiver::receivePacket().

void ArBasePacket::duplicatePacket ArBasePacket packet  )  [virtual]
 

Makes this packet a duplicate of another packet.

Copies the given packets buffer into the buffer of this packet, also sets this length and readlength to what the given packet has

Parameters:
packet the packet to duplicate

Definition at line 399 of file ArBasePacket.cpp.

void ArBasePacket::empty void   )  [virtual]
 

resets the length for more data to be added

Sets the packet length back to be the packets header length again

Definition at line 128 of file ArBasePacket.cpp.

Referenced by ArDPPTU::blank(), ArRobotPacketSender::com(), ArRobotPacketSender::comInt(), ArRobotPacketSender::comStr(), ArRobotPacketSender::comStrN(), ArSick::disconnect(), ArSonyPTZ::init(), ArAMPTU::init(), ArSick::internalConnectHandler(), ArAMPTU::pan(), ArAMPTU::panRel(), ArAMPTU::panSlew(), ArAMPTU::panTilt(), ArAMPTU::panTiltRel(), ArAMPTU::pause(), ArAMPTU::purge(), ArVCC4::readPacket(), ArSickPacketReceiver::receivePacket(), ArRobotPacketReceiver::receivePacket(), ArAMPTU::requestStatus(), ArAMPTU::resume(), ArVCC4::sendLEDControlMode(), ArAMPTU::tilt(), ArAMPTU::tiltRel(), and ArAMPTU::tiltSlew().

void ArBasePacket::resetRead void   )  [virtual]
 

Restart the reading process.

Sets the length read back to the header length so the packet can be reread using the other methods

Reimplemented in ArSickPacket.

Definition at line 119 of file ArBasePacket.cpp.

Referenced by ArRobot::asyncConnectHandler(), ArVCC4::readPacket(), and ArRobotPacketReceiver::receivePacket().

void ArBasePacket::strNToBuf const char *  str,
int  length
[virtual]
 

Copies length bytes from str into packet buffer.

Parameters:
str character array to copy into the packet buffer
length how many characters to copy from str into the packet buffer

Definition at line 215 of file ArBasePacket.cpp.

Referenced by ArRobotPacketSender::comStrN(), and ArSick::internalConnectHandler().

void ArBasePacket::strToBuf const char *  str  )  [virtual]
 

Puts a string into packet buffer.

Parameters:
str string to copy into buffer

Definition at line 205 of file ArBasePacket.cpp.

Referenced by ArRobotPacketSender::comStr().

void ArBasePacket::strToBufPadded const char *  str,
int  length
[virtual]
 

Copies length bytes from str, if str ends before length, pads data.

If string ends before length it pads the string with NUL ('') characters.

Parameters:
str character array to copy into buffer
length how many bytes to copy from the str into packet

Definition at line 227 of file ArBasePacket.cpp.


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:43 2005 for Aria by  doxygen 1.4.0