22#include "google/protobuf/util/json_util.h"
24#include "modules/dreamview/proto/preprocess_table.pb.h"
39using google::protobuf::util::JsonStringToMessage;
45 websocket_(websocket),
46 map_service_(map_service) {
48 RegisterMessageHandlers();
56void HMI::RegisterMessageHandlers() {
58 hmi_worker_->RegisterStatusUpdateHandler(
59 [
this](
const bool status_changed, HMIStatus* status) {
60 if (!status_changed) {
66 if (status->current_map().empty()) {
67 monitor_log_buffer_.WARN(
"You haven't selected a map yet!");
69 if (status->current_vehicle().empty()) {
70 monitor_log_buffer_.WARN(
"You haven't selected a vehicle yet!");
78 SendVehicleParam(conn);
88 AERROR <<
"Truncated HMIAction request.";
92 if (!HMIAction_Parse(action, &hmi_action)) {
93 AERROR <<
"Invalid HMIAction string: " << action;
98 hmi_worker_->Trigger(hmi_action, value);
100 hmi_worker_->Trigger(hmi_action);
107 <<
"Failed to load new simulation map: " << value;
121 uint64_t event_time_ms;
133 hmi_worker_->SubmitAudioEvent(event_time_ms, obstacle_id, audio_type,
134 moving_result, audio_direction,
136 monitor_log_buffer_.INFO(
"Audio event added.");
138 AERROR <<
"Truncated SubmitAudioEvent request.";
139 monitor_log_buffer_.WARN(
"Failed to submit an audio event.");
148 uint64_t event_time_ms;
149 std::string event_msg;
150 std::vector<std::string> event_types;
156 hmi_worker_->SubmitDriveEvent(event_time_ms, event_msg, event_types,
158 monitor_log_buffer_.INFO(
"Drive event added.");
160 AERROR <<
"Truncated SubmitDriveEvent request.";
161 monitor_log_buffer_.WARN(
"Failed to submit a drive event.");
172 "SensorCalibrationPreprocess",
175 std::string current_mode = hmi_worker_->GetStatus().current_mode();
176 std::string task_type;
177 if (current_mode == FLAGS_lidar_calibration_mode) {
178 task_type =
"lidar_to_gnss";
179 }
else if (current_mode == FLAGS_camera_calibration_mode) {
180 task_type =
"camera_to_lidar";
182 AERROR <<
"Unsupported mode:" << current_mode;
186 const auto iter = json.find(
"data");
187 if (iter == json.end()) {
188 AERROR <<
"The json has no such key: data";
191 PreprocessTable preprocess_table;
192 if (!JsonStringToMessage(json[
"data"].dump(), &preprocess_table).ok()) {
194 <<
"Failed to get user configuration: invalid preprocess table."
199 std::string output_file =
200 absl::StrCat(
"modules/tools/sensor_calibration/config/",
201 task_type,
"_user.config");
203 AERROR <<
"Failed to generate user configuration file";
205 hmi_worker_->SensorCalibrationPreprocess(task_type);
209 "VehicleCalibrationPreprocess",
211 hmi_worker_->VehicleCalibrationPreprocess();
216 if (websocket_ ==
nullptr) {
220 const auto& vehicle_param =
222 const std::string json_str =
224 if (conn !=
nullptr) {
225 websocket_->
SendData(conn, json_str);
232 const auto status_json =
234 websocket_->
SendData(conn, status_json.dump());
238 const std::string& scenario_set_name) {
239 return hmi_worker_->UpdateScenarioSetToStatus(scenario_set_id,
244 return hmi_worker_->UpdateDynamicModelToStatus(dynamic_model_name);
252 hmi_worker_->UpdateCameraSensorChannelToStatus(channel_name);
257 hmi_worker_->UpdatePointCloudChannelToStatus(channel_name);
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
static bool GetNumber(const nlohmann::json &json, const std::string &key, T *value)
Get a number value from the given json[key].
static bool GetStringVector(const nlohmann::json &json, const std::string &key, std::vector< std::string > *value)
Get a string vector from the given json[key].
static nlohmann::json ProtoToTypedJson(const std::string &json_type, const google::protobuf::Message &proto)
Convert proto to a json string.
static bool GetBoolean(const nlohmann::json &json, const std::string &key, bool *value)
Get a boolean value from the given json[key].
static bool GetString(const nlohmann::json &json, const std::string &key, std::string *value)
Get a string value from the given json[key].
HMI(WebSocketHandler *websocket, MapService *map_service)
std::function< nlohmann::json(const std::string &function_name, const nlohmann::json ¶m_json)> DvCallback
bool UpdateDynamicModelToStatus(const std::string &dynamic_model_name)
bool UpdatePointChannelToStatus(const std::string &channel_name)
bool UpdateRecordToStatus()
bool UpdateCameraChannelToStatus(const std::string &channel_name)
bool UpdateScenarioSetToStatus(const std::string &scenario_set_id, const std::string &scenario_set_name)
void Start(DvCallback callback_api)
bool UpdateVehicleToStatus()
bool ReloadMap(bool force_reload)
static void LoadLidarHeight(const std::string &file_path)
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
bool BroadcastData(const std::string &data, bool skippable=false)
Sends the provided data to all the connected clients.
void RegisterMessageHandler(std::string type, MessageHandler handler)
Add a new message handler for a message type.
bool SendData(Connection *conn, const std::string &data, bool skippable=false, int op_code=MG_WEBSOCKET_OPCODE_TEXT)
Sends the provided data to a specific connected client.
void RegisterConnectionReadyHandler(ConnectionReadyHandler handler)
Add a new handler for new connections.
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
optional VehicleParam vehicle_param