36 #define M_PI 3.14159265358979323846 47 data_start_offset_(0),
77 printf(
"Livox file version[%d]\n",
file_ver_);
130 memcpy((
void *)&device_info, (
void *)&device_info_v0,
132 memcpy((
void *)&device_info.
roll, (
void *)&device_info_v0.
roll,
146 lvx_file_.read((
char *)(&frame_header),
sizeof(frame_header));
160 if ((mode & std::ios::in) == std::ios::in) {
162 lvx_file_.open(filename, mode | std::ios_base::binary | std::ios_base::ate);
171 printf(
"Filesize %lu\n",
size_);
194 lvx_file_.open(filename, mode | std::ios_base::binary);
208 time_t curtime = time(
nullptr);
211 tm *local_time = localtime(&curtime);
212 strftime(filename,
sizeof(filename),
"%Y%m%d%H%M%S", local_time);
214 return Open(filename, std::ios::out | std::ios::binary);
261 memcpy(&write_buffer[cur_offset_], (
void *)&device_info_v0,
262 sizeof(device_info_v0));
263 cur_offset_ +=
sizeof(device_info_v0);
267 lvx_file_.write(&write_buffer[cur_offset_], cur_offset_);
271 std::list<LvxFilePacket> &point_packet_list_temp) {
274 std::unique_ptr<char[]> write_buffer(
new char[
kMaxFrameSize]);
278 for (
auto iter : point_packet_list_temp) {
284 memcpy(write_buffer.get() + cur_pos, (
void *)&frame_header,
288 for (
auto iter : point_packet_list_temp) {
289 if (cur_pos + iter.pack_size >= kMaxFrameSize) {
290 lvx_file_.write((
char *)write_buffer.get(), cur_pos);
292 memcpy(write_buffer.get() + cur_pos, (
void *)&(iter), iter.pack_size);
293 cur_pos += iter.pack_size;
295 memcpy(write_buffer.get() + cur_pos, (
void *)&(iter), iter.pack_size);
296 cur_pos += iter.pack_size;
299 lvx_file_.write((
char *)write_buffer.get(), cur_pos);
311 memcpy((
void *)&packet, (
void *)data,
GetEthPacketLen(data->data_type));
330 if (tmp_size >=
size_) {
331 printf(
"At the file end %lu\n", tmp_size);
340 lvx_file_.read((
char *)&frame_header,
sizeof(frame_header));
349 read_length = packets_of_frame->
data_size;
351 lvx_file_.read((
char *)&frame_header_v0,
sizeof(frame_header_v0));
360 read_length = packets_of_frame->
data_size;
387 if (
"Livox" == (std::string)root->
name()) {
389 device = device->next_sibling()) {
390 if (
"Device" == (std::string)device->name() &&
391 (strncmp(item.
info.broadcast_code, device->value(),
392 kBroadcastCodeSize) == 0)) {
399 if (
"roll" == (std::string)
param->name()) {
400 info.
roll =
static_cast<float>(atof(
param->value()));
402 if (
"pitch" == (std::string)
param->name()) {
403 info.
pitch =
static_cast<float>(atof(
param->value()));
405 if (
"yaw" == (std::string)
param->name()) {
406 info.
yaw =
static_cast<float>(atof(
param->value()));
408 if (
"x" == (std::string)
param->name()) {
409 info.
x =
static_cast<float>(atof(
param->value()));
411 if (
"y" == (std::string)
param->name()) {
412 info.
y =
static_cast<float>(atof(
param->value()));
414 if (
"z" == (std::string)
param->name()) {
415 info.
z =
static_cast<float>(atof(
param->value()));
This file contains rapidxml parser and DOM implementation.
LvxFilePublicHeader public_header_
bool ReadAndCheckHeader()
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
uint64_t PrivateHeaderOffset()
const uint32_t kMaxLvxFileHeaderLength
Represents data loaded from a file.
uint32_t cur_frame_index_
LvxFilePrivateHeader private_header_
const uint32_t kLvxHeaderMagicCode
const uint32_t kMaxFrameSize
uint64_t DataStartOffset()
const char * kLvxHeaderSigStr
uint8_t hub_broadcast_code[16]
int GetDeviceInfo(uint8_t idx, LvxFileDeviceInfo *info)
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
int GetPacketsOfFrame(OutPacketBuffer *PacketsOfFrame)
int GetLvxFileReadProgress()
int Open(const char *filename, std::ios_base::openmode mode)
void SaveFrameToLvxFile(std::list< LvxFilePacket > &point_packet_list_temp)
std::vector< LvxFileDeviceInfo > device_info_list_
unsigned __int64 uint64_t
uint64_t DataSizeOfFrame(FrameHeader &frame_header)
uint8_t lidar_broadcast_code[16]
void BasePointsHandle(LivoxEthPacket *data, LvxFilePacket &packet)
LvxFilePrivateHeaderV0 private_header_v0_
void AddDeviceInfo(LvxFileDeviceInfo &info)
uint32_t GetEthPacketLen(uint32_t data_type)
void ParseExtrinsicXml(DeviceItem &item, LvxFileDeviceInfo &info)
bool AddAndCheckDeviceInfo()