Apollo  6.0
Open source self driving car software
parser.h
Go to the documentation of this file.
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 
22 #include "google/protobuf/message.h"
23 
24 #include "modules/drivers/gnss/proto/config.pb.h"
25 
27 
28 namespace apollo {
29 namespace drivers {
30 namespace gnss {
31 
32 // convert gps time (base on Jan 6 1980) to system time (base on Jan 1 1970)
33 // notice: Jan 6 1980
34 //
35 // linux shell:
36 // time1 = date +%s -d"Jan 6, 1980 00:00:01"
37 // time2 = date +%s -d"Jan 1, 1970 00:00:01"
38 // dif_tick = time1-time2
39 // 315964800 = 315993601 - 28801
40 
41 #define EPOCH_AND_SYSTEM_DIFF_SECONDS 315964800
42 
43 // A helper function that returns a pointer to a protobuf message of type T.
44 template <class T>
45 inline T *As(::google::protobuf::Message *message_ptr) {
46  return dynamic_cast<T *>(message_ptr);
47 }
48 
49 // An abstract class of Parser.
50 // One should use the create_xxx() functions to create a Parser object.
51 class Parser {
52  public:
53  // A general pointer to a protobuf message.
54  using MessagePtr = ::google::protobuf::Message *;
55  // Return a pointer to a NovAtel parser. The caller should take ownership.
56  static Parser *CreateNovatel(const config::Config &config);
57 
58  // Return a pointer to rtcm v3 parser. The caller should take ownership.
59  static Parser *CreateRtcmV3(bool is_base_station = false);
60 
61  virtual ~Parser() {}
62 
63  // Updates the parser with new data. The caller must keep the data valid until
64  // GetMessage()
65  // returns NONE.
66  void Update(const uint8_t *data, size_t length) {
67  data_ = data;
68  data_end_ = data + length;
69  }
70 
71  void Update(const std::string &data) {
72  Update(reinterpret_cast<const uint8_t *>(data.data()), data.size());
73  }
74 
75  enum class MessageType {
76  NONE,
77  GNSS,
78  GNSS_RANGE,
79  IMU,
80  INS,
81  INS_STAT,
82  WHEEL,
85  GPGGA,
87  RAWIMU,
91  HEADING,
92  };
93 
94  // Gets a parsed protobuf message. The caller must consume the message before
95  // calling another
96  // GetMessage() or Update();
97  virtual MessageType GetMessage(MessagePtr *message_ptr) = 0;
98 
99  protected:
100  Parser() {}
101 
102  // Point to the beginning and end of data. Do not take ownership.
103  const uint8_t *data_ = nullptr;
104  const uint8_t *data_end_ = nullptr;
105 
106  private:
108 };
109 
110 } // namespace gnss
111 } // namespace drivers
112 } // namespace apollo
void Update(const uint8_t *data, size_t length)
Definition: parser.h:66
virtual ~Parser()
Definition: parser.h:61
::google::protobuf::Message * MessagePtr
Definition: parser.h:54
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
MessageType
Definition: parser.h:75
void Update(const std::string &data)
Definition: parser.h:71
Definition: parser.h:51
static Parser * CreateRtcmV3(bool is_base_station=false)
Parser()
Definition: parser.h:100
virtual MessageType GetMessage(MessagePtr *message_ptr)=0
T * As(::google::protobuf::Message *message_ptr)
Definition: parser.h:45
#define DISABLE_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:32
const uint8_t * data_
Definition: parser.h:103
static Parser * CreateNovatel(const config::Config &config)
const uint8_t * data_end_
Definition: parser.h:104