forked from Livox-SDK/Livox-SDK2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params_check.cpp
182 lines (154 loc) · 6.46 KB
/
params_check.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
// The MIT License (MIT)
//
// Copyright (c) 2022 Livox. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#include "params_check.h"
#include "livox_lidar_def.h"
#include "comm/define.h"
#include "base/logging.h"
#include <iostream>
#include <string>
#include <memory>
#include <vector>
#include <set>
namespace livox {
namespace lidar {
ParamsCheck::ParamsCheck(std::shared_ptr<std::vector<LivoxLidarCfg>>& lidars_cfg_ptr,
std::shared_ptr<std::vector<LivoxLidarCfg>>& custom_lidars_cfg_ptr) : lidars_cfg_ptr_(lidars_cfg_ptr),
custom_lidars_cfg_ptr_(custom_lidars_cfg_ptr) {}
bool ParamsCheck::Check() {
if (lidars_cfg_ptr_ == nullptr && custom_lidars_cfg_ptr_ == nullptr) {
LOG_ERROR("Params check failed, all params is nullptr.");
return false;
}
if (lidars_cfg_ptr_->empty() && custom_lidars_cfg_ptr_->empty()) {
LOG_ERROR("Params check failed, all livox lidars config is empty.");
return false;
}
if (!CheckLidarIp()) {
return false;
}
CheckLidarPort();
if (!CheckLidarMulticastIp()) {
return false;
}
return true;
}
bool ParamsCheck::CheckLidarIp() {
std::set<std::string> lidars_ip;
for (auto it = lidars_cfg_ptr_->begin(); it != lidars_cfg_ptr_->end(); ++it) {
if (it->lidar_net_info.lidar_ipaddr.empty()) {
continue;
}
if (lidars_ip.find(it->lidar_net_info.lidar_ipaddr) != lidars_ip.end()) {
LOG_ERROR("Params check failed, lidar ip conflict, the liar ip:{}", it->lidar_net_info.lidar_ipaddr.c_str());
return false;
}
lidars_ip.insert(it->lidar_net_info.lidar_ipaddr);
}
for (auto it = custom_lidars_cfg_ptr_->begin(); it != custom_lidars_cfg_ptr_->end(); ++it) {
if (it->lidar_net_info.lidar_ipaddr.empty()) {
LOG_ERROR("Params check failed, custom lidar ipaddr is empty.");
return false;
}
if (lidars_ip.find(it->lidar_net_info.lidar_ipaddr) != lidars_ip.end()) {
LOG_ERROR("Params check failed, lidar ip conflict the lidar ip:{}", it->lidar_net_info.lidar_ipaddr.c_str());
return false;
}
lidars_ip.insert(it->lidar_net_info.lidar_ipaddr);
}
return true;
}
bool ParamsCheck::CheckLidarMulticastIp() {
for (auto it = lidars_cfg_ptr_->begin(); it != lidars_cfg_ptr_->end(); ++it) {
if (it->host_net_info.multicast_ip.empty()) {
LOG_INFO("Device type:{} point cloud data and IMU data unicast is enabled.", it->device_type);
continue;
}
std::vector<uint8_t> vec_host_ip;
if (!BuildRequest::IpToU8(it->host_net_info.multicast_ip, ".", vec_host_ip)) {
return false;
}
std::reverse(vec_host_ip.begin(), vec_host_ip.end());
uint32_t net_ip = 0;
memcpy(&net_ip, vec_host_ip.data(), sizeof(uint8_t) * 4);
if (net_ip <= 0xE0000000 || net_ip > 0xEFFFFFFF) {
LOG_ERROR("Params check failed, lidar multicast ip error:{}", it->host_net_info.multicast_ip.c_str());
return false;
}
LOG_INFO("Device type:{} point cloud and IMU data multicast ip:{}", it->device_type, it->host_net_info.multicast_ip.c_str());
}
for (auto it = custom_lidars_cfg_ptr_->begin(); it != custom_lidars_cfg_ptr_->end(); ++it) {
if (it->host_net_info.multicast_ip.empty()) {
LOG_INFO("Lidar ip:{} point cloud data and IMU data unicast is enabled.", it->lidar_net_info.lidar_ipaddr.c_str());
continue;
}
std::vector<uint8_t> vec_host_ip;
if (!BuildRequest::IpToU8(it->host_net_info.multicast_ip, ".", vec_host_ip)) {
return false;
}
std::reverse(vec_host_ip.begin(), vec_host_ip.end());
uint32_t net_ip = 0;
memcpy(&net_ip, vec_host_ip.data(), sizeof(uint8_t) * 4);
if (net_ip <= 0xE0000000 || net_ip > 0xEFFFFFFF) {
LOG_ERROR("Params check failed, lidar multicast ip error:{}", it->host_net_info.multicast_ip.c_str());
return false;
}
LOG_INFO("Lidar ip:{} point cloud and IMU data multicast ip:{}", it->lidar_net_info.lidar_ipaddr.c_str(), it->host_net_info.multicast_ip.c_str());
}
return true;
}
void ParamsCheck::CheckLidarPort() {
for (auto it = lidars_cfg_ptr_->begin(); it != lidars_cfg_ptr_->end(); ++it) {
CheckPort(it->device_type, it->lidar_net_info);
}
for (auto it = custom_lidars_cfg_ptr_->begin(); it != custom_lidars_cfg_ptr_->end(); ++it) {
CheckPort(it->device_type, it->lidar_net_info);
}
}
void ParamsCheck::CheckPort(const uint8_t dev_type, LivoxLidarNetInfo& lidar_net_info) {
if (dev_type != kLivoxLidarTypeMid360) {
return;
}
if (lidar_net_info.cmd_data_port != kMid360LidarCmdPort) {
LOG_ERROR("Mid360 lidar command data port must be {}", kMid360LidarCmdPort);
lidar_net_info.cmd_data_port = kMid360LidarCmdPort;
}
if (lidar_net_info.push_msg_port != kMid360LidarPushMsgPort) {
LOG_ERROR("Mid360 lidar push msg port must be {}", kMid360LidarPushMsgPort);
lidar_net_info.push_msg_port = kMid360LidarPushMsgPort;
}
if (lidar_net_info.point_data_port != kMid360LidarPointCloudPort) {
LOG_ERROR("Mid360 lidar point cloud port must be {}", kMid360LidarPointCloudPort);
lidar_net_info.point_data_port = kMid360LidarPointCloudPort;
}
if (lidar_net_info.imu_data_port != kMid360LidarImuDataPort) {
LOG_ERROR("Mid360 lidar imu data port must be {}", kMid360LidarImuDataPort);
lidar_net_info.imu_data_port = kMid360LidarImuDataPort;
}
if (lidar_net_info.log_data_port != kMid360LidarLogPort) {
LOG_ERROR("Mid360 lidar log port must be {}", kMid360LidarLogPort);
lidar_net_info.log_data_port = kMid360LidarLogPort;
}
}
} // namespace lidar
} // namespace livox