lds_lidar.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. /** Livox LiDAR data source, data from dependent lidar */
  25. #ifndef LDS_LIDAR_H_
  26. #define LDS_LIDAR_H_
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <memory>
  30. #include "livox_def.h"
  31. #include "livox_sdk.h"
  32. #include <chrono>
  33. #include <thread_safe_map.h>
  34. namespace livox
  35. {
  36. typedef enum
  37. {
  38. kConnectStateOff = 0,
  39. kConnectStateOn = 1,
  40. kConnectStateConfig = 2,
  41. kConnectStateSampling = 3,
  42. } LidarConnectState;
  43. typedef enum
  44. {
  45. kConfigFan = 1,
  46. kConfigReturnMode = 2,
  47. kConfigCoordinate = 4,
  48. kConfigImuRate = 8
  49. } LidarConfigCodeBit;
  50. typedef enum
  51. {
  52. kCoordinateCartesian = 0,
  53. kCoordinateSpherical
  54. } CoordinateType;
  55. typedef struct
  56. {
  57. bool enable_fan;
  58. uint32_t return_mode;
  59. uint32_t coordinate;
  60. uint32_t imu_rate;
  61. volatile uint32_t set_bits;
  62. volatile uint32_t get_bits;
  63. } UserConfig;
  64. typedef struct
  65. {
  66. uint8_t handle;
  67. LidarConnectState connect_state;
  68. DeviceInfo info;
  69. UserConfig config;
  70. } LidarDevice;
  71. /**
  72. * LiDAR data source, data from dependent lidar.
  73. */
  74. class LdsLidar
  75. {
  76. public:
  77. LdsLidar();
  78. LdsLidar(const LdsLidar &) = delete;
  79. virtual ~LdsLidar();
  80. static int InitLdsLidar();
  81. int AddBroadcastCode(std::string sn);
  82. int DeInitLdsLidar(void);
  83. protected:
  84. private:
  85. virtual void LidarDataCallback(uint8_t handle, LivoxEthPacket *data,uint32_t data_num);
  86. LdsLidar &operator=(const LdsLidar &) = delete;
  87. static void GetLidarDataCb(uint8_t handle, LivoxEthPacket *data, \
  88. uint32_t data_num, void *client_data);
  89. static void OnDeviceBroadcast(const BroadcastDeviceInfo *info);
  90. static void OnDeviceChange(const DeviceInfo *info, DeviceEvent type);
  91. static void StartSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data);
  92. static void StopSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data);
  93. static void DeviceInformationCb(livox_status status, uint8_t handle, \
  94. DeviceInformationResponse *ack, void *clent_data);
  95. static void LidarErrorStatusCb(livox_status status, uint8_t handle, ErrorMessage *message);
  96. static void ControlFanCb(livox_status status, uint8_t handle, \
  97. uint8_t response, void *clent_data);
  98. static void SetPointCloudReturnModeCb(livox_status status, uint8_t handle, \
  99. uint8_t response, void *clent_data);
  100. static void SetCoordinateCb(livox_status status, uint8_t handle, \
  101. uint8_t response, void *clent_data);
  102. static void SetImuRatePushFrequencyCb(livox_status status, uint8_t handle, \
  103. uint8_t response, void *clent_data);
  104. int AddBroadcastCodeToWhitelist(const char *broadcast_code);
  105. void AddLocalBroadcastCode(void);
  106. bool FindInWhitelist(const char *broadcast_code);
  107. void EnableAutoConnectMode(void)
  108. {
  109. auto_connect_mode_ = true;
  110. }
  111. void DisableAutoConnectMode(void)
  112. {
  113. auto_connect_mode_ = false;
  114. }
  115. bool IsAutoConnectMode(void)
  116. {
  117. return auto_connect_mode_;
  118. }
  119. bool auto_connect_mode_;
  120. uint32_t whitelist_count_;
  121. char broadcast_code_whitelist_[kMaxLidarCount][kBroadcastCodeSize];
  122. uint32_t lidar_count_;
  123. uint32_t data_recveive_count_[kMaxLidarCount];
  124. };
  125. }
  126. #endif