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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 
30 struct usb_struct {
31  unsigned char usb_message_header;
32  unsigned char usb_command_identifier;
33  unsigned char command_type;
34  unsigned char unused0;
35  unsigned char unused1;
36  unsigned char unused2;
37  unsigned short can_message_header;
38  unsigned char unused3;
39  unsigned char can_message[8];
40  unsigned char usb_message_checksum;
41 };
42 
43 typedef union usb_packet {
44  unsigned char pkt_data[18];
45  struct usb_struct pkt;
46 } usb_packet_t;
47 
48 class USBpacket {
49 
50 private:
51  unsigned short make_can_header( long id, unsigned int dlc, unsigned int flags );
52  unsigned char compute_checksum();
53 
54 
55 public:
56 
57  typedef enum { CANA_DEV, USB_CMD_RESET } CommandType;
58 
59  usb_packet_t pkt;
60 
61  USBpacket();
62  USBpacket( const CanPacket &pkt );
63  operator CanPacket ();
64  bool check();
65 
66  void print();
67 
68 };
69 
70 
71 class USBIO {
72 private:
73  int fd;
74  bool synced;
75 public:
76  USBIO() { fd = -1; synced = false; }
77  int Init(const char *dev);
78  int ReadPacket(CanPacket *pkt);
79  int SyncRead( USBpacket &p );
80  int WritePacket(CanPacket &pkt);
81  int Shutdown();
82 };
83 
84 #endif
T min(T a, T b)
Return the minimum of a, b.
Definition: utility.h:109
#define PLAYER_WARN1(msg, a)
Error message macros.
Definition: error.h:89
uint32_t blobs_count
The number of blobs.
Definition: player_interfaces.h:1103
Data: detected blobs (PLAYER_BLOBFINDER_DATA_BLOBS)
Definition: player_interfaces.h:1096
Definition: usb_packet.h:30
uint32_t color
A descriptive color for the blob (useful for gui's).
Definition: player_interfaces.h:1074
#define PLAYER_MSG3(level, msg, a, b, c)
Error message macros.
Definition: error.h:107
uint32_t right
Bounding box for the blob [pixels].
Definition: player_interfaces.h:1084
double ReadFloat(int section, const char *name, double value)
Read a floating point (double) value.
Definition: usb_packet.h:71
Definition: canio.h:45
uint32_t height
The image dimensions.
Definition: player_interfaces.h:1101
uint32_t left
Bounding box for the blob [pixels].
Definition: player_interfaces.h:1082
Generic message header.
Definition: player.h:160
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:657
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:663
#define PLAYER_CAMERA_FORMAT_RGB888
Image format : 24-bit color (8 bits R, 8 bits G, 8 bits B).
Definition: player_interfaces.h:2942
uint32_t bottom
Bounding box for the blob [pixels].
Definition: player_interfaces.h:1088
#define PLAYER_BLOBFINDER_DATA_BLOBS
Structure describing a single blob.
Definition: player_interfaces.h:1055
virtual void Main(void)=0
Main method for driver thread.
int ReadInt(int section, const char *name, int value)
Read an integer value.
double ReadLength(int section, const char *name, double value)
Read a length (includes unit conversion, if any).
uint32_t y
The blob centroid [pixels].
Definition: player_interfaces.h:1080
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:94
#define PLAYER_ERROR2(msg, a, b)
Error message macros.
Definition: error.h:82
float range
Range to the blob center [meters].
Definition: player_interfaces.h:1090
uint32_t area
The blob area [pixels].
Definition: player_interfaces.h:1076
#define PLAYER_CAMERA_DATA_STATE
Data subtype: state.
Definition: player_interfaces.h:2922
uint32_t id
Blob id.
Definition: player_interfaces.h:1071
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
virtual int MainSetup()
Sets up the resources needed by the driver thread.
Definition: imagebase.cc:83
virtual void MainQuit()
Cleanup method for driver thread (called when main exits)
Definition: imagebase.cc:104
Definition: imagebase.h:61
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
Data: state (PLAYER_CAMERA_DATA_STATE)
Definition: player_interfaces.h:2950
uint32_t top
Bounding box for the blob [pixels].
Definition: player_interfaces.h:1086
Class for loading configuration file information.
Definition: configfile.h:195
A device address.
Definition: player.h:144
An autopointer for the message queue.
Definition: message.h:72
#define PLAYER_ERROR1(msg, a)
Error message macros.
Definition: error.h:81
uint32_t width
The image dimensions.
Definition: player_interfaces.h:1099
#define PLAYER_CAMERA_COMPRESS_RAW
Compression method: raw.
Definition: player_interfaces.h:2945
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:80
Base class for drivers which oeprate with a thread.
Definition: driver.h:551
#define PLAYER_CAMERA_FORMAT_MONO8
Image format : 8-bit monochrome.
Definition: player_interfaces.h:2936
player_blobfinder_blob_t * blobs
The list of blobs.
Definition: player_interfaces.h:1105
Definition: usb_packet.h:48
Base class for all drivers.
Definition: driver.h:107
Structure describing a single blob.
Definition: player_interfaces.h:1068
Definition: usb_packet.h:43
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:104
#define PLAYER_MSG2(level, msg, a, b)
Error message macros.
Definition: error.h:106
uint32_t x
The blob centroid [pixels].
Definition: player_interfaces.h:1078
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:75
T max(T a, T b)
Return the maximum of a, b.
Definition: utility.h:122