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 NLNETPACKETRECEIVERTCP_H 00027 #define NLNETPACKETRECEIVERTCP_H 00028 00029 #include "Aria.h" 00030 #include "ArNetPacket.h" 00031 00039 class ArNetPacketReceiverTcp 00040 { 00041 public: 00043 AREXPORT ArNetPacketReceiverTcp(); 00045 AREXPORT ~ArNetPacketReceiverTcp(); 00046 00048 AREXPORT void setSocket(ArSocket *socket); 00050 AREXPORT ArSocket *getSocket(void); 00051 00053 AREXPORT void setProcessPacketCB(ArFunctor1<ArNetPacket *> *functor); 00054 00056 AREXPORT ArFunctor1<ArNetPacket *> *getProcessPacketCB(void); 00057 00059 AREXPORT bool readData(void); 00060 00062 void setQuiet(bool quiet) { myQuiet = quiet; } 00064 bool getQuiet(void) { return myQuiet; } 00065 protected: 00066 enum Ret { 00067 RET_CONN_CLOSED, // the connection was closed 00068 RET_GOT_PACKET, // we got a good packet 00069 RET_BAD_PACKET, // we got a bad packet (checksum wrong) 00070 RET_FAILED_READ, // our read failed (no data) 00071 RET_TIMED_OUT}; // we were reading and timed out 00073 AREXPORT Ret readPacket(int msWait); 00074 00075 00076 enum State { STATE_SYNC1, STATE_SYNC2, STATE_LENGTH1, 00077 STATE_LENGTH2, STATE_ACQUIRE_DATA }; 00078 State myState; 00079 ArFunctor1<ArNetPacket *> *myProcessPacketCB; 00080 bool myQuiet; 00081 ArSocket *mySocket; 00082 ArTime myLastPacket; 00083 ArNetPacket myPacket; 00084 char myReadBuff[ArNetPacket::MAX_LENGTH+ArNetPacket::HEADER_LENGTH+ArNetPacket::FOOTER_LENGTH]; 00085 int myReadCount; 00086 int myReadLength; 00087 int myReadCommand; 00088 unsigned char mySync1; 00089 unsigned char mySync2; 00090 00091 }; 00092 00093 #endif // NLNETPACKETRECEIVERTCP