Apollo 11.0
自动驾驶开放平台
parser.h
浏览该文件的文档.
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
17#pragma once
18
19#include <cstdint>
20#include <string>
21#include <vector>
22
23#include "google/protobuf/message.h"
24
25#include "modules/drivers/gnss/proto/config.pb.h"
26
28
29namespace apollo {
30namespace drivers {
31namespace gnss {
32
33// A general pointer to a protobuf message.
34using MessagePtr = ::google::protobuf::Message *;
35enum class MessageType {
36 NONE,
37 GNSS,
39 IMU,
40 INS,
42 WHEEL,
45 GPGGA,
47 RAWIMU,
51 HEADING,
52};
57using MessageInfoVec = std::vector<MessageInfo>;
58
59// convert gps time (base on Jan 6 1980) to system time (base on Jan 1 1970)
60// notice: Jan 6 1980
61//
62// linux shell:
63// time1 = date +%s -d"Jan 6, 1980 00:00:01"
64// time2 = date +%s -d"Jan 1, 1970 00:00:01"
65// dif_tick = time1-time2
66// 315964800 = 315993601 - 28801
67
68#define EPOCH_AND_SYSTEM_DIFF_SECONDS 315964800
69
70// A helper function that returns a pointer to a protobuf message of type T.
71template <class T>
72inline T *As(::google::protobuf::Message *message_ptr) {
73 return dynamic_cast<T *>(message_ptr);
74}
75
76// An abstract class of Parser.
77// One should use the create_xxx() functions to create a Parser object.
78class Parser {
79 public:
80 // Return a pointer to a parser. The caller should take ownership.
81 static Parser *CreateNovatel(const config::Config &config);
82 static Parser *CreateHuaCeText(const config::Config &config);
83 static Parser *CreateAsensingBinary(const config::Config &config);
84 static Parser *CreateAsensingCan(const config::Config &config);
85 static Parser *CreateBroadGnssText(const config::Config &config);
86
87 static Parser *CreateParser(const config::Config &config) {
88 switch (config.data().format()) {
90 return Parser::CreateNovatel(config);
92 return Parser::CreateHuaCeText(config);
94 return Parser::CreateAsensingBinary(config);
96 return Parser::CreateAsensingCan(config);
98 return Parser::CreateBroadGnssText(config);
99 default:
100 return nullptr;
101 }
102 }
103
104 // Return a pointer to rtcm v3 parser. The caller should take ownership.
105 static Parser *CreateRtcmV3(bool is_base_station = false);
106
107 virtual ~Parser() {}
108
109 // Updates the parser with new data. The caller must keep the data valid until
110 // GetMessage()
111 // returns NONE.
112 void Update(const uint8_t *data, size_t length) {
113 data_ = data;
114 data_end_ = data + length;
115 }
116
117 void Update(const std::string &data) {
118 Update(reinterpret_cast<const uint8_t *>(data.data()), data.size());
119 }
120 // Gets a parsed protobuf message. The caller must consume the message before
121 // calling another
122 // GetMessage() or Update();
123 virtual MessageType GetMessage(MessagePtr *message_ptr) {
124 return MessageType::NONE;
125 }
126
127 void GetMessagesByChannel(const uint8_t &channel, MessageInfoVec *messages) {
128 if (channel == 0) {
129 GetMessages(messages);
130 } else {
131 GetMessages(channel, messages);
132 }
133 }
134
135 virtual void GetMessages(const uint8_t &channel, MessageInfoVec *messages) {}
136
137 virtual void GetMessages(MessageInfoVec *messages) {}
138
139 virtual bool GetInsStat(MessagePtr *message_ptr) { return false; }
140
141 protected:
143
144 // Point to the beginning and end of data. Do not take ownership.
145 const uint8_t *data_ = nullptr;
146 const uint8_t *data_end_ = nullptr;
147
148 private:
150};
151
152} // namespace gnss
153} // namespace drivers
154} // namespace apollo
virtual void GetMessages(const uint8_t &channel, MessageInfoVec *messages)
Definition parser.h:135
virtual void GetMessages(MessageInfoVec *messages)
Definition parser.h:137
static Parser * CreateAsensingCan(const config::Config &config)
static Parser * CreateAsensingBinary(const config::Config &config)
void Update(const std::string &data)
Definition parser.h:117
static Parser * CreateRtcmV3(bool is_base_station=false)
virtual bool GetInsStat(MessagePtr *message_ptr)
Definition parser.h:139
void GetMessagesByChannel(const uint8_t &channel, MessageInfoVec *messages)
Definition parser.h:127
static Parser * CreateParser(const config::Config &config)
Definition parser.h:87
const uint8_t * data_
Definition parser.h:145
void Update(const uint8_t *data, size_t length)
Definition parser.h:112
static Parser * CreateHuaCeText(const config::Config &config)
static Parser * CreateNovatel(const config::Config &config)
const uint8_t * data_end_
Definition parser.h:146
static Parser * CreateBroadGnssText(const config::Config &config)
virtual MessageType GetMessage(MessagePtr *message_ptr)
Definition parser.h:123
#define DISABLE_COPY_AND_ASSIGN(TypeName)
Definition macros.h:32
::google::protobuf::Message * MessagePtr
Definition parser.h:34
T * As(::google::protobuf::Message *message_ptr)
Definition parser.h:72
std::vector< MessageInfo > MessageInfoVec
Definition parser.h:57
class register implement
Definition arena_queue.h:37