21#include "absl/strings/str_cat.h"
22#include "absl/strings/str_join.h"
23#include "absl/strings/str_split.h"
34using google::protobuf::Map;
37 std::vector<std::string> parts = absl::StrSplit(origin,
'_');
38 for (
auto &part : parts) {
41 part[0] =
static_cast<char>(toupper(part[0]));
45 return absl::StrJoin(parts,
" ");
50 std::string_view extension) {
51 Map<std::string, std::string> result;
52 const std::string pattern = absl::StrCat(dir,
"/*", extension);
57 filename.substr(0, filename.length() - extension.length()));
58 result.insert({file_title, file_path});
65 Map<std::string, std::string> result;
67 for (
const auto &subdir : subdirs) {
69 const auto subdir_path = absl::StrCat(dir,
"/", subdir);
70 result.insert({subdir_title, subdir_path});
77 if (config_path.empty()) {
78 *config.mutable_modes() =
80 Map<std::string, std::string> dv_plus_modes =
82 for (
auto iter = dv_plus_modes.begin(); iter != dv_plus_modes.end();
84 config.mutable_modes()->insert({iter->first, iter->second});
88 *config.mutable_modes() =
92 <<
"No modes config loaded";
95 *config.mutable_vehicles() =
ListDirAsDict(FLAGS_vehicles_config_path);
96 AINFO <<
"Loaded HMI config: " << config.DebugString();
103 <<
"Unable to parse HMIMode from file " << mode_config_path;
109 <<
"Unable to parse HMIMode from file "
110 << FLAGS_global_components_config_path;
112 (*mode.mutable_global_components())[iter.first] = iter.second;
114 AINFO <<
"Loaded HMI mode: " << mode.DebugString();
121 const std::string &module_name = iter.first;
125 <<
"None dag file is provided for " << module_name;
127 Module &
module = LookupOrInsert(mode->mutable_modules(), module_name, {});
128 module.set_required_for_safety(cyber_module.required_for_safety());
132 module.set_start_command("nohup mainboard");
134 if (!process_group.empty()) {
135 absl::StrAppend(module.mutable_start_command(),
" -p ", process_group);
137 for (
const std::string &dag : cyber_module.
dag_files()) {
138 absl::StrAppend(module.mutable_start_command(),
" -d ", dag);
140 absl::StrAppend(module.mutable_start_command(),
" &");
143 const std::string &first_dag = cyber_module.
dag_files(0);
144 module.set_stop_command(absl::StrCat("pkill -f \"", first_dag, "\""));
146 module.mutable_process_monitor_config()->add_command_keywords("mainboard");
147 module.mutable_process_monitor_config()->add_command_keywords(first_dag);
149 mode->clear_cyber_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.
static void TranslateCyberModules(HMIMode *mode)
transfer the mode's cyber modules to modules.
static apollo::dreamview::HMIMode LoadMode(const std::string &mode_config_path)
Load HMIMode.
static apollo::dreamview::HMIConfig LoadConfig(const std::string config_path="")
Load HMIConfig.
std::vector< std::string > Glob(const std::string &pattern)
Expand path pattern to matched paths.
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,...
std::string GetFileName(const std::string &path, const bool remove_extension)
std::vector< std::string > ListSubPaths(const std::string &directory_path, const unsigned char d_type)
List sub-paths.
Map< std::string, std::string > ListFilesAsDict(std::string_view dir, std::string_view extension)
optional string process_group
repeated string dag_files
map< string, string > modes
map< string, CyberModule > cyber_modules
map< string, MonitoredComponent > global_components