Apollo 9.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 ()
 
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)
 
 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.h 第 56 行定义.

成员类型定义说明

◆ DvCallback [1/2]

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

在文件 hmi_worker.h 第 58 行定义.

◆ DvCallback [2/2]

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

在文件 hmi_worker.h 第 58 行定义.

◆ StatusUpdateHandler [1/2]

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

在文件 hmi_worker.h 第 72 行定义.

◆ StatusUpdateHandler [2/2]

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

在文件 hmi_worker.h 第 76 行定义.

构造及析构函数说明

◆ HMIWorker() [1/4]

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

在文件 hmi_worker.h 第 60 行定义.

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.h 第 60 行定义.

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.cc 第 1889 行定义.

1890 {
1891 return KVDB::Put(key, value);
1892}

◆ ChangeMapVal()

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

◆ DeleteDataRecorder()

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

在文件 hmi_worker.cc 第 1791 行定义.

1791 {
1792 std::string delete_cmd =
1793 "/apollo/scripts/record_bag.py --delete --default_name " +
1794 FLAGS_data_record_default_name;
1795 int ret = std::system(delete_cmd.data());
1796 if (ret == 0) {
1797 return true;
1798 } else {
1799 AERROR << "Failed to delete the record";
1800 return false;
1801 }
1802}
#define AERROR
Definition log.h:44

◆ DeleteObjectToDB()

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

在文件 hmi_worker.cc 第 1894 行定义.

1894 {
1895 return KVDB::Delete(key);
1896}

◆ DeleteRtkDataRecorder()

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

在文件 hmi_worker.cc 第 2036 行定义.

2036 {
2037 if (!cyber::common::PathExists(FLAGS_default_rtk_record_file)) {
2038 AERROR << "Failed to delete the ret record, file not exist";
2039 return false;
2040 }
2041 if (std::remove(FLAGS_default_rtk_record_file.data()) == 0) {
2042 return true;
2043 } else {
2044 AERROR << "Failed to delete the record, delete command execution failed";
2045 return false;
2046 }
2047 }
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.cc 第 2120 行定义.

2120 {
2121 if (current_mode_.has_layout()) {
2122 const auto default_layout_json =
2124 "default_layout", current_mode_.layout());
2125 return default_layout_json["data"].dump();
2126 }
2127 AWARN << "There is no default layout for the current mode.";
2128 return "";
2129}
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.cc 第 2164 行定义.

2164 {
2165 return plugin_panels_json_.empty() ? "" : plugin_panels_json_.dump();
2166}

◆ GetObjectFromDB()

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

在文件 hmi_worker.cc 第 1898 行定义.

1898 {
1899 return KVDB::Get(key).value_or("");
1900}

◆ GetScenarioSetPath() [1/2]

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

在文件 hmi_worker.cc 第 788 行定义.

789 {
790 CHECK_NOTNULL(scenario_set_path);
791 GetScenarioResourcePath(scenario_set_path);
792 *scenario_set_path = *scenario_set_path + scenario_set_id;
793 return;
794}

◆ 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.cc 第 681 行定义.

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.cc 第 1903 行定义.

1903 {
1904 return KVDB::GetWithStart(type);
1905}

◆ 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.cc 第 1020 行定义.

1020 {
1021 std::string record_id;
1022 PlayRecordStatus current_play_record_status;
1023 PlayRecordStatus expected_play_record_status;
1024 PlayRecordStatus reasonable_play_record_status;
1025 {
1026 RLock rlock(status_mutex_);
1027 auto record_status = status_.current_record_status();
1028 record_id = record_status.current_record_id();
1029 current_play_record_status = record_status.play_record_status();
1030 if (record_id.empty()) {
1031 AERROR << "Failed to pause record for record has not been selected"
1032 "or process is not exists!";
1033 return false;
1034 }
1035 if (!RecordIsLoaded(record_id)) {
1036 AERROR << "Failed to pause record for record has not been loaded!";
1037 return false;
1038 }
1039 }
1040 if (action_type.compare("continue") == 0) {
1041 expected_play_record_status = PlayRecordStatus::RUNNING;
1042 reasonable_play_record_status = PlayRecordStatus::PAUSED;
1043 } else if (action_type.compare("pause") == 0) {
1044 expected_play_record_status = PlayRecordStatus::PAUSED;
1045 reasonable_play_record_status = PlayRecordStatus::RUNNING;
1046 } else {
1047 AERROR << "Invalid action type for play record.";
1048 return false;
1049 }
1050 if (reasonable_play_record_status != current_play_record_status) {
1051 return false;
1052 }
1053 auto *record_player_factory = RecordPlayerFactory::Instance();
1054 auto player_ptr = record_player_factory->GetRecordPlayer(record_id);
1055 if (!player_ptr) {
1056 AERROR << "Failed to get record player.";
1057 return false;
1058 }
1059 player_ptr->HandleNohupThreadStatus();
1060
1061 {
1062 WLock wlock(status_mutex_);
1063 status_.mutable_current_record_status()->set_play_record_status(
1064 expected_play_record_status);
1065 status_changed_ = true;
1066 }
1067 record_player_factory->IncreaseRecordPriority(record_id);
1068 return true;
1069}
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.cc 第 2092 行定义.

2092 {
2093 std::stringstream commandStream;
2094 commandStream << "pgrep -f " << process_name;
2095 std::string command = commandStream.str();
2096
2097 FILE *fp = popen(command.c_str(), "r");
2098 if (fp) {
2099 char result[128];
2100 if (fgets(result, sizeof(result), fp) != nullptr) {
2101 AINFO << process_name << " is running";
2102 pclose(fp);
2103 return true;
2104 } else {
2105 AINFO << process_name << " is not running";
2106 }
2107 pclose(fp);
2108 }
2109 return false;
2110}
#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.cc 第 1418 行定义.

1420 {
1421 if (RecordIsLoaded(record_name)) {
1422 AERROR << "Record is loaded,no need to load";
1423 return false;
1424 }
1425 // check if record player factory can continue load
1426 auto record_player_factory = RecordPlayerFactory::Instance();
1427 if (!record_player_factory->EnableContinueLoad()) {
1428 // can not load record,need to remove lru record
1429 std::string remove_record_id;
1430 if (record_player_factory->RemoveLRURecord(&remove_record_id)) {
1431 // remove successfully, change removed record status
1432 {
1433 WLock wlock(status_mutex_);
1434 auto status_records = status_.mutable_records();
1435 (*status_records)[remove_record_id].set_load_record_status(
1436 LoadRecordStatus::NOT_LOAD);
1437 (*status_records)[remove_record_id].clear_total_time_s();
1438 }
1439 }
1440 }
1441 if (!ReadRecordInfo(record_file_path, total_time_s)) {
1442 return false;
1443 }
1444 if (!record_player_factory->RegisterRecordPlayer(record_name,
1445 record_file_path)) {
1446 return false;
1447 }
1448 return true;
1449}

◆ LoadRecordAndChangeStatus()

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

在文件 hmi_worker.cc 第 1371 行定义.

1371 {
1372 std::string record_file_path;
1373 {
1374 RLock rlock(status_mutex_);
1375 auto &status_records = status_.records();
1376 auto iter = status_records.find(record_name);
1377 if (iter == status_records.end()) {
1378 AERROR << "Cannot load unknown record!";
1379 return false;
1380 }
1381 if (RecordIsLoaded(record_name)) {
1382 AERROR << "Cannot load already loaded record.";
1383 return false;
1384 }
1385 if (iter->second.record_file_path().empty()) {
1386 AERROR << "Cannot load record without record file path!";
1387 return false;
1388 }
1389 record_file_path = iter->second.record_file_path();
1390 }
1391 {
1392 WLock wlock(status_mutex_);
1393 auto status_records = status_.mutable_records();
1394 (*status_records)[record_name].set_load_record_status(
1395 LoadRecordStatus::LOADING);
1396 }
1397 double total_time_s;
1398 if (LoadRecord(record_name, record_file_path, &total_time_s)) {
1399 {
1400 WLock wlock(status_mutex_);
1401 auto status_records = status_.mutable_records();
1402 (*status_records)[record_name].set_load_record_status(
1403 LoadRecordStatus::LOADED);
1404 (*status_records)[record_name].set_total_time_s(total_time_s);
1405 }
1406 RecordPlayerFactory::Instance()->IncreaseRecordPriority(record_name);
1407 } else {
1408 {
1409 WLock wlock(status_mutex_);
1410 auto status_records = status_.mutable_records();
1411 (*status_records)[record_name].set_load_record_status(
1412 LoadRecordStatus::NOT_LOAD);
1413 }
1414 }
1415 return true;
1416}
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.cc 第 1367 行定义.

1367 {
1368 std::string directory_path;
1369 GetRecordPath(&directory_path);
1370 if (!cyber::common::PathExists(directory_path)) {
1371 AERROR << "Failed to find records!";
1372 return false;
1373 }
1374 DIR *directory = opendir(directory_path.c_str());
1375 if (directory == nullptr) {
1376 AERROR << "Cannot open record directory" << directory_path;
1377 return false;
1378 }
1379 struct dirent *file;
1380 std::map<std::string, LoadRecordInfo> new_records;
1381 while ((file = readdir(directory)) != nullptr) {
1382 if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) {
1383 continue;
1384 }
1385 if (file->d_type == DT_DIR) {
1386 continue;
1387 }
1388 const std::string record_id = file->d_name;
1389 const int index = record_id.rfind(".record");
1390 // Skip format that dv cannot parse: record not ending in record
1391 size_t record_suffix_length = 7;
1392 if (record_id.length() - index != record_suffix_length) {
1393 continue;
1394 }
1395 if (index != -1 && record_id[0] != '.') {
1396 const std::string local_record_resource = record_id.substr(0, index);
1397 // compatible records with dv and dv_plus
1398 new_records[local_record_resource] = {};
1399 new_records[local_record_resource].set_download_status(1);
1400 }
1401 }
1402 closedir(directory);
1403 {
1404 WLock wlock(status_mutex_);
1405 auto status_records = status_.mutable_records();
1406 status_records->clear();
1407 for (auto iter = new_records.begin(); iter != new_records.end(); iter++) {
1408 (*status_records)[iter->first] = iter->second;
1409 }
1410 status_changed_ = true;
1411 }
1412 return true;
1413}

◆ LoadRecords() [2/2]

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

◆ LoadRtkRecords()

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

在文件 hmi_worker.cc 第 1916 行定义.

1916 {
1917 {
1918 WLock wLock(status_mutex_);
1919 status_.clear_rtk_records();
1920 }
1921 std::string directory_path;
1922 GetRtkRecordPath(&directory_path);
1923 if (!cyber::common::PathExists(directory_path)) {
1924 AERROR << "Failed to find rtk records!";
1925 return false;
1926 }
1927 DIR *directory = opendir(directory_path.c_str());
1928 if (directory == nullptr) {
1929 AERROR << "Cannot open rtk record directory" << directory_path;
1930 return false;
1931 }
1932 struct dirent *file;
1933 std::map<std::string, double> new_records;
1934 while ((file = readdir(directory)) != nullptr) {
1935 if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) {
1936 continue;
1937 }
1938 if (file->d_type == DT_DIR) {
1939 continue;
1940 }
1941 const std::string record_id = file->d_name;
1942 const int index = record_id.rfind(".csv");
1943 if (index != -1 && record_id[0] != '.') {
1944 const std::string local_record_resource = record_id.substr(0, index);
1945 {
1946 WLock wLock(status_mutex_);
1947 status_.add_rtk_records(local_record_resource);
1948 }
1949 }
1950 }
1951 closedir(directory);
1952 {
1953 WLock wlock(status_mutex_);
1954 status_changed_ = true;
1955 }
1956 return true;
1957}

◆ RecordIsLoaded()

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

在文件 hmi_worker.cc 第 1208 行定义.

1208 {
1209 {
1210 RLock rlock(status_mutex_);
1211 auto iter = status_.records().find(record_id);
1212 return iter != status_.records().end() &&
1213 (iter->second.load_record_status() == LoadRecordStatus::LOADED);
1214 }
1215}

◆ RegisterStatusUpdateHandler() [1/2]

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

在文件 hmi_worker.h 第 74 行定义.

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

◆ RegisterStatusUpdateHandler() [2/2]

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

在文件 hmi_worker.h 第 78 行定义.

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

◆ ReloadVehicles() [1/2]

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

在文件 hmi_worker.cc 第 1451 行定义.

1451 {
1452 AINFO << "load config";
1453 HMIConfig config = util::HMIUtil::LoadConfig(FLAGS_dv_hmi_modes_config_path);
1454 std::string msg;
1455 AINFO << "serialize new config";
1456 config.SerializeToString(&msg);
1457
1458 WLock wlock(status_mutex_);
1459 AINFO << "parse new config";
1460 config_.ParseFromString(msg);
1461 AINFO << "init status";
1462 // status_.clear_modes();
1463 // status_.clear_maps();
1464 AINFO << "clear vehicles";
1465 status_.clear_vehicles();
1466 // InitStatus();
1467 // Populate vehicles and current_vehicle.
1468 AINFO << "reload vehicles";
1469 for (const auto &vehicle : config_.vehicles()) {
1470 status_.add_vehicles(vehicle.first);
1471 }
1472 status_changed_ = true;
1473 return true;
1474}
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.cc 第 1071 行定义.

1071 {
1072 std::string record_id;
1073 {
1074 RLock rlock(status_mutex_);
1075 auto record_status = status_.current_record_status();
1076 record_id = record_status.current_record_id();
1077 if (record_status.current_record_id().empty()) {
1078 AERROR << "Failed to play record for record has not been selected!";
1079 return false;
1080 }
1081 if (!RecordIsLoaded(record_id)) {
1082 AERROR << "Failed to play record for record has not been loaded!";
1083 return false;
1084 }
1085 if (record_status.play_record_status() == PlayRecordStatus::RUNNING) {
1086 AERROR << "Record has been played,ignore dumplicate request.";
1087 return false;
1088 }
1089 }
1090 std::string record_path;
1091 GetRecordPath(&record_path);
1092 record_path = record_path + record_id + ".record";
1093
1094 if (!cyber::common::PathExists(record_path)) {
1095 AERROR << "Failed to find record!";
1096 return false;
1097 }
1098 // play the record
1099 auto *record_player_factory = RecordPlayerFactory::Instance();
1100 auto player_ptr = record_player_factory->GetRecordPlayer(record_id);
1101 bool play_record_res = (player_ptr != nullptr);
1102 PlayRecordStatus play_record_status;
1103 if (!play_record_res) {
1104 AERROR << "Failed to get record related player";
1105 play_record_status = PlayRecordStatus::CLOSED;
1106 } else {
1107 player_ptr->PreloadPlayRecord();
1108 player_ptr->NohupPlayRecord();
1109 // get channel msgs for frontend after start play record
1110 callback_api_("GetDataHandlerConf", {});
1111 play_record_status = PlayRecordStatus::RUNNING;
1112 }
1113 {
1114 WLock wlock(status_mutex_);
1115 auto record_status = status_.mutable_current_record_status();
1116 record_status->set_play_record_status(play_record_status);
1117 status_changed_ = true;
1118 }
1119 record_player_factory->IncreaseRecordPriority(record_id);
1120 return play_record_res;
1121}

◆ 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.cc 第 1123 行定义.

1123 {
1124 std::string record_id;
1125 double total_time_s;
1126 PlayRecordStatus last_record_status;
1127 {
1128 RLock rlock(status_mutex_);
1129 auto record_status = status_.current_record_status();
1130 record_id = record_status.current_record_id();
1131 last_record_status = record_status.play_record_status();
1132 if (record_status.current_record_id().empty()) {
1133 AERROR << "Failed to reset record progress for record has not been "
1134 "selected!";
1135 return false;
1136 }
1137 if (!RecordIsLoaded(record_id)) {
1138 AERROR << "Failed to reset record progress for record has not been "
1139 "loaded!";
1140 return false;
1141 }
1142 total_time_s = status_.records().at(record_id).total_time_s();
1143 }
1144 AERROR << "total : " << total_time_s;
1145 if (progress > total_time_s) {
1146 AERROR << "Failed to reset record progress for progress exceeds the "
1147 "record's total time.";
1148 return false;
1149 }
1150 auto *record_player_factory = RecordPlayerFactory::Instance();
1151 auto player_ptr = record_player_factory->GetRecordPlayer(record_id);
1152 if (!player_ptr) {
1153 AERROR << "Failed to get record player.";
1154 return false;
1155 }
1156 player_ptr->Reset();
1157 player_ptr->PreloadPlayRecord(
1158 progress, (last_record_status != PlayRecordStatus::RUNNING));
1159 player_ptr->NohupPlayRecord();
1160 // When a record is selected and the progress is reset; we consider
1161 // the record to be stuck at the current progress in a paused state
1162 // to keep logic consistent
1163 if (last_record_status == PlayRecordStatus::CLOSED) {
1164 last_record_status = PlayRecordStatus::PAUSED;
1165 }
1166 // get channel msgs for frontend after start play record
1167 callback_api_("GetDataHandlerConf", {});
1168 {
1169 WLock wlock(status_mutex_);
1170 auto record_status = status_.mutable_current_record_status();
1171 record_status->set_play_record_status(last_record_status);
1172 record_status->set_curr_time_s(progress);
1173 status_changed_ = true;
1174 }
1175 record_player_factory->IncreaseRecordPriority(record_id);
1176 return true;
1177}

◆ SaveDataRecorder()

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

在文件 hmi_worker.cc 第 1769 行定义.

1769 {
1770 std::string data_record_default_path =
1771 std::string(cyber::common::GetEnv("HOME", "/home/apollo")) +
1772 "/.apollo/resources/records/" + FLAGS_data_record_default_name;
1773 if (!cyber::common::PathExists(data_record_default_path)) {
1774 AERROR << "Failed to save the record, the dreamview recording record does "
1775 "not exist, please record through dreamview.";
1776 return -2;
1777 }
1778 std::string save_cmd = "/apollo/scripts/record_bag.py --default_name " +
1779 FLAGS_data_record_default_name + " --rename " +
1780 new_name;
1781 int ret = std::system(save_cmd.data());
1782 if (ret == 0) {
1783 LoadRecords();
1784 return 1;
1785 } else {
1786 AERROR << "Failed to save the record, a file with the same name exists";
1787 return -1;
1788 }
1789}
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.cc 第 2019 行定义.

2019 {
2020 std::string new_rtk_record_file =
2021 FLAGS_default_rtk_record_path + new_name + ".csv";
2022 if (cyber::common::PathExists(new_rtk_record_file)) {
2023 AERROR << "Failed to save the ret record, a file with the same name exists";
2024 return -1;
2025 }
2026 if (std::rename(FLAGS_default_rtk_record_file.data(),
2027 new_rtk_record_file.data()) == 0) {
2028 UpdateRtkRecordToStatus(new_name);
2029 return 1;
2030 } else {
2031 AERROR << "Failed to save the ret record, save command execution failed";
2032 return -3;
2033 }
2034}
void UpdateRtkRecordToStatus(const std::string &new_name)

◆ SensorCalibrationPreprocess() [1/2]

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

在文件 hmi_worker.cc 第 420 行定义.

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

◆ 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.cc 第 100 行定义.

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.cc 第 1733 行定义.

1733 {
1734 std::string start_cmd =
1735 "/apollo/scripts/record_bag.py --start --all --dreamview "
1736 "--default_name " +
1737 FLAGS_data_record_default_name;
1738 int ret = std::system(start_cmd.data());
1739 if (ret == 0) {
1740 auto *monitors = FuelMonitorManager::Instance()->GetCurrentMonitors();
1741 if (monitors != nullptr) {
1742 auto iter = monitors->find(FLAGS_data_collection_monitor_name);
1743 if (iter != monitors->end()) {
1744 auto *data_collection_monitor = iter->second.get();
1745 if (data_collection_monitor->IsEnabled() && record_count_ == 0) {
1746 data_collection_monitor->Restart();
1747 }
1748 }
1749 ++record_count_;
1750 }
1751 return true;
1752 } else {
1753 AERROR << "Failed to start the cyber_recorder process";
1754 return false;
1755 }
1756}
const std::string start_cmd
Definition teleop.cc:53

◆ StartPlayRtkRecorder()

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

在文件 hmi_worker.cc 第 1981 行定义.

1981 {
1982 Json result;
1983 if (!ChangeDrivingMode(Chassis::COMPLETE_AUTO_DRIVE)) {
1984 AERROR << "Failed to play rtk: Failed to enter auto drive.";
1985 result["error"] = "Failed to enter auto drive";
1986 result["isOk"] = false;
1987 return result;
1988 }
1989 std::string record_id;
1990 {
1991 RLock rlock(status_mutex_);
1992 record_id = status_.current_rtk_record_id();
1993 }
1994 std::string start_cmd =
1995 "nohup /apollo/scripts/rtk_player.sh start " + record_id + " &";
1996 int ret = std::system(start_cmd.data());
1997 if (ret == 0) {
1998 AINFO << "Start the rtk_recorder process Successful.";
1999 result["isOk"] = true;
2000 } else {
2001 AERROR << "Failed to play rtk: Failed to start the rtk_recorder process.";
2002 result["error"] = "Failed to start the rtk_recorder process";
2003 result["isOk"] = false;
2004 }
2005 return result;
2006}
nlohmann::json Json

◆ StartRtkDataRecorder()

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

在文件 hmi_worker.cc 第 1959 行定义.

1959 {
1960 std::string start_cmd = "nohup /apollo/scripts/rtk_recorder.sh start &";
1961 int ret = std::system(start_cmd.data());
1962 if (ret == 0) {
1963 return true;
1964 } else {
1965 AERROR << "Failed to start the rtk_recorder process";
1966 return false;
1967 }
1968}

◆ StartTerminal()

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

在文件 hmi_worker.cc 第 1907 行定义.

1907 {
1908 return std::system(FLAGS_terminal_start_cmd.data()) == 0;
1909}

◆ Stop() [1/2]

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

在文件 hmi_worker.cc 第 113 行定义.

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.cc 第 1758 行定义.

1758 {
1759 std::string stop_cmd = "/apollo/scripts/record_bag.py --stop";
1760 int ret = std::system(stop_cmd.data());
1761 if (ret == 0) {
1762 return true;
1763 } else {
1764 AERROR << "Failed to stop the cyber_recorder process";
1765 return false;
1766 }
1767}
const std::string stop_cmd
Definition teleop.cc:54

◆ StopPlayRtkRecorder()

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

在文件 hmi_worker.cc 第 2008 行定义.

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

◆ StopRtkDataRecorder()

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

在文件 hmi_worker.cc 第 1970 行定义.

1970 {
1971 std::string stop_cmd = "/apollo/scripts/rtk_recorder.sh stop";
1972 int ret = std::system(stop_cmd.data());
1973 if (ret == 9) {
1974 return true;
1975 } else {
1976 AERROR << "Failed to stop the rtk_recorder process";
1977 return false;
1978 }
1979}

◆ 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.cc 第 359 行定义.

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

◆ 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.cc 第 396 行定义.

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

◆ 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.cc 第 277 行定义.

277 {
278 AERROR << "HMIAction " << HMIAction_Name(action) << " was triggered!";
279 switch (action) {
280 case HMIAction::NONE:
281 break;
283 SetupMode();
284 break;
286 return ChangeDrivingMode(Chassis::COMPLETE_AUTO_DRIVE);
288 return ChangeDrivingMode(Chassis::COMPLETE_MANUAL);
290 ResetMode();
291 break;
293 LoadScenarios();
294 break;
296 LoadDynamicModels();
297 break;
299 LoadRecords();
300 break;
302 StopRecordPlay();
303 break;
304 default:
305 AERROR << "HMIAction not implemented, yet!";
306 return false;
307 }
308 return true;
309}

◆ 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.cc 第 311 行定义.

311 {
312 AINFO << "HMIAction " << HMIAction_Name(action) << "(" << value
313 << ") was triggered!";
314 switch (action) {
316 ChangeMode(value);
317 break;
319 ChangeMap(value);
320 break;
322 ChangeVehicle(value);
323 break;
325 StartModule(value);
326 break;
328 StopModule(value);
329 break;
331 ChangeScenarioSet(value);
332 break;
334 DeleteScenarioSet(value);
335 ChangeScenario("");
336 break;
338 ChangeScenario(value);
339 break;
341 ChangeDynamicModel(value);
342 break;
344 DeleteDynamicModel(value);
345 break;
347 DeleteRecord(value);
348 break;
350 ChangeRecord(value);
351 break;
352 default:
353 AERROR << "HMIAction not implemented, yet!";
354 return false;
355 }
356 return true;
357}

◆ 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.cc 第 1476 行定义.

1477 {
1478 {
1479 WLock wlock(status_mutex_);
1480 if (status_.current_camera_sensor_channel() == channel_name) {
1481 AINFO << "Input channel name is current camera sensor channel";
1482 return;
1483 }
1484 status_.set_current_camera_sensor_channel(channel_name);
1485 status_changed_ = true;
1486 }
1487}

◆ UpdateCameraSensorChannelToStatus() [2/2]

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

◆ UpdateComponentStatus() [1/2]

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

在文件 hmi_worker.cc 第 733 行定义.

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.cc 第 1031 行定义.

1032 {
1033 Json param_json({});
1034 param_json["dynamic_model_name"] = dynamic_model_name;
1035 Json callback_res = callback_api_("AddDynamicModel", param_json);
1036 if (!callback_res.contains("result") || !callback_res["result"]) {
1037 AERROR << "Failed to add dynamic model to local dynamic model list for "
1038 "register failed!";
1039 return false;
1040 }
1041 {
1042 WLock wlock(status_mutex_);
1043 for (const auto &iter : status_.dynamic_models()) {
1044 if (iter == dynamic_model_name) {
1045 AERROR << "Do not need to add new dynamic model for is duplicate!";
1046 return true;
1047 }
1048 }
1049 status_.add_dynamic_models(dynamic_model_name);
1050 status_changed_ = true;
1051 }
1052 return true;
1053}

◆ 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.cc 第 1334 行定义.

1334 {
1335 if (map_tar_name.empty()) {
1336 ReloadMaps();
1337 return true;
1338 }
1339 std::string map_dir = FLAGS_maps_data_path + "/";
1340 std::string map_name_prefix;
1341 int index = map_tar_name.rfind(".tar.xz");
1342 if (index != -1 && map_tar_name[0] != '.') {
1343 map_name_prefix = map_tar_name.substr(0, index);
1344 map_dir = map_dir + map_name_prefix;
1345 } else {
1346 AERROR << "The map name does not meet the standard!" << map_tar_name;
1347 return false;
1348 }
1349 if (!cyber::common::PathExists(map_dir)) {
1350 AERROR << "Failed to find maps!";
1351 return false;
1352 }
1353 map_name_prefix = util::HMIUtil::TitleCase(map_name_prefix);
1354 {
1355 WLock wlock(status_mutex_);
1356 auto iter = status_.maps().begin();
1357 for (; iter != status_.maps().end(); iter++) {
1358 if (*iter == map_name_prefix) {
1359 break;
1360 }
1361 }
1362 if (iter != status_.maps().end()) {
1363 return true;
1364 }
1365 status_.add_maps(map_name_prefix);
1366 status_changed_ = true;
1367 }
1368 return true;
1369}
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.cc 第 1489 行定义.

1490 {
1491 {
1492 WLock wlock(status_mutex_);
1493 if (status_.current_point_cloud_channel() == channel_name) {
1494 AINFO << "Input channel name is current camera sensor channel";
1495 return;
1496 }
1497 status_.set_current_point_cloud_channel(channel_name);
1498 status_changed_ = true;
1499 }
1500}

◆ 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.cc 第 2069 行定义.

2069 {
2070 WLock wlock(status_mutex_);
2071 status_.add_rtk_records(new_name);
2072 status_changed_ = true;
2073}

◆ UpdateScenarioSet()

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

在文件 hmi_worker.cc 第 1055 行定义.

1057 {
1058 std::string scenario_set_directory_path;
1059 GetScenarioSetPath(scenario_set_id, &scenario_set_directory_path);
1060 scenario_set_directory_path = scenario_set_directory_path + "/scenarios/";
1061 new_scenario_set->set_scenario_set_name(scenario_set_name);
1062 if (!cyber::common::PathExists(scenario_set_directory_path)) {
1063 AERROR << "Scenario set has no scenarios!";
1064 return true;
1065 }
1066 DIR *directory = opendir(scenario_set_directory_path.c_str());
1067 if (directory == nullptr) {
1068 AERROR << "Cannot open directory " << scenario_set_directory_path;
1069 return false;
1070 }
1071
1072 struct dirent *file;
1073 while ((file = readdir(directory)) != nullptr) {
1074 // skip directory_path/. and directory_path/..
1075 if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) {
1076 continue;
1077 }
1078 const std::string file_name = file->d_name;
1079 if (!absl::EndsWith(file_name, ".json")) {
1080 continue;
1081 }
1082 const int index = file_name.rfind(".json");
1083 if (index == 0) {
1084 // name: ".json" is invalid.
1085 continue;
1086 }
1087 const std::string scenario_id = file_name.substr(0, index);
1088 const std::string file_path = scenario_set_directory_path + file_name;
1089 SimTicket new_sim_ticket;
1090 if (!cyber::common::GetProtoFromJsonFile(file_path, &new_sim_ticket)) {
1091 AERROR << "Cannot parse this scenario:" << file_path;
1092 return false;
1093 }
1094 if (!new_sim_ticket.has_scenario()) {
1095 AERROR << "Cannot get scenario.";
1096 return false;
1097 }
1098 if (!new_sim_ticket.description_en_tokens_size()) {
1099 AERROR << "Cannot get scenario name.";
1100 return false;
1101 }
1102 if (!new_sim_ticket.scenario().has_map_dir()) {
1103 AERROR << "Cannot get scenario map dir.";
1104 return false;
1105 }
1106 if (!new_sim_ticket.scenario().has_start()) {
1107 AERROR << "Cannot get scenario start_point.";
1108 return false;
1109 }
1110 auto &scenario_start_point = new_sim_ticket.scenario().start();
1111 if (!scenario_start_point.has_x() || !scenario_start_point.has_y()) {
1112 AERROR << "Scenario start_point is invalid!";
1113 return false;
1114 }
1115 std::string scenario_name = new_sim_ticket.description_en_tokens(0);
1116 for (int i = 1; i < new_sim_ticket.description_en_tokens_size(); i++) {
1117 scenario_name =
1118 scenario_name + "_" + new_sim_ticket.description_en_tokens(i);
1119 }
1120 ScenarioInfo *scenario_info = new_scenario_set->add_scenarios();
1121 scenario_info->set_scenario_id(scenario_id);
1122 scenario_info->set_scenario_name(scenario_name);
1123 // change scenario json map dir to map name
1124 // format:modules/map/data/${map_name}
1125 const std::string map_dir = new_sim_ticket.scenario().map_dir();
1126 size_t idx = map_dir.find_last_of('/');
1127 if (idx == map_dir.npos) {
1128 AERROR << "Cannot get scenario map name.";
1129 return false;
1130 }
1131 const std::string map_name = map_dir.substr(idx + 1);
1132 if (map_name.empty()) {
1133 AERROR << "Cannot get scenario map name.";
1134 return false;
1135 }
1136 // replay engine use xx_xx like:apollo_map
1137 // dv need Apollo Map
1138 scenario_info->set_map_name(util::HMIUtil::TitleCase(map_name));
1139 auto start_point = scenario_info->mutable_start_point();
1140 start_point->set_x(scenario_start_point.x());
1141 start_point->set_y(scenario_start_point.y());
1142 }
1143 closedir(directory);
1144 return true;
1145}
void 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.cc 第 1013 行定义.

1014 {
1015 ScenarioSet new_scenario_set;
1016 if (!UpdateScenarioSet(scenario_set_id, scenario_set_name,
1017 &new_scenario_set)) {
1018 AERROR << "Failed to update scenario_set!";
1019 return false;
1020 }
1021 {
1022 WLock wlock(status_mutex_);
1023 auto scenario_set = status_.mutable_scenario_set();
1024 scenario_set->erase(scenario_set_id);
1025 (*scenario_set)[scenario_set_id] = new_scenario_set;
1026 status_changed_ = true;
1027 }
1028 return true;
1029}
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.cc 第 427 行定义.

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

◆ VehicleCalibrationPreprocess() [2/2]

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

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