p2os/packet.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2000
4  * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 /*
24  * $Id: packet.h 9120 2013-01-07 00:18:52Z jpgr87 $
25  * part of the P2OS parser. this class has methods for building,
26  * printing, sending and receiving P2OS packets.
27  *
28  */
29 
30 #ifndef _PACKET_H
31 #define _PACKET_H
32 
33 #include <string.h>
34 
35 #include <libplayercore/globals.h>
36 #include <libplayercore/wallclocktime.h>
37 
38 #define PACKET_LEN 256
39 
40 class P2OSPacket
41 {
42  public:
43  unsigned char packet[PACKET_LEN];
44  unsigned char size;
45  double timestamp;
46 
47  int CalcChkSum();
48 
49  void Print();
50  void PrintHex();
51  int Build( unsigned char *data, unsigned char datasize );
52  int Send( int fd );
53  int Receive( int fd, bool ignore_checksum );
54  bool Check( bool ignore_checksum = false );
55 
56  bool operator!= ( P2OSPacket p ) {
57  if ( size != p.size) return(true);
58 
59  if ( memcmp( packet, p.packet, size ) != 0 ) return (true);
60 
61  return(false);
62  }
63 };
64 
65 #endif
Definition: p2os/packet.h:40