Apollo 10.0
自动驾驶开放平台
rtcm_parser.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include <memory>
20
21#include "modules/common_msgs/sensor_msgs/gnss_raw_observation.pb.h"
22
23#include "cyber/cyber.h"
27
28namespace apollo {
29namespace drivers {
30namespace gnss {
31
32using ::apollo::drivers::gnss::EpochObservation;
33using ::apollo::drivers::gnss::GnssEphemeris;
34
36 const std::shared_ptr<apollo::cyber::Node>& node)
37 : config_(config), node_(node) {}
38
40 rtcm_parser_.reset(new Rtcm3Parser(true));
41
42 if (!rtcm_parser_) {
43 AERROR << "Failed to create rtcm parser.";
44 return false;
45 }
46
47 gnssephemeris_writer_ =
48 node_->CreateWriter<GnssEphemeris>(FLAGS_gnss_rtk_eph_topic);
49 epochobservation_writer_ =
50 node_->CreateWriter<EpochObservation>(FLAGS_gnss_rtk_obs_topic);
51 init_flag_ = true;
52 return true;
53}
54
55void RtcmParser::ParseRtcmData(const std::string& msg) {
56 if (!init_flag_) {
57 return;
58 }
59
60 rtcm_parser_->Update(msg);
61 MessageType type;
62 MessagePtr msg_ptr;
63
64 while (cyber::OK()) {
65 type = rtcm_parser_->GetMessage(&msg_ptr);
66 if (type == MessageType::NONE) {
67 break;
68 }
69 DispatchMessage(type, msg_ptr);
70 }
71}
72
73void RtcmParser::DispatchMessage(MessageType type, MessagePtr message) {
74 switch (type) {
76 PublishEphemeris(message);
77 break;
78
80 PublishObservation(message);
81 break;
82
83 default:
84 break;
85 }
86}
87
88void RtcmParser::PublishEphemeris(const MessagePtr& message) {
89 auto eph = std::make_shared<GnssEphemeris>(*As<GnssEphemeris>(message));
90 gnssephemeris_writer_->Write(eph);
91}
92
93void RtcmParser::PublishObservation(const MessagePtr& message) {
94 auto observation =
95 std::make_shared<EpochObservation>(*As<EpochObservation>(message));
96 epochobservation_writer_->Write(observation);
97}
98
99} // namespace gnss
100} // namespace drivers
101} // namespace apollo
::google::protobuf::Message * MessagePtr
Definition rtcm_parser.h:34
void ParseRtcmData(const std::string &msg)
RtcmParser(const config::Config &config, const std::shared_ptr< apollo::cyber::Node > &node)
#define AERROR
Definition log.h:44
bool OK()
Definition state.h:44
::google::protobuf::Message * MessagePtr
Definition parser.h:34
class register implement
Definition arena_queue.h:37