usb_packet.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2009
4  * Eric Grele and Goutham Mallapragda.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22 
23 #ifndef _USB_PACKET_H_
24 #define _USB_PACKET_H_
25 
26 #include "canio.h"
27 #include <libplayercommon/playercommon.h>
28 
29 typedef struct usb_packet {
30  union {
31  unsigned char pkt_data[18];
32  struct {
33  unsigned char usb_message_header;
34  unsigned char usb_command_identifier;
35  unsigned char command_type;
36  unsigned char unused0;
37  unsigned char unused1;
38  unsigned char unused2;
39  unsigned short can_message_header;
40  unsigned char unused3;
41  unsigned char can_message[8];
42  unsigned char usb_message_checksum;
43  };
44  };
45 } usb_packet_t;
46 
47 class USBpacket {
48 
49 private:
50  unsigned short make_can_header( long id, unsigned int dlc, unsigned int flags );
51  unsigned char compute_checksum();
52 
53 
54 public:
55 
56  typedef enum { CANA_DEV, USB_CMD_RESET } CommandType;
57 
58  usb_packet_t pkt;
59 
60  USBpacket();
61  USBpacket( const CanPacket &pkt );
62  operator CanPacket ();
63  bool check();
64 
65  void print();
66 
67 };
68 
69 
70 class USBIO {
71 private:
72  int fd;
73  bool synced;
74 public:
75  USBIO() { fd = -1; synced = false; }
76  int Init(const char *dev);
77  int ReadPacket(CanPacket *pkt);
78  int SyncRead( USBpacket &p );
79  int WritePacket(CanPacket &pkt);
80  int Shutdown();
81 };
82 
83 #endif

Last updated 12 September 2005 21:38:45