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

#include <hmi_worker.h>

apollo::dreamview::HMIWorker 的协作图:

Public 类型

using DvCallback = std::function< nlohmann::json(const std::string &function_name, const nlohmann::json &param_json)>
 
using StatusUpdateHandler = std::function< void(const bool status_changed, HMIStatus *status)>
 
using DvCallback = std::function< nlohmann::json(const std::string &function_name, const nlohmann::json &param_json)>
 
using StatusUpdateHandler = std::function< void(const bool status_changed, HMIStatus *status)>
 

Public 成员函数

 HMIWorker ()
 
 HMIWorker (const std::shared_ptr< apollo::cyber::Node > &node)
 
void Start (DvCallback callback_api)
 
void Stop ()
 
bool Trigger (const HMIAction action)
 
bool Trigger (const HMIAction action, const std::string &value)
 
void RegisterStatusUpdateHandler (StatusUpdateHandler handler)
 
void SubmitAudioEvent (const uint64_t event_time_ms, const int obstacle_id, const int audio_type, const int moving_result, const int audio_direction, const bool is_siren_on)
 
void SubmitDriveEvent (const uint64_t event_time_ms, const std::string &event_msg, const std::vector< std::string > &event_types, const bool is_reportable)
 
void SensorCalibrationPreprocess (const std::string &task_type)
 
void VehicleCalibrationPreprocess ()
 
HMIStatus GetStatus () const
 
bool UpdateScenarioSetToStatus (const std::string &scenario_set_id, const std::string &scenario_set_name)
 
bool UpdateScenarioSet (const std::string &scenario_set_id, const std::string &scenario_set_name, ScenarioSet *new_scenario_set)
 
bool UpdateDynamicModelToStatus (const std::string &dynamic_model_name)
 
void UpdateComponentStatus ()
 
bool LoadRecords ()
 
bool ReloadVehicles ()
 
bool GetScenarioSetPath (const std::string &scenario_set_id, std::string *scenario_set_path)
 
void UpdateCameraSensorChannelToStatus (const std::string &channel_name)
 
void UpdatePointCloudChannelToStatus (const std::string &channel_name)
 
 HMIWorker (apollo::common::monitor::MonitorLogBuffer monitor_log_buffer)
 
 HMIWorker (const std::shared_ptr< apollo::cyber::Node > &node, const apollo::common::monitor::MonitorLogBuffer &monitor_log_buffer)
 
void Start (DvCallback callback_api)
 
void Stop ()
 
bool Trigger (const HMIAction action)
 
bool Trigger (const HMIAction action, const std::string &value)
 
void RegisterStatusUpdateHandler (StatusUpdateHandler handler)
 
void SubmitAudioEvent (const uint64_t event_time_ms, const int obstacle_id, const int audio_type, const int moving_result, const int audio_direction, const bool is_siren_on)
 
void SubmitDriveEvent (const uint64_t event_time_ms, const std::string &event_msg, const std::vector< std::string > &event_types, const bool is_reportable)
 
void SensorCalibrationPreprocess (const std::string &task_type)
 
void VehicleCalibrationPreprocess ()
 
HMIStatus GetStatus () const
 
bool UpdateDynamicModelToStatus (const std::string &dynamic_model_name)
 
void UpdateComponentStatus ()
 
bool UpdateMapToStatus (const std::string &map_name)
 
bool LoadRecords ()
 
bool LoadRecordAndChangeStatus (const std::string &record_name)
 
bool LoadRecord (const std::string &record_name, const std::string &record_file_path, double *total_time_s)
 
bool RecordIsLoaded (const std::string &record_id)
 
bool RePlayRecord ()
 
bool LoadRtkRecords ()
 
void UpdateRtkRecordToStatus (const std::string &new_name)
 
bool handlePlayRecordProcess (const std::string &action_type)
 control the nohup play record process by action_type
 
bool ResetRecordProgress (const double &progress)
 reset the play record progress to jump.
 
bool ReloadVehicles ()
 
void GetScenarioSetPath (const std::string &scenario_set_id, std::string *scenario_set_path)
 
void UpdateCameraSensorChannelToStatus (const std::string &channel_name)
 
void UpdatePointCloudChannelToStatus (const std::string &channel_name)
 
bool StartDataRecorder ()
 
bool StopDataRecorder ()
 
int SaveDataRecorder (const std::string &new_name)
 
bool DeleteDataRecorder ()
 
bool StartRtkDataRecorder ()
 
bool StopRtkDataRecorder ()
 
bool DeleteRtkDataRecorder ()
 
int SaveRtkDataRecorder (const std::string &new_name)
 
bool StopPlayRtkRecorder ()
 
nlohmann::json StartPlayRtkRecorder ()
 
void ChangeMapVal (const std::string &map_name)
 
bool AddOrModifyObjectToDB (const std::string &key, const std::string &value)
 
bool DeleteObjectToDB (const std::string &key)
 
std::string GetObjectFromDB (const std::string &key)
 
std::vector< std::pair< std::string, std::string > > GetTuplesWithTypeFromDB (const std::string &type)
 
bool StartTerminal ()
 
bool isProcessRunning (const std::string &process_name)
 Check if a process exists
 
std::string GetCurrentModeDefaultLayout ()
 Get dv current mode default layout.
 
std::string GetDvPluginPanelsJsonStr ()
 Get dv plugin panels json of frontend.
 

详细描述

在文件 hmi_worker.h56 行定义.

成员类型定义说明

◆ DvCallback [1/2]

using apollo::dreamview::HMIWorker::DvCallback = std::function<nlohmann::json( const std::string& function_name, const nlohmann::json& param_json)>

在文件 hmi_worker.h58 行定义.

◆ DvCallback [2/2]

using apollo::dreamview::HMIWorker::DvCallback = std::function<nlohmann::json( const std::string& function_name, const nlohmann::json& param_json)>

在文件 hmi_worker.h58 行定义.

◆ StatusUpdateHandler [1/2]

using apollo::dreamview::HMIWorker::StatusUpdateHandler = std::function<void(const bool status_changed, HMIStatus* status)>

在文件 hmi_worker.h72 行定义.

◆ StatusUpdateHandler [2/2]

using apollo::dreamview::HMIWorker::StatusUpdateHandler = std::function<void(const bool status_changed, HMIStatus* status)>

在文件 hmi_worker.h76 行定义.

构造及析构函数说明

◆ HMIWorker() [1/4]

apollo::dreamview::HMIWorker::HMIWorker ( )
inline

在文件 hmi_worker.h60 行定义.

std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33

◆ HMIWorker() [2/4]

apollo::dreamview::HMIWorker::HMIWorker ( const std::shared_ptr< apollo::cyber::Node > &  node)
explicit

◆ HMIWorker() [3/4]

apollo::dreamview::HMIWorker::HMIWorker ( apollo::common::monitor::MonitorLogBuffer  monitor_log_buffer)
inlineexplicit

在文件 hmi_worker.h60 行定义.

62 : HMIWorker(cyber::CreateNode("HMI"), monitor_log_buffer) {}

◆ HMIWorker() [4/4]

apollo::dreamview::HMIWorker::HMIWorker ( const std::shared_ptr< apollo::cyber::Node > &  node,
const apollo::common::monitor::MonitorLogBuffer monitor_log_buffer 
)

成员函数说明

◆ AddOrModifyObjectToDB()

bool apollo::dreamview::HMIWorker::AddOrModifyObjectToDB ( const std::string &  key,
const std::string &  value 
)

在文件 hmi_worker.cc1925 行定义.

1926 {
1927 return KVDB::Put(key, value);
1928}

◆ ChangeMapVal()

void apollo::dreamview::HMIWorker::ChangeMapVal ( const std::string &  map_name)

◆ DeleteDataRecorder()

bool apollo::dreamview::HMIWorker::DeleteDataRecorder ( )

在文件 hmi_worker.cc1827 行定义.

1827 {
1828 std::string delete_cmd =
1829 "/apollo/scripts/record_bag.py --delete --default_name " +
1830 FLAGS_data_record_default_name;
1831 int ret = std::system(delete_cmd.data());
1832 if (ret == 0) {
1833 return true;
1834 } else {
1835 AERROR << "Failed to delete the record";
1836 return false;
1837 }
1838}
#define AERROR
Definition log.h:44

◆ DeleteObjectToDB()

bool apollo::dreamview::HMIWorker::DeleteObjectToDB ( const std::string &  key)

在文件 hmi_worker.cc1930 行定义.

1930 {
1931 return KVDB::Delete(key);
1932}

◆ DeleteRtkDataRecorder()

bool apollo::dreamview::HMIWorker::DeleteRtkDataRecorder ( )

在文件 hmi_worker.cc2072 行定义.

2072 {
2073 if (!cyber::common::PathExists(FLAGS_default_rtk_record_file)) {
2074 AERROR << "Failed to delete the ret record, file not exist";
2075 return false;
2076 }
2077 if (std::remove(FLAGS_default_rtk_record_file.data()) == 0) {
2078 return true;
2079 } else {
2080 AERROR << "Failed to delete the record, delete command execution failed";
2081 return false;
2082 }
2083}
bool PathExists(const std::string &path)
Check if the path exists.
Definition file.cc:195

◆ GetCurrentModeDefaultLayout()

std::string apollo::dreamview::HMIWorker::GetCurrentModeDefaultLayout ( )

Get dv current mode default layout.

返回
the default layout.

在文件 hmi_worker.cc2164 行定义.

2164 {
2165 if (current_mode_.has_layout()) {
2166 const auto default_layout_json =
2168 "default_layout", current_mode_.layout());
2169 return default_layout_json["data"].dump();
2170 }
2171 AWARN << "There is no default layout for the current mode.";
2172 return "";
2173}
static nlohmann::json ProtoToTypedJson(const std::string &json_type, const google::protobuf::Message &proto)
Convert proto to a json string.
Definition json_util.cc:37
#define AWARN
Definition log.h:43

◆ GetDvPluginPanelsJsonStr()

std::string apollo::dreamview::HMIWorker::GetDvPluginPanelsJsonStr ( )

Get dv plugin panels json of frontend.

返回
the plugin panels json.

在文件 hmi_worker.cc2208 行定义.

2208 {
2209 return plugin_panels_json_.empty() ? "" : plugin_panels_json_.dump();
2210}

◆ GetObjectFromDB()

std::string apollo::dreamview::HMIWorker::GetObjectFromDB ( const std::string &  key)

在文件 hmi_worker.cc1934 行定义.

1934 {
1935 return KVDB::Get(key).value_or("");
1936}

◆ GetScenarioSetPath() [1/2]

bool apollo::dreamview::HMIWorker::GetScenarioSetPath ( const std::string &  scenario_set_id,
std::string *  scenario_set_path 
)

在文件 hmi_worker.cc792 行定义.

793 {
794 CHECK_NOTNULL(scenario_set_path);
795 if (!GetScenarioResourcePath(scenario_set_path)) {
796 return false;
797 }
798 *scenario_set_path = *scenario_set_path + scenario_set_id;
799 return true;
800}

◆ GetScenarioSetPath() [2/2]

void apollo::dreamview::HMIWorker::GetScenarioSetPath ( const std::string &  scenario_set_id,
std::string *  scenario_set_path 
)

◆ GetStatus() [1/2]

HMIStatus apollo::dreamview::HMIWorker::GetStatus ( ) const

在文件 hmi_worker.cc681 行定义.

681 {
682 RLock rlock(status_mutex_);
683 return status_;
684}
boost::shared_lock< boost::shared_mutex > RLock

◆ GetStatus() [2/2]

HMIStatus apollo::dreamview::HMIWorker::GetStatus ( ) const

◆ GetTuplesWithTypeFromDB()

std::vector< std::pair< std::string, std::string > > apollo::dreamview::HMIWorker::GetTuplesWithTypeFromDB ( const std::string &  type)

在文件 hmi_worker.cc1939 行定义.

1939 {
1940 return KVDB::GetWithStart(type);
1941}

◆ handlePlayRecordProcess()

bool apollo::dreamview::HMIWorker::handlePlayRecordProcess ( const std::string &  action_type)

control the nohup play record process by action_type

参数
action_typeThe action to control the nohup play record process optional values like pause and continue.
返回
If the action executed successfully.

在文件 hmi_worker.cc1041 行定义.

1041 {
1042 std::string record_id;
1043 PlayRecordStatus current_play_record_status;
1044 PlayRecordStatus expected_play_record_status;
1045 PlayRecordStatus reasonable_play_record_status;
1046 {
1047 RLock rlock(status_mutex_);
1048 auto record_status = status_.current_record_status();
1049 record_id = record_status.current_record_id();
1050 current_play_record_status = record_status.play_record_status();
1051 if (record_id.empty()) {
1052 AERROR << "Failed to pause record for record has not been selected"
1053 "or process is not exists!";
1054 return false;
1055 }
1056 if (!RecordIsLoaded(record_id)) {
1057 AERROR << "Failed to pause record for record has not been loaded!";
1058 return false;
1059 }
1060 }
1061 if (action_type.compare("continue") == 0) {
1062 expected_play_record_status = PlayRecordStatus::RUNNING;
1063 reasonable_play_record_status = PlayRecordStatus::PAUSED;
1064 } else if (action_type.compare("pause") == 0) {
1065 expected_play_record_status = PlayRecordStatus::PAUSED;
1066 reasonable_play_record_status = PlayRecordStatus::RUNNING;
1067 } else {
1068 AERROR << "Invalid action type for play record.";
1069 return false;
1070 }
1071 if (reasonable_play_record_status != current_play_record_status) {
1072 return false;
1073 }
1074 auto *record_player_factory = RecordPlayerFactory::Instance();
1075 auto player_ptr = record_player_factory->GetRecordPlayer(record_id);
1076 if (!player_ptr) {
1077 AERROR << "Failed to get record player.";
1078 return false;
1079 }
1080 player_ptr->HandleNohupThreadStatus();
1081
1082 {
1083 WLock wlock(status_mutex_);
1084 status_.mutable_current_record_status()->set_play_record_status(
1085 expected_play_record_status);
1086 status_changed_ = true;
1087 }
1088 record_player_factory->IncreaseRecordPriority(record_id);
1089 return true;
1090}
bool RecordIsLoaded(const std::string &record_id)
boost::unique_lock< boost::shared_mutex > WLock

◆ isProcessRunning()

bool apollo::dreamview::HMIWorker::isProcessRunning ( const std::string &  process_name)

Check if a process exists

参数
process_nameThe name of the process to check
返回
True if the process exists

在文件 hmi_worker.cc2128 行定义.

2128 {
2129 std::stringstream commandStream;
2130 commandStream << "pgrep -f " << process_name;
2131 std::string command = commandStream.str();
2132
2133 FILE *fp = popen(command.c_str(), "r");
2134 if (fp) {
2135 char result[128];
2136 if (fgets(result, sizeof(result), fp) != nullptr) {
2137 AINFO << process_name << " is running";
2138 pclose(fp);
2139 return true;
2140 } else {
2141 AINFO << process_name << " is not running";
2142 }
2143 pclose(fp);
2144 }
2145 return false;
2146}
#define AINFO
Definition log.h:42

◆ LoadRecord()

bool apollo::dreamview::HMIWorker::LoadRecord ( const std::string &  record_name,
const std::string &  record_file_path,
double *  total_time_s 
)

在文件 hmi_worker.cc1442 行定义.

1444 {
1445 if (RecordIsLoaded(record_name)) {
1446 AERROR << "Record is loaded,no need to load";
1447 return false;
1448 }
1449 // check if record player factory can continue load
1450 auto record_player_factory = RecordPlayerFactory::Instance();
1451 if (!record_player_factory->EnableContinueLoad()) {
1452 // can not load record,need to remove lru record
1453 std::string remove_record_id;
1454 if (record_player_factory->RemoveLRURecord(&remove_record_id)) {
1455 // remove successfully, change removed record status
1456 {
1457 WLock wlock(status_mutex_);
1458 auto status_records = status_.mutable_records();
1459 (*status_records)[remove_record_id].set_load_record_status(
1460 LoadRecordStatus::NOT_LOAD);
1461 (*status_records)[remove_record_id].clear_total_time_s();
1462 }
1463 }
1464 }
1465 if (!ReadRecordInfo(record_file_path, total_time_s)) {
1466 return false;
1467 }
1468 if (!record_player_factory->RegisterRecordPlayer(record_name,
1469 record_file_path)) {
1470 return false;
1471 }
1472 return true;
1473}

◆ LoadRecordAndChangeStatus()

bool apollo::dreamview::HMIWorker::LoadRecordAndChangeStatus ( const std::string &  record_name)

在文件 hmi_worker.cc1395 行定义.

1395 {
1396 std::string record_file_path;
1397 {
1398 RLock rlock(status_mutex_);
1399 auto &status_records = status_.records();
1400 auto iter = status_records.find(record_name);
1401 if (iter == status_records.end()) {
1402 AERROR << "Cannot load unknown record!";
1403 return false;
1404 }
1405 if (RecordIsLoaded(record_name)) {
1406 AERROR << "Cannot load already loaded record.";
1407 return false;
1408 }
1409 if (iter->second.record_file_path().empty()) {
1410 AERROR << "Cannot load record without record file path!";
1411 return false;
1412 }
1413 record_file_path = iter->second.record_file_path();
1414 }
1415 {
1416 WLock wlock(status_mutex_);
1417 auto status_records = status_.mutable_records();
1418 (*status_records)[record_name].set_load_record_status(
1419 LoadRecordStatus::LOADING);
1420 }
1421 double total_time_s;
1422 if (LoadRecord(record_name, record_file_path, &total_time_s)) {
1423 {
1424 WLock wlock(status_mutex_);
1425 auto status_records = status_.mutable_records();
1426 (*status_records)[record_name].set_load_record_status(
1427 LoadRecordStatus::LOADED);
1428 (*status_records)[record_name].set_total_time_s(total_time_s);
1429 }
1430 RecordPlayerFactory::Instance()->IncreaseRecordPriority(record_name);
1431 } else {
1432 {
1433 WLock wlock(status_mutex_);
1434 auto status_records = status_.mutable_records();
1435 (*status_records)[record_name].set_load_record_status(
1436 LoadRecordStatus::NOT_LOAD);
1437 }
1438 }
1439 return true;
1440}
bool LoadRecord(const std::string &record_name, const std::string &record_file_path, double *total_time_s)

◆ LoadRecords() [1/2]

bool apollo::dreamview::HMIWorker::LoadRecords ( )

在文件 hmi_worker.cc1407 行定义.

1407 {
1408 std::string directory_path;
1409 if (!GetRecordPath(&directory_path)) {
1410 AERROR << "Failed to get record path!";
1411 return false;
1412 }
1413 if (!cyber::common::PathExists(directory_path)) {
1414 AERROR << "Failed to find records!";
1415 return false;
1416 }
1417 DIR *directory = opendir(directory_path.c_str());
1418 if (directory == nullptr) {
1419 AERROR << "Cannot open record directory" << directory_path;
1420 return false;
1421 }
1422 struct dirent *file;
1423 std::map<std::string, LoadRecordInfo> new_records;
1424 while ((file = readdir(directory)) != nullptr) {
1425 if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) {
1426 continue;
1427 }
1428 if (file->d_type == DT_DIR) {
1429 continue;
1430 }
1431 const std::string record_id = file->d_name;
1432 const int index = record_id.rfind(".record");
1433 // Skip format that dv cannot parse: record not ending in record
1434 size_t record_suffix_length = 7;
1435 if (record_id.length() - index != record_suffix_length) {
1436 continue;
1437 }
1438 if (index != -1 && record_id[0] != '.') {
1439 const std::string local_record_resource = record_id.substr(0, index);
1440 // compatible records with dv and dv_plus
1441 new_records[local_record_resource] = {};
1442 new_records[local_record_resource].set_download_status(1);
1443 }
1444 }
1445 closedir(directory);
1446 {
1447 WLock wlock(status_mutex_);
1448 auto status_records = status_.mutable_records();
1449 status_records->clear();
1450 for (auto iter = new_records.begin(); iter != new_records.end(); iter++) {
1451 (*status_records)[iter->first] = iter->second;
1452 }
1453 status_changed_ = true;
1454 }
1455 return true;
1456}

◆ LoadRecords() [2/2]

bool apollo::dreamview::HMIWorker::LoadRecords ( )

◆ LoadRtkRecords()

bool apollo::dreamview::HMIWorker::LoadRtkRecords ( )

在文件 hmi_worker.cc1952 行定义.

1952 {
1953 {
1954 WLock wLock(status_mutex_);
1955 status_.clear_rtk_records();
1956 }
1957 std::string directory_path;
1958 GetRtkRecordPath(&directory_path);
1959 if (!cyber::common::PathExists(directory_path)) {
1960 AERROR << "Failed to find rtk records!";
1961 return false;
1962 }
1963 DIR *directory = opendir(directory_path.c_str());
1964 if (directory == nullptr) {
1965 AERROR << "Cannot open rtk record directory" << directory_path;
1966 return false;
1967 }
1968 struct dirent *file;
1969 std::map<std::string, double> new_records;
1970 while ((file = readdir(directory)) != nullptr) {
1971 if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) {
1972 continue;
1973 }
1974 if (file->d_type == DT_DIR) {
1975 continue;
1976 }
1977 const std::string record_id = file->d_name;
1978 const int index = record_id.rfind(".csv");
1979 if (index != -1 && record_id[0] != '.') {
1980 const std::string local_record_resource = record_id.substr(0, index);
1981 {
1982 WLock wLock(status_mutex_);
1983 status_.add_rtk_records(local_record_resource);
1984 }
1985 }
1986 }
1987 closedir(directory);
1988 {
1989 WLock wlock(status_mutex_);
1990 status_changed_ = true;
1991 }
1992 return true;
1993}

◆ RecordIsLoaded()

bool apollo::dreamview::HMIWorker::RecordIsLoaded ( const std::string &  record_id)

在文件 hmi_worker.cc1232 行定义.

1232 {
1233 {
1234 RLock rlock(status_mutex_);
1235 auto iter = status_.records().find(record_id);
1236 return iter != status_.records().end() &&
1237 (iter->second.load_record_status() == LoadRecordStatus::LOADED);
1238 }
1239}

◆ RegisterStatusUpdateHandler() [1/2]

void apollo::dreamview::HMIWorker::RegisterStatusUpdateHandler ( StatusUpdateHandler  handler)
inline

在文件 hmi_worker.h74 行定义.

74 {
75 status_update_handlers_.push_back(handler);
76 }

◆ RegisterStatusUpdateHandler() [2/2]

void apollo::dreamview::HMIWorker::RegisterStatusUpdateHandler ( StatusUpdateHandler  handler)
inline

在文件 hmi_worker.h78 行定义.

78 {
79 status_update_handlers_.push_back(handler);
80 }

◆ ReloadVehicles() [1/2]

bool apollo::dreamview::HMIWorker::ReloadVehicles ( )

在文件 hmi_worker.cc1505 行定义.

1505 {
1506 AINFO << "load config";
1507 HMIConfig config = util::HMIUtil::LoadConfig(FLAGS_dv_hmi_modes_config_path);
1508 std::string msg;
1509 AINFO << "serialize new config";
1510 config.SerializeToString(&msg);
1511
1512 WLock wlock(status_mutex_);
1513 AINFO << "parse new config";
1514 config_.ParseFromString(msg);
1515 AINFO << "init status";
1516 // status_.clear_modes();
1517 // status_.clear_maps();
1518 AINFO << "clear vehicles";
1519 status_.clear_vehicles();
1520 // InitStatus();
1521 // Populate vehicles and current_vehicle.
1522 AINFO << "reload vehicles";
1523 for (const auto &vehicle : config_.vehicles()) {
1524 status_.add_vehicles(vehicle.first);
1525 }
1526 status_changed_ = true;
1527 return true;
1528}
static apollo::dreamview::HMIConfig LoadConfig(const std::string config_path="")
Load HMIConfig.
Definition hmi_util.cc:75

◆ ReloadVehicles() [2/2]

bool apollo::dreamview::HMIWorker::ReloadVehicles ( )

◆ RePlayRecord()

bool apollo::dreamview::HMIWorker::RePlayRecord ( )

在文件 hmi_worker.cc1092 行定义.

1092 {
1093 std::string record_id;
1094 {
1095 RLock rlock(status_mutex_);
1096 auto record_status = status_.current_record_status();
1097 record_id = record_status.current_record_id();
1098 if (record_status.current_record_id().empty()) {
1099 AERROR << "Failed to play record for record has not been selected!";
1100 return false;
1101 }
1102 if (!RecordIsLoaded(record_id)) {
1103 AERROR << "Failed to play record for record has not been loaded!";
1104 return false;
1105 }
1106 if (record_status.play_record_status() == PlayRecordStatus::RUNNING) {
1107 AERROR << "Record has been played,ignore dumplicate request.";
1108 return false;
1109 }
1110 }
1111 std::string record_path;
1112 if (!GetRecordPath(&record_path)) {
1113 AERROR << "Failed to get record path!";
1114 return false;
1115 }
1116 record_path = record_path + record_id + ".record";
1117
1118 if (!cyber::common::PathExists(record_path)) {
1119 AERROR << "Failed to find record!";
1120 return false;
1121 }
1122 // play the record
1123 auto *record_player_factory = RecordPlayerFactory::Instance();
1124 auto player_ptr = record_player_factory->GetRecordPlayer(record_id);
1125 bool play_record_res = (player_ptr != nullptr);
1126 PlayRecordStatus play_record_status;
1127 if (!play_record_res) {
1128 AERROR << "Failed to get record related player";
1129 play_record_status = PlayRecordStatus::CLOSED;
1130 } else {
1131 player_ptr->PreloadPlayRecord();
1132 player_ptr->NohupPlayRecord();
1133 // get channel msgs for frontend after start play record
1134 callback_api_("GetDataHandlerConf", {});
1135 play_record_status = PlayRecordStatus::RUNNING;
1136 }
1137 {
1138 WLock wlock(status_mutex_);
1139 auto record_status = status_.mutable_current_record_status();
1140 record_status->set_play_record_status(play_record_status);
1141 status_changed_ = true;
1142 }
1143 record_player_factory->IncreaseRecordPriority(record_id);
1144 return play_record_res;
1145}

◆ ResetRecordProgress()

bool apollo::dreamview::HMIWorker::ResetRecordProgress ( const double &  progress)

reset the play record progress to jump.

参数
progressThe progress to jump.
返回
If the action executed successfully.

在文件 hmi_worker.cc1147 行定义.

1147 {
1148 std::string record_id;
1149 double total_time_s;
1150 PlayRecordStatus last_record_status;
1151 {
1152 RLock rlock(status_mutex_);
1153 auto record_status = status_.current_record_status();
1154 record_id = record_status.current_record_id();
1155 last_record_status = record_status.play_record_status();
1156 if (record_status.current_record_id().empty()) {
1157 AERROR << "Failed to reset record progress for record has not been "
1158 "selected!";
1159 return false;
1160 }
1161 if (!RecordIsLoaded(record_id)) {
1162 AERROR << "Failed to reset record progress for record has not been "
1163 "loaded!";
1164 return false;
1165 }
1166 total_time_s = status_.records().at(record_id).total_time_s();
1167 }
1168 AERROR << "total : " << total_time_s;
1169 if (progress > total_time_s) {
1170 AERROR << "Failed to reset record progress for progress exceeds the "
1171 "record's total time.";
1172 return false;
1173 }
1174 auto *record_player_factory = RecordPlayerFactory::Instance();
1175 auto player_ptr = record_player_factory->GetRecordPlayer(record_id);
1176 if (!player_ptr) {
1177 AERROR << "Failed to get record player.";
1178 return false;
1179 }
1180 player_ptr->Reset();
1181 player_ptr->PreloadPlayRecord(
1182 progress, (last_record_status != PlayRecordStatus::RUNNING));
1183 player_ptr->NohupPlayRecord();
1184 // When a record is selected and the progress is reset; we consider
1185 // the record to be stuck at the current progress in a paused state
1186 // to keep logic consistent
1187 if (last_record_status == PlayRecordStatus::CLOSED) {
1188 last_record_status = PlayRecordStatus::PAUSED;
1189 }
1190 // get channel msgs for frontend after start play record
1191 callback_api_("GetDataHandlerConf", {});
1192 {
1193 WLock wlock(status_mutex_);
1194 auto record_status = status_.mutable_current_record_status();
1195 record_status->set_play_record_status(last_record_status);
1196 record_status->set_curr_time_s(progress);
1197 status_changed_ = true;
1198 }
1199 record_player_factory->IncreaseRecordPriority(record_id);
1200 return true;
1201}

◆ SaveDataRecorder()

int apollo::dreamview::HMIWorker::SaveDataRecorder ( const std::string &  new_name)

在文件 hmi_worker.cc1805 行定义.

1805 {
1806 std::string data_record_default_path =
1807 std::string(cyber::common::GetEnv("HOME", "/home/apollo")) +
1808 "/.apollo/resources/records/" + FLAGS_data_record_default_name;
1809 if (!cyber::common::PathExists(data_record_default_path)) {
1810 AERROR << "Failed to save the record, the dreamview recording record does "
1811 "not exist, please record through dreamview.";
1812 return -2;
1813 }
1814 std::string save_cmd = "/apollo/scripts/record_bag.py --default_name " +
1815 FLAGS_data_record_default_name + " --rename " +
1816 new_name;
1817 int ret = std::system(save_cmd.data());
1818 if (ret == 0) {
1819 LoadRecords();
1820 return 1;
1821 } else {
1822 AERROR << "Failed to save the record, a file with the same name exists";
1823 return -1;
1824 }
1825}
std::string GetEnv(const std::string &var_name, const std::string &default_value="")
Definition environment.h:29

◆ SaveRtkDataRecorder()

int apollo::dreamview::HMIWorker::SaveRtkDataRecorder ( const std::string &  new_name)

在文件 hmi_worker.cc2055 行定义.

2055 {
2056 std::string new_rtk_record_file =
2057 FLAGS_default_rtk_record_path + new_name + ".csv";
2058 if (cyber::common::PathExists(new_rtk_record_file)) {
2059 AERROR << "Failed to save the ret record, a file with the same name exists";
2060 return -1;
2061 }
2062 if (std::rename(FLAGS_default_rtk_record_file.data(),
2063 new_rtk_record_file.data()) == 0) {
2064 UpdateRtkRecordToStatus(new_name);
2065 return 1;
2066 } else {
2067 AERROR << "Failed to save the ret record, save command execution failed";
2068 return -3;
2069 }
2070}
void UpdateRtkRecordToStatus(const std::string &new_name)

◆ SensorCalibrationPreprocess() [1/2]

void apollo::dreamview::HMIWorker::SensorCalibrationPreprocess ( const std::string &  task_type)

在文件 hmi_worker.cc419 行定义.

419 {
420 std::string start_command = absl::StrCat(
421 "nohup bash modules/tools/sensor_calibration/extract_data.sh -t ",
422 task_type, " &");
423 System(start_command);
424}

◆ SensorCalibrationPreprocess() [2/2]

void apollo::dreamview::HMIWorker::SensorCalibrationPreprocess ( const std::string &  task_type)

◆ Start() [1/2]

void apollo::dreamview::HMIWorker::Start ( DvCallback  callback_api)

在文件 hmi_worker.cc100 行定义.

100 {
101 callback_api_ = callback_api;
102 InitReadersAndWriters();
104 [this](const bool status_changed, HMIStatus *status) {
105 apollo::common::util::FillHeader("HMI", status);
106 status_writer_->Write(*status);
107 status->clear_header();
108 });
109 ResetComponentStatusTimer();
110 thread_future_ = cyber::Async(&HMIWorker::StatusUpdateThreadLoop, this);
111}
void RegisterStatusUpdateHandler(StatusUpdateHandler handler)
Definition hmi_worker.h:74

◆ Start() [2/2]

void apollo::dreamview::HMIWorker::Start ( DvCallback  callback_api)

◆ StartDataRecorder()

bool apollo::dreamview::HMIWorker::StartDataRecorder ( )

在文件 hmi_worker.cc1769 行定义.

1769 {
1770 std::string start_cmd =
1771 "/apollo/scripts/record_bag.py --start --all --dreamview "
1772 "--default_name " +
1773 FLAGS_data_record_default_name;
1774 int ret = std::system(start_cmd.data());
1775 if (ret == 0) {
1776 auto *monitors = FuelMonitorManager::Instance()->GetCurrentMonitors();
1777 if (monitors != nullptr) {
1778 auto iter = monitors->find(FLAGS_data_collection_monitor_name);
1779 if (iter != monitors->end()) {
1780 auto *data_collection_monitor = iter->second.get();
1781 if (data_collection_monitor->IsEnabled() && record_count_ == 0) {
1782 data_collection_monitor->Restart();
1783 }
1784 }
1785 ++record_count_;
1786 }
1787 return true;
1788 } else {
1789 AERROR << "Failed to start the cyber_recorder process";
1790 return false;
1791 }
1792}
const std::string start_cmd
Definition teleop.cc:53

◆ StartPlayRtkRecorder()

Json apollo::dreamview::HMIWorker::StartPlayRtkRecorder ( )

在文件 hmi_worker.cc2017 行定义.

2017 {
2018 Json result;
2019 if (!ChangeDrivingMode(Chassis::COMPLETE_AUTO_DRIVE)) {
2020 AERROR << "Failed to play rtk: Failed to enter auto drive.";
2021 result["error"] = "Failed to enter auto drive";
2022 result["isOk"] = false;
2023 return result;
2024 }
2025 std::string record_id;
2026 {
2027 RLock rlock(status_mutex_);
2028 record_id = status_.current_rtk_record_id();
2029 }
2030 std::string start_cmd =
2031 "nohup /apollo/scripts/rtk_player.sh start " + record_id + " &";
2032 int ret = std::system(start_cmd.data());
2033 if (ret == 0) {
2034 AINFO << "Start the rtk_recorder process Successful.";
2035 result["isOk"] = true;
2036 } else {
2037 AERROR << "Failed to play rtk: Failed to start the rtk_recorder process.";
2038 result["error"] = "Failed to start the rtk_recorder process";
2039 result["isOk"] = false;
2040 }
2041 return result;
2042}
nlohmann::json Json

◆ StartRtkDataRecorder()

bool apollo::dreamview::HMIWorker::StartRtkDataRecorder ( )

在文件 hmi_worker.cc1995 行定义.

1995 {
1996 std::string start_cmd = "nohup /apollo/scripts/rtk_recorder.sh start &";
1997 int ret = std::system(start_cmd.data());
1998 if (ret == 0) {
1999 return true;
2000 } else {
2001 AERROR << "Failed to start the rtk_recorder process";
2002 return false;
2003 }
2004}

◆ StartTerminal()

bool apollo::dreamview::HMIWorker::StartTerminal ( )

在文件 hmi_worker.cc1943 行定义.

1943 {
1944 return std::system(FLAGS_terminal_start_cmd.data()) == 0;
1945}

◆ Stop() [1/2]

void apollo::dreamview::HMIWorker::Stop ( )

在文件 hmi_worker.cc113 行定义.

113 {
114 stop_ = true;
115 if (thread_future_.valid()) {
116 thread_future_.get();
117 }
118}

◆ Stop() [2/2]

void apollo::dreamview::HMIWorker::Stop ( )

◆ StopDataRecorder()

bool apollo::dreamview::HMIWorker::StopDataRecorder ( )

在文件 hmi_worker.cc1794 行定义.

1794 {
1795 std::string stop_cmd = "/apollo/scripts/record_bag.py --stop";
1796 int ret = std::system(stop_cmd.data());
1797 if (ret == 0) {
1798 return true;
1799 } else {
1800 AERROR << "Failed to stop the cyber_recorder process";
1801 return false;
1802 }
1803}
const std::string stop_cmd
Definition teleop.cc:54

◆ StopPlayRtkRecorder()

bool apollo::dreamview::HMIWorker::StopPlayRtkRecorder ( )

在文件 hmi_worker.cc2044 行定义.

2044 {
2045 std::string stop_cmd = "/apollo/scripts/rtk_player.sh stop";
2046 int ret = std::system(stop_cmd.data());
2047 if (ret == 9) {
2048 return true;
2049 } else {
2050 AERROR << "Failed to stop the rtk_recorder process";
2051 return false;
2052 }
2053}

◆ StopRtkDataRecorder()

bool apollo::dreamview::HMIWorker::StopRtkDataRecorder ( )

在文件 hmi_worker.cc2006 行定义.

2006 {
2007 std::string stop_cmd = "/apollo/scripts/rtk_recorder.sh stop";
2008 int ret = std::system(stop_cmd.data());
2009 if (ret == 9) {
2010 return true;
2011 } else {
2012 AERROR << "Failed to stop the rtk_recorder process";
2013 return false;
2014 }
2015}

◆ SubmitAudioEvent() [1/2]

void apollo::dreamview::HMIWorker::SubmitAudioEvent ( const uint64_t  event_time_ms,
const int  obstacle_id,
const int  audio_type,
const int  moving_result,
const int  audio_direction,
const bool  is_siren_on 
)

在文件 hmi_worker.cc358 行定义.

362 {
363 std::shared_ptr<AudioEvent> audio_event = std::make_shared<AudioEvent>();
364 apollo::common::util::FillHeader("HMI", audio_event.get());
365 // Here we reuse the header time field as the event occurring time.
366 // A better solution might be adding an event time field to DriveEvent proto
367 // to make it clear.
368 audio_event->mutable_header()->set_timestamp_sec(
369 static_cast<double>(event_time_ms) / 1000.0);
370 audio_event->set_id(obstacle_id);
371 audio_event->set_audio_type(
372 static_cast<apollo::audio::AudioType>(audio_type));
373 audio_event->set_moving_result(
374 static_cast<apollo::audio::MovingResult>(moving_result));
375 audio_event->set_audio_direction(
376 static_cast<apollo::audio::AudioDirection>(audio_direction));
377 audio_event->set_siren_is_on(is_siren_on);
378
379 // Read the current localization pose
380 localization_reader_->Observe();
381 if (localization_reader_->Empty()) {
382 AERROR << "Failed to get localization associated with the audio event: "
383 << audio_event->DebugString() << "\n Localization reader is empty!";
384 return;
385 }
386
387 const std::shared_ptr<LocalizationEstimate> localization =
388 localization_reader_->GetLatestObserved();
389 audio_event->mutable_pose()->CopyFrom(localization->pose());
390 AINFO << "AudioEvent: " << audio_event->DebugString();
391
392 audio_event_writer_->Write(audio_event);
393}

◆ SubmitAudioEvent() [2/2]

void apollo::dreamview::HMIWorker::SubmitAudioEvent ( const uint64_t  event_time_ms,
const int  obstacle_id,
const int  audio_type,
const int  moving_result,
const int  audio_direction,
const bool  is_siren_on 
)

◆ SubmitDriveEvent() [1/2]

void apollo::dreamview::HMIWorker::SubmitDriveEvent ( const uint64_t  event_time_ms,
const std::string &  event_msg,
const std::vector< std::string > &  event_types,
const bool  is_reportable 
)

在文件 hmi_worker.cc395 行定义.

398 {
399 std::shared_ptr<DriveEvent> drive_event = std::make_shared<DriveEvent>();
400 apollo::common::util::FillHeader("HMI", drive_event.get());
401 // TODO(xiaoxq): Here we reuse the header time field as the event occurring
402 // time. A better solution might be adding the field to DriveEvent proto to
403 // make it clear.
404 drive_event->mutable_header()->set_timestamp_sec(
405 static_cast<double>(event_time_ms) / 1000.0);
406 drive_event->set_event(event_msg);
407 drive_event->set_is_reportable(is_reportable);
408 for (const auto &type_name : event_types) {
409 DriveEvent::Type type;
410 if (DriveEvent::Type_Parse(type_name, &type)) {
411 drive_event->add_type(type);
412 } else {
413 AERROR << "Failed to parse drive event type:" << type_name;
414 }
415 }
416 drive_event_writer_->Write(drive_event);
417}

◆ SubmitDriveEvent() [2/2]

void apollo::dreamview::HMIWorker::SubmitDriveEvent ( const uint64_t  event_time_ms,
const std::string &  event_msg,
const std::vector< std::string > &  event_types,
const bool  is_reportable 
)

◆ Trigger() [1/4]

bool apollo::dreamview::HMIWorker::Trigger ( const HMIAction  action)

在文件 hmi_worker.cc276 行定义.

276 {
277 AERROR << "HMIAction " << HMIAction_Name(action) << " was triggered!";
278 switch (action) {
279 case HMIAction::NONE:
280 break;
282 SetupMode();
283 break;
285 return ChangeDrivingMode(Chassis::COMPLETE_AUTO_DRIVE);
287 return ChangeDrivingMode(Chassis::COMPLETE_MANUAL);
289 ResetMode();
290 break;
292 LoadScenarios();
293 break;
295 LoadDynamicModels();
296 break;
298 LoadRecords();
299 break;
301 StopRecordPlay();
302 break;
303 default:
304 AERROR << "HMIAction not implemented, yet!";
305 return false;
306 }
307 return true;
308}

◆ Trigger() [2/4]

bool apollo::dreamview::HMIWorker::Trigger ( const HMIAction  action)

◆ Trigger() [3/4]

bool apollo::dreamview::HMIWorker::Trigger ( const HMIAction  action,
const std::string &  value 
)

在文件 hmi_worker.cc310 行定义.

310 {
311 AINFO << "HMIAction " << HMIAction_Name(action) << "(" << value
312 << ") was triggered!";
313 switch (action) {
315 ChangeMode(value);
316 break;
318 ChangeMap(value);
319 break;
321 ChangeVehicle(value);
322 break;
324 StartModule(value);
325 break;
327 StopModule(value);
328 break;
330 ChangeScenarioSet(value);
331 break;
333 DeleteScenarioSet(value);
334 ChangeScenario("");
335 break;
337 ChangeScenario(value);
338 break;
340 ChangeDynamicModel(value);
341 break;
343 DeleteDynamicModel(value);
344 break;
346 DeleteRecord(value);
347 break;
349 ChangeRecord(value);
350 break;
351 default:
352 AERROR << "HMIAction not implemented, yet!";
353 return false;
354 }
355 return true;
356}

◆ Trigger() [4/4]

bool apollo::dreamview::HMIWorker::Trigger ( const HMIAction  action,
const std::string &  value 
)

◆ UpdateCameraSensorChannelToStatus() [1/2]

void apollo::dreamview::HMIWorker::UpdateCameraSensorChannelToStatus ( const std::string &  channel_name)

在文件 hmi_worker.cc1530 行定义.

1531 {
1532 {
1533 WLock wlock(status_mutex_);
1534 if (status_.current_camera_sensor_channel() == channel_name) {
1535 AINFO << "Input channel name is current camera sensor channel";
1536 return;
1537 }
1538 status_.set_current_camera_sensor_channel(channel_name);
1539 status_changed_ = true;
1540 }
1541}

◆ UpdateCameraSensorChannelToStatus() [2/2]

void apollo::dreamview::HMIWorker::UpdateCameraSensorChannelToStatus ( const std::string &  channel_name)

◆ UpdateComponentStatus() [1/2]

void apollo::dreamview::HMIWorker::UpdateComponentStatus ( )

在文件 hmi_worker.cc733 行定义.

733 {
734 constexpr double kSecondsTillTimeout(2.5);
735 const double now = Clock::NowInSeconds();
736 if (now - last_status_received_s_.load() > kSecondsTillTimeout) {
737 if (!monitor_timed_out_) {
738 WLock wlock(status_mutex_);
739
740 const uint64_t now_ms = static_cast<uint64_t>(now * 2e3);
741 static constexpr bool kIsReportable = true;
742 SubmitDriveEvent(now_ms, "Monitor timed out", {"PROBLEM"}, kIsReportable);
743 AWARN << "System fault. Auto disengage.";
745
746 for (auto &monitored_component :
747 *status_.mutable_monitored_components()) {
748 monitored_component.second.set_status(ComponentStatus::UNKNOWN);
749 monitored_component.second.set_message(
750 "Status not reported by Monitor.");
751 }
752 status_changed_ = true;
753 }
754 monitor_timed_out_ = true;
755 } else {
756 monitor_timed_out_ = false;
757 }
758}
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
bool Trigger(const HMIAction action)
void SubmitDriveEvent(const uint64_t event_time_ms, const std::string &event_msg, const std::vector< std::string > &event_types, const bool is_reportable)

◆ UpdateComponentStatus() [2/2]

void apollo::dreamview::HMIWorker::UpdateComponentStatus ( )

◆ UpdateDynamicModelToStatus() [1/2]

bool apollo::dreamview::HMIWorker::UpdateDynamicModelToStatus ( const std::string &  dynamic_model_name)

在文件 hmi_worker.cc1046 行定义.

1047 {
1048 Json param_json({});
1049 param_json["dynamic_model_name"] = dynamic_model_name;
1050 Json callback_res = callback_api_("AddDynamicModel", param_json);
1051 if (!callback_res.contains("result") || !callback_res["result"]) {
1052 AERROR << "Failed to add dynamic model to local dynamic model list for "
1053 "register failed!";
1054 return false;
1055 }
1056 {
1057 WLock wlock(status_mutex_);
1058 for (const auto &iter : status_.dynamic_models()) {
1059 if (iter == dynamic_model_name) {
1060 AERROR << "Do not need to add new dynamic model for is duplicate!";
1061 return true;
1062 }
1063 }
1064 status_.add_dynamic_models(dynamic_model_name);
1065 status_changed_ = true;
1066 }
1067 return true;
1068}

◆ UpdateDynamicModelToStatus() [2/2]

bool apollo::dreamview::HMIWorker::UpdateDynamicModelToStatus ( const std::string &  dynamic_model_name)

◆ UpdateMapToStatus()

bool apollo::dreamview::HMIWorker::UpdateMapToStatus ( const std::string &  map_name)

在文件 hmi_worker.cc1358 行定义.

1358 {
1359 if (map_tar_name.empty()) {
1360 ReloadMaps();
1361 return true;
1362 }
1363 std::string map_dir = FLAGS_maps_data_path + "/";
1364 std::string map_name_prefix;
1365 int index = map_tar_name.rfind(".tar.xz");
1366 if (index != -1 && map_tar_name[0] != '.') {
1367 map_name_prefix = map_tar_name.substr(0, index);
1368 map_dir = map_dir + map_name_prefix;
1369 } else {
1370 AERROR << "The map name does not meet the standard!" << map_tar_name;
1371 return false;
1372 }
1373 if (!cyber::common::PathExists(map_dir)) {
1374 AERROR << "Failed to find maps!";
1375 return false;
1376 }
1377 map_name_prefix = util::HMIUtil::TitleCase(map_name_prefix);
1378 {
1379 WLock wlock(status_mutex_);
1380 auto iter = status_.maps().begin();
1381 for (; iter != status_.maps().end(); iter++) {
1382 if (*iter == map_name_prefix) {
1383 break;
1384 }
1385 }
1386 if (iter != status_.maps().end()) {
1387 return true;
1388 }
1389 status_.add_maps(map_name_prefix);
1390 status_changed_ = true;
1391 }
1392 return true;
1393}
static std::string TitleCase(std::string_view origin)
Convert a string to be title-like.
Definition hmi_util.cc:36

◆ UpdatePointCloudChannelToStatus() [1/2]

void apollo::dreamview::HMIWorker::UpdatePointCloudChannelToStatus ( const std::string &  channel_name)

在文件 hmi_worker.cc1543 行定义.

1544 {
1545 {
1546 WLock wlock(status_mutex_);
1547 if (status_.current_point_cloud_channel() == channel_name) {
1548 AINFO << "Input channel name is current camera sensor channel";
1549 return;
1550 }
1551 status_.set_current_point_cloud_channel(channel_name);
1552 status_changed_ = true;
1553 }
1554}

◆ UpdatePointCloudChannelToStatus() [2/2]

void apollo::dreamview::HMIWorker::UpdatePointCloudChannelToStatus ( const std::string &  channel_name)

◆ UpdateRtkRecordToStatus()

void apollo::dreamview::HMIWorker::UpdateRtkRecordToStatus ( const std::string &  new_name)

在文件 hmi_worker.cc2105 行定义.

2105 {
2106 WLock wlock(status_mutex_);
2107 status_.add_rtk_records(new_name);
2108 status_changed_ = true;
2109}

◆ UpdateScenarioSet()

bool apollo::dreamview::HMIWorker::UpdateScenarioSet ( const std::string &  scenario_set_id,
const std::string &  scenario_set_name,
ScenarioSet new_scenario_set 
)

在文件 hmi_worker.cc1070 行定义.

1072 {
1073 std::string scenario_set_directory_path;
1074 if (!GetScenarioSetPath(scenario_set_id, &scenario_set_directory_path)) {
1075 AERROR << "Cannot get scenario set path!";
1076 return false;
1077 }
1078 scenario_set_directory_path = scenario_set_directory_path + "/scenarios/";
1079 new_scenario_set->set_scenario_set_name(scenario_set_name);
1080 if (!cyber::common::PathExists(scenario_set_directory_path)) {
1081 AERROR << "Scenario set has no scenarios!";
1082 return true;
1083 }
1084 DIR *directory = opendir(scenario_set_directory_path.c_str());
1085 if (directory == nullptr) {
1086 AERROR << "Cannot open directory " << scenario_set_directory_path;
1087 return false;
1088 }
1089
1090 struct dirent *file;
1091 while ((file = readdir(directory)) != nullptr) {
1092 // skip directory_path/. and directory_path/..
1093 if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) {
1094 continue;
1095 }
1096 const std::string file_name = file->d_name;
1097 if (!absl::EndsWith(file_name, ".json")) {
1098 continue;
1099 }
1100 const int index = file_name.rfind(".json");
1101 if (index == 0) {
1102 // name: ".json" is invalid.
1103 continue;
1104 }
1105 const std::string scenario_id = file_name.substr(0, index);
1106 const std::string file_path = scenario_set_directory_path + file_name;
1107 SimTicket new_sim_ticket;
1108 if (!cyber::common::GetProtoFromJsonFile(file_path, &new_sim_ticket)) {
1109 AERROR << "Cannot parse this scenario:" << file_path;
1110 return false;
1111 }
1112 if (!new_sim_ticket.has_scenario()) {
1113 AERROR << "Cannot get scenario.";
1114 return false;
1115 }
1116 if (!new_sim_ticket.description_en_tokens_size()) {
1117 AERROR << "Cannot get scenario name.";
1118 return false;
1119 }
1120 if (!new_sim_ticket.scenario().has_map_dir()) {
1121 AERROR << "Cannot get scenario map dir.";
1122 return false;
1123 }
1124 if (!new_sim_ticket.scenario().has_start()) {
1125 AERROR << "Cannot get scenario start_point.";
1126 return false;
1127 }
1128 auto &scenario_start_point = new_sim_ticket.scenario().start();
1129 if (!scenario_start_point.has_x() || !scenario_start_point.has_y()) {
1130 AERROR << "Scenario start_point is invalid!";
1131 return false;
1132 }
1133 std::string scenario_name = new_sim_ticket.description_en_tokens(0);
1134 for (int i = 1; i < new_sim_ticket.description_en_tokens_size(); i++) {
1135 scenario_name =
1136 scenario_name + "_" + new_sim_ticket.description_en_tokens(i);
1137 }
1138 ScenarioInfo *scenario_info = new_scenario_set->add_scenarios();
1139 scenario_info->set_scenario_id(scenario_id);
1140 scenario_info->set_scenario_name(scenario_name);
1141 // change scenario json map dir to map name
1142 // format:modules/map/data/${map_name}
1143 const std::string map_dir = new_sim_ticket.scenario().map_dir();
1144 size_t idx = map_dir.find_last_of('/');
1145 if (idx == map_dir.npos) {
1146 AERROR << "Cannot get scenario map name.";
1147 return false;
1148 }
1149 const std::string map_name = map_dir.substr(idx + 1);
1150 if (map_name.empty()) {
1151 AERROR << "Cannot get scenario map name.";
1152 return false;
1153 }
1154 // replay engine use xx_xx like:apollo_map
1155 // dv need Apollo Map
1156 scenario_info->set_map_name(util::HMIUtil::TitleCase(map_name));
1157 auto start_point = scenario_info->mutable_start_point();
1158 start_point->set_x(scenario_start_point.x());
1159 start_point->set_y(scenario_start_point.y());
1160 }
1161 closedir(directory);
1162 return true;
1163}
bool GetScenarioSetPath(const std::string &scenario_set_id, std::string *scenario_set_path)
bool GetProtoFromJsonFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the json file specified by the file_name as ascii representation of protobufs,...
Definition file.cc:149

◆ UpdateScenarioSetToStatus()

bool apollo::dreamview::HMIWorker::UpdateScenarioSetToStatus ( const std::string &  scenario_set_id,
const std::string &  scenario_set_name 
)

在文件 hmi_worker.cc1028 行定义.

1029 {
1030 ScenarioSet new_scenario_set;
1031 if (!UpdateScenarioSet(scenario_set_id, scenario_set_name,
1032 &new_scenario_set)) {
1033 AERROR << "Failed to update scenario_set!";
1034 return false;
1035 }
1036 {
1037 WLock wlock(status_mutex_);
1038 auto scenario_set = status_.mutable_scenario_set();
1039 scenario_set->erase(scenario_set_id);
1040 (*scenario_set)[scenario_set_id] = new_scenario_set;
1041 status_changed_ = true;
1042 }
1043 return true;
1044}
bool UpdateScenarioSet(const std::string &scenario_set_id, const std::string &scenario_set_name, ScenarioSet *new_scenario_set)

◆ VehicleCalibrationPreprocess() [1/2]

void apollo::dreamview::HMIWorker::VehicleCalibrationPreprocess ( )

在文件 hmi_worker.cc426 行定义.

426 {
427 std::string start_command = absl::StrCat(
428 "nohup bash modules/tools/vehicle_calibration/preprocess.sh "
429 "--vehicle_type=\"",
430 status_.current_vehicle(), "\" --record_num=", record_count_, " &");
431 System(start_command);
432}

◆ VehicleCalibrationPreprocess() [2/2]

void apollo::dreamview::HMIWorker::VehicleCalibrationPreprocess ( )

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