63 const char *user_config_path) {
65 printf(
"LiDAR data source is already inited!\n");
71 printf(
"Livox-SDK init fail!\n");
75 LivoxSdkVersion _sdkversion;
76 GetLivoxSdkVersion(&_sdkversion);
77 printf(
"Livox SDK version %d.%d.%d\n", _sdkversion.major, _sdkversion.minor,
84 for (
auto input_str : broadcast_code_strs) {
92 printf(
"Disable auto connect mode!\n");
94 printf(
"List all broadcast code in whiltelist:\n");
101 "No broadcast code was added to whitelist, swith to automatic " 102 "connection mode!\n");
108 printf(
"Timesync init fail\n");
113 printf(
"Set Timesync callback fail\n");
123 printf(
"Livox-SDK init fail!\n");
128 if (g_lds_ldiar ==
nullptr) {
132 printf(
"Livox-SDK init success!\n");
139 printf(
"LiDAR data source is not exit");
144 printf(
"Livox SDK Deinit completely!\n");
159 uint32_t data_num,
void *client_data) {
163 LivoxEthPacket *eth_packet = data;
165 if (!data || !data_num || (handle >= kMaxLidarCount)) {
173 if (info ==
nullptr) {
177 if (info->dev_type == kDeviceTypeHub) {
178 printf(
"In lidar mode, couldn't connect a hub : %s\n",
179 info->broadcast_code);
184 printf(
"In automatic connection mode, will connect %s\n",
185 info->broadcast_code);
188 printf(
"Not in the whitelist, please add %s to if want to connect!\n",
189 info->broadcast_code);
196 result = AddLidarToConnect(info->broadcast_code, &handle);
197 if (result == kStatusSuccess && handle < kMaxLidarCount) {
205 if (g_lds_ldiar->
GetRawConfig(info->broadcast_code, config)) {
206 printf(
"Could not find raw config, set config to default!\n");
223 printf(
"Add lidar to connect is failed : %d %d \n", result, handle);
229 if (info ==
nullptr) {
234 if (handle >= kMaxLidarCount) {
239 if (type == kEventConnect) {
243 p_lidar->
info = *info;
245 }
else if (type == kEventDisconnect) {
246 printf(
"Lidar[%s] disconnect!\n", info->broadcast_code);
248 }
else if (type == kEventStateChange) {
249 p_lidar->
info = *info;
253 printf(
"Lidar[%s] status_code[%d] working state[%d] feature[%d]\n",
254 p_lidar->
info.broadcast_code,
255 p_lidar->
info.status.status_code.error_code, p_lidar->
info.state,
256 p_lidar->
info.feature);
260 if (p_lidar->
info.state == kLidarStateNormal) {
271 if (kDeviceTypeLidarMid40 != info->type) {
272 LidarSetPointCloudReturnMode(
279 (kDeviceTypeLidarMid40 != info->type)) {
280 LidarSetImuPushFrequency(handle, (ImuFreq)(p_lidar->
config.
imu_rate),
292 if (kDeviceTypeLidarTele == info->type) {
295 printf(
"Enable high sensitivity\n");
299 printf(
"Disable high sensitivity\n");
311 DeviceInformationResponse *ack,
313 if (status != kStatusSuccess) {
314 printf(
"Device Query Informations Failed : %d\n", status);
317 printf(
"firmware version: %d.%d.%d.%d\n", ack->firmware_version[0],
318 ack->firmware_version[1], ack->firmware_version[2],
319 ack->firmware_version[3]);
325 ErrorMessage *message) {
326 static uint32_t error_message_count = 0;
327 if (message != NULL) {
328 ++error_message_count;
329 if (0 == (error_message_count % 100)) {
330 printf(
"handle: %u\n", handle);
331 printf(
"temp_status : %u\n", message->lidar_error_code.temp_status);
332 printf(
"volt_status : %u\n", message->lidar_error_code.volt_status);
333 printf(
"motor_status : %u\n", message->lidar_error_code.motor_status);
334 printf(
"dirty_warn : %u\n", message->lidar_error_code.dirty_warn);
335 printf(
"firmware_err : %u\n", message->lidar_error_code.firmware_err);
336 printf(
"pps_status : %u\n", message->lidar_error_code.device_status);
337 printf(
"fan_status : %u\n", message->lidar_error_code.fan_status);
338 printf(
"self_heating : %u\n", message->lidar_error_code.self_heating);
339 printf(
"ptp_status : %u\n", message->lidar_error_code.ptp_status);
340 printf(
"time_sync_status : %u\n",
341 message->lidar_error_code.time_sync_status);
342 printf(
"system_status : %u\n", message->lidar_error_code.system_status);
348 uint8_t response,
void *clent_data) {}
351 uint8_t response,
void *clent_data) {
354 if (handle >= kMaxLidarCount) {
359 if (status == kStatusSuccess) {
360 printf(
"Set return mode success!\n");
369 LidarSetPointCloudReturnMode(
372 printf(
"Set return mode fail, try again!\n");
377 uint8_t response,
void *clent_data) {
380 if (handle >= kMaxLidarCount) {
385 if (status == kStatusSuccess) {
386 printf(
"Set coordinate success!\n");
401 printf(
"Set coordinate fail, try again!\n");
406 uint8_t response,
void *clent_data) {
409 if (handle >= kMaxLidarCount) {
414 if (status == kStatusSuccess) {
415 printf(
"Set imu rate success!\n");
424 LidarSetImuPushFrequency(handle, (ImuFreq)(p_lidar->
config.
imu_rate),
426 printf(
"Set imu rate fail, try again!\n");
432 livox_status status,
uint8_t handle,
433 LidarGetExtrinsicParameterResponse *response,
void *clent_data) {
435 if (handle >= kMaxLidarCount) {
439 if (status == kStatusSuccess) {
440 if (response !=
nullptr) {
441 printf(
"Lidar[%d] get ExtrinsicParameter status[%d] response[%d]\n",
442 handle, status, response->ret_code);
445 p_extrinsic->
euler[0] =
static_cast<float>(response->roll *
PI / 180.0);
446 p_extrinsic->
euler[1] =
static_cast<float>(response->pitch *
PI / 180.0);
447 p_extrinsic->
euler[2] =
static_cast<float>(response->yaw *
PI / 180.0);
448 p_extrinsic->
trans[0] =
static_cast<float>(response->x / 1000.0);
449 p_extrinsic->
trans[1] =
static_cast<float>(response->y / 1000.0);
450 p_extrinsic->
trans[2] =
static_cast<float>(response->z / 1000.0);
453 p_extrinsic->
enable =
true;
455 printf(
"Lidar[%d] get ExtrinsicParameter success!\n", handle);
464 printf(
"Lidar[%d] get ExtrinsicParameter fail!\n", handle);
466 }
else if (status == kStatusTimeout) {
467 printf(
"Lidar[%d] get ExtrinsicParameter timeout!\n", handle);
472 DeviceParameterResponse *response,
476 if (handle >= kMaxLidarCount) {
481 if (status == kStatusSuccess) {
483 printf(
"Set high sensitivity success!\n");
496 printf(
"Set high sensitivity fail, try again!\n");
502 uint8_t response,
void *clent_data) {
505 if (handle >= kMaxLidarCount) {
510 if (status == kStatusSuccess) {
513 printf(
"Lidar start sample fail : state[%d] handle[%d] res[%d]\n", status,
516 printf(
"Lidar start sample success\n");
518 }
else if (status == kStatusTimeout) {
520 printf(
"Lidar start sample timeout : state[%d] handle[%d] res[%d]\n",
521 status, handle, response);
527 uint8_t response,
void *clent_data) {}
530 uint8_t response,
void *client_data) {
531 if (handle >= kMaxLidarCount) {
534 printf(
"Set lidar[%d] sync time status[%d] response[%d]\n", handle, status,
543 for (
uint8_t handle = 0; handle < kMaxLidarCount; handle++) {
544 p_lidar = &(lds_lidar->
lidars_[handle]);
546 p_lidar->
info.state == kLidarStateNormal) {
547 livox_status status = LidarSetRmcSyncTime(handle, rmc, rmc_length,
549 if (status != kStatusSuccess) {
550 printf(
"Set GPRMC synchronization time error code: %d.\n", status);
558 if (!broadcast_code || (strlen(broadcast_code) > kBroadcastCodeSize) ||
564 printf(
"%s is alrealy exist!\n", broadcast_code);
575 if (!broadcast_code) {
581 kBroadcastCodeSize) == 0) {
591 if (!doc.HasMember(
"timesync_config") || !doc[
"timesync_config"].IsObject())
595 if (!
object.IsObject())
break;
597 if (!
object.HasMember(
"enable_timesync") ||
598 !
object[
"enable_timesync"].IsBool())
602 if (!
object.HasMember(
"device_name") || !
object[
"device_name"].IsString())
604 std::string device_name =
object[
"device_name"].GetString();
608 if (!
object.HasMember(
"comm_device_type") ||
609 !
object[
"comm_device_type"].IsInt())
614 if (!
object.HasMember(
"baudrate_index") ||
615 !
object[
"baudrate_index"].IsInt())
618 object[
"baudrate_index"].GetInt();
620 if (!
object.HasMember(
"parity_index") || !
object[
"parity_index"].IsInt())
623 object[
"parity_index"].GetInt();
627 printf(
"Enable timesync : \n");
629 printf(
"Uart[%s],baudrate index[%d],parity index[%d]\n",
635 printf(
"Disable timesync\n");
645 FILE *raw_file = std::fopen(pathname,
"rb");
647 printf(
"Open json config file fail!\n");
651 char read_buffer[32768];
652 rapidjson::FileReadStream config_file(raw_file, read_buffer,
653 sizeof(read_buffer));
656 if (!doc.ParseStream(config_file).HasParseError()) {
657 if (doc.HasMember(
"lidar_config") && doc[
"lidar_config"].IsArray()) {
659 size_t len = array.Size();
660 for (
size_t i = 0; i < len; i++) {
662 if (
object.IsObject()) {
664 memset(&config, 0,
sizeof(config));
665 if (
object.HasMember(
"broadcast_code") &&
666 object[
"broadcast_code"].IsString()) {
667 std::string broadcast_code =
object[
"broadcast_code"].GetString();
671 printf(
"User config file parse error\n");
675 if (
object.HasMember(
"enable_connect") &&
676 object[
"enable_connect"].IsBool()) {
679 if (
object.HasMember(
"enable_fan") &&
object[
"enable_fan"].IsBool()) {
680 config.
enable_fan =
object[
"enable_fan"].GetBool();
682 if (
object.HasMember(
"return_mode") &&
683 object[
"return_mode"].IsInt()) {
684 config.
return_mode =
object[
"return_mode"].GetInt();
686 if (
object.HasMember(
"coordinate") &&
object[
"coordinate"].IsInt()) {
687 config.
coordinate =
object[
"coordinate"].GetInt();
689 if (
object.HasMember(
"imu_rate") &&
object[
"imu_rate"].IsInt()) {
690 config.
imu_rate =
object[
"imu_rate"].GetInt();
692 if (
object.HasMember(
"extrinsic_parameter_source") &&
693 object[
"extrinsic_parameter_source"].IsInt()) {
695 object[
"extrinsic_parameter_source"].GetInt();
697 if (
object.HasMember(
"enable_high_sensitivity") &&
698 object[
"enable_high_sensitivity"].GetBool()) {
700 object[
"enable_high_sensitivity"].GetBool();
703 printf(
"broadcast code[%s] : %d %d %d %d %d %d\n",
710 printf(
"Raw config is already exist : %s \n",
720 printf(
"Parse timesync config fail\n");
724 printf(
"User config file parse error[%d]\n",
725 doc.ParseStream(config_file).HasParseError());
728 std::fclose(raw_file);
745 if (broadcast_code ==
nullptr) {
750 if (strncmp(ite_config.broadcast_code, broadcast_code,
751 kBroadcastCodeSize) == 0) {
760 if (broadcast_code ==
nullptr) {
765 if (strncmp(ite_config.broadcast_code, broadcast_code,
766 kBroadcastCodeSize) == 0) {
770 config.
imu_rate = ite_config.imu_rate;
static void SetImuRatePushFrequencyCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
int32_t InitTimeSync(const TimeSyncConfig &config)
bool enable_high_sensitivity
const uint32_t kDeviceTypeLidarMid70
static void SetRmcSyncTimeCb(livox_status status, uint8_t handle, uint8_t response, void *client_data)
std::vector< UserRawConfig > raw_config_
int GetRawConfig(const char *broadcast_code, UserRawConfig &config)
union livox_ros::CommDevConfig::@0 config
ExtrinsicParameter extrinsic_parameter
static void SetCoordinateCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
static void OnDeviceChange(const DeviceInfo *info, DeviceEvent type)
static TimeSync * GetInstance()
static void SetPointCloudReturnModeCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
static void OnDeviceBroadcast(const BroadcastDeviceInfo *info)
void EnableAutoConnectMode(void)
static void ControlFanCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
uint32_t whitelist_count_
int ParseConfigFile(const char *pathname)
char broadcast_code_whitelist_[kMaxLidarCount][kBroadcastCodeSize]
bool enable_high_sensitivity
bool IsExistInRawConfig(const char *broadcast_code)
int AddBroadcastCodeToWhitelist(const char *broadcast_code)
uint32_t extrinsic_parameter_source
TimeSyncConfig timesync_config_
virtual void PrepareExit(void)
int AddRawUserConfig(UserRawConfig &config)
static void StartSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
uint32_t extrinsic_parameter_source
static void ReceiveSyncTimeCallback(const char *rmc, uint32_t rmc_length, void *client_data)
static void ResetLidar(LidarDevice *lidar, uint8_t data_src)
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
static void OnLidarDataCb(uint8_t handle, LivoxEthPacket *data, uint32_t data_num, void *client_data)
static void GetLidarExtrinsicParameterCb(livox_status status, uint8_t handle, LidarGetExtrinsicParameterResponse *response, void *clent_data)
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
volatile uint32_t set_bits
int InitLdsLidar(std::vector< std::string > &broadcast_code_strs, const char *user_config_path)
bool IsBroadcastCodeExistInWhitelist(const char *broadcast_code)
char name[kDevNameLengthMax]
void StorageRawPacket(uint8_t handle, LivoxEthPacket *eth_packet)
volatile bool is_initialized_
static void SetHighSensitivityCb(livox_status status, uint8_t handle, DeviceParameterResponse *response, void *clent_data)
static void DeviceInformationCb(livox_status status, uint8_t handle, DeviceInformationResponse *ack, void *clent_data)
int32_t SetReceiveSyncTimeCb(FnReceiveSyncTimeCb cb, void *data)
void DisableAutoConnectMode(void)
void EulerAnglesToRotationMatrix(EulerAngle euler, RotationMatrix matrix)
bool IsAutoConnectMode(void)
int ParseTimesyncConfig(rapidjson::Document &doc)
void ResetLds(uint8_t data_src)
LidarDevice lidars_[kMaxSourceLidar]
static void StopSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
volatile LidarConnectState connect_state
static void LidarErrorStatusCb(livox_status status, uint8_t handle, ErrorMessage *message)