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 <dataspeed_can_msgs/Frame.h>
55 #include "DbcIterator.hpp"
56 
57 namespace dataspeed_can_tools
58 {
59 
60 typedef struct {
62  double factor;
63  int length;
64  double maximum;
65  double minimum;
66  std::string sig_name;
67  double offset;
70  int start_bit;
72  unsigned short multiplexNum;
74 
75 typedef struct {
77  std::string msg_name;
78  uint32_t id;
79  std::vector<RosCanSigStruct> sigs;
81 
82 class CanExtractor {
83 public:
84  CanExtractor(const std::string &dbc_file, bool offline, bool expand = true, bool unknown = false);
85  CanExtractor(const std::vector<std::string> &dbc_file, bool offline, bool expand = true, bool unknown = false);
86 
87  bool getMessage(RosCanMsgStruct& can_msg);
89  bool openBag(const std::string &fname, rosbag::compression::CompressionType compression = rosbag::compression::Uncompressed);
90  bool closeBag();
91  void pubMessage(const can_msgs::Frame& msg, const ros::Time &stamp = ros::Time(0));
92  void pubMessage(const dataspeed_can_msgs::Frame& msg, const ros::Time &stamp = ros::Time(0));
93  void pubMessage(const can_msgs::Frame::ConstPtr& msg, const ros::Time &stamp = ros::Time(0)) { pubMessage(*msg, stamp); }
94  void pubMessage(const dataspeed_can_msgs::Frame::ConstPtr& msg, const ros::Time &stamp = ros::Time(0)) { pubMessage(*msg, stamp); }
95 
96 private:
97  template<class T>
98  void writeToBag(const std::string& frame, const ros::Time& stamp, const T& msg);
99  template<class T>
100  void pubCanSig(const RosCanMsgStruct& info, const T& sig_msg, const ros::Time& stamp, size_t i);
101  void pubCanMsgSignals(const RosCanMsgStruct &info, const std::vector<uint8_t>& buffer, const ros::Time &stamp);
102  void pubCanMsg(const RosCanMsgStruct& info, const can_msgs::Frame& msg, const ros::Time& stamp);
103  void pubCanMsg(const RosCanMsgStruct& info, const dataspeed_can_msgs::Frame& msg, const ros::Time& stamp);
104  static uint64_t unsignedSignalData(const std::vector<uint8_t> &buffer, const RosCanSigStruct& sig_props);
105  static int64_t signedSignalData(const std::vector<uint8_t> &buffer, const RosCanSigStruct& sig_props);
106  template<class T>
107  static T buildMsg(const RosCanSigStruct& info, const std::vector<uint8_t> &buffer, bool sign);
108  static int getAppropriateSize(const RosCanSigStruct& sig_props, bool output_signed);
110 
113  bool bag_open_;
114  std::string bag_fname_;
115  bool offline_;
116  bool expand_;
117  bool unknown_;
118 
119  std::map<uint32_t, RosCanMsgStruct> msgs_;
120  std::map<uint32_t, int> unknown_msgs_;
121 };
122 
123 } // dataspeed_can_tools
124 
125 #endif /* CANEXTRACTOR_H_ */
void pubCanMsgSignals(const RosCanMsgStruct &info, const std::vector< uint8_t > &buffer, const ros::Time &stamp)
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:93
static uint64_t unsignedSignalData(const std::vector< uint8_t > &buffer, const RosCanSigStruct &sig_props)
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)
std::map< uint32_t, RosCanMsgStruct > msgs_
Definition: CanExtractor.h:119
ByteOrder
Definition: DbcSignal.hpp:42
void pubMessage(const dataspeed_can_msgs::Frame::ConstPtr &msg, const ros::Time &stamp=ros::Time(0))
Definition: CanExtractor.h:94
std::map< uint32_t, int > unknown_msgs_
Definition: CanExtractor.h:120
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)
static T buildMsg(const RosCanSigStruct &info, const std::vector< uint8_t > &buffer, bool sign)
static int64_t signedSignalData(const std::vector< uint8_t > &buffer, const RosCanSigStruct &sig_props)
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:79
void initPublishers(RosCanMsgStruct &info, ros::NodeHandle &nh)


dataspeed_can_tools
Author(s): Micho Radovnikovich
autogenerated on Wed Feb 8 2023 03:16:49