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 {
61  ros::Publisher sig_pub;
62  double factor;
63  int length;
64  double maximum;
65  double minimum;
66  std::string sig_name;
67  double offset;
68  ByteOrder order;
69  Sign sign;
70  int start_bit;
71  Multiplexor multiplexor;
72  unsigned short multiplexNum;
73 } RosCanSigStruct;
74 
75 typedef struct {
76  ros::Publisher message_pub;
77  std::string msg_name;
78  uint32_t id;
79  std::vector<RosCanSigStruct> sigs;
80 } RosCanMsgStruct;
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);
88  void initPublishers(RosCanMsgStruct& info, ros::NodeHandle& nh);
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_ */
DBCIterator
Definition: DbcIterator.hpp:47
dataspeed_can_tools::CanExtractor::bag_open_
bool bag_open_
Definition: CanExtractor.h:145
dataspeed_can_tools::CanExtractor::writeToBag
void writeToBag(const std::string &frame, const ros::Time &stamp, const T &msg)
Definition: CanExtractor.cpp:326
rosbag::Bag
ros::Publisher
DbcIterator.hpp
dataspeed_can_tools::CanExtractor::bag_fname_
std::string bag_fname_
Definition: CanExtractor.h:146
dataspeed_can_tools::CanExtractor::pubCanMsg
void pubCanMsg(const RosCanMsgStruct &info, const can_msgs::Frame &msg, const ros::Time &stamp)
Definition: CanExtractor.cpp:348
ros.h
dataspeed_can_tools::CanExtractor::pubCanMsgSignals
void pubCanMsgSignals(const RosCanMsgStruct &info, const std::vector< uint8_t > &buffer, const ros::Time &stamp)
Definition: CanExtractor.cpp:364
dataspeed_can_tools::CanExtractor::pubMessage
void pubMessage(const can_msgs::Frame &msg, const ros::Time &stamp=ros::Time(0))
Definition: CanExtractor.cpp:422
dataspeed_can_tools::CanExtractor::getMessage
bool getMessage(RosCanMsgStruct &can_msg)
Definition: CanExtractor.cpp:216
dataspeed_can_tools::CanExtractor::unsignedSignalData
static uint64_t unsignedSignalData(const std::vector< uint8_t > &buffer, const RosCanSigStruct &sig_props)
Definition: CanExtractor.cpp:89
dataspeed_can_tools::CanExtractor::openBag
bool openBag(const std::string &fname, rosbag::compression::CompressionType compression=rosbag::compression::Uncompressed)
Definition: CanExtractor.cpp:278
bag.h
dataspeed_can_tools::CanExtractor::unknown_
bool unknown_
Definition: CanExtractor.h:149
dataspeed_can_tools::CanExtractor::initPublishers
void initPublishers(RosCanMsgStruct &info, ros::NodeHandle &nh)
Definition: CanExtractor.cpp:262
dataspeed_can_tools::CanExtractor::offline_
bool offline_
Definition: CanExtractor.h:147
dataspeed_can_tools::CanExtractor::dbc_
DBCIterator dbc_
Definition: CanExtractor.h:143
dataspeed_can_tools::RosCanSigStruct
Definition: CanExtractor.h:92
dataspeed_can_tools::CanExtractor::buildMsg
static T buildMsg(const RosCanSigStruct &info, const std::vector< uint8_t > &buffer, bool sign)
Definition: CanExtractor.cpp:161
dataspeed_can_tools::CanExtractor::msgs_
std::map< uint32_t, RosCanMsgStruct > msgs_
Definition: CanExtractor.h:151
dataspeed_can_tools::CanExtractor::closeBag
bool closeBag()
Definition: CanExtractor.cpp:289
dataspeed_can_tools
Definition: CanExtractor.cpp:37
package.h
rosbag::compression::CompressionType
CompressionType
Multiplexor
Multiplexor
Definition: DbcSignal.hpp:52
dataspeed_can_tools::CanExtractor::registerCanSignalPublisher
static void registerCanSignalPublisher(RosCanSigStruct &info, ros::NodeHandle &nh)
Definition: CanExtractor.cpp:299
dataspeed_can_tools::CanExtractor::unknown_msgs_
std::map< uint32_t, int > unknown_msgs_
Definition: CanExtractor.h:152
ros::Time
dataspeed_can_tools::CanExtractor::bag_
rosbag::Bag bag_
Definition: CanExtractor.h:144
rosbag::compression::Uncompressed
Uncompressed
dataspeed_can_tools::CanExtractor::signedSignalData
static int64_t signedSignalData(const std::vector< uint8_t > &buffer, const RosCanSigStruct &sig_props)
Definition: CanExtractor.cpp:150
dataspeed_can_tools::CanExtractor::pubCanSig
void pubCanSig(const RosCanMsgStruct &info, const T &sig_msg, const ros::Time &stamp, size_t i)
Definition: CanExtractor.cpp:337
dataspeed_can_tools::CanExtractor::CanExtractor
CanExtractor(const std::string &dbc_file, bool offline, bool expand=true, bool unknown=false)
Definition: CanExtractor.cpp:71
Sign
Sign
Definition: DbcSignal.hpp:47
dataspeed_can_tools::CanExtractor::getAppropriateSize
static int getAppropriateSize(const RosCanSigStruct &sig_props, bool output_signed)
Definition: CanExtractor.cpp:172
ros::NodeHandle
dataspeed_can_tools::CanExtractor::expand_
bool expand_
Definition: CanExtractor.h:148
ByteOrder
ByteOrder
Definition: DbcSignal.hpp:42


dataspeed_can_tools
Author(s): Micho Radovnikovich
autogenerated on Sat Feb 4 2023 03:39:25