Apollo 11.0
自动驾驶开放平台
protocol_asensing.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 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 <functional>
20#include <map>
21#include <memory>
22#include <string>
23#include <vector>
24
25typedef struct {
26 /*俯仰角*/
27 float Pitch_deg;
28 /*横滚角*/
29 float Roll_deg;
30 /*航向角*/
31 float Yaw_deg;
32
33 float GyroX;
34 float GyroY;
35 float GyroZ;
36 float AccX_g; /* 零偏修正后加速度计 */
37 float AccY_g; /* 零偏修正后加速度计 */
38 float AccZ_g; /* 零偏修正后加速度计 */
39
40 double Lon_gnss_deg; // RTK融合后Longitude (deg)
41 double Lat_gnss_deg; // RTK融合后Latitude (deg)
42 float Alt_gnss_m; // RTK融合后Altitude (m)
43
44 double Lon_deg; // IMU融合后Longitude (deg)
45 double Lat_deg; // IMU融合后Latitude (deg)
46 float Alt_m; // IMU融合后Altitude (m)
47
48 float VelN_mps; /*融合后 NED north velocity (m/s) */
49 float VelE_mps; /*融合后 NED east velocity (m/s) */
50 float VelD_mps; /*融合后 NED down velocity (m/s) */
51
52 uint8_t InsStatus; /*初始化标志位*/
53
54 uint8_t ModeStatus;
55
56 uint8_t LoopType;
57 float data1;
58 float data2;
59 float data3;
60
61 int64_t SysTime_ms; /*时间戳 系统时间*/
62
63 uint8_t flag_pos;
64
65 // rtk age
67} InsType;
68
69template <typename T>
70T toValue(const uint8_t* add, int& index) {
71 T result = *reinterpret_cast<const T*>(add + index);
72 index += sizeof(T);
73 return result;
74}
75
76template <typename T>
77T toValue(const char* add, int& index) {
78 T result = *reinterpret_cast<const T*>(add + index);
79 index += sizeof(T);
80 return result;
81}
82
84 public:
86 virtual ~ProtocolAsensing();
87
88 /* subclass parse Protocol */
89 virtual void subData(const uint8_t* sub_address, int& index) {
90 printf("get protocol type:%02X %02X %02X \n", sub_address[index],
91 sub_address[index + 1], sub_address[index + 2]);
92 }
93
94 void addData(const std::string& data);
95 void clearCache();
96 bool registProtocol(const std::string& protocolFlag, int length,
97 ProtocolAsensing* sub);
98 void toQuaternion(double* rpy, double* quaterArray);
99
100 inline int getLength(const std::string& flag) {
101 return protocolLengthMap[flag];
102 }
103 inline uint32_t getDataSize() { return receive_data_.size(); }
104 inline void changeLength(const std::string& flag, int len) {
105 protocolLengthMap[flag] = len;
106 }
107
108 std::string getProtocol() { return cur_protocol_; }
109
110 private:
111 bool analysisData(const std::string& data);
112
113 private:
114 std::string receive_data_; // 解析自定义数据
115 std::string cur_protocol_;
116
117 static std::map<std::string, int> protocolLengthMap;
118 static std::map<std::string, ProtocolAsensing*> protocolMap;
119};
120
121class Decode_0A final : public ProtocolAsensing {
122 public:
123 explicit Decode_0A();
124 virtual ~Decode_0A();
125
126 void subData(const uint8_t* sub_address, int& index);
127
128 private:
129 /* protocol info */
130 std::string m_type = "BDDB0A";
131 int m_length = 34;
132
133 std::string filename1;
134 std::string content1;
135};
136
137class Decode_0B final : public ProtocolAsensing {
138 public:
139 explicit Decode_0B();
140 virtual ~Decode_0B();
141
142 void subData(const uint8_t* sub_address, int& index);
143 void parse0B(const uint8_t* data, int& pos);
144 void parseGnss(const uint8_t* data, int& pos);
145
147 uint8_t update_ins = 0;
148
149 /* protocol info */
150 std::string m_typeImu = "BDDB0B";
151 int m_lengthImu = 63;
152 std::string m_typeGnss = "BDDB10";
153 int m_lengthGnss = 83;
154
155 private:
156 std::string filename2;
157 std::string content2;
158
159 std::string filename0b;
160 std::string content0b;
161};
162
163bool createFileAndWrite(const std::string& filename,
164 const std::string& content);
165bool AppendCsv(const std::string& filename,
166 const std::vector<std::string>& data);
void subData(const uint8_t *sub_address, int &index)
Definition decode_0A.cc:34
virtual ~Decode_0A()
Definition decode_0A.cc:32
std::string m_typeGnss
void parseGnss(const uint8_t *data, int &pos)
Definition decode_0B.cc:232
virtual ~Decode_0B()
Definition decode_0B.cc:77
std::string m_typeImu
void parse0B(const uint8_t *data, int &pos)
Definition decode_0B.cc:95
void subData(const uint8_t *sub_address, int &index)
Definition decode_0B.cc:79
void toQuaternion(double *rpy, double *quaterArray)
bool registProtocol(const std::string &protocolFlag, int length, ProtocolAsensing *sub)
std::string getProtocol()
int getLength(const std::string &flag)
void changeLength(const std::string &flag, int len)
void addData(const std::string &data)
virtual void subData(const uint8_t *sub_address, int &index)
bool createFileAndWrite(const std::string &filename, const std::string &content)
T toValue(const uint8_t *add, int &index)
bool AppendCsv(const std::string &filename, const std::vector< std::string > &data)
uint8_t InsStatus
double Lon_gnss_deg
double Lat_gnss_deg
float differential_age
uint8_t flag_pos
uint8_t LoopType
uint8_t ModeStatus
int64_t SysTime_ms