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