Apollo 10.0
自动驾驶开放平台
apollo::dreamview::util::HMIUtil类 参考

#include <hmi_util.h>

apollo::dreamview::util::HMIUtil 的协作图:

静态 Public 成员函数

static apollo::dreamview::HMIConfig LoadConfig (const std::string config_path="")
 Load HMIConfig.
 
static apollo::dreamview::HMIMode LoadMode (const std::string &mode_config_path)
 Load HMIMode.
 
static void TranslateCyberModules (HMIMode *mode)
 transfer the mode's cyber modules to modules.
 
static std::string TitleCase (std::string_view origin)
 Convert a string to be title-like.
 
static google::protobuf::Map< std::string, std::string > ListDirAsDict (const std::string &dir)
 List all directory as a dict in a directory.
 

详细描述

在文件 hmi_util.h30 行定义.

成员函数说明

◆ ListDirAsDict()

Map< std::string, std::string > apollo::dreamview::util::HMIUtil::ListDirAsDict ( const std::string &  dir)
static

List all directory as a dict in a directory.

参数
dirthe directory to be listed.
返回
the listed result.

在文件 hmi_util.cc64 行定义.

64 {
65 Map<std::string, std::string> result;
66 const auto subdirs = cyber::common::ListSubPaths(dir);
67 for (const auto &subdir : subdirs) {
68 const auto subdir_title = HMIUtil::TitleCase(subdir);
69 const auto subdir_path = absl::StrCat(dir, "/", subdir);
70 result.insert({subdir_title, subdir_path});
71 }
72 return result;
73}
static std::string TitleCase(std::string_view origin)
Convert a string to be title-like.
Definition hmi_util.cc:36
std::vector< std::string > ListSubPaths(const std::string &directory_path, const unsigned char d_type)
List sub-paths.
Definition file.cc:353

◆ LoadConfig()

HMIConfig apollo::dreamview::util::HMIUtil::LoadConfig ( const std::string  config_path = "")
static

Load HMIConfig.

参数
config_paththe hmi modes conf path.
返回
HMIConfig.

在文件 hmi_util.cc75 行定义.

75 {
76 HMIConfig config;
77 if (config_path.empty()) {
78 *config.mutable_modes() =
79 ListFilesAsDict(FLAGS_dv_hmi_modes_config_path, ".pb.txt");
80 Map<std::string, std::string> dv_plus_modes =
81 ListFilesAsDict(FLAGS_dv_plus_hmi_modes_config_path, ".pb.txt");
82 for (auto iter = dv_plus_modes.begin(); iter != dv_plus_modes.end();
83 iter++) {
84 config.mutable_modes()->insert({iter->first, iter->second});
85 }
86 } else {
87 // Get available modes, maps and vehicles by listing data directory.
88 *config.mutable_modes() =
89 ListFilesAsDict(config_path, ".pb.txt");
90 }
91 ACHECK(!config.modes().empty())
92 << "No modes config loaded";
93
94 *config.mutable_maps() = ListDirAsDict(FLAGS_maps_data_path);
95 *config.mutable_vehicles() = ListDirAsDict(FLAGS_vehicles_config_path);
96 AINFO << "Loaded HMI config: " << config.DebugString();
97 return config;
98}
static google::protobuf::Map< std::string, std::string > ListDirAsDict(const std::string &dir)
List all directory as a dict in a directory.
Definition hmi_util.cc:64
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
Map< std::string, std::string > ListFilesAsDict(std::string_view dir, std::string_view extension)
Definition hmi_util.cc:49

◆ LoadMode()

HMIMode apollo::dreamview::util::HMIUtil::LoadMode ( const std::string &  mode_config_path)
static

Load HMIMode.

返回
HMIMode.

在文件 hmi_util.cc100 行定义.

100 {
101 HMIMode mode;
102 ACHECK(cyber::common::GetProtoFromFile(mode_config_path, &mode))
103 << "Unable to parse HMIMode from file " << mode_config_path;
105 // For global components.
106 HMIMode mode_temp;
107 ACHECK(cyber::common::GetProtoFromFile(FLAGS_global_components_config_path,
108 &mode_temp))
109 << "Unable to parse HMIMode from file "
110 << FLAGS_global_components_config_path;
111 for (const auto &iter : mode_temp.global_components()) {
112 (*mode.mutable_global_components())[iter.first] = iter.second;
113 }
114 AINFO << "Loaded HMI mode: " << mode.DebugString();
115 return mode;
116}
static void TranslateCyberModules(HMIMode *mode)
transfer the mode's cyber modules to modules.
Definition hmi_util.cc:118
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132

◆ TitleCase()

std::string apollo::dreamview::util::HMIUtil::TitleCase ( std::string_view  origin)
static

Convert a string to be title-like.

E.g.: "hello_world" -> "Hello World".

参数
originthe origin string to be convert
返回
the string after convert

在文件 hmi_util.cc36 行定义.

36 {
37 std::vector<std::string> parts = absl::StrSplit(origin, '_');
38 for (auto &part : parts) {
39 if (!part.empty()) {
40 // Upper case the first char.
41 part[0] = static_cast<char>(toupper(part[0]));
42 }
43 }
44
45 return absl::StrJoin(parts, " ");
46}

◆ TranslateCyberModules()

void apollo::dreamview::util::HMIUtil::TranslateCyberModules ( HMIMode mode)
static

transfer the mode's cyber modules to modules.

参数
modethe mode to be transfered.

在文件 hmi_util.cc118 行定义.

118 {
119 // Translate cyber_modules to regular modules.
120 for (const auto &iter : mode->cyber_modules()) {
121 const std::string &module_name = iter.first;
122 const CyberModule &cyber_module = iter.second;
123 // Each cyber module should have at least one dag file.
124 ACHECK(!cyber_module.dag_files().empty())
125 << "None dag file is provided for " << module_name;
126
127 Module &module = LookupOrInsert(mode->mutable_modules(), module_name, {});
128 module.set_required_for_safety(cyber_module.required_for_safety());
129
130 // Construct start_command:
131 // nohup mainboard -p <process_group> -d <dag> ... &
132 module.set_start_command("nohup mainboard");
133 const auto &process_group = cyber_module.process_group();
134 if (!process_group.empty()) {
135 absl::StrAppend(module.mutable_start_command(), " -p ", process_group);
136 }
137 for (const std::string &dag : cyber_module.dag_files()) {
138 absl::StrAppend(module.mutable_start_command(), " -d ", dag);
139 }
140 absl::StrAppend(module.mutable_start_command(), " &");
141
142 // Construct stop_command: pkill -f '<dag[0]>'
143 const std::string &first_dag = cyber_module.dag_files(0);
144 module.set_stop_command(absl::StrCat("pkill -f \"", first_dag, "\""));
145 // Construct process_monitor_config.
146 module.mutable_process_monitor_config()->add_command_keywords("mainboard");
147 module.mutable_process_monitor_config()->add_command_keywords(first_dag);
148 }
149 mode->clear_cyber_modules();
150}

该类的文档由以下文件生成: