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 
42 
43 void recv(const can_msgs::Frame::ConstPtr& msg)
44 {
45  if (!msg->is_error && !msg->is_rtr) {
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 }
84 
#define ROS_FATAL(...)
dataspeed_can_tools::CanExtractor * extractor_
Definition: dbc_node.cpp:41
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void recv(const can_msgs::Frame::ConstPtr &msg)
Definition: dbc_node.cpp:43
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ROSCPP_DECL void spin()
int main(int argc, char **argv)
Definition: dbc_node.cpp:58
bool getParam(const std::string &key, std::string &s) const
void pubMessage(const can_msgs::Frame &msg, const ros::Time &stamp=ros::Time(0))
bool getMessage(RosCanMsgStruct &can_msg)
void initPublishers(RosCanMsgStruct &info, ros::NodeHandle &nh)
ros::NodeHandle * nh_
Definition: dbc_node.cpp:40
#define ROS_DEBUG(...)


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