65 const char *user_config_path) {
67 printf(
"LiDAR data source is already inited!\n");
73 printf(
"Livox-SDK init fail!\n");
77 LivoxSdkVersion _sdkversion;
78 GetLivoxSdkVersion(&_sdkversion);
79 printf(
"Livox SDK version %d.%d.%d\n", _sdkversion.major, _sdkversion.minor,
85 for (
auto input_str : broadcast_code_strs) {
87 printf(
"Cmdline input broadcast code : %s\n", input_str.c_str());
94 printf(
"Disable auto connect mode!\n");
96 printf(
"List all broadcast code in whiltelist:\n");
103 "No broadcast code was added to whitelist, swith to automatic " 104 "connection mode!\n");
110 printf(
"Livox-SDK init fail!\n");
115 if (g_lds_hub ==
nullptr) {
119 printf(
"Livox-SDK init success!\n");
126 printf(
"LiDAR data source is not exit");
131 printf(
"Livox SDK Deinit completely!\n");
140 uint32_t data_num,
void *client_data) {
142 LivoxEthPacket *eth_packet = data;
144 if (!data || !data_num) {
149 uint8_t handle = HubGetLidarHandle(eth_packet->slot, eth_packet->id);
150 if (handle >= kMaxLidarCount) {
162 if (info->dev_type != kDeviceTypeHub) {
163 printf(
"It's not a hub : %s\n", info->broadcast_code);
168 printf(
"In automatic connection mode, will connect %s\n",
169 info->broadcast_code);
172 printf(
"Not in the whitelist, please add %s to if want to connect!\n",
173 info->broadcast_code);
182 result = AddHubToConnect(info->broadcast_code, &handle);
183 if (result == kStatusSuccess && handle < kMaxLidarCount) {
188 printf(
"add to connect\n");
191 if (strncmp(info->broadcast_code,
193 sizeof(info->broadcast_code)) != 0) {
194 printf(
"Could not find hub raw config, set config to default!\n");
208 printf(
"Add Hub to connect is failed : %d %d \n", result, handle);
219 if (info->handle >= kMaxLidarCount) {
224 if (type == kEventHubConnectionChange) {
228 printf(
"Hub[%s] connect on\n", p_hub->
info.broadcast_code);
230 }
else if (type == kEventDisconnect) {
233 printf(
"Hub[%s] disconnect!\n", info->broadcast_code);
234 }
else if (type == kEventStateChange) {
236 printf(
"Hub[%s] StateChange\n", info->broadcast_code);
240 printf(
"Hub[%s] status_code[%d] working state[%d] feature[%d]\n",
241 p_hub->
info.broadcast_code,
242 p_hub->
info.status.status_code.error_code, p_hub->
info.state,
243 p_hub->
info.feature);
245 if (p_hub->
info.state == kLidarStateNormal) {
252 HubQueryLidarInformationResponse *response,
255 if ((handle >= kMaxLidarCount) || !response) {
259 if ((status == kStatusSuccess) && !response->ret_code) {
260 if (response->count) {
261 printf(
"Hub have %d lidars:\n", response->count);
262 for (
int i = 0; i < response->count; i++) {
263 uint32_t index = HubGetLidarHandle(response->device_info_list[i].slot,
264 response->device_info_list[i].id);
265 if (index < kMaxLidarCount) {
268 p_lidar->
info.handle = index;
269 p_lidar->
info.slot = response->device_info_list[i].slot;
270 p_lidar->
info.id = response->device_info_list[i].id;
271 p_lidar->
info.type = response->device_info_list[i].dev_type;
273 strncpy(p_lidar->
info.broadcast_code,
274 response->device_info_list[i].broadcast_code,
275 sizeof(p_lidar->
info.broadcast_code));
276 printf(
"[%d]%s DeviceType[%d] Slot[%d] Ver[%d.%d.%d.%d]\n", index,
277 p_lidar->
info.broadcast_code, p_lidar->
info.type,
278 p_lidar->
info.slot, response->device_info_list[i].version[0],
279 response->device_info_list[i].version[1],
280 response->device_info_list[i].version[2],
281 response->device_info_list[i].version[3]);
286 printf(
"Hub have no lidar, will not start sample!\n");
290 printf(
"Device Query Informations Failed %d\n", status);
297 ErrorMessage *message) {
298 static uint32_t error_message_count = 0;
299 if (message != NULL) {
300 ++error_message_count;
301 if (0 == (error_message_count % 100)) {
302 printf(
"handle: %u\n", handle);
303 printf(
"sync_status : %u\n", message->hub_error_code.sync_status);
304 printf(
"temp_status : %u\n", message->hub_error_code.temp_status);
305 printf(
"lidar_status :%u\n", message->hub_error_code.lidar_status);
306 printf(
"lidar_link_status : %u\n",
307 message->hub_error_code.lidar_link_status);
308 printf(
"firmware_err : %u\n", message->hub_error_code.firmware_err);
309 printf(
"system_status : %u\n", message->hub_error_code.system_status);
318 livox_status status,
uint8_t handle,
319 HubSetPointCloudReturnModeResponse *response,
void *clent_data) {
321 if ((handle >= kMaxLidarCount) || !response) {
325 if ((status != kStatusSuccess) || (response->ret_code)) {
326 printf(
"Hub set return mode fail!\n");
329 printf(
"Hub set return mode success!\n");
339 uint8_t response,
void *clent_data) {
342 if (handle >= kMaxLidarCount) {
347 if (status == kStatusSuccess) {
349 printf(
"Set coordinate success!\n");
361 printf(
"Set coordinate fail, try again!\n");
366 livox_status status,
uint8_t handle,
367 HubSetImuPushFrequencyResponse *response,
void *clent_data) {
369 if ((handle >= kMaxLidarCount) || !response) {
373 if ((status != kStatusSuccess) || (response->ret_code)) {
374 printf(
"Hub set imu freq fail [%d]!\n", response->ret_code);
377 printf(
"Hub set imu frequency success!\n");
388 uint8_t response,
void *clent_data) {
390 if (handle >= kMaxLidarCount) {
395 if ((status != kStatusSuccess) || (response != 0)) {
397 printf(
"Hub start sample fail : state[%d] handle[%d] res[%d]\n", status,
400 for (
int i = 0; i < kMaxLidarCount; i++) {
407 printf(
"Hub start sample success!\n");
417 HubSetPointCloudReturnModeRequest *req =
418 (HubSetPointCloudReturnModeRequest *)req_buf;
420 for (
int i = 0; i < kMaxLidarCount; i++) {
423 if ((p_lidar->
info.type != kDeviceTypeLidarMid40) &&
427 printf(
"Could not find raw config, set config to default!\n");
433 strncpy(req->lidar_cfg_list[req->count].broadcast_code,
434 p_lidar->
info.broadcast_code,
435 sizeof(req->lidar_cfg_list[req->count].broadcast_code));
436 req->lidar_cfg_list[req->count].mode = config.
return_mode;
443 1 +
sizeof(SetPointCloudReturnModeRequestItem) * req->count;
444 HubSetPointCloudReturnMode(req, length,
452 HubSetImuPushFrequencyRequest *req = (HubSetImuPushFrequencyRequest *)req_buf;
454 for (
int i = 0; i < kMaxLidarCount; i++) {
457 if ((p_lidar->
info.type != kDeviceTypeLidarMid40) &&
462 printf(
"Could not find raw config, set config to default!\n");
468 strncpy(req->lidar_cfg_list[req->count].broadcast_code,
469 p_lidar->
info.broadcast_code,
470 sizeof(req->lidar_cfg_list[req->count].broadcast_code));
471 req->lidar_cfg_list[req->count].freq = config.
imu_rate;
477 uint32_t length = 1 +
sizeof(SetImuPushFrequencyRequestItem) * req->count;
491 printf(
"Hub set coordinate spherical\n");
493 printf(
"Hub set coordinate cartesian\n");
504 if (!broadcast_code || (strlen(broadcast_code) > kBroadcastCodeSize) ||
510 printf(
"%s is alrealy exist!\n", broadcast_code);
521 if (!broadcast_code) {
527 kBroadcastCodeSize) == 0) {
537 DeviceInfo *_lidars =
538 (DeviceInfo *)malloc(
sizeof(DeviceInfo) * kMaxLidarCount);
540 uint8_t count = kMaxLidarCount;
541 uint8_t status = GetConnectedDevices(_lidars, &count);
542 if (status == kStatusSuccess) {
543 printf(
"Hub have lidars : \n");
545 for (i = 0; i < count; ++i) {
546 uint8_t handle = _lidars[i].handle;
547 if (handle < kMaxLidarCount) {
551 printf(
"[%d] : %s\r\n", _lidars[i].handle, _lidars[i].broadcast_code);
562 FILE *raw_file = std::fopen(pathname,
"rb");
564 printf(
"Open json config file fail!\n");
568 char read_buffer[32768];
569 rapidjson::FileReadStream config_file(raw_file, read_buffer,
570 sizeof(read_buffer));
573 if (!doc.ParseStream(config_file).HasParseError()) {
574 if (doc.HasMember(
"hub_config") && doc[
"hub_config"].IsObject()) {
577 memset(&hub_config, 0,
sizeof(hub_config));
578 if (
object.HasMember(
"broadcast_code") &&
579 object[
"broadcast_code"].IsString()) {
580 std::string broadcast_code =
object[
"broadcast_code"].GetString();
584 if (
object.HasMember(
"enable_connect") &&
585 object[
"enable_connect"].IsBool()) {
588 if (
object.HasMember(
"coordinate") &&
object[
"coordinate"].IsInt()) {
589 hub_config.
coordinate =
object[
"coordinate"].GetInt();
600 printf(
"Add hub[%s] [%d] to whitelist\n",
604 printf(
"Add hub[%s] to whitelist fail\n",
609 printf(
"User hub config file parse error\n");
613 if (doc.HasMember(
"lidar_config") && doc[
"lidar_config"].IsArray()) {
615 size_t len = array.Size();
616 for (
size_t i = 0; i < len; i++) {
618 if (
object.IsObject()) {
620 memset(&config, 0,
sizeof(config));
621 if (
object.HasMember(
"broadcast_code") &&
622 object[
"broadcast_code"].IsString()) {
623 std::string broadcast_code =
object[
"broadcast_code"].GetString();
627 printf(
"User config file parse error\n");
631 if (
object.HasMember(
"enable_fan") &&
object[
"enable_fan"].IsBool()) {
632 config.
enable_fan =
object[
"enable_fan"].GetBool();
634 if (
object.HasMember(
"return_mode") &&
635 object[
"return_mode"].IsInt()) {
636 config.
return_mode =
object[
"return_mode"].GetInt();
638 if (
object.HasMember(
"imu_rate") &&
object[
"imu_rate"].IsInt()) {
639 config.
imu_rate =
object[
"imu_rate"].GetInt();
651 printf(
"Lidar Raw config is already exist : %s \n",
658 printf(
"User config file parse error[%d]\n",
659 doc.ParseStream(config_file).HasParseError());
662 std::fclose(raw_file);
673 printf(
"Add lidar raw user config : %s \n", config.
broadcast_code);
679 if (broadcast_code ==
nullptr) {
684 if (strncmp(ite_config.broadcast_code, broadcast_code,
685 kBroadcastCodeSize) == 0) {
694 if (broadcast_code ==
nullptr) {
699 if (strncmp(ite_config.broadcast_code, broadcast_code,
700 kBroadcastCodeSize) == 0) {
704 config.
imu_rate = ite_config.imu_rate;
int AddRawUserConfig(UserRawConfig &config)
static void HubQueryLidarInfoCb(livox_status status, uint8_t handle, HubQueryLidarInformationResponse *response, void *client_data)
char broadcast_code_whitelist_[kMaxLidarCount][kBroadcastCodeSize]
static void SetCoordinateCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
static void OnDeviceChange(const DeviceInfo *info, DeviceEvent type)
static void HubSetImuRatePushFrequencyCb(livox_status status, uint8_t handle, HubSetImuPushFrequencyResponse *response, void *clent_data)
const uint32_t kDeviceTypeLidarMid70
static void ControlFanCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
static void HubSetPointCloudReturnModeCb(livox_status status, uint8_t handle, HubSetPointCloudReturnModeResponse *response, void *clent_data)
static void OnDeviceBroadcast(const BroadcastDeviceInfo *info)
volatile bool is_initialized_
int AddBroadcastCodeToWhitelist(const char *broadcast_code)
bool IsExistInRawConfig(const char *broadcast_code)
UserRawConfig hub_raw_config_
static void OnHubDataCb(uint8_t hub_handle, LivoxEthPacket *data, uint32_t data_num, void *client_data)
static LdsHub * g_lds_hub
void EnableAutoConnectMode(void)
static void ResetLidar(LidarDevice *lidar, uint8_t data_src)
static void StopSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
void DisableAutoConnectMode(void)
int InitLdsHub(std::vector< std::string > &broadcast_code_strs, const char *user_config_path)
int ParseConfigFile(const char *pathname)
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
volatile uint32_t set_bits
static void ConfigPointCloudReturnMode(LdsHub *lds_hub)
uint32_t whitelist_count_
void StorageRawPacket(uint8_t handle, LivoxEthPacket *eth_packet)
static void ConfigLidarsOfHub(LdsHub *lds_hub)
virtual void PrepareExit(void)
std::vector< UserRawConfig > lidar_raw_config_
static void StartSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
bool IsAutoConnectMode(void)
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
void UpdateHubLidarinfo(void)
bool IsBroadcastCodeExistInWhitelist(const char *broadcast_code)
void ResetLds(uint8_t data_src)
static void ConfigImuPushFrequency(LdsHub *lds_hub)
LdsHub(uint32_t interval_ms)
LidarDevice lidars_[kMaxSourceLidar]
int GetRawConfig(const char *broadcast_code, UserRawConfig &config)
static void HubErrorStatusCb(livox_status status, uint8_t handle, ErrorMessage *message)
volatile LidarConnectState connect_state