27std::map<std::string, int> plugin_function_map = {
28 {
"UpdateScenarioSetToStatus", 0},
29 {
"UpdateRecordToStatus", 1},
30 {
"UpdateDynamicModelToStatus", 2},
31 {
"UpdateVehicleToStatus", 3}};
32std::map<std::string, int> hmi_function_map = {
33 {
"SimControlRestart", 0}, {
"MapServiceReloadMap", 1},
34 {
"LoadDynamicModels", 2}, {
"ChangeDynamicModel", 3},
35 {
"DeleteDynamicModel", 4}, {
"AddDynamicModel", 5},
36 {
"RestartDynamicModel", 6},
49void Dreamview::TerminateProfilingMode() {
51 AWARN <<
"Profiling timer called shutdown!";
57 if (FLAGS_dreamview_profiling_mode &&
58 FLAGS_dreamview_profiling_duration > 0.0) {
60 FLAGS_dreamview_profiling_duration,
61 [
this]() { this->TerminateProfilingMode(); },
false));
64 AWARN <<
"============================================================";
65 AWARN <<
"| Dreamview running in profiling mode, exit in "
66 << FLAGS_dreamview_profiling_duration <<
" seconds |";
67 AWARN <<
"============================================================";
72 std::vector<std::string> options = {
73 "document_root", FLAGS_static_file_dir,
74 "listening_ports", FLAGS_server_ports,
75 "websocket_timeout_ms", FLAGS_websocket_timeout_ms,
76 "request_timeout_ms", FLAGS_request_timeout_ms,
77 "enable_keep_alive",
"yes",
79 "keep_alive_timeout_ms",
"500"};
80 if (PathExists(FLAGS_ssl_certificate)) {
81 options.push_back(
"ssl_certificate");
82 options.push_back(FLAGS_ssl_certificate);
83 }
else if (FLAGS_ssl_certificate.size() > 0) {
84 AERROR <<
"Certificate file " << FLAGS_ssl_certificate
85 <<
" does not exist!";
87 server_.reset(
new CivetServer(options));
97 perception_camera_updater_.reset(
100 hmi_.reset(
new HMI(websocket_.get(), map_service_.get()));
103 websocket_.get(), map_ws_.get(), camera_ws_.get(),
104 plugin_ws_.get(), map_service_.get(),
105 perception_camera_updater_.get(), plugin_manager_.get(),
106 FLAGS_routing_from_file));
107 point_cloud_updater_.reset(
110 server_->addWebSocketHandler(
"/websocket", *websocket_);
111 server_->addWebSocketHandler(
"/map", *map_ws_);
112 server_->addWebSocketHandler(
"/pointcloud", *point_cloud_ws_);
113 server_->addWebSocketHandler(
"/camera", *camera_ws_);
114 server_->addWebSocketHandler(
"/plugin", *plugin_ws_);
115 server_->addHandler(
"/image", *image_);
119 server_->addWebSocketHandler(
"/teleop", *teleop_ws_);
125 sim_world_updater_->Start();
126 point_cloud_updater_->Start([
this](
const std::string& param_string) ->
bool {
127 return PointCloudCallback(param_string);
129 hmi_->Start([
this](
const std::string& function_name,
130 const nlohmann::json& param_json) -> nlohmann::json {
131 nlohmann::json ret = HMICallbackSimControl(function_name, param_json);
132 ADEBUG <<
"ret: " << ret.dump();
135 perception_camera_updater_->Start(
136 [
this](
const std::string& param_string) ->
bool {
137 return PerceptionCameraCallback(param_string);
139 plugin_manager_->Start([
this](
const std::string& function_name,
140 const nlohmann::json& param_json) ->
bool {
141 return PluginCallbackHMI(function_name, param_json);
151 SimControlManager::Instance()->Stop();
152 point_cloud_updater_->Stop();
154 perception_camera_updater_->Stop();
155 plugin_manager_->Stop();
158nlohmann::json Dreamview::HMICallbackSimControl(
159 const std::string& function_name,
const nlohmann::json& param_json) {
160 nlohmann::json callback_res = {};
161 callback_res[
"result"] =
false;
162 if (hmi_function_map.find(function_name) == hmi_function_map.end()) {
163 AERROR <<
"Donnot support this callback";
166 switch (hmi_function_map[function_name]) {
169 if (param_json.contains(
"x") && param_json.contains(
"y")) {
170 const double x = param_json[
"x"];
171 const double y = param_json[
"y"];
172 SimControlManager::Instance()->Restart(x, y);
173 callback_res[
"result"] =
true;
177 map_service_->ReloadMap(
true);
178 callback_res[
"result"] =
true;
183 if (SimControlManager::Instance()->IsEnabled()) {
184 nlohmann::json load_res =
185 SimControlManager::Instance()->LoadDynamicModels();
186 callback_res[
"loaded_dynamic_models"] =
187 load_res[
"loaded_dynamic_models"];
188 callback_res[
"result"] =
true;
190 AERROR <<
"Sim control is not enabled!";
196 if (param_json.contains(
"dynamic_model_name") &&
197 SimControlManager::Instance()->IsEnabled()) {
198 callback_res[
"result"] =
199 SimControlManager::Instance()->ChangeDynamicModel(
200 param_json[
"dynamic_model_name"]);
202 AERROR <<
"Sim control is not enabled or missing dynamic model name "
209 if (param_json.contains(
"dynamic_model_name") &&
210 SimControlManager::Instance()->IsEnabled()) {
211 callback_res[
"result"] =
212 SimControlManager::Instance()->DeleteDynamicModel(
213 param_json[
"dynamic_model_name"]);
215 AERROR <<
"Sim control is not enabled or missing dynamic model name "
222 if (param_json.contains(
"dynamic_model_name") &&
223 SimControlManager::Instance()->IsEnabled()) {
224 callback_res[
"result"] = SimControlManager::Instance()->AddDynamicModel(
225 param_json[
"dynamic_model_name"]);
227 AERROR <<
"Sim control is not enabled or missing dynamic model name "
234 map_service_->ReloadMap(
true);
235 SimControlManager::Instance()->Restart();
236 callback_res[
"result"] =
true;
245bool Dreamview::PluginCallbackHMI(
const std::string& function_name,
246 const nlohmann::json& param_json) {
248 if (plugin_function_map.find(function_name) == plugin_function_map.end()) {
249 AERROR <<
"Donnot support this callback";
252 switch (plugin_function_map[function_name]) {
255 if (param_json.contains(
"data") &&
256 param_json[
"data"].contains(
"scenario_set_id") &&
257 param_json[
"data"].contains(
"scenario_set_name")) {
258 const std::string scenario_set_id =
259 param_json[
"data"][
"scenario_set_id"];
260 const std::string scenario_set_name =
261 param_json[
"data"][
"scenario_set_name"];
262 if (!scenario_set_id.empty() && !scenario_set_name.empty()) {
263 callback_res = hmi_->UpdateScenarioSetToStatus(scenario_set_id,
269 callback_res = hmi_->UpdateRecordToStatus();
272 if (param_json.contains(
"data") &&
273 param_json[
"data"].contains(
"dynamic_model_name")) {
274 const std::string dynamic_model_name =
275 param_json[
"data"][
"dynamic_model_name"];
276 if (!dynamic_model_name.empty()) {
277 callback_res = hmi_->UpdateDynamicModelToStatus(dynamic_model_name);
282 callback_res = hmi_->UpdateVehicleToStatus();
290bool Dreamview::PerceptionCameraCallback(
const std::string& param_string) {
291 bool callback_res =
false;
292 callback_res = hmi_->UpdateCameraChannelToStatus(param_string);
296bool Dreamview::PointCloudCallback(
const std::string& param_string) {
297 bool callback_res =
false;
298 callback_res = hmi_->UpdatePointChannelToStatus(param_string);
A general class to denote the return status of an API call.
@Brief This is a helper class that can load vehicle configurations.
static void Init()
Initialize vehicle configurations with default configuration file pointed by gflags FLAGS_vehicle_con...
Used to perform oneshot or periodic timing tasks
apollo::common::Status Init()
apollo::common::Status Start()
The ImageHandler, built on top of CivetHandler, converts the received ROS image message to an image s...
A wrapper around WebSocketHandler to keep pushing PointCloud to frontend via websocket while handling...
A wrapper around SimulationWorldService and WebSocketHandler to keep pushing SimulationWorld to front...
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
bool PathExists(const std::string &path)
Check if the path exists.