Apollo 10.0
自动驾驶开放平台
apollo::dreamview::MapUpdater类 参考

A wrapper around WebSocketHandler to keep pushing map to frontend via websocket. 更多...

#include <map_updater.h>

类 apollo::dreamview::MapUpdater 继承关系图:
apollo::dreamview::MapUpdater 的协作图:

Public 成员函数

 MapUpdater (WebSocketHandler *websocket, const MapService *map_service)
 Constructor with the websocket handler.
 
 ~MapUpdater () override
 
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 OnTimer (const std::string &channel_name="")
 
void PublishMessage (const std::string &channel_name="") override
 Publish Message to dreamview frontend.
 
- Public 成员函数 继承自 apollo::dreamview::UpdaterBase
 UpdaterBase ()
 Updaterbase
 
virtual ~UpdaterBase ()
 

详细描述

A wrapper around WebSocketHandler to keep pushing map to frontend via websocket.

在文件 map_updater.h50 行定义.

构造及析构函数说明

◆ MapUpdater()

apollo::dreamview::MapUpdater::MapUpdater ( WebSocketHandler websocket,
const MapService map_service 
)

Constructor with the websocket handler.

参数
websocketPointer of the websocket handler that has been attached to the server.
map_serviceA service object that handles map data.

在文件 map_updater.cc34 行定义.

36 : node_(cyber::CreateNode("map_updater")),
37 websocket_(websocket),
38 map_service_(map_service) {
39 localization_reader_ =
41 FLAGS_localization_topic,
42 [this](
43 const std::shared_ptr<apollo::localization::LocalizationEstimate>
44 &msg) { UpdateAdcPosition(msg); });
45}
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33

◆ ~MapUpdater()

apollo::dreamview::MapUpdater::~MapUpdater ( )
inlineoverride

在文件 map_updater.h59 行定义.

59{}

成员函数说明

◆ OnTimer()

void apollo::dreamview::MapUpdater::OnTimer ( const std::string &  channel_name = "")

在文件 map_updater.cc70 行定义.

70{ PublishMessage(); }
void PublishMessage(const std::string &channel_name="") override
Publish Message to dreamview frontend.

◆ PublishMessage()

void apollo::dreamview::MapUpdater::PublishMessage ( const std::string &  channel_name = "")
overridevirtual

Publish Message to dreamview frontend.

实现了 apollo::dreamview::UpdaterBase.

在文件 map_updater.cc55 行定义.

55 {
56 auto retrieved = map_service_->RetrieveMapElements(map_element_ids_);
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);
67 websocket_->BroadcastBinaryData(stream_data_string);
68}
hdmap::Map RetrieveMapElements(const MapElementIds &ids) const
bool BroadcastBinaryData(const std::string &data, bool skippable=false)
Sends the provided binary data to all the connected clients.

◆ StartStream()

void apollo::dreamview::MapUpdater::StartStream ( const double &  time_interval_ms,
const std::string &  channel_name = "",
nlohmann::json *  subscribe_param = nullptr 
)
overridevirtual

Start data flow.

参数
time_interval_msData stream sending frequency. 0 means single subscribe
subscribe_paramsubscribe some updater may need extra params

实现了 apollo::dreamview::UpdaterBase.

在文件 map_updater.cc72 行定义.

74 {
75 if (subscribe_param == nullptr ||
76 !ContainsKey(*subscribe_param, "mapElementIds")) {
77 AERROR << "Subscribe map must bring elementIds param";
78 return;
79 }
80 // json to message
81 map_element_ids_.Clear();
82 nlohmann::json element_ids_json;
83 if (!JsonUtil::GetJsonByPath(*subscribe_param, {"mapElementIds"},
84 &element_ids_json)) {
85 AERROR << "ElementIds param is wrong type.";
86 return;
87 }
88 if (!JsonStringToMessage(element_ids_json.dump(), &map_element_ids_).ok()) {
89 AERROR << "Failed to parse elementIds from json!";
90 return;
91 }
92 if (time_interval_ms > 0) {
93 timer_.reset(new cyber::Timer(
94 time_interval_ms, [this]() { this->OnTimer(); }, false));
95 timer_->Start();
96 } else {
97 this->OnTimer();
98 }
99}
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.
Definition json_util.cc:73
void OnTimer(const std::string &channel_name="")
#define AERROR
Definition log.h:44

◆ StopStream()

void apollo::dreamview::MapUpdater::StopStream ( const std::string &  channel_name = "")
overridevirtual

Stop data flow.

实现了 apollo::dreamview::UpdaterBase.

在文件 map_updater.cc101 行定义.

101 {
102 if (timer_) {
103 timer_->Stop();
104 }
105}

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