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

ArBasePacket.h

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #ifndef ARBASEPACKET_H
00028 #define ARBASEPACKET_H
00029 
00030 
00031 #include <string>
00032 #include "ariaTypedefs.h"
00033 
00035 
00069 class ArBasePacket
00070 {
00071 public:
00072     
00074   ArBasePacket(ArTypes::UByte2 bufferSize = 0,
00075                         ArTypes::UByte2 headerLength = 0, 
00076                         char * buf = NULL,
00077                         ArTypes::UByte2 footerLength = 0);
00078   
00080   virtual ~ArBasePacket();
00081 
00083   virtual void empty(void);
00084 
00086   virtual void finalizePacket(void) {}
00087 
00089   virtual void log(void);
00091   virtual void printHex(void);
00092 
00093   // Utility functions to write different data types to a buffer. They will
00094   // increment the length.
00095 
00097   virtual void byteToBuf(ArTypes::Byte val);
00099   virtual void byte2ToBuf(ArTypes::Byte2 val);
00101   virtual void byte4ToBuf(ArTypes::Byte4 val);
00102 
00104   virtual void uByteToBuf(ArTypes::UByte val);
00106   virtual void uByte2ToBuf(ArTypes::UByte2 val);
00108   virtual void uByte4ToBuf(ArTypes::UByte4 val);
00109 
00111   virtual void strToBuf(const char *str);
00113   virtual void strNToBuf(const char *str, int length);
00115   virtual void strToBufPadded(const char *str, int length);
00117   virtual void dataToBuf(const char *data, int length);
00118   
00119   // Utility functions to read differet data types from a bufer. Each read
00120   // will increment the myReadLength.
00122   virtual ArTypes::Byte bufToByte(void);
00124   virtual ArTypes::Byte2 bufToByte2(void);
00126   virtual ArTypes::Byte4 bufToByte4(void);
00127 
00129   virtual ArTypes::UByte bufToUByte(void);
00131   virtual ArTypes::UByte2 bufToUByte2(void);
00133   virtual ArTypes::UByte4 bufToUByte4(void);
00134 
00136   virtual void bufToStr(char *buf, int len);
00138   virtual void bufToData(char * data, int length);
00139 
00141   virtual void resetRead(void);
00142 
00143   // Accessors
00144 
00146   virtual ArTypes::UByte2 getLength(void) { return myLength; }
00148   virtual ArTypes::UByte2 getDataLength(void) { return myLength - myHeaderLength - myFooterLength; }
00149   
00151   virtual ArTypes::UByte2 getReadLength(void) { return myReadLength; }
00153   virtual ArTypes::UByte2 getDataReadLength(void) { return myReadLength - myHeaderLength; }
00155   virtual ArTypes::UByte2 getHeaderLength(void)
00156     { return myHeaderLength; }
00158   virtual ArTypes::UByte2 getFooterLength(void)
00159     { return myFooterLength; }
00160 
00162   virtual ArTypes::UByte2 getMaxLength(void) { return myMaxLength; }
00163   
00165   virtual const char * getBuf(void);
00166 
00168   virtual void setBuf(char *buf, ArTypes::UByte2 bufferSize);
00170   virtual void ArBasePacket::setMaxLength(ArTypes::UByte2 bufferSize);
00172   virtual bool setLength(ArTypes::UByte2 length);
00174   virtual void setReadLength(ArTypes::UByte2 readLength);
00176   virtual bool setHeaderLength(ArTypes::UByte2 length);
00178   virtual void duplicatePacket(ArBasePacket *packet);
00179 protected:
00180   // internal function to make sure we have enough length left in the packet
00181   bool isNextGood(int bytes);
00182 
00183   // internal data
00184   ArTypes::UByte2 myHeaderLength;
00185   ArTypes::UByte2 myFooterLength;
00186   ArTypes::UByte2 myMaxLength;
00187 
00188   ArTypes::UByte2 myReadLength;
00189   bool myOwnMyBuf;
00190 
00191   // Actual packet data
00192   char *myBuf;
00193   ArTypes::UByte2 myLength;
00194 };
00195 
00196 
00197 #endif // ARPACKET_H

Generated on Wed Oct 19 12:56:34 2005 for Aria by  doxygen 1.4.0