19#include "google/protobuf/util/json_util.h"
24#include "modules/common_msgs/localization_msgs/localization.pb.h"
30using google::protobuf::util::JsonStringToMessage;
31using apollo::common::util::ContainsKey;
36 : node_(cyber::CreateNode(
"map_updater")),
37 websocket_(websocket),
38 map_service_(map_service) {
39 localization_reader_ =
41 FLAGS_localization_topic,
43 const std::shared_ptr<apollo::localization::LocalizationEstimate>
44 &msg) { UpdateAdcPosition(msg); });
47void MapUpdater::UpdateAdcPosition(
48 const std::shared_ptr<apollo::localization::LocalizationEstimate>
50 const auto &pose = localization->
pose();
51 adc_point_.set_x(pose.position().x() + map_service_->
GetXOffset());
52 adc_point_.set_y(pose.position().y() + map_service_->
GetYOffset());
57 retrieved.SerializeToString(&retrieved_map_string_);
58 StreamData stream_data;
59 std::string stream_data_string;
60 stream_data.set_action(
"stream");
61 stream_data.set_data_name(
"map");
62 std::vector<uint8_t> byte_data(retrieved_map_string_.begin(),
63 retrieved_map_string_.end());
64 stream_data.set_data(&(byte_data[0]), byte_data.size());
65 stream_data.set_type(
"map");
66 stream_data.SerializeToString(&stream_data_string);
73 const std::string &channel_name,
74 nlohmann::json *subscribe_param) {
75 if (subscribe_param ==
nullptr ||
76 !ContainsKey(*subscribe_param,
"mapElementIds")) {
77 AERROR <<
"Subscribe map must bring elementIds param";
81 map_element_ids_.Clear();
82 nlohmann::json element_ids_json;
85 AERROR <<
"ElementIds param is wrong type.";
88 if (!JsonStringToMessage(element_ids_json.dump(), &map_element_ids_).ok()) {
89 AERROR <<
"Failed to parse elementIds from json!";
92 if (time_interval_ms > 0) {
94 time_interval_ms, [
this]() { this->
OnTimer(); },
false));
static bool GetJsonByPath(const nlohmann::json &json, const std::vector< std::string > &paths, nlohmann::json *value)
Get the json from the given json and path.
Used to perform oneshot or periodic timing tasks
double GetYOffset() const
double GetXOffset() const
hdmap::Map RetrieveMapElements(const MapElementIds &ids) const
void OnTimer(const std::string &channel_name="")
MapUpdater(WebSocketHandler *websocket, const MapService *map_service)
Constructor with the websocket handler.
void StartStream(const double &time_interval_ms, const std::string &channel_name="", nlohmann::json *subscribe_param=nullptr) override
Start data flow.
void StopStream(const std::string &channel_name="") override
Stop data flow.
void PublishMessage(const std::string &channel_name="") override
Publish Message to dreamview frontend.
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
bool BroadcastBinaryData(const std::string &data, bool skippable=false)
Sends the provided binary data to all the connected clients.
optional apollo::localization::Pose pose