packet.h

00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2000  
00004  *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
00005  *                      
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 /*
00024  * $Id: packet.h 4356 2008-02-15 08:53:55Z thjc $
00025  *   part of the P2OS parser.  this class has methods for building,
00026  *   printing, sending and receiving P2OS packets.
00027  *
00028  */
00029 
00030 #ifndef _PACKET_H
00031 #define _PACKET_H
00032 
00033 #include <string.h>
00034 
00035 #include <libplayercore/globals.h>
00036 #include <libplayercore/wallclocktime.h>
00037 
00038 #define PACKET_LEN 256
00039 
00040 class P2OSPacket 
00041 {
00042  public:
00043   unsigned char packet[PACKET_LEN];
00044   unsigned char size;
00045   double timestamp;
00046 
00047   int CalcChkSum();
00048 
00049   void Print();
00050   void PrintHex();
00051   int Build( unsigned char *data, unsigned char datasize );
00052   int Send( int fd );
00053   int Receive( int fd );
00054   bool Check();
00055   
00056   bool operator!= ( P2OSPacket p ) {
00057     if ( size != p.size) return(true);
00058 
00059     if ( memcmp( packet, p.packet, size ) != 0 ) return (true);
00060 
00061     return(false);
00062   }
00063 };
00064 
00065 #endif

Last updated 12 September 2005 21:38:45