Apollo 11.0
自动驾驶开放平台
apollo::drivers::lslidar::driver::InputPCAP类 参考

lslidar input from PCAP dump file. 更多...

#include <input.h>

类 apollo::drivers::lslidar::driver::InputPCAP 继承关系图:
apollo::drivers::lslidar::driver::InputPCAP 的协作图:

Public 成员函数

 InputPCAP (uint16_t port=MSOP_DATA_PORT_NUMBER, std::string lidar_ip="192.168.1.200", int packet_size=1212, double packet_rate=0.0, std::string filename="", bool read_once=false, bool read_fast=false, double repeat_delay=0.0)
 
virtual ~InputPCAP ()
 destructor
 
virtual int GetPacket (LslidarPacket *pkt)
 Get one lslidar packet.
 
- Public 成员函数 继承自 apollo::drivers::lslidar::driver::Input
 Input (uint16_t portport=MSOP_DATA_PORT_NUMBER, std::string lidar_ip="192.168.1.200", int packet_size=1212)
 
virtual ~Input ()
 

额外继承的成员函数

- Protected 属性 继承自 apollo::drivers::lslidar::driver::Input
int port_
 
int sockfd_
 
uint64_t pointcloudTimeStamp
 
in_addr devip_
 
int packet_size_
 

详细描述

lslidar input from PCAP dump file.

Dump files can be grabbed by libpcap

在文件 input.h69 行定义.

构造及析构函数说明

◆ InputPCAP()

apollo::drivers::lslidar::driver::InputPCAP::InputPCAP ( uint16_t  port = MSOP_DATA_PORT_NUMBER,
std::string  lidar_ip = "192.168.1.200",
int  packet_size = 1212,
double  packet_rate = 0.0,
std::string  filename = "",
bool  read_once = false,
bool  read_fast = false,
double  repeat_delay = 0.0 
)

在文件 input.cc148 行定义.

156 :
157 Input(port, lidar_ip, packet_size),
158 packet_rate_(packet_rate),
159 filename_(filename) {
160 pcap_ = NULL;
161 empty_ = true;
162 packet_rate_ = packet_rate;
163 lidar_ip_ = lidar_ip;
164 // get parameters using private node handle
165 read_once_ = read_once;
166 read_fast_ = read_fast;
167 repeat_delay_ = repeat_delay;
168
169 if (read_once_)
170 AINFO << "Read input file only once.";
171 if (read_fast_)
172 AINFO << "Read input file as quickly as possible.";
173 if (repeat_delay_ > 0.0)
174 AINFO << "Delay %.3f seconds before repeating input file."
175 << repeat_delay_;
176
177 // Open the PCAP dump file
178 AERROR << "Opening PCAP file " << filename_;
179 if ((pcap_ = pcap_open_offline(filename_.c_str(), errbuf_)) == NULL) {
180 AERROR << "Error opening lslidar socket dump file.";
181 return;
182 }
183
184 std::stringstream filter;
185 if (lidar_ip != "") {
186 filter << "src host " << lidar_ip << " && ";
187 }
188 filter << "udp dst port " << port;
189 pcap_compile(
190 pcap_,
191 &pcap_packet_filter_,
192 filter.str().c_str(),
193 1,
194 PCAP_NETMASK_UNKNOWN);
195}
Input(uint16_t portport=MSOP_DATA_PORT_NUMBER, std::string lidar_ip="192.168.1.200", int packet_size=1212)
Definition input.cc:35
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42

◆ ~InputPCAP()

apollo::drivers::lslidar::driver::InputPCAP::~InputPCAP ( void  )
virtual

destructor

在文件 input.cc198 行定义.

198 {
199 pcap_close(pcap_);
200}

成员函数说明

◆ GetPacket()

int apollo::drivers::lslidar::driver::InputPCAP::GetPacket ( LslidarPacket pkt)
virtual

Get one lslidar packet.

重载 apollo::drivers::lslidar::driver::Input .

在文件 input.cc203 行定义.

203 {
204 struct pcap_pkthdr *header;
205 const u_char *pkt_data;
206
207 // while (flag == 1)
208 while (!apollo::cyber::IsShutdown()) {
209 int res;
210 if ((res = pcap_next_ex(pcap_, &header, &pkt_data)) >= 0) {
211 // Skip packets not for the correct port and from the
212 // selected IP address.
213 if (!lidar_ip_.empty()
214 && (0
215 == pcap_offline_filter(
216 &pcap_packet_filter_, header, pkt_data)))
217 continue;
218
219 // Keep the reader from blowing through the file.
220 if (read_fast_ == false)
221 usleep(static_cast<int>(1000 * 1000 / packet_rate_ / 1.1));
222 if (1206 == packet_size_) {
223 uint8_t bytes[1206];
224 memcpy(bytes, pkt_data + 42, packet_size_);
225 pkt->set_data(bytes, packet_size_);
226 } else if (1212 == packet_size_) {
227 uint8_t bytes[1212];
228 memcpy(bytes, pkt_data + 42, packet_size_);
229 pkt->set_data(bytes, packet_size_);
230 }
231
232 empty_ = false;
233 return 0; // success
234 }
235
236 if (empty_) {
237 AINFO << "Error " << res
238 << " reading lslidar packet: " << pcap_geterr(pcap_);
239 return -1;
240 }
241
242 if (read_once_) {
243 AINFO << "end of file reached -- done reading.";
244 return -1;
245 }
246
247 if (repeat_delay_ > 0.0) {
248 AINFO << "end of file reached -- delaying" << repeat_delay_
249 << "seconds.";
250 usleep(rint(repeat_delay_ * 1000000.0));
251 }
252
253 AINFO << "replaying lslidar dump file";
254
255 // I can't figure out how to rewind the file, because it
256 // starts with some kind of header. So, close the file
257 // and reopen it with pcap.
258 pcap_close(pcap_);
259 pcap_ = pcap_open_offline(filename_.c_str(), errbuf_);
260 empty_ = true; // maybe the file disappeared?
261 } // loop back and try again
262 return 0;
263}
bool IsShutdown()
Definition state.h:46

该类的文档由以下文件生成: