Apollo 11.0
自动驾驶开放平台
msg_exporter_main.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#include <fstream>
18#include <memory>
19
20#include "absl/strings/str_split.h"
21#include "cyber/common/log.h"
22#include "cyber/cyber.h"
24
25namespace apollo {
26namespace perception {
27namespace msg {
28
29bool config_parser(const std::string& config_file,
30 std::vector<std::string>* channels,
31 std::vector<std::string>* child_frame_ids) {
32 std::ifstream fin(config_file);
33 if (!fin.is_open()) {
34 return false;
35 }
36 channels->clear();
37 child_frame_ids->clear();
38 std::string line;
39 std::getline(fin, line);
40 while (!fin.eof()) {
41 std::cout << line << std::endl;
42 if (line[0] == '#') {
43 std::getline(fin, line);
44 continue;
45 }
46 const std::vector<std::string> splits = absl::StrSplit(line, ' ');
47 if (splits.size() == 3 && std::stoi(splits[2]) > 0) {
48 channels->push_back(splits[0]);
49 child_frame_ids->push_back(splits[1]);
50 }
51 std::getline(fin, line);
52 }
53 fin.close();
54 for (std::size_t i = 0; i < channels->size(); ++i) {
55 std::cout << "\t\tRead channel " << channels->at(i) << " child_frame_id "
56 << child_frame_ids->at(i) << std::endl;
57 }
58 return true;
59}
60
61} // namespace msg
62} // namespace perception
63} // namespace apollo
64
65// Usage:
66// $ ./msg_exporter export_msg.config
67// $ cyber_recorder play -f record_name.record
68int main(int argc, char** argv) {
69 if (argc < 2) {
70 std::cout << "export_msgs config_file" << std::endl;
71 return -1;
72 }
73 // apollo::cyber::Logger::Init(argv[0]);
74 apollo::cyber::Init(argv[0]); // cybertron init function
75 std::shared_ptr<apollo::cyber::Node> node(
76 apollo::cyber::CreateNode("export_node"));
77 if (!node) {
78 std::cout << "Failed to create export node." << std::endl;
79 return -1;
80 }
81 std::vector<std::string> channels;
82 std::vector<std::string> child_frame_ids;
83 std::cout << "start to load config file: " << argv[1] << std::endl;
84 if (!apollo::perception::msg::config_parser(argv[1], &channels,
85 &child_frame_ids)) {
86 std::cout << "Failed to read config file" << std::endl;
87 return -1;
88 }
89 apollo::perception::msg::MsgExporter msg_exporter(node, channels,
90 child_frame_ids);
91 while (apollo::cyber::OK()) {
92 sleep(1);
93 }
94 return 0;
95}
int main(int argc, char **argv)
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:99
bool OK()
Definition state.h:44
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33
bool config_parser(const std::string &config_file, std::vector< std::string > *channels, std::vector< std::string > *child_frame_ids)
class register implement
Definition arena_queue.h:37