Apollo 10.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 *CreateAsensing(const config::Config &config);
84 static Parser *CreateBroadGnssText(const config::Config &config);
85 static Parser *CreateEnbroad(const config::Config &config);
86 static Parser *CreateForsenseText(const config::Config &config);
87
88 static Parser *CreateParser(const config::Config &config) {
89 switch (config.data().format()) {
91 return Parser::CreateNovatel(config);
93 return Parser::CreateHuaCeText(config);
95 return Parser::CreateAsensing(config);
97 return Parser::CreateBroadGnssText(config);
99 return Parser::CreateEnbroad(config);
101 return Parser::CreateForsenseText(config);
102 default:
103 return nullptr;
104 }
105 }
106
107 // Return a pointer to rtcm v3 parser. The caller should take ownership.
108 static Parser *CreateRtcmV3(bool is_base_station = false);
109
110 virtual ~Parser() {}
111
112 // Updates the parser with new data. The caller must keep the data valid until
113 // GetMessage()
114 // returns NONE.
115 void Update(const uint8_t *data, size_t length) {
116 data_ = data;
117 data_end_ = data + length;
118 }
119
120 void Update(const std::string &data) {
121 Update(reinterpret_cast<const uint8_t *>(data.data()), data.size());
122 }
123 // Gets a parsed protobuf message. The caller must consume the message before
124 // calling another
125 // GetMessage() or Update();
126 virtual MessageType GetMessage(MessagePtr *message_ptr) {
127 return MessageType::NONE;
128 }
129
130 virtual void GetMessages(MessageInfoVec *messages) {}
131
132 virtual bool GetInsStat(MessagePtr *message_ptr) { return false; }
133
134 protected:
136
137 // Point to the beginning and end of data. Do not take ownership.
138 const uint8_t *data_ = nullptr;
139 const uint8_t *data_end_ = nullptr;
140
141 private:
143};
144
145} // namespace gnss
146} // namespace drivers
147} // namespace apollo
static Parser * CreateForsenseText(const config::Config &config)
virtual void GetMessages(MessageInfoVec *messages)
Definition parser.h:130
void Update(const std::string &data)
Definition parser.h:120
static Parser * CreateRtcmV3(bool is_base_station=false)
static Parser * CreateEnbroad(const config::Config &config)
virtual bool GetInsStat(MessagePtr *message_ptr)
Definition parser.h:132
static Parser * CreateParser(const config::Config &config)
Definition parser.h:88
const uint8_t * data_
Definition parser.h:138
void Update(const uint8_t *data, size_t length)
Definition parser.h:115
static Parser * CreateHuaCeText(const config::Config &config)
static Parser * CreateNovatel(const config::Config &config)
const uint8_t * data_end_
Definition parser.h:139
static Parser * CreateBroadGnssText(const config::Config &config)
static Parser * CreateAsensing(const config::Config &config)
virtual MessageType GetMessage(MessagePtr *message_ptr)
Definition parser.h:126
#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