Skip to content

Commit

Permalink
all modules:fix lint
Browse files Browse the repository at this point in the history
Change-Id: I8c869d39b5f895dd5cae592eb735baaad64a6eb6
  • Loading branch information
dreamholy committed Nov 4, 2022
1 parent f7b0f38 commit 8cb90a9
Show file tree
Hide file tree
Showing 73 changed files with 568 additions and 513 deletions.
17 changes: 17 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Stop searching for additional config files.
set noparent

# Disable a warning about C++ features that were not in the original
# C++11 specification (and so might not be well-supported).
filter=-build/c++11
filter=-build/include_alpha,+build/include_order
filter=+build/include_what_you_use


# Disable header_guard warning
# Consider using #pragma once instead
filter=-build/header_guard
filter=+runtime/printf,+runtime/printf_format

linelength=80
includeorder=standardcfirst
14 changes: 7 additions & 7 deletions cyber/common/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "nlohmann/json.hpp"

#include "google/protobuf/util/json_util.h"

#include <cerrno>
#include <cstddef>
#include <fstream>
#include <string>

#include "google/protobuf/util/json_util.h"
#include "nlohmann/json.hpp"

namespace apollo {
namespace cyber {
namespace common {
Expand Down Expand Up @@ -123,16 +123,16 @@ bool GetProtoFromFile(const std::string &file_name,
}

bool GetProtoFromJsonFile(const std::string &file_name,
google::protobuf::Message *message) {
using google::protobuf::util::JsonStringToMessage;
google::protobuf::Message *message) {
using google::protobuf::util::JsonParseOptions;
using google::protobuf::util::JsonStringToMessage;
std::ifstream ifs(file_name);
if(!ifs.is_open()){
if (!ifs.is_open()) {
AERROR << "Failed to open file " << file_name;
return false;
}
nlohmann::json Json;
ifs>> Json;
ifs >> Json;
ifs.close();
JsonParseOptions options;
options.ignore_unknown_fields = true;
Expand Down
33 changes: 23 additions & 10 deletions modules/dreamview/backend/common/dreamview_gflags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,35 @@ DEFINE_string(plugin_path,
DEFINE_string(plugin_config_file_name_suffix, "_plugin_config.pb.txt",
"PLugin config file name!");

DEFINE_string(plugin_channel_prefix,"/apollo/dreamview/plugins/","plugins must use this as channel prefix");
DEFINE_string(plugin_channel_prefix,
"/apollo/dreamview/plugins/", "plugins must use this as channel prefix");

DEFINE_string(resource_scenario_path,"/.apollo/resources/scenario_sets/","Scenario set placement");
DEFINE_string(resource_scenario_path,
"/.apollo/resources/scenario_sets/", "Scenario set placement");

DEFINE_string(resource_dynamic_model_path,"/.apollo/resources/dynamic_models/models/","Dynamic Models placement");
DEFINE_string(resource_dynamic_model_path,
"/.apollo/resources/dynamic_models/models/", "Dynamic Models placement");

DEFINE_string(dynamic_model_library_path,"/.apollo/resources/dynamic_models/library/","Dynamic Model libs placement");
DEFINE_string(dynamic_model_library_path,
"/.apollo/resources/dynamic_models/library/",
"Dynamic Model libs placement");

DEFINE_string(sim_obstacle_stop_command,"pkill -9 -f \"sim_obstacle\" ","Sim obstacle stop command");
DEFINE_string(sim_obstacle_stop_command,
"pkill -9 -f \"sim_obstacle\" ", "Sim obstacle stop command");

DEFINE_string(sim_obstacle_path,"/.apollo/dreamview/plugins/sim_obstacle/sim_obstacle","sim obstacle binary placement.");
DEFINE_string(sim_obstacle_path,
"/.apollo/dreamview/plugins/sim_obstacle/sim_obstacle",
"sim obstacle binary placement.");

DEFINE_string(gflag_command_arg," --flagfile=/apollo/modules/common/data/global_flagfile.txt","sim obstacle need use gflag!");
DEFINE_string(gflag_command_arg,
" --flagfile=/apollo/modules/common/data/global_flagfile.txt",
"sim obstacle need use gflag!");

DEFINE_string(sim_perfect_control,"Simulation Perfect Control","sim perfect control!");
DEFINE_string(sim_perfect_control,
"Simulation Perfect Control", "sim perfect control!");

DEFINE_string(resource_record_path,"/.apollo/resources/records/","Records placement");
DEFINE_string(resource_record_path,
"/.apollo/resources/records/", "Records placement");

DEFINE_string(cyber_recorder_stop_command, "pkill -9 cyber_recorder", "stop play recorder");
DEFINE_string(cyber_recorder_stop_command,
"pkill -9 cyber_recorder", "stop play recorder");
87 changes: 43 additions & 44 deletions modules/dreamview/backend/dreamview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
#include "modules/common/configs/vehicle_config_helper.h"
#include "modules/dreamview/backend/common/dreamview_gflags.h"
namespace {
std::map<std::string, int> plugin_function_map = {{"UpdateScenarioSetToStatus", 0},{"UpdateRecordToStatus",1},
{"UpdateDynamicModelToStatus", 2}};
std::map<std::string, int> plugin_function_map = {
{"UpdateScenarioSetToStatus", 0},
{"UpdateRecordToStatus", 1},
{"UpdateDynamicModelToStatus", 2}};
std::map<std::string, int> hmi_function_map = {
{"SimControlRestart", 0},
{"MapServiceReloadMap", 1},
{"LoadDynamicModels", 2},
{"ChangeDynamicModel", 3},
{"DeleteDynamicModel", 4},
{"AddDynamicModel",5},
{"SimControlRestart", 0}, {"MapServiceReloadMap", 1},
{"LoadDynamicModels", 2}, {"ChangeDynamicModel", 3},
{"DeleteDynamicModel", 4}, {"AddDynamicModel", 5},
};
}
} // namespace

namespace apollo {
namespace dreamview {
Expand Down Expand Up @@ -100,9 +99,8 @@ Status Dreamview::Init() {
plugin_manager_.reset(new PluginManager(plugin_ws_.get()));
sim_world_updater_.reset(new SimulationWorldUpdater(
websocket_.get(), map_ws_.get(), camera_ws_.get(),
sim_control_manager_.get(),
plugin_ws_.get(), map_service_.get(), perception_camera_updater_.get(),
plugin_manager_.get(),
sim_control_manager_.get(), plugin_ws_.get(), map_service_.get(),
perception_camera_updater_.get(), plugin_manager_.get(),
FLAGS_routing_from_file));
point_cloud_updater_.reset(
new PointCloudUpdater(point_cloud_ws_.get(), sim_world_updater_.get()));
Expand All @@ -111,7 +109,7 @@ Status Dreamview::Init() {
server_->addWebSocketHandler("/map", *map_ws_);
server_->addWebSocketHandler("/pointcloud", *point_cloud_ws_);
server_->addWebSocketHandler("/camera", *camera_ws_);
server_->addWebSocketHandler("/plugin",*plugin_ws_);
server_->addWebSocketHandler("/plugin", *plugin_ws_);
server_->addHandler("/image", *image_);
#if WITH_TELEOP == 1
teleop_ws_.reset(new WebSocketHandler("Teleop"));
Expand All @@ -132,7 +130,7 @@ Status Dreamview::Start() {
});
perception_camera_updater_->Start();
plugin_manager_->Start([this](const std::string& function_name,
const nlohmann::json& param_json) -> bool {
const nlohmann::json& param_json) -> bool {
return PluginCallbackHMI(function_name, param_json);
});
#if WITH_TELEOP == 1
Expand All @@ -150,34 +148,33 @@ void Dreamview::Stop() {
plugin_manager_->Stop();
}

nlohmann::json Dreamview::HMICallbackSimControl(const std::string& function_name,
const nlohmann::json& param_json) {
nlohmann::json Dreamview::HMICallbackSimControl(
const std::string& function_name, const nlohmann::json& param_json) {
nlohmann::json callback_res = {};
callback_res["result"] = false;
if (hmi_function_map.find(function_name) == hmi_function_map.end()) {
AERROR << "Donnot support this callback";
return callback_res;
}
std::string dynamic_model_name;
switch(hmi_function_map[function_name]) {
switch (hmi_function_map[function_name]) {
case 0: {
// 解析结果
if (param_json.contains("x") &&
param_json.contains("y")) {
if (param_json.contains("x") && param_json.contains("y")) {
const double x = param_json["x"];
const double y = param_json["y"];
sim_control_manager_->Restart(x, y);
callback_res["result"] = true;
}
} break;
case 1:{
case 1: {
map_service_->ReloadMap(true);
callback_res["result"]= true;
callback_res["result"] = true;
break;
}
case 2:{
case 2: {
// loadDynamicModels
if(sim_control_manager_->IsEnabled()){
if (sim_control_manager_->IsEnabled()) {
nlohmann::json load_res = sim_control_manager_->LoadDynamicModels();
callback_res["loaded_dynamic_models"] =
load_res["loaded_dynamic_models"];
Expand All @@ -187,7 +184,7 @@ nlohmann::json Dreamview::HMICallbackSimControl(const std::string& function_name
}
break;
}
case 3:{
case 3: {
// 解析结果
if (param_json.contains("dynamic_model_name") &&
sim_control_manager_->IsEnabled()) {
Expand All @@ -200,27 +197,29 @@ nlohmann::json Dreamview::HMICallbackSimControl(const std::string& function_name
}
break;
}
case 4:{
case 4: {
// 解析结果
if (param_json.contains("dynamic_model_name")&&sim_control_manager_->IsEnabled()) {
if (param_json.contains("dynamic_model_name") &&
sim_control_manager_->IsEnabled()) {
dynamic_model_name = param_json["dynamic_model_name"];
callback_res["result"]=sim_control_manager_->DeleteDynamicModel(dynamic_model_name);
}else{
AERROR<<"Sim control is not enabled or missing dynamic model name param!";
callback_res["result"] =
sim_control_manager_->DeleteDynamicModel(dynamic_model_name);
} else {
AERROR << "Sim control is not enabled or missing dynamic model name "
"param!";
}
break;
break;
}
case 5:
{
case 5: {
// addDynamicModel
if (param_json.contains("dynamic_model_name") && sim_control_manager_->IsEnabled())
{
if (param_json.contains("dynamic_model_name") &&
sim_control_manager_->IsEnabled()) {
dynamic_model_name = param_json["dynamic_model_name"];
callback_res["result"] = sim_control_manager_->AddDynamicModel(dynamic_model_name);
}
else
{
AERROR << "Sim control is not enabled or missing dynamic model name param!";
callback_res["result"] =
sim_control_manager_->AddDynamicModel(dynamic_model_name);
} else {
AERROR << "Sim control is not enabled or missing dynamic model name "
"param!";
}
break;
}
Expand All @@ -237,7 +236,7 @@ bool Dreamview::PluginCallbackHMI(const std::string& function_name,
AERROR << "Donnot support this callback";
return false;
}
switch(plugin_function_map[function_name]) {
switch (plugin_function_map[function_name]) {
case 0: {
// 解析结果
if (param_json.contains("scenario_set_id") &&
Expand All @@ -250,12 +249,12 @@ bool Dreamview::PluginCallbackHMI(const std::string& function_name,
}
}
} break;
case 1:{
if(param_json.contains("record_id")&&param_json.contains("status")){
case 1: {
if (param_json.contains("record_id") && param_json.contains("status")) {
const std::string record_id = param_json["record_id"];
const std::string record_status = param_json["status"];
if(!record_id.empty()&&record_status.empty()){
callback_res = hmi_->UpdateRecordToStatus(record_id,record_status);
if (!record_id.empty() && record_status.empty()) {
callback_res = hmi_->UpdateRecordToStatus(record_id, record_status);
}
}
} break;
Expand Down
8 changes: 5 additions & 3 deletions modules/dreamview/backend/dreamview.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <memory>
#include <string>
#include <map>

#include "CivetServer.h"

Expand All @@ -28,10 +29,10 @@
#include "modules/dreamview/backend/hmi/hmi.h"
#include "modules/dreamview/backend/map/map_service.h"
#include "modules/dreamview/backend/perception_camera_updater/perception_camera_updater.h"
#include "modules/dreamview/backend/plugins/plugin_manager.h"
#include "modules/dreamview/backend/point_cloud/point_cloud_updater.h"
#include "modules/dreamview/backend/sim_control_manager/sim_control_manager.h"
#include "modules/dreamview/backend/simulation_world/simulation_world_updater.h"
#include "modules/dreamview/backend/plugins/plugin_manager.h"
#if WITH_TELEOP == 1
#include "modules/dreamview/backend/teleop/teleop.h"
#endif
Expand All @@ -53,9 +54,10 @@ class Dreamview {

private:
void TerminateProfilingMode();
bool PluginCallbackHMI(const std::string& function_name, const nlohmann::json &param_json);
bool PluginCallbackHMI(const std::string& function_name,
const nlohmann::json& param_json);
nlohmann::json HMICallbackSimControl(const std::string& function_name,
const nlohmann::json& param_json);
const nlohmann::json& param_json);

std::unique_ptr<cyber::Timer> exit_timer_;

Expand Down
9 changes: 6 additions & 3 deletions modules/dreamview/backend/hmi/hmi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,18 @@ void HMI::SendStatus(WebSocketHandler::Connection* conn) {
websocket_->SendData(conn, status_json.dump());
}

bool HMI::UpdateScenarioSetToStatus(const std::string& scenario_set_id, const std::string& scenario_set_name){
return hmi_worker_->UpdateScenarioSetToStatus(scenario_set_id, scenario_set_name);
bool HMI::UpdateScenarioSetToStatus(const std::string& scenario_set_id,
const std::string& scenario_set_name) {
return hmi_worker_->UpdateScenarioSetToStatus(scenario_set_id,
scenario_set_name);
}

bool HMI::UpdateDynamicModelToStatus(std::string& dynamic_model_name) {
return hmi_worker_->UpdateDynamicModelToStatus(dynamic_model_name);
}

bool HMI::UpdateRecordToStatus(const std::string& record_id,const std::string& record_status){
bool HMI::UpdateRecordToStatus(const std::string& record_id,
const std::string& record_status) {
return hmi_worker_->UpdateRecordToStatus(record_id, record_status);
}
} // namespace dreamview
Expand Down
9 changes: 5 additions & 4 deletions modules/dreamview/backend/hmi/hmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ namespace dreamview {

class HMI {
public:
using DvCallback = std::function<nlohmann::json(const std::string &function_name,
const nlohmann::json &param_json)>;
using DvCallback = std::function<nlohmann::json(
const std::string &function_name, const nlohmann::json &param_json)>;
HMI(WebSocketHandler *websocket, MapService *map_service);
void Start(DvCallback callback_api);
void Stop();
bool UpdateScenarioSetToStatus(const std::string& scenario_set_id, const std::string& scenario_set_name);
bool UpdateDynamicModelToStatus(std::string& dynamic_model_name);
bool UpdateScenarioSetToStatus(const std::string &scenario_set_id,
const std::string &scenario_set_name);
bool UpdateDynamicModelToStatus(std::string &dynamic_model_name);
bool UpdateRecordToStatus(const std::string &record_id,
const std::string &record_status);

Expand Down
Loading

0 comments on commit 8cb90a9

Please sign in to comment.