Libbarrett  1.2.4
include/barrett/bus/can_socket.h
Go to the documentation of this file.
00001 
00032 #ifndef BARRETT_BUS_CAN_SOCKET_H_
00033 #define BARRETT_BUS_CAN_SOCKET_H_
00034 
00035 
00036 #include <stdexcept>
00037 
00038 #include <barrett/detail/ca_macro.h>
00039 #include <barrett/thread/real_time_mutex.h>
00040 #include <barrett/bus/abstract/communications_bus.h>
00041 
00042 
00043 namespace barrett {
00044 namespace bus {
00045 
00046 
00047 namespace detail {
00048 struct can_handle;  // OS-dependent implementation
00049 }
00050 
00051 
00052 // TODO(dc): expose a receive timeout option?
00053 class CANSocket : public CommunicationsBus {
00054 public:
00055         
00056         static const size_t MAX_MESSAGE_LEN = 8;  
00060         CANSocket();
00061         CANSocket(int port) throw(std::runtime_error);
00062         ~CANSocket();
00065         virtual thread::RealTimeMutex& getMutex() const { return mutex; }
00068         virtual void open(int port) throw(std::logic_error, std::runtime_error);
00071         virtual void close();
00074         virtual bool isOpen() const;
00077         virtual int send(int busId, const unsigned char* data, size_t len) const;
00080         virtual int receiveRaw(int& busId, unsigned char* data, size_t& len, bool blocking = true) const;
00081 
00082 protected:
00083         mutable thread::RealTimeMutex mutex;
00084         detail::can_handle* handle;
00085 
00086 private:
00087         DISALLOW_COPY_AND_ASSIGN(CANSocket);
00088 };
00089 
00090 
00091 }
00092 }
00093 
00094 
00095 #endif /* BARRETT_BUS_CAN_SOCKET_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines