CanDriver.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2015-2020, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #ifndef _DATASPEED_CAN_USB_CAN_DRIVER_H_
36 #define _DATASPEED_CAN_USB_CAN_DRIVER_H_
37 
38 #include <ros/ros.h>
39 
40 // ROS messages
41 #include <can_msgs/Frame.h>
42 
43 // Mutex
44 #include <boost/thread/mutex.hpp>
45 #include <boost/thread/lock_guard.hpp>
46 
47 // Module Version class
49 
50 namespace lusb
51 {
52 class UsbDevice;
53 }
54 
56 {
57 class CanUsb;
58 
59 class CanDriver
60 {
61 public:
62  CanDriver(ros::NodeHandle &nh, ros::NodeHandle &nh_priv, lusb::UsbDevice *dev = NULL,
63  const std::string &name = std::string("Dataspeed USB CAN Tool"),
64  const ModuleVersion &firmware = ModuleVersion(10,4,0));
65  ~CanDriver();
66 
67 private:
68  void timerServiceCallback(const ros::WallTimerEvent& event);
69  void timerFlushCallback(const ros::WallTimerEvent& event);
70  void recvRos(const can_msgs::Frame::ConstPtr& msg, unsigned int channel);
71 
72  void recvDevice(unsigned int channel, uint32_t id, bool extended, uint8_t dlc, const uint8_t data[8]);
73  void serviceDevice();
74  bool sampleTimeOffset(ros::WallDuration &offset, ros::WallDuration &delay);
75  inline ros::WallTime stampDev2Ros(unsigned int dev_stamp) {
76  return ros::WallTime(dev_stamp / 1000000, (dev_stamp % 1000000) * 1000);
77  }
78 
79  // NodeHandle
82 
83  // Parameters
84  bool sync_time_;
86  std::string mac_addr_;
87  struct Filter {
88  uint32_t mask;
89  uint32_t match;
90  };
91  struct Channel {
92  Channel() : bitrate(0), mode(0) {}
93  int bitrate;
94  uint8_t mode;
95  std::vector<Filter> filters;
96  };
97  std::vector<Channel> channels_;
98 
99  // Timers
102 
103  // USB Device
105 
106  // Subscribed topics
107  std::vector<ros::Subscriber> subs_;
108 
109  // Published topics
111  std::vector<ros::Publisher> pubs_;
112  std::vector<ros::Publisher> pubs_err_;
113 
114  // Mutex for vector of publishers
115  boost::mutex mutex_;
116 
117  // Name prefix for print statements
118  std::string name_;
119 
120  // Number of total drops for status warnings
121  uint32_t total_drops_;
122 
123  // Latest firmware version
125 };
126 
127 } // namespace dataspeed_can_usb
128 
129 #endif // _DATASPEED_CAN_USB_CAN_DRIVER_H_
130 
std::vector< ros::Subscriber > subs_
Definition: CanDriver.h:107
std::vector< ros::Publisher > pubs_err_
Definition: CanDriver.h:112
ros::NodeHandle nh_priv_
Definition: CanDriver.h:81
ros::WallTimer timer_flush_
Definition: CanDriver.h:101
std::vector< ros::Publisher > pubs_
Definition: CanDriver.h:111
ros::Publisher pub_version_
Definition: CanDriver.h:110
ros::WallTime stampDev2Ros(unsigned int dev_stamp)
Definition: CanDriver.h:75
std::vector< Filter > filters
Definition: CanDriver.h:95
std::vector< Channel > channels_
Definition: CanDriver.h:97
ros::WallTimer timer_service_
Definition: CanDriver.h:100


dataspeed_can_usb
Author(s): Kevin Hallenbeck
autogenerated on Thu Jul 9 2020 03:42:00