rmp_io.h
Go to the documentation of this file.
00001 
00039 #ifndef RMP_IO_H
00040 #define RMP_IO_H
00041 
00042 #include <vector>
00043 #include <cstdio>
00044 
00045 #include <boost/thread.hpp>
00046 
00047 #include <segwayrmp/segwayrmp.h>
00048 
00049 namespace segwayrmp {
00050 
00055 struct Packet {
00056   unsigned short id; 
00057   unsigned char channel; 
00058   unsigned char data[8]; 
00060   Packet() : id(0), channel(0) {
00061     for (int i = 0; i < 8; ++i) { data[i] = 0x00; }
00062   }
00063 };
00064 
00068 class RMPIO {
00069 public:
00070     RMPIO() : canceled(false) {}
00074   virtual void connect() = 0;
00075   
00079   virtual void disconnect() = 0;
00080   
00088   virtual int read(unsigned char* buffer, int size) = 0;
00089   
00097   virtual int write(unsigned char* buffer, int size) = 0;
00098   
00104   void getPacket(Packet &packet);
00105   
00111   void sendPacket(Packet &packet);
00112   
00118   bool isConnected() {return this->connected;}
00119 
00123   void cancel() {this->canceled = true;}
00124   
00125 protected:
00126   void fillBuffer();
00127   unsigned char computeChecksum(unsigned char* usb_packet);
00128   
00129   bool connected;
00130   bool canceled;
00131   
00132   std::vector<unsigned char> data_buffer;
00133 };
00134 
00135 DEFINE_EXCEPTION(PacketRetrievalException, "Error retrieving a packet from the"
00136   " SegwayRMP: ", "Unspecified");
00137 
00138 } // Namespace segwayrmp
00139 
00140 #endif


libsegwayrmp
Author(s): William Woodall
autogenerated on Fri Jan 3 2014 11:28:21