src
dbc_node.cpp
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
#include <
ros/ros.h
>
36
#include <
ros/package.h
>
37
#include "
CanExtractor.h
"
38
#include <can_msgs/Frame.h>
39
40
ros::NodeHandle
*
nh_
;
41
dataspeed_can_tools::CanExtractor
*
extractor_
;
42
43
void
recv
(
const
can_msgs::Frame::ConstPtr& msg)
44
{
45
if
(!msg->is_error && !msg->is_rtr) {
46
dataspeed_can_tools::RosCanMsgStruct
info;
47
info.
id
= msg->id | (msg->is_extended ? 0x80000000 : 0x00000000);
48
49
if
(
extractor_
->
getMessage
(info)) {
50
ROS_DEBUG
(
"New message ID (%d), initializing publishers..."
, info.
id
);
51
extractor_
->
initPublishers
(info, *
nh_
);
52
}
53
54
extractor_
->
pubMessage
(msg);
55
}
56
}
57
58
int
main
(
int
argc,
char
** argv)
59
{
60
ros::init
(argc, argv,
"can_parser_node"
);
61
ros::NodeHandle
nh;
nh_
= &nh;
62
ros::NodeHandle
nh_priv(
"~"
);
63
64
std::vector<std::string> dbc_files;
65
if
(!nh_priv.
getParam
(
"dbc_files"
, dbc_files)) {
66
ROS_FATAL
(
"DBC file not specified. Exiting."
);
67
}
68
bool
expand;
69
nh_priv.
param
(
"expand"
, expand,
true
);
70
bool
unknown;
71
nh_priv.
param
(
"unknown"
, unknown,
false
);
72
73
printf(
"Opening dbc files: \n"
);
74
for
(
unsigned
int
i = 0; i < dbc_files.size(); i++) {
75
printf(
" - %s\n"
, dbc_files[i].c_str());
76
}
77
dataspeed_can_tools::CanExtractor
extractor(dbc_files,
false
, expand, unknown);
78
extractor_
= &extractor;
79
80
ros::Subscriber
sub_can = nh.
subscribe
(
"can_rx"
, 100,
recv
);
81
82
ros::spin
();
83
}
dataspeed_can_tools::RosCanMsgStruct::id
uint32_t id
Definition:
CanExtractor.h:110
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros.h
dataspeed_can_tools::CanExtractor::pubMessage
void pubMessage(const can_msgs::Frame &msg, const ros::Time &stamp=ros::Time(0))
Definition:
CanExtractor.cpp:422
nh_
ros::NodeHandle * nh_
Definition:
dbc_node.cpp:40
dataspeed_can_tools::CanExtractor::getMessage
bool getMessage(RosCanMsgStruct &can_msg)
Definition:
CanExtractor.cpp:216
recv
void recv(const can_msgs::Frame::ConstPtr &msg)
Definition:
dbc_node.cpp:43
dataspeed_can_tools::CanExtractor::initPublishers
void initPublishers(RosCanMsgStruct &info, ros::NodeHandle &nh)
Definition:
CanExtractor.cpp:262
CanExtractor.h
extractor_
dataspeed_can_tools::CanExtractor * extractor_
Definition:
dbc_node.cpp:41
dataspeed_can_tools::RosCanMsgStruct
Definition:
CanExtractor.h:107
main
int main(int argc, char **argv)
Definition:
dbc_node.cpp:58
ROS_DEBUG
#define ROS_DEBUG(...)
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
package.h
ROS_FATAL
#define ROS_FATAL(...)
ros::NodeHandle::param
T param(const std::string ¶m_name, const T &default_val) const
ros::spin
ROSCPP_DECL void spin()
dataspeed_can_tools::CanExtractor
Definition:
CanExtractor.h:114
ros::NodeHandle
ros::Subscriber
dataspeed_can_tools
Author(s): Micho Radovnikovich
autogenerated on Sat Feb 4 2023 03:39:25