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

ArBasePacket.h

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
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 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #ifndef ARBASEPACKET_H
00027 #define ARBASEPACKET_H
00028 
00029 
00030 #include <string>
00031 #include "ariaTypedefs.h"
00032 
00034 
00068 class ArBasePacket
00069 {
00070 public:
00071     
00073   AREXPORT ArBasePacket(ArTypes::UByte2 bufferSize = 0,
00074     ArTypes::UByte2 headerLength = 0, 
00075     char * buf = NULL,
00076     ArTypes::UByte2 footerLength = 0);
00077 
00079   AREXPORT virtual ~ArBasePacket();
00080 
00082   AREXPORT virtual void empty(void);
00083 
00085   AREXPORT virtual void finalizePacket(void) {}
00086 
00088   AREXPORT virtual void log(void);
00090   AREXPORT virtual void printHex(void);
00091 
00093   AREXPORT virtual bool isValid(void);
00094 
00096   AREXPORT virtual void resetValid();
00097 
00098   // Utility functions to write different data types to a buffer. They will
00099   // increment the length.
00100 
00102   AREXPORT virtual void byteToBuf(ArTypes::Byte val);
00104   AREXPORT virtual void byte2ToBuf(ArTypes::Byte2 val);
00106   AREXPORT virtual void byte4ToBuf(ArTypes::Byte4 val);
00107 
00109   AREXPORT virtual void uByteToBuf(ArTypes::UByte val);
00111   AREXPORT virtual void uByte2ToBuf(ArTypes::UByte2 val);
00113   AREXPORT virtual void uByte4ToBuf(ArTypes::UByte4 val);
00114 
00116   AREXPORT virtual void strToBuf(const char *str);
00117 
00122   AREXPORT virtual void strNToBuf(const char *str, int length);
00124   AREXPORT virtual void strToBufPadded(const char *str, int length);
00126   AREXPORT virtual void dataToBuf(const char *data, int length);
00128   AREXPORT virtual void dataToBuf(const unsigned char *data, int length);
00129 
00130   // Utility functions to read differet data types from a bufer. Each read
00131   // will increment the myReadLength.
00133   AREXPORT virtual ArTypes::Byte bufToByte(void);
00135   AREXPORT virtual ArTypes::Byte2 bufToByte2(void);
00137   AREXPORT virtual ArTypes::Byte4 bufToByte4(void);
00138 
00140   AREXPORT virtual ArTypes::UByte bufToUByte(void);
00142   AREXPORT virtual ArTypes::UByte2 bufToUByte2(void);
00144   AREXPORT virtual ArTypes::UByte4 bufToUByte4(void);
00145 
00147   AREXPORT virtual void bufToStr(char *buf, int len);
00149   AREXPORT virtual void bufToData(char * data, int length);
00151   AREXPORT virtual void bufToData(unsigned char * data, int length);
00152 
00154   AREXPORT virtual void resetRead(void);
00155 
00156   // Accessors
00157 
00159   AREXPORT virtual ArTypes::UByte2 getLength(void) { return myLength; }
00161   AREXPORT virtual ArTypes::UByte2 getDataLength(void) { return myLength - myHeaderLength - myFooterLength; }
00162 
00164   AREXPORT virtual ArTypes::UByte2 getReadLength(void) { return myReadLength; }
00166   AREXPORT virtual ArTypes::UByte2 getDataReadLength(void) { return myReadLength - myHeaderLength; }
00168   AREXPORT virtual ArTypes::UByte2 getHeaderLength(void)
00169   { return myHeaderLength; }
00171   AREXPORT virtual ArTypes::UByte2 getFooterLength(void)
00172   { return myFooterLength; }
00173 
00175   AREXPORT virtual ArTypes::UByte2 getMaxLength(void) { return myMaxLength; }
00176 
00178   AREXPORT virtual const char * getBuf(void);
00179 
00181   AREXPORT virtual void setBuf(char *buf, ArTypes::UByte2 bufferSize);
00183   AREXPORT virtual void setMaxLength(ArTypes::UByte2 bufferSize);
00185   AREXPORT virtual bool setLength(ArTypes::UByte2 length);
00187   AREXPORT virtual void setReadLength(ArTypes::UByte2 readLength);
00189   AREXPORT virtual bool setHeaderLength(ArTypes::UByte2 length);
00191   AREXPORT virtual void duplicatePacket(ArBasePacket *packet);
00192 protected:
00193   // internal function to make sure we have enough length left to read in the packet
00194   AREXPORT bool isNextGood(int bytes);
00195 
00197   AREXPORT bool hasWriteCapacity(int bytes);
00198 
00199   // internal data
00200   ArTypes::UByte2 myHeaderLength;
00201   ArTypes::UByte2 myFooterLength;
00202   ArTypes::UByte2 myMaxLength;
00203 
00204   ArTypes::UByte2 myReadLength;
00205   bool myOwnMyBuf;
00206 
00207   // Actual packet data
00208   char *myBuf;
00209   ArTypes::UByte2 myLength;
00210 
00211   // Whether no error has occurred in reading/writing the packet.
00212   bool myIsValid;
00213 
00214 };
00215 
00216 
00217 #endif // ARPACKET_H

Generated on Tue Feb 20 10:51:39 2007 for Aria by  doxygen 1.4.0