提交 2af05c4e 编写于 作者: A Aaron Xiao 提交者: Dong Li

HMI: Check module path to decide if it is available. (#1058)

* HMI: Check module path to decide if it is available.

* HMI: Code clean.
上级 19c3696b
......@@ -91,6 +91,17 @@ Map<std::string, std::string> ListDirAsDict(const std::string &dir) {
HMI::HMI(WebSocketHandler *websocket) : websocket_(websocket) {
CHECK(common::util::GetProtoFromFile(FLAGS_hmi_config_filename, &config_))
<< "Unable to parse HMI config file " << FLAGS_hmi_config_filename;
// If the module path doesn't exist, remove it from list.
auto *modules = config_.mutable_modules();
for (auto iter = modules->begin(); iter != modules->end();) {
const auto &conf = iter->second;
if (conf.has_path() && !common::util::PathExists(conf.path())) {
iter = modules->erase(iter);
} else {
++iter;
}
}
// Get available maps and vehicles by listing data directory.
*config_.mutable_available_maps() = ListDirAsDict(FLAGS_map_data_path);
*config_.mutable_available_vehicles() =
......
......@@ -26,6 +26,21 @@ modules {
}
}
}
modules {
key: "mobileye"
value: {
display_name: "Mobileye"
path: "modules/drivers/mobileye"
supported_commands {
key: "start"
value: "scripts/mobileye.sh start"
}
supported_commands {
key: "stop"
value: "scripts/mobileye.sh stop"
}
}
}
modules {
key: "localization"
value: {
......
......@@ -4,7 +4,9 @@ package apollo.dreamview;
message Component {
optional string display_name = 1;
map<string, string> supported_commands = 2;
// If the path is given, HMI will check if it's available.
optional string path = 2;
map<string, string> supported_commands = 3;
}
message HMIConfig {
......
......@@ -44,6 +44,7 @@ modules {
modules {
name: "mobileye"
display_name: "Mobileye"
path: "modules/drivers/mobileye"
supported_commands {
name: "start"
command: "scripts/mobileye.sh"
......
......@@ -18,7 +18,9 @@ message Command {
message Component {
optional string name = 1;
optional string display_name = 2;
repeated Command supported_commands = 3;
// If the path is given, HMI will check if it's available.
optional string path = 3;
repeated Command supported_commands = 4;
}
message Config {
......
......@@ -68,6 +68,11 @@ class Config(object):
cls.pb_singleton = text_format.Merge(conf_file.read(),
config_pb2.Config())
conf_pb = cls.pb_singleton
for i in range(len(conf_pb.modules) - 1, -1, -1):
# If the module path doesn't exist, remove it from list.
module_path = conf_pb.modules[i].path
if module_path and not os.path.exists(module_path):
del conf_pb.modules[i]
# Init logger
file_handler = logging.handlers.TimedRotatingFileHandler(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册