39 #include <boost/foreach.hpp> 40 #include <can_msgs/Frame.h> 45 printf(
"Usage: dbc_bag <bag_file> <topic> <dbc_file> [dbc_files]... [-O output_file]\n");
46 printf(
" [--unknown / -u] [--expand / -e]\n");
47 printf(
" [--lz4] [--bz2]\n");
48 printf(
" [--help / -h]\n");
51 int main(
int argc,
char** argv)
54 std::string bag_file_in;
55 std::string bag_file_out;
57 std::vector<std::string> dbc_files;
59 bool _unknown =
false;
64 unsigned int count = 0;
65 for (
int i = 1; i < argc; i++) {
66 std::string str = argv[i];
67 if (str ==
"--help" || str ==
"-h") {
70 }
else if (str ==
"--unknown" || str ==
"-u") {
72 }
else if (str ==
"--expand" || str ==
"-e") {
74 }
else if (str ==
"--lz4") {
76 }
else if (str ==
"--bz2") {
78 }
else if (str ==
"-O") {
81 bag_file_out = argv[i];
86 }
else if (count == 1) {
89 dbc_files.push_back(str);
98 if (bag_file_out.empty()) {
99 bag_file_out = bag_file_in +
".dbc.bag";
102 printf(
"Opening input bag file: '%s'\n", bag_file_in.c_str());
106 printf(
"Processing can_msgs/Frame on topic: '%s'\n", topic.c_str());
109 printf(
"Opening dbc files: \n");
110 for (
size_t i = 0; i < dbc_files.size(); i++) {
111 printf(
" - %s\n", dbc_files[i].c_str());
115 printf(
"Opening output bag file: '%s'\n", bag_file_out.c_str());
122 extractor.
openBag(bag_file_out, compression);
124 const ros::Time stamp_end = view.getEndTime();
125 const ros::Time stamp_begin = view.getBeginTime();
126 if (stamp_end > stamp_begin) {
127 int last_percent = 0;
129 can_msgs::Frame::ConstPtr msg = m.
instantiate<can_msgs::Frame>();
131 can_msg.
id = msg->id | (msg->is_extended ? 0x80000000 : 0x00000000);
135 int percent = 100 * (msg->header.stamp - stamp_begin).toSec() / (stamp_end - stamp_begin).toSec();
136 if (percent >= last_percent) {
137 printf(
"Processing: %d%% complete\n", last_percent);
142 printf(
"Warning: no messages\n");
146 printf(
"Successfully wrote parsed CAN data to bag\n");
void open(std::string const &filename, uint32_t mode=bagmode::Read)
ros::Time const & getTime() const
boost::shared_ptr< T > instantiate() const
int main(int argc, char **argv)