lvx_file.h
Go to the documentation of this file.
1 //
2 // The MIT License (MIT)
3 //
4 // Copyright (c) 2019 Livox. All rights reserved.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //
24 #ifndef LIVOX_FILE_H_
25 #define LIVOX_FILE_H_
26 
27 #include <fstream>
28 #include <ios>
29 #include <list>
30 #include <memory>
31 #include <mutex>
32 #include <vector>
33 #include "livox_sdk.h"
34 
35 namespace livox_ros {
36 
37 #define kMaxPointSize 1500
38 #define kDefaultFrameDurationTime 50
39 const uint32_t kMaxFrameSize = 2048 * 1024;
40 
41 typedef enum {
45 } DeviceState;
46 
47 typedef enum {
58 } LvxFileState;
59 
60 typedef enum {
65 
66 typedef struct {
69  DeviceInfo info;
70 } DeviceItem;
71 
72 #pragma pack(1)
73 
74 typedef struct {
75  uint8_t signature[16];
76  uint8_t version[4];
79 
80 typedef struct {
84 
85 typedef struct {
86  uint8_t lidar_broadcast_code[16];
87  uint8_t hub_broadcast_code[16];
91  float roll;
92  float pitch;
93  float yaw;
94  float x;
95  float y;
96  float z;
98 
99 typedef struct {
108  uint8_t timestamp[8];
109  uint8_t raw_point[kMaxPointSize];
111 } LvxFilePacket;
112 
113 typedef struct {
117 } FrameHeader;
118 
119 typedef struct {
122 } LvxFileFrame;
123 
125 
126 typedef struct {
127  uint8_t lidar_broadcast_code[16];
128  uint8_t hub_broadcast_code[16];
131  float roll;
132  float pitch;
133  float yaw;
134  float x;
135  float y;
136  float z;
138 
139 typedef struct {
148  uint8_t timestamp[8];
149  LivoxPoint raw_point[100];
151 
152 typedef struct {
157 } FrameHeaderV0;
158 
159 typedef struct {
163 
164 typedef struct {
165  uint32_t buffer_capacity; /* max buffer size */
166  uint32_t data_size; /* frame data erea size */
167  uint8_t *packet; /* packet data erea */
169 
170 #pragma pack()
171 
173  public:
174  LvxFileHandle();
175  ~LvxFileHandle() = default;
176 
177  int Open(const char *filename, std::ios_base::openmode mode);
178  bool Eof();
179 
180  int InitLvxFile();
181  void InitLvxFileHeader();
182  void SaveFrameToLvxFile(std::list<LvxFilePacket> &point_packet_list_temp);
183  void BasePointsHandle(LivoxEthPacket *data, LvxFilePacket &packet);
184  void CloseLvxFile();
185 
187  device_info_list_.push_back(info);
188  }
189  int GetDeviceInfoListSize() { return device_info_list_.size(); }
190  int GetDeviceCount() { return device_count_; }
191  int GetDeviceInfo(uint8_t idx, LvxFileDeviceInfo *info);
192  int GetFileState(void) { return state_; };
193  int GetPacketsOfFrame(OutPacketBuffer *PacketsOfFrame);
195  int GetFileVersion() { return file_ver_; }
196 
197  private:
198  std::fstream lvx_file_;
199  std::vector<LvxFileDeviceInfo> device_info_list_;
210  int mode_;
211  int state_;
212 
217 
218  bool ReadAndCheckHeader();
219  bool AddAndCheckDeviceInfo();
220  bool PrepareDataRead();
221 
223  return (frame_header.next_offset - frame_header.current_offset -
224  sizeof(frame_header));
225  }
226 
228  return (frame_header_v0.next_offset - frame_header_v0.current_offset -
229  sizeof(frame_header_v0));
230  }
231 };
232 
233 } // namespace livox_ros
234 #endif
LvxFilePublicHeader public_header_
Definition: lvx_file.h:202
filename
DeviceState device_state
Definition: lvx_file.h:68
uint64_t DataSizeOfFrame(FrameHeaderV0 &frame_header_v0)
Definition: lvx_file.h:227
uint64_t PrivateHeaderOffset()
Definition: lvx_file.cpp:94
LvxFilePrivateHeader private_header_
Definition: lvx_file.h:203
const uint32_t kMaxFrameSize
Definition: lvx_file.h:39
FrameHeaderV0 header
Definition: lvx_file.h:160
uint64_t DataStartOffset()
Definition: lvx_file.cpp:98
LvxFilePacket * packet
Definition: lvx_file.h:121
unsigned char uint8_t
Definition: stdint.h:125
#define kMaxPointSize
Definition: lvx_file.h:37
int GetDeviceInfo(uint8_t idx, LvxFileDeviceInfo *info)
Definition: lvx_file.cpp:314
LvxFilePacketV0 * packet
Definition: lvx_file.h:161
int GetPacketsOfFrame(OutPacketBuffer *PacketsOfFrame)
Definition: lvx_file.cpp:323
int Open(const char *filename, std::ios_base::openmode mode)
Definition: lvx_file.cpp:159
void SaveFrameToLvxFile(std::list< LvxFilePacket > &point_packet_list_temp)
Definition: lvx_file.cpp:270
uint64_t current_offset
Definition: lvx_file.h:114
std::vector< LvxFileDeviceInfo > device_info_list_
Definition: lvx_file.h:199
LvxFileVersion
Definition: lvx_file.h:60
unsigned int uint32_t
Definition: stdint.h:127
unsigned __int64 uint64_t
Definition: stdint.h:137
uint64_t data_start_offset_
Definition: lvx_file.h:208
uint64_t DataSizeOfFrame(FrameHeader &frame_header)
Definition: lvx_file.h:222
void BasePointsHandle(LivoxEthPacket *data, LvxFilePacket &packet)
Definition: lvx_file.cpp:309
LvxFilePrivateHeaderV0 private_header_v0_
Definition: lvx_file.h:204
DeviceInfo info
Definition: lvx_file.h:69
void AddDeviceInfo(LvxFileDeviceInfo &info)
Definition: lvx_file.h:186
FrameHeader header
Definition: lvx_file.h:120
std::fstream lvx_file_
Definition: lvx_file.h:198
LvxFileState
Definition: lvx_file.h:47


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46