CanDriver.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2015-2018, Dataspeed Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Dataspeed Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 #ifndef _DATASPEED_CAN_USB_CAN_DRIVER_H_
00036 #define _DATASPEED_CAN_USB_CAN_DRIVER_H_
00037 
00038 #include <ros/ros.h>
00039 
00040 // ROS messages
00041 #include <can_msgs/Frame.h>
00042 
00043 // Mutex
00044 #include <boost/thread/mutex.hpp>
00045 #include <boost/thread/lock_guard.hpp>
00046 
00047 // Module Version class
00048 #include <dataspeed_can_usb/ModuleVersion.h>
00049 
00050 namespace lusb
00051 {
00052 class UsbDevice;
00053 }
00054 
00055 namespace dataspeed_can_usb
00056 {
00057 class CanUsb;
00058 
00059 class CanDriver
00060 {
00061 public:
00062   CanDriver(ros::NodeHandle &nh, ros::NodeHandle &nh_priv, lusb::UsbDevice *dev = NULL,
00063             const std::string &name = std::string("Dataspeed USB CAN Tool"),
00064             const ModuleVersion &firmware = ModuleVersion(10,4,0));
00065   ~CanDriver();
00066 
00067 private:
00068   void timerServiceCallback(const ros::WallTimerEvent& event);
00069   void timerFlushCallback(const ros::WallTimerEvent& event);
00070   void recvRos(const can_msgs::Frame::ConstPtr& msg, unsigned int channel);
00071 
00072   void recvDevice(unsigned int channel, uint32_t id, bool extended, uint8_t dlc, const uint8_t data[8]);
00073   void serviceDevice();
00074   bool sampleTimeOffset(ros::WallDuration &offset, ros::WallDuration &delay);
00075   inline ros::WallTime stampDev2Ros(unsigned int dev_stamp) {
00076     return ros::WallTime(dev_stamp / 1000000, (dev_stamp % 1000000) * 1000);
00077   }
00078 
00079   // NodeHandle
00080   ros::NodeHandle nh_;
00081   ros::NodeHandle nh_priv_;
00082 
00083   // Parameters
00084   bool sync_time_;
00085   bool error_topic_;
00086   std::string mac_addr_;
00087   struct Filter {
00088     uint32_t mask;
00089     uint32_t match;
00090   };
00091   struct Channel {
00092     Channel() : bitrate(0), mode(0) {}
00093     int bitrate;
00094     uint8_t mode;
00095     std::vector<Filter> filters;
00096   };
00097   std::vector<Channel> channels_;
00098 
00099   // Timers
00100   ros::WallTimer timer_service_;
00101   ros::WallTimer timer_flush_;
00102 
00103   // USB Device
00104   CanUsb *dev_;
00105 
00106   // Subscribed topics
00107   std::vector<ros::Subscriber> subs_;
00108 
00109   // Published topics
00110   ros::Publisher pub_version_;
00111   std::vector<ros::Publisher> pubs_;
00112   std::vector<ros::Publisher> pubs_err_;
00113 
00114   // Mutex for vector of publishers
00115   boost::mutex mutex_;
00116 
00117   // Name prefix for print statements
00118   std::string name_;
00119 
00120   // Number of total drops for status warnings
00121   uint32_t total_drops_;
00122 
00123   // Latest firmware version
00124   ModuleVersion firmware_;
00125 };
00126 
00127 } // namespace dataspeed_can_usb
00128 
00129 #endif // _DATASPEED_CAN_USB_CAN_DRIVER_H_
00130 


dataspeed_can_usb
Author(s): Kevin Hallenbeck
autogenerated on Thu Jun 6 2019 21:16:43