CanExtractor.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 CANEXTRACTOR_H_
36 #define CANEXTRACTOR_H_
37 
38 #include <ros/ros.h>
39 #include <rosbag/bag.h>
40 #include <ros/package.h>
41 
42 #include <std_msgs/Bool.h>
43 #include <std_msgs/UInt8.h>
44 #include <std_msgs/UInt16.h>
45 #include <std_msgs/UInt32.h>
46 #include <std_msgs/UInt64.h>
47 #include <std_msgs/Int8.h>
48 #include <std_msgs/Int16.h>
49 #include <std_msgs/Int32.h>
50 #include <std_msgs/Int64.h>
51 #include <std_msgs/Float64.h>
52 
53 #include <can_msgs/Frame.h>
54 #include "DbcIterator.hpp"
55 
56 namespace dataspeed_can_tools
57 {
58 
59 typedef struct {
61  double factor;
62  int length;
63  double maximum;
64  double minimum;
65  std::string sig_name;
66  double offset;
69  int start_bit;
71  unsigned short multiplexNum;
73 
74 typedef struct {
76  std::string msg_name;
77  uint32_t id;
78  std::vector<RosCanSigStruct> sigs;
80 
81 class CanExtractor {
82 public:
83  CanExtractor(const std::string &dbc_file, bool offline, bool expand = true, bool unknown = false);
84  CanExtractor(const std::vector<std::string> &dbc_file, bool offline, bool expand = true, bool unknown = false);
85 
86  bool getMessage(RosCanMsgStruct& can_msg);
88  bool openBag(const std::string &fname, rosbag::compression::CompressionType compression = rosbag::compression::Uncompressed);
89  bool closeBag();
90  void pubMessage(const can_msgs::Frame& msg, const ros::Time &stamp = ros::Time(0));
91  void pubMessage(const can_msgs::Frame::ConstPtr& msg, const ros::Time &stamp = ros::Time(0)) { pubMessage(*msg, stamp); }
92 
93 private:
94  template<class T>
95  void writeToBag(const std::string& frame, const ros::Time& stamp, const T& msg);
96  template<class T>
97  void pubCanSig(const RosCanMsgStruct& info, const T& sig_msg, const ros::Time& stamp, size_t i);
98  void pubCanMsg(const RosCanMsgStruct& info, const can_msgs::Frame& msg, const ros::Time& stamp);
99  static uint64_t unsignedSignalData(uint64_t raw_data, const RosCanSigStruct& sig_props);
100  static int64_t signedSignalData(uint64_t raw_data, const RosCanSigStruct& sig_props);
101  template<class T>
102  static T buildMsg(const RosCanSigStruct& info, const uint64_t& data, bool sign);
103  static int getAppropriateSize(const RosCanSigStruct& sig_props, bool output_signed);
105 
108  bool bag_open_;
109  std::string bag_fname_;
110  bool offline_;
111  bool expand_;
112  bool unknown_;
113 
114  std::map<uint32_t, RosCanMsgStruct> msgs_;
115  std::map<uint32_t, int> unknown_msgs_;
116 };
117 
118 } // dataspeed_can_tools
119 
120 #endif /* CANEXTRACTOR_H_ */
121 
void pubCanSig(const RosCanMsgStruct &info, const T &sig_msg, const ros::Time &stamp, size_t i)
void pubMessage(const can_msgs::Frame::ConstPtr &msg, const ros::Time &stamp=ros::Time(0))
Definition: CanExtractor.h:91
Sign
Definition: DbcSignal.hpp:47
void writeToBag(const std::string &frame, const ros::Time &stamp, const T &msg)
static void registerCanSignalPublisher(RosCanSigStruct &info, ros::NodeHandle &nh)
static T buildMsg(const RosCanSigStruct &info, const uint64_t &data, bool sign)
std::map< uint32_t, RosCanMsgStruct > msgs_
Definition: CanExtractor.h:114
static int64_t signedSignalData(uint64_t raw_data, const RosCanSigStruct &sig_props)
ByteOrder
Definition: DbcSignal.hpp:42
static uint64_t unsignedSignalData(uint64_t raw_data, const RosCanSigStruct &sig_props)
std::map< uint32_t, int > unknown_msgs_
Definition: CanExtractor.h:115
void pubCanMsg(const RosCanMsgStruct &info, const can_msgs::Frame &msg, const ros::Time &stamp)
Multiplexor
Definition: DbcSignal.hpp:52
bool openBag(const std::string &fname, rosbag::compression::CompressionType compression=rosbag::compression::Uncompressed)
static int getAppropriateSize(const RosCanSigStruct &sig_props, bool output_signed)
void pubMessage(const can_msgs::Frame &msg, const ros::Time &stamp=ros::Time(0))
CanExtractor(const std::string &dbc_file, bool offline, bool expand=true, bool unknown=false)
bool getMessage(RosCanMsgStruct &can_msg)
std::vector< RosCanSigStruct > sigs
Definition: CanExtractor.h:78
void initPublishers(RosCanMsgStruct &info, ros::NodeHandle &nh)


dataspeed_can_tools
Author(s): Micho Radovnikovich
autogenerated on Thu Jul 9 2020 03:41:59