lds_hub.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 
27 #ifndef LIVOX_ROS_DRIVER_LDS_HUB_H_
28 #define LIVOX_ROS_DRIVER_LDS_HUB_H_
29 
30 #include <memory>
31 #include <vector>
32 
33 #include "lds.h"
34 #include "livox_sdk.h"
35 
36 namespace livox_ros {
37 
41 class LdsHub : public Lds {
42  public:
43  static LdsHub *GetInstance(uint32_t interval_ms) {
44  static LdsHub lds_hub(interval_ms);
45  return &lds_hub;
46  }
47 
48  int InitLdsHub(std::vector<std::string> &broadcast_code_strs,
49  const char *user_config_path);
50  int DeInitLdsHub(void);
51 
52  private:
53  LdsHub(uint32_t interval_ms);
54  LdsHub(const LdsHub &) = delete;
55  ~LdsHub();
56  LdsHub &operator=(const LdsHub &) = delete;
57  virtual void PrepareExit(void);
58 
59  static void OnHubDataCb(uint8_t hub_handle, LivoxEthPacket *data,
60  uint32_t data_num, void *client_data);
61  static void OnDeviceBroadcast(const BroadcastDeviceInfo *info);
62  static void OnDeviceChange(const DeviceInfo *info, DeviceEvent type);
63  static void StartSampleCb(livox_status status, uint8_t handle,
64  uint8_t response, void *clent_data);
65  static void StopSampleCb(livox_status status, uint8_t handle,
66  uint8_t response, void *clent_data);
67  static void HubQueryLidarInfoCb(livox_status status, uint8_t handle,
68  HubQueryLidarInformationResponse *response,
69  void *client_data);
70  static void ControlFanCb(livox_status status, uint8_t handle,
71  uint8_t response, void *clent_data);
72  static void HubSetPointCloudReturnModeCb(
73  livox_status status, uint8_t handle,
74  HubSetPointCloudReturnModeResponse *response, void *clent_data);
75  static void SetCoordinateCb(livox_status status, uint8_t handle,
76  uint8_t response, void *clent_data);
77  static void HubSetImuRatePushFrequencyCb(
78  livox_status status, uint8_t handle,
79  HubSetImuPushFrequencyResponse *response, void *clent_data);
80  static void HubErrorStatusCb(livox_status status, uint8_t handle,
81  ErrorMessage *message);
82  static void ConfigPointCloudReturnMode(LdsHub *lds_hub);
83  static void ConfigImuPushFrequency(LdsHub *lds_hub);
84  static void ConfigLidarsOfHub(LdsHub *lds_hub);
85 
86  void ResetLdsHub(void);
87  void StateReset(void);
88  int AddBroadcastCodeToWhitelist(const char *broadcast_code);
89  bool IsBroadcastCodeExistInWhitelist(const char *broadcast_code);
90  void UpdateHubLidarinfo(void);
91 
94  bool IsAutoConnectMode(void) { return auto_connect_mode_; }
95  int ParseConfigFile(const char *pathname);
96  int AddRawUserConfig(UserRawConfig &config);
97  bool IsExistInRawConfig(const char *broadcast_code);
98  int GetRawConfig(const char *broadcast_code, UserRawConfig &config);
100  for (int i = 0; i < kMaxLidarCount; i++) {
101  if (lidars_[i].config.set_bits) {
102  return false;
103  }
104  }
105  return true;
106  }
107 
110  volatile bool is_initialized_;
111  char broadcast_code_whitelist_[kMaxLidarCount][kBroadcastCodeSize];
112 
114 
115  std::vector<UserRawConfig> lidar_raw_config_;
117 };
118 
119 } // namespace livox_ros
120 #endif
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
LdsHub & operator=(const LdsHub &)=delete
static void HubSetImuRatePushFrequencyCb(livox_status status, uint8_t handle, HubSetImuPushFrequencyResponse *response, void *clent_data)
Definition: lds_hub.cpp:365
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
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
void StateReset(void)
volatile bool is_initialized_
Definition: lds_hub.h:110
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
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
void EnableAutoConnectMode(void)
Definition: lds_hub.h:92
static void StopSampleCb(livox_status status, uint8_t handle, uint8_t response, void *clent_data)
Definition: lds_hub.cpp:412
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
static void ConfigPointCloudReturnMode(LdsHub *lds_hub)
Definition: lds_hub.cpp:415
uint32_t whitelist_count_
Definition: lds_hub.h:109
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
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
void UpdateHubLidarinfo(void)
Definition: lds_hub.cpp:536
bool IsBroadcastCodeExistInWhitelist(const char *broadcast_code)
Definition: lds_hub.cpp:520
static void ConfigImuPushFrequency(LdsHub *lds_hub)
Definition: lds_hub.cpp:450
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 LdsHub * GetInstance(uint32_t interval_ms)
Definition: lds_hub.h:43
static void HubErrorStatusCb(livox_status status, uint8_t handle, ErrorMessage *message)
Definition: lds_hub.cpp:296
bool IsAllLidarSetBitsClear()
Definition: lds_hub.h:99


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