lds_hub.cpp
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 
25 #include "lds_hub.h"
26 
27 #include <stdio.h>
28 #include <string.h>
29 #include <memory>
30 #include <thread>
31 
32 #include "rapidjson/document.h"
34 #include "rapidjson/stringbuffer.h"
35 
36 namespace livox_ros {
37 
41 static LdsHub *g_lds_hub = nullptr;
42 
46 LdsHub::LdsHub(uint32_t interval_ms) : Lds(interval_ms, kSourceRawHub) {
47  auto_connect_mode_ = true;
48  whitelist_count_ = 0;
49  is_initialized_ = false;
50 
51  whitelist_count_ = 0;
53 
54  ResetLdsHub();
55 }
56 
58 
59 void LdsHub::ResetLdsHub(void) {
62 }
63 
64 int LdsHub::InitLdsHub(std::vector<std::string> &broadcast_code_strs,
65  const char *user_config_path) {
66  if (is_initialized_) {
67  printf("LiDAR data source is already inited!\n");
68  return -1;
69  }
70 
71  if (!Init()) {
72  Uninit();
73  printf("Livox-SDK init fail!\n");
74  return -1;
75  }
76 
77  LivoxSdkVersion _sdkversion;
78  GetLivoxSdkVersion(&_sdkversion);
79  printf("Livox SDK version %d.%d.%d\n", _sdkversion.major, _sdkversion.minor,
80  _sdkversion.patch);
81 
82  SetBroadcastCallback(LdsHub::OnDeviceBroadcast);
83  SetDeviceStateUpdateCallback(LdsHub::OnDeviceChange);
84 
85  for (auto input_str : broadcast_code_strs) {
86  AddBroadcastCodeToWhitelist(input_str.c_str());
87  printf("Cmdline input broadcast code : %s\n", input_str.c_str());
88  }
89 
90  ParseConfigFile(user_config_path);
91 
92  if (whitelist_count_) {
94  printf("Disable auto connect mode!\n");
95 
96  printf("List all broadcast code in whiltelist:\n");
97  for (uint32_t i = 0; i < whitelist_count_; i++) {
98  printf("%s\n", broadcast_code_whitelist_[i]);
99  }
100  } else {
102  printf(
103  "No broadcast code was added to whitelist, swith to automatic "
104  "connection mode!\n");
105  }
106 
108  if (!Start()) {
109  Uninit();
110  printf("Livox-SDK init fail!\n");
111  return -1;
112  }
113 
115  if (g_lds_hub == nullptr) {
116  g_lds_hub = this;
117  }
118  is_initialized_ = true;
119  printf("Livox-SDK init success!\n");
120 
121  return 0;
122 }
123 
125  if (!is_initialized_) {
126  printf("LiDAR data source is not exit");
127  return -1;
128  }
129 
130  Uninit();
131  printf("Livox SDK Deinit completely!\n");
132 
133  return 0;
134 }
135 
137 
139 void LdsHub::OnHubDataCb(uint8_t hub_handle, LivoxEthPacket *data,
140  uint32_t data_num, void *client_data) {
141  LdsHub *lds_hub = static_cast<LdsHub *>(client_data);
142  LivoxEthPacket *eth_packet = data;
143 
144  if (!data || !data_num) {
145  return;
146  }
147 
149  uint8_t handle = HubGetLidarHandle(eth_packet->slot, eth_packet->id);
150  if (handle >= kMaxLidarCount) {
151  return;
152  }
153 
154  lds_hub->StorageRawPacket(handle, eth_packet);
155 }
156 
157 void LdsHub::OnDeviceBroadcast(const BroadcastDeviceInfo *info) {
158  if (info == NULL) {
159  return;
160  }
161 
162  if (info->dev_type != kDeviceTypeHub) {
163  printf("It's not a hub : %s\n", info->broadcast_code);
164  return;
165  }
166 
167  if (g_lds_hub->IsAutoConnectMode()) {
168  printf("In automatic connection mode, will connect %s\n",
169  info->broadcast_code);
170  } else {
171  if (!g_lds_hub->IsBroadcastCodeExistInWhitelist(info->broadcast_code)) {
172  printf("Not in the whitelist, please add %s to if want to connect!\n",
173  info->broadcast_code);
174  return;
175  }
176  }
177 
178  LidarDevice *p_hub = &g_lds_hub->hub_;
179  if (p_hub->connect_state == kConnectStateOff) {
180  bool result = false;
181  uint8_t handle = 0;
182  result = AddHubToConnect(info->broadcast_code, &handle);
183  if (result == kStatusSuccess && handle < kMaxLidarCount) {
184  SetDataCallback(handle, LdsHub::OnHubDataCb, (void *)g_lds_hub);
185  p_hub->handle = handle;
187 
188  printf("add to connect\n");
189 
190  UserRawConfig config;
191  if (strncmp(info->broadcast_code,
192  g_lds_hub->hub_raw_config_.broadcast_code,
193  sizeof(info->broadcast_code)) != 0) {
194  printf("Could not find hub raw config, set config to default!\n");
195  config.enable_fan = 1;
196  config.return_mode = kFirstReturn;
198  config.imu_rate = kImuFreq200Hz;
199  } else {
200  config = g_lds_hub->hub_raw_config_;
201  }
202 
203  p_hub->config.enable_fan = config.enable_fan;
204  p_hub->config.return_mode = config.return_mode;
205  p_hub->config.coordinate = config.coordinate;
206  p_hub->config.imu_rate = config.imu_rate;
207  } else {
208  printf("Add Hub to connect is failed : %d %d \n", result, handle);
209  }
210  }
211 }
212 
214 void LdsHub::OnDeviceChange(const DeviceInfo *info, DeviceEvent type) {
215  if (info == NULL) {
216  return;
217  }
218 
219  if (info->handle >= kMaxLidarCount) {
220  return;
221  }
222 
223  LidarDevice *p_hub = &g_lds_hub->hub_;
224  if (type == kEventHubConnectionChange) {
225  if (p_hub->connect_state == kConnectStateOff) {
227  p_hub->info = *info;
228  printf("Hub[%s] connect on\n", p_hub->info.broadcast_code);
229  }
230  } else if (type == kEventDisconnect) {
231  g_lds_hub->ResetLds(0);
232  g_lds_hub->ResetLidar(p_hub, 0);
233  printf("Hub[%s] disconnect!\n", info->broadcast_code);
234  } else if (type == kEventStateChange) {
235  p_hub->info = *info;
236  printf("Hub[%s] StateChange\n", info->broadcast_code);
237  }
238 
239  if (p_hub->connect_state == kConnectStateOn) {
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);
244  SetErrorMessageCallback(p_hub->handle, LdsHub::HubErrorStatusCb);
245  if (p_hub->info.state == kLidarStateNormal) {
246  HubQueryLidarInformation(HubQueryLidarInfoCb, g_lds_hub);
247  }
248  }
249 }
250 
251 void LdsHub::HubQueryLidarInfoCb(livox_status status, uint8_t handle,
252  HubQueryLidarInformationResponse *response,
253  void *client_data) {
254  LdsHub *lds_hub = static_cast<LdsHub *>(client_data);
255  if ((handle >= kMaxLidarCount) || !response) {
256  return;
257  }
258 
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) {
266  LidarDevice *p_lidar = &lds_hub->lidars_[index];
267  p_lidar->handle = index;
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]);
282  }
283  }
284  ConfigLidarsOfHub(lds_hub);
285  } else {
286  printf("Hub have no lidar, will not start sample!\n");
287  HubQueryLidarInformation(HubQueryLidarInfoCb, lds_hub);
288  }
289  } else {
290  printf("Device Query Informations Failed %d\n", status);
291  HubQueryLidarInformation(HubQueryLidarInfoCb, lds_hub);
292  }
293 }
294 
296 void LdsHub::HubErrorStatusCb(livox_status status, uint8_t handle,
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);
310  }
311  }
312 }
313 
314 void LdsHub::ControlFanCb(livox_status status, uint8_t handle, uint8_t response,
315  void *clent_data) {}
316 
318  livox_status status, uint8_t handle,
319  HubSetPointCloudReturnModeResponse *response, void *clent_data) {
320  LdsHub *lds_hub = static_cast<LdsHub *>(clent_data);
321  if ((handle >= kMaxLidarCount) || !response) {
322  return;
323  }
324 
325  if ((status != kStatusSuccess) || (response->ret_code)) {
326  printf("Hub set return mode fail!\n");
328  } else {
329  printf("Hub set return mode success!\n");
330  lds_hub->hub_.config.set_bits &= ~((uint32_t)(kConfigReturnMode));
331  if (!lds_hub->hub_.config.set_bits) {
332  HubStartSampling(LdsHub::StartSampleCb, lds_hub);
334  }
335  }
336 }
337 
338 void LdsHub::SetCoordinateCb(livox_status status, uint8_t handle,
339  uint8_t response, void *clent_data) {
340  LdsHub *lds_hub = static_cast<LdsHub *>(clent_data);
341 
342  if (handle >= kMaxLidarCount) {
343  return;
344  }
345 
346  LidarDevice *p_hub = &(lds_hub->hub_);
347  if (status == kStatusSuccess) {
348  p_hub->config.set_bits &= ~((uint32_t)(kConfigCoordinate));
349  printf("Set coordinate success!\n");
350 
351  if (!p_hub->config.set_bits) {
352  HubStartSampling(LdsHub::StartSampleCb, lds_hub);
354  }
355  } else {
356  if (p_hub->config.coordinate != 0) {
357  SetSphericalCoordinate(handle, LdsHub::SetCoordinateCb, lds_hub);
358  } else {
359  SetCartesianCoordinate(handle, LdsHub::SetCoordinateCb, lds_hub);
360  }
361  printf("Set coordinate fail, try again!\n");
362  }
363 }
364 
366  livox_status status, uint8_t handle,
367  HubSetImuPushFrequencyResponse *response, void *clent_data) {
368  LdsHub *lds_hub = static_cast<LdsHub *>(clent_data);
369  if ((handle >= kMaxLidarCount) || !response) {
370  return;
371  }
372 
373  if ((status != kStatusSuccess) || (response->ret_code)) {
374  printf("Hub set imu freq fail [%d]!\n", response->ret_code);
375  ConfigImuPushFrequency(lds_hub);
376  } else {
377  printf("Hub set imu frequency success!\n");
378  lds_hub->hub_.config.set_bits &= ~((uint32_t)(kConfigImuRate));
379  if (!lds_hub->hub_.config.set_bits) {
380  HubStartSampling(LdsHub::StartSampleCb, lds_hub);
382  }
383  }
384 }
385 
387 void LdsHub::StartSampleCb(livox_status status, uint8_t handle,
388  uint8_t response, void *clent_data) {
389  LdsHub *lds_hub = static_cast<LdsHub *>(clent_data);
390  if (handle >= kMaxLidarCount) {
391  return;
392  }
393 
394  LidarDevice *p_hub = &lds_hub->hub_;
395  if ((status != kStatusSuccess) || (response != 0)) {
397  printf("Hub start sample fail : state[%d] handle[%d] res[%d]\n", status,
398  handle, response);
399 
400  for (int i = 0; i < kMaxLidarCount; i++) {
401  LidarDevice *p_lidar = &(lds_hub->lidars_[i]);
402  if (p_lidar->connect_state == kConnectStateSampling) {
403  p_lidar->connect_state = kConnectStateOn;
404  }
405  }
406  } else {
407  printf("Hub start sample success!\n");
408  }
409 }
410 
412 void LdsHub::StopSampleCb(livox_status status, uint8_t handle, uint8_t response,
413  void *clent_data) {}
414 
416  uint8_t req_buf[1024];
417  HubSetPointCloudReturnModeRequest *req =
418  (HubSetPointCloudReturnModeRequest *)req_buf;
419  req->count = 0;
420  for (int i = 0; i < kMaxLidarCount; i++) {
421  LidarDevice *p_lidar = &(lds_hub->lidars_[i]);
422 
423  if ((p_lidar->info.type != kDeviceTypeLidarMid40) &&
424  (p_lidar->connect_state == kConnectStateSampling)) {
425  UserRawConfig config;
426  if (lds_hub->GetRawConfig(p_lidar->info.broadcast_code, config)) {
427  printf("Could not find raw config, set config to default!\n");
428  config.enable_fan = 1;
429  config.return_mode = kFirstReturn;
431  config.imu_rate = kImuFreq200Hz;
432  }
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;
437  req->count++;
438  }
439  }
440 
441  if (req->count) {
442  uint32_t length =
443  1 + sizeof(SetPointCloudReturnModeRequestItem) * req->count;
444  HubSetPointCloudReturnMode(req, length,
447  }
448 }
449 
451  uint8_t req_buf[1024];
452  HubSetImuPushFrequencyRequest *req = (HubSetImuPushFrequencyRequest *)req_buf;
453  req->count = 0;
454  for (int i = 0; i < kMaxLidarCount; i++) {
455  LidarDevice *p_lidar = &(lds_hub->lidars_[i]);
456 
457  if ((p_lidar->info.type != kDeviceTypeLidarMid40) &&
458  (p_lidar->info.type != kDeviceTypeLidarMid70) &&
459  (p_lidar->connect_state == kConnectStateSampling)) {
460  UserRawConfig config;
461  if (lds_hub->GetRawConfig(p_lidar->info.broadcast_code, config)) {
462  printf("Could not find raw config, set config to default!\n");
463  config.enable_fan = 1;
464  config.return_mode = kFirstReturn;
466  config.imu_rate = kImuFreq200Hz;
467  }
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;
472  req->count++;
473  }
474  }
475 
476  if (req->count) {
477  uint32_t length = 1 + sizeof(SetImuPushFrequencyRequestItem) * req->count;
478  HubSetImuPushFrequency(req, length, LdsHub::HubSetImuRatePushFrequencyCb,
479  lds_hub);
480  lds_hub->hub_.config.set_bits |= kConfigImuRate;
481  }
482 }
483 
486  ConfigImuPushFrequency(lds_hub);
487 
488  if (lds_hub->hub_.config.coordinate != 0) {
489  SetSphericalCoordinate(lds_hub->hub_.handle, LdsHub::SetCoordinateCb,
490  lds_hub);
491  printf("Hub set coordinate spherical\n");
492  } else {
493  printf("Hub set coordinate cartesian\n");
494  SetCartesianCoordinate(lds_hub->hub_.handle, LdsHub::SetCoordinateCb,
495  lds_hub);
496  }
498 
500 }
501 
503 int LdsHub::AddBroadcastCodeToWhitelist(const char *broadcast_code) {
504  if (!broadcast_code || (strlen(broadcast_code) > kBroadcastCodeSize) ||
505  (whitelist_count_ >= kMaxLidarCount)) {
506  return -1;
507  }
508 
509  if (IsBroadcastCodeExistInWhitelist(broadcast_code)) {
510  printf("%s is alrealy exist!\n", broadcast_code);
511  return -1;
512  }
513 
514  strcpy(broadcast_code_whitelist_[whitelist_count_], broadcast_code);
516 
517  return 0;
518 }
519 
520 bool LdsHub::IsBroadcastCodeExistInWhitelist(const char *broadcast_code) {
521  if (!broadcast_code) {
522  return false;
523  }
524 
525  for (uint32_t i = 0; i < whitelist_count_; i++) {
526  if (strncmp(broadcast_code, broadcast_code_whitelist_[i],
527  kBroadcastCodeSize) == 0) {
528  return true;
529  }
530  }
531 
532  return false;
533 }
534 
537  DeviceInfo *_lidars =
538  (DeviceInfo *)malloc(sizeof(DeviceInfo) * kMaxLidarCount);
539 
540  uint8_t count = kMaxLidarCount;
541  uint8_t status = GetConnectedDevices(_lidars, &count);
542  if (status == kStatusSuccess) {
543  printf("Hub have lidars : \n");
544  int i = 0;
545  for (i = 0; i < count; ++i) {
546  uint8_t handle = _lidars[i].handle;
547  if (handle < kMaxLidarCount) {
548  lidars_[handle].handle = handle;
549  lidars_[handle].info = _lidars[i];
551  printf("[%d] : %s\r\n", _lidars[i].handle, _lidars[i].broadcast_code);
552  }
553  }
554  }
555  if (_lidars) {
556  free(_lidars);
557  }
558 }
559 
561 int LdsHub::ParseConfigFile(const char *pathname) {
562  FILE *raw_file = std::fopen(pathname, "rb");
563  if (!raw_file) {
564  printf("Open json config file fail!\n");
565  return -1;
566  }
567 
568  char read_buffer[32768];
569  rapidjson::FileReadStream config_file(raw_file, read_buffer,
570  sizeof(read_buffer));
571 
573  if (!doc.ParseStream(config_file).HasParseError()) {
574  if (doc.HasMember("hub_config") && doc["hub_config"].IsObject()) {
575  const rapidjson::Value &object = doc["hub_config"];
576  UserRawConfig hub_config;
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();
581  std::memcpy(hub_config.broadcast_code, broadcast_code.c_str(),
582  sizeof(hub_config.broadcast_code));
583 
584  if (object.HasMember("enable_connect") &&
585  object["enable_connect"].IsBool()) {
586  hub_config.enable_connect = object["enable_connect"].GetBool();
587  }
588  if (object.HasMember("coordinate") && object["coordinate"].IsInt()) {
589  hub_config.coordinate = object["coordinate"].GetInt();
590  }
591 
592  printf("Hub[%s] : %d %d %d %d %d\n", hub_config.broadcast_code,
593  hub_config.enable_connect, hub_config.enable_fan,
594  hub_config.return_mode, hub_config.coordinate,
595  hub_config.imu_rate);
596 
597  if (hub_config.enable_connect) {
598  if (!AddBroadcastCodeToWhitelist(hub_config.broadcast_code)) {
599  hub_raw_config_ = hub_config;
600  printf("Add hub[%s] [%d] to whitelist\n",
602  } else {
603  memset(&hub_raw_config_, 0, sizeof(hub_raw_config_));
604  printf("Add hub[%s] to whitelist fail\n",
606  }
607  }
608  } else {
609  printf("User hub config file parse error\n");
610  }
611  }
612 
613  if (doc.HasMember("lidar_config") && doc["lidar_config"].IsArray()) {
614  const rapidjson::Value &array = doc["lidar_config"];
615  size_t len = array.Size();
616  for (size_t i = 0; i < len; i++) {
617  const rapidjson::Value &object = array[i];
618  if (object.IsObject()) {
619  UserRawConfig config;
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();
624  std::memcpy(config.broadcast_code, broadcast_code.c_str(),
625  sizeof(config.broadcast_code));
626  } else {
627  printf("User config file parse error\n");
628  continue;
629  }
630 
631  if (object.HasMember("enable_fan") && object["enable_fan"].IsBool()) {
632  config.enable_fan = object["enable_fan"].GetBool();
633  }
634  if (object.HasMember("return_mode") &&
635  object["return_mode"].IsInt()) {
636  config.return_mode = object["return_mode"].GetInt();
637  }
638  if (object.HasMember("imu_rate") && object["imu_rate"].IsInt()) {
639  config.imu_rate = object["imu_rate"].GetInt();
640  }
643  } else {
644  config.coordinate = 0;
645  }
646  printf("Lidar[%s] : %d %d %d %d %d\n", config.broadcast_code,
647  config.enable_connect, config.enable_fan, config.return_mode,
648  config.coordinate, config.imu_rate);
649 
650  if (AddRawUserConfig(config)) {
651  printf("Lidar Raw config is already exist : %s \n",
652  config.broadcast_code);
653  }
654  }
655  }
656  }
657  } else {
658  printf("User config file parse error[%d]\n",
659  doc.ParseStream(config_file).HasParseError());
660  }
661 
662  std::fclose(raw_file);
663 
664  return 0;
665 }
666 
668  if (IsExistInRawConfig(config.broadcast_code)) {
669  return -1;
670  }
671 
672  lidar_raw_config_.push_back(config);
673  printf("Add lidar raw user config : %s \n", config.broadcast_code);
674 
675  return 0;
676 }
677 
678 bool LdsHub::IsExistInRawConfig(const char *broadcast_code) {
679  if (broadcast_code == nullptr) {
680  return false;
681  }
682 
683  for (auto ite_config : lidar_raw_config_) {
684  if (strncmp(ite_config.broadcast_code, broadcast_code,
685  kBroadcastCodeSize) == 0) {
686  return true;
687  }
688  }
689 
690  return false;
691 }
692 
693 int LdsHub::GetRawConfig(const char *broadcast_code, UserRawConfig &config) {
694  if (broadcast_code == nullptr) {
695  return -1;
696  }
697 
698  for (auto ite_config : lidar_raw_config_) {
699  if (strncmp(ite_config.broadcast_code, broadcast_code,
700  kBroadcastCodeSize) == 0) {
701  config.enable_fan = ite_config.enable_fan;
702  config.return_mode = ite_config.return_mode;
703  config.coordinate = ite_config.coordinate;
704  config.imu_rate = ite_config.imu_rate;
705  return 0;
706  }
707  }
708 
709  return -1;
710 }
711 
712 } // namespace livox_ros
DeviceInfo info
Definition: lds.h:185
int AddRawUserConfig(UserRawConfig &config)
Definition: lds_hub.cpp:667
static void HubQueryLidarInfoCb(livox_status status, uint8_t handle, HubQueryLidarInformationResponse *response, void *client_data)
Definition: lds_hub.cpp:251
char broadcast_code_whitelist_[kMaxLidarCount][kBroadcastCodeSize]
Definition: lds_hub.h:111
static void SetCoordinateCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
Definition: lds_hub.cpp:338
static void OnDeviceChange(const DeviceInfo *info, DeviceEvent type)
Definition: lds_hub.cpp:214
uint32_t imu_rate
Definition: lds.h:144
static void HubSetImuRatePushFrequencyCb(livox_status status, uint8_t handle, HubSetImuPushFrequencyResponse *response, void *clent_data)
Definition: lds_hub.cpp:365
const uint32_t kDeviceTypeLidarMid70
Definition: lds.h:249
uint32_t coordinate
Definition: lds.h:152
static void ControlFanCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
Definition: lds_hub.cpp:314
int DeInitLdsHub(void)
Definition: lds_hub.cpp:124
UserConfig config
Definition: lds.h:190
static void HubSetPointCloudReturnModeCb(livox_status status, uint8_t handle, HubSetPointCloudReturnModeResponse *response, void *clent_data)
Definition: lds_hub.cpp:317
static void OnDeviceBroadcast(const BroadcastDeviceInfo *info)
Definition: lds_hub.cpp:157
volatile bool is_initialized_
Definition: lds_hub.h:110
uint32_t imu_rate
Definition: lds.h:153
unsigned char uint8_t
Definition: stdint.h:125
int AddBroadcastCodeToWhitelist(const char *broadcast_code)
Definition: lds_hub.cpp:503
void ResetLdsHub(void)
Definition: lds_hub.cpp:59
uint32_t return_mode
Definition: lds.h:142
bool IsExistInRawConfig(const char *broadcast_code)
Definition: lds_hub.cpp:678
UserRawConfig hub_raw_config_
Definition: lds_hub.h:116
static void OnHubDataCb(uint8_t hub_handle, LivoxEthPacket *data, uint32_t data_num, void *client_data)
Definition: lds_hub.cpp:139
static LdsHub * g_lds_hub
Definition: lds_hub.cpp:41
uint32_t return_mode
Definition: lds.h:151
void EnableAutoConnectMode(void)
Definition: lds_hub.h:92
static void ResetLidar(LidarDevice *lidar, uint8_t data_src)
Definition: lds.cpp:563
static void StopSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
Definition: lds_hub.cpp:412
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2575
unsigned int uint32_t
Definition: stdint.h:127
void DisableAutoConnectMode(void)
Definition: lds_hub.h:93
int InitLdsHub(std::vector< std::string > &broadcast_code_strs, const char *user_config_path)
Definition: lds_hub.cpp:64
int ParseConfigFile(const char *pathname)
Definition: lds_hub.cpp:561
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:3029
volatile uint32_t set_bits
Definition: lds.h:156
static void ConfigPointCloudReturnMode(LdsHub *lds_hub)
Definition: lds_hub.cpp:415
uint32_t whitelist_count_
Definition: lds_hub.h:109
void StorageRawPacket(uint8_t handle, LivoxEthPacket *eth_packet)
Definition: lds.cpp:637
static void ConfigLidarsOfHub(LdsHub *lds_hub)
Definition: lds_hub.cpp:484
LidarDevice hub_
Definition: lds_hub.h:113
bool auto_connect_mode_
Definition: lds_hub.h:108
virtual void PrepareExit(void)
Definition: lds_hub.cpp:136
uint32_t coordinate
Definition: lds.h:143
std::vector< UserRawConfig > lidar_raw_config_
Definition: lds_hub.h:115
static void StartSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
Definition: lds_hub.cpp:387
bool IsAutoConnectMode(void)
Definition: lds_hub.h:94
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
void UpdateHubLidarinfo(void)
Definition: lds_hub.cpp:536
bool IsBroadcastCodeExistInWhitelist(const char *broadcast_code)
Definition: lds_hub.cpp:520
void ResetLds(uint8_t data_src)
Definition: lds.cpp:581
static void ConfigImuPushFrequency(LdsHub *lds_hub)
Definition: lds_hub.cpp:450
char broadcast_code[16]
Definition: lds.h:139
LdsHub(uint32_t interval_ms)
Definition: lds_hub.cpp:46
LidarDevice lidars_[kMaxSourceLidar]
Definition: lds.h:446
int GetRawConfig(const char *broadcast_code, UserRawConfig &config)
Definition: lds_hub.cpp:693
static void HubErrorStatusCb(livox_status status, uint8_t handle, ErrorMessage *message)
Definition: lds_hub.cpp:296
volatile LidarConnectState connect_state
Definition: lds.h:184
uint8_t handle
Definition: lds.h:173


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