feature:support for conneting horizon

This commit is contained in:
Livox-SDK
2019-12-19 15:25:48 +08:00
parent 83def61d80
commit da19f31bc4
1442 changed files with 52220 additions and 16430 deletions
+404 -72
View File
@@ -31,9 +31,9 @@
/** Device type. */
typedef enum {
kDeviceTypeHub = 0, /**< Livox Hub. */
kDeviceTypeLidarMid40 = 1, /**< Mid-40. */
kDeviceTypeLidarTele = 2, /**< Tele. */
kDeviceTypeHub = 0, /**< Livox Hub. */
kDeviceTypeLidarMid40 = 1, /**< Mid-40. */
kDeviceTypeLidarTele = 2, /**< Tele. */
kDeviceTypeLidarHorizon = 3 /**< Horizon. */
} DeviceType;
@@ -44,7 +44,7 @@ typedef enum {
kLidarStatePowerSaving = 2, /**< Power-saving state. */
kLidarStateStandBy = 3, /**< Standby state. */
kLidarStateError = 4, /**< Error state. */
kLidarStateUnknown = 5
kLidarStateUnknown = 5 /**< Unknown state. */
} LidarState;
/** Lidar mode. */
@@ -60,21 +60,35 @@ typedef enum {
kLidarFeatureRainFog = 1 /**< Rain and fog feature. */
} LidarFeature;
/** Lidar IP mode. */
typedef enum {
kLidarDynamicIpMode = 0, /**< Dynamic IP. */
kLidarStaticIpMode = 1 /**< Static IP. */
} LidarIpMode;
/** Function return value definition. */
typedef enum {
kStatusSuccess = 0, /**< Success. */
kStatusFailure = 1, /**< Failure. */
kStatusNotConnected = 2, /**< Requested device is not connected. */
kStatusNotSupported = 3, /**< Operation is not supported on this device. */
kStatusTimeout = 4, /**< Operation timeouts. */
kStatusNotEnoughMemory = 5 /**< No enough memory. */
} ResponseStatus;
kStatusSendFailed = -9, /**< Command send failed. */
kStatusHandlerImplNotExist = -8, /**< Handler implementation not exist. */
kStatusInvalidHandle = -7, /**< Device handle invalid. */
kStatusChannelNotExist = -6, /**< Command channel not exist. */
kStatusNotEnoughMemory = -5, /**< No enough memory. */
kStatusTimeout = -4, /**< Operation timeouts. */
kStatusNotSupported = -3, /**< Operation is not supported on this device. */
kStatusNotConnected = -2, /**< Requested device is not connected. */
kStatusFailure = -1, /**< Failure. */
kStatusSuccess = 0 /**< Success. */
} LivoxStatus;
/** Fuction return value defination, refer to \ref LivoxStatus. */
typedef int32_t livox_status;
/** Device update type, indicating the change of device connection or working state. */
typedef enum {
kEventConnect = 0, /**< Device is connected. */
kEventDisconnect = 1, /**< Device is removed. */
kEventStateChange = 2 /**< Device working state changes or an error occurs. */
kEventConnect = 0, /**< Device is connected. */
kEventDisconnect = 1, /**< Device is removed. */
kEventStateChange = 2, /**< Device working state changes or an error occurs. */
kEventHubConnectionChange = 3 /**< Hub is connected or LiDAR unit(s) is/are removed. */
} DeviceEvent;
/** Timestamp sync mode define. */
@@ -87,11 +101,36 @@ typedef enum {
kTimestampTypeUnknown = 5 /**< Unknown mode. */
} TimestampType;
/** Point data type. */
typedef enum {
kCartesian, /**< Cartesian coordinate point cloud. */
kSpherical, /**< Spherical coordinate point cloud. */
kExtendCartesian, /**< Extend cartesian coordinate point cloud. */
kExtendSpherical, /**< Extend spherical coordinate point cloud. */
kDualExtendCartesian, /**< Dual extend cartesian coordinate point cloud. */
kDualExtendSpherical, /**< Dual extend spherical coordinate point cloud. */
kImu, /**< IMU data. */
kMaxPointDataType /**< Max Point Data Type. */
} PointDataType;
/** Point cloud return mode. */
typedef enum {
kFirstReturn, /**< First single return mode . */
kStrongestReturn, /**< Strongest single return mode. */
kDualReturn /**< Dual return mode. */
} PointCloudReturnMode;
/** IMU push frequency. */
typedef enum {
kImuFreq0Hz, /**< IMU push closed. */
kImuFreq200Hz, /**< IMU push frequency 200Hz. */
} ImuFreq;
#pragma pack(1)
#define LIVOX_SDK_MAJOR_VERSION 1
#define LIVOX_SDK_MINOR_VERSION 2
#define LIVOX_SDK_PATCH_VERSION 1
#define LIVOX_SDK_MAJOR_VERSION 2
#define LIVOX_SDK_MINOR_VERSION 0
#define LIVOX_SDK_PATCH_VERSION 0
#define kBroadcastCodeSize 16
@@ -121,29 +160,131 @@ typedef struct {
/** Standard point cloud format */
typedef struct {
float x; /**< X axis, Unit:m */
float y; /**< X axis, Unit:m */
float z; /**< X axis, Unit:m */
float y; /**< Y axis, Unit:m */
float z; /**< Z axis, Unit:m */
uint8_t reflectivity; /**< Reflectivity */
} LivoxPoint;
/** Extend cartesian coordinate format. */
typedef struct {
int32_t x; /**< X axis, Unit:mm */
int32_t y; /**< Y axis, Unit:mm */
int32_t z; /**< Z axis, Unit:mm */
uint8_t reflectivity; /**< Reflectivity */
uint8_t tag; /**< Tag */
} LivoxExtendRawPoint;
/** Extend spherical coordinate format. */
typedef struct {
uint32_t depth; /**< Radial distance, Unit:mm */
uint16_t theta; /**< Polar angle, Unit:0.01rad */
uint16_t phi; /**< Azimuthal angle, Unit:0.01rad */
uint8_t reflectivity; /**< Reflectivity */
uint8_t tag; /**< Tag */
} LivoxExtendSpherPoint;
/** Dual extend cartesian coordinate format. */
typedef struct {
int32_t x1; /**< X axis, Unit:mm */
int32_t y1; /**< Y axis, Unit:mm */
int32_t z1; /**< Z axis, Unit:mm */
uint8_t reflectivity1; /**< Reflectivity */
uint8_t tag1; /**< Tag */
int32_t x2; /**< X axis, Unit:mm */
int32_t y2; /**< Y axis, Unit:mm */
int32_t z2; /**< Z axis, Unit:mm */
uint8_t reflectivity2; /**< Reflectivity */
uint8_t tag2; /**< Tag */
} LivoxDualExtendRawPoint;
/** Dual extend spherical coordinate format. */
typedef struct {
uint16_t theta; /**< Polar angle, Unit:0.01rad */
uint16_t phi; /**< Azimuthal angle, Unit:0.01rad */
uint32_t depth1; /**< Radial distance, Unit:mm */
uint8_t reflectivity1; /**< Reflectivity */
uint8_t tag1; /**< Tag */
uint32_t depth2; /**< Radial distance, Unit:mm */
uint8_t reflectivity2; /**< Reflectivity */
uint8_t tag2; /**< Tag */
} LivoxDualExtendSpherPoint;
/** IMU data format. */
typedef struct {
float gyro_x; /**< Gyroscope X axis, Unit:rad/s */
float gyro_y; /**< Gyroscope Y axis, Unit:rad/s */
float gyro_z; /**< Gyroscope Z axis, Unit:rad/s */
float acc_x; /**< Accelerometer X axis, Unit:g */
float acc_y; /**< Accelerometer Y axis, Unit:g */
float acc_z; /**< Accelerometer Z axis, Unit:g */
} LivoxImuPoint;
/** LiDAR error code. */
typedef struct {
uint32_t temp_status : 2; /**< 0: Temperature in Normal State. 1: High or Low. 2: Extremely High or Extremely Low. */
uint32_t volt_status : 2; /**< 0: Voltage in Normal State. 1: High. 2: Extremely High. */
uint32_t motor_status : 2; /**< 0: Motor in Normal State. 1: Motor in Warning State. 2:Motor in Error State, Unable to Work. */
uint32_t dirty_warn : 2; /**< 0: Not Dirty or Blocked. 1: Dirty or Blocked. */
uint32_t firmware_err : 1; /**< 0: Firmware is OK. 1: Firmware is Abnormal, Need to be Upgraded. */
uint32_t pps_status : 1; /**< 0: No PPS Signal. 1: PPS Signal is OK. */
uint32_t device_status : 1; /**< 0: Normal. 1: Warning for Approaching the End of Service Life. */
uint32_t fan_status : 1; /**< 0: Fan in Normal State. 1: Fan in Warning State. */
uint32_t self_heating : 1; /**< 0: Normal. 1: Low Temperature Self Heating On. */
uint32_t ptp_status : 1; /**< 0: No 1588 Signal. 1: 1588 Signal is OK. */
/** 0: System dose not start time synchronization.
* 1: Using PTP 1588 synchronization.
* 2: Using GPS synchronization.
* 3: Using PPS synchronization.
* 4: System time synchronization is abnormal.(The highest priority synchronization signal is abnormal)
*/
uint32_t time_sync_status : 3;
uint32_t rsvd : 13; /**< Reserved. */
uint32_t system_status : 2; /**< 0: Normal. 1: Warning. 2: Error. */
} LidarErrorCode;
/** Hub error code. */
typedef struct {
/** 0: No synchronization signal.
* 1: 1588 synchronization.
* 2: GPS synchronization.
* 3: System time synchronization is abnormal.(The highest priority synchronization signal is abnormal)
*/
uint32_t sync_status : 2;
uint32_t temp_status : 2; /**< 0: Temperature in Normal State. 1: High or Low. 2: Extremely High or Extremely Low. */
uint32_t lidar_status : 1; /**< 0: LiDAR State is Normal. 1: LiDAR State is Abnormal. */
uint32_t lidar_link_status : 1; /**< 0: LiDAR Connection is Normal. 1: LiDAR Connection is Abnormal. */
uint32_t firmware_err : 1; /**< 0: LiDAR Firmware is OK. 1: LiDAR Firmware is Abnormal, Need to be Upgraded. */
uint32_t rsvd : 23; /**< Reserved. */
uint32_t system_status : 2; /**< 0: Normal. 1: Warning. 2: Error. */
} HubErrorCode;
/**
* Device error message.
*/
typedef union {
uint32_t error_code; /**< Error code. */
LidarErrorCode lidar_error_code; /**< Lidar error code. */
HubErrorCode hub_error_code; /**< Hub error code. */
} ErrorMessage;
/** Point cloud packet. */
typedef struct {
uint8_t version; /**< Packet protocol version. */
uint8_t slot; /**< Slot number used for connecting LiDAR. */
uint8_t id; /**< LiDAR id. */
uint8_t rsvd; /**< Reserved. */
uint8_t version; /**< Packet protocol version. */
uint8_t slot; /**< Slot number used for connecting LiDAR. */
uint8_t id; /**< LiDAR id. */
uint8_t rsvd; /**< Reserved. */
uint32_t err_code; /**< Device error status indicator information. */
uint8_t timestamp_type; /**< Timestamp type. */
/** Point cloud coordinate format, 1 for spherical coordinate data, 0 for cartesian coordinate data. */
uint8_t timestamp_type; /**< Timestamp type. */
/** Point cloud coordinate format, refer to \ref PointDataType . */
uint8_t data_type;
uint8_t timestamp[8]; /**< Nanosecond or UTC format timestamp. */
uint8_t data[1]; /**< Point cloud data. */
uint8_t timestamp[8]; /**< Nanosecond or UTC format timestamp. */
uint8_t data[1]; /**< Point cloud data. */
} LivoxEthPacket;
/** Information of LiDAR work state. */
typedef union {
uint32_t status_code; /**< LiDAR work state status code. */
uint32_t progress; /**< LiDAR work state switching progress. */
uint32_t progress; /**< LiDAR work state switching progress. */
ErrorMessage status_code; /**< LiDAR work state status code. */
} StatusUnion;
/** Information of the connected LiDAR or hub. */
@@ -155,17 +296,19 @@ typedef struct {
uint8_t type; /**< Device type, refer to \ref DeviceType. */
uint16_t data_port; /**< Point cloud data UDP port. */
uint16_t cmd_port; /**< Control command UDP port. */
uint16_t sensor_port; /**< IMU data UDP port. */
char ip[16]; /**< IP address. */
LidarState state; /**< LiDAR state. */
LidarFeature feature; /**< LiDAR feature. */
StatusUnion status; /** LiDAR work state status. */
StatusUnion status; /**< LiDAR work state status. */
} DeviceInfo;
/** The information of broadcast device. */
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code, null-terminated string, 15 characters at most. */
uint8_t dev_type; /**< Device type, refer to \ref DeviceType. */
uint16_t reserved; /**< Reserved. */
uint16_t reserved; /**< Reserved. */
char ip[16]; /**< Device ip. */
} BroadcastDeviceInfo;
/** The information of LiDAR units that are connected to the Livox Hub. */
@@ -180,7 +323,7 @@ typedef struct {
/** LiDAR mode configuration information. */
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code, null-terminated string, 15 characters at most. */
uint8_t state; /**< LiDAR state. */
uint8_t state; /**< LiDAR state, refer to \ref LidarMode. */
} LidarModeRequestItem;
typedef struct {
@@ -197,6 +340,52 @@ typedef struct {
uint8_t feature; /**< Close or open the rain and fog feature. */
} RainFogSuppressRequestItem;
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
uint8_t state; /**< Fan state: 1 for turn on fan, 0 for turn off fan. */
} FanControlRequestItem;
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
} GetFanStateRequestItem;
typedef struct {
uint8_t ret_code; /**< Return code. */
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
uint8_t state; /**< Fan state: 1 for fan is on, 0 for fan is off. */
} GetFanStateResponseItem;
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
uint8_t mode; /**< Point cloud return mode, refer to \ref PointCloudReturnMode. */
} SetPointCloudReturnModeRequestItem;
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
} GetPointCloudReturnModeRequestItem;
typedef struct {
uint8_t ret_code; /**< Return code. */
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
uint8_t mode; /**< Point cloud return mode, refer to \ref PointCloudReturnMode. */
} GetPointCloudReturnModeResponseItem;
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
uint8_t freq; /**< IMU push frequency, refer to \ref ImuFreq. */
} SetImuPushFrequencyRequestItem;
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
} GetImuPushFrequencyRequestItem;
typedef struct {
uint8_t ret_code; /**< Return code. */
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
uint8_t freq; /**< IMU push frequency, refer to \ref ImuFreq. */
} GetImuPushFrequencyResponseItem;
/** LiDAR configuration information. */
typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Device broadcast code. */
@@ -224,16 +413,17 @@ typedef struct {
char broadcast_code[kBroadcastCodeSize]; /**< Broadcast code. */
uint8_t state; /**< LiDAR state. */
uint8_t feature; /**< LiDAR feature. */
StatusUnion error_union; /** LiDAR work state. */
StatusUnion error_union; /**< LiDAR work state. */
} LidarStateItem;
/**
* The request body for the command of handshake.
*/
typedef struct {
uint32_t ip_addr; /**< IP address of the device. */
uint16_t data_port; /**< UDP port of the data connection. */
uint16_t cmd_port; /**< UDP port of the command connection. */
uint32_t ip_addr; /**< IP address of the device. */
uint16_t data_port; /**< UDP port of the data connection. */
uint16_t cmd_port; /**< UDP port of the command connection. */
uint16_t sensor_port; /**< UDP port of the sensor connection. */
} HandshakeRequest;
/**
@@ -244,18 +434,11 @@ typedef struct {
uint8_t firmware_version[4]; /**< Firmware version. */
} DeviceInformationResponse;
/**
* The response body of getting device error status.
*/
typedef struct {
uint32_t error_code; /**< Error code. */
} ErrorMessage;
/**
* The request body of the command for setting device's IP mode.
*/
typedef struct {
uint8_t ip_mode; /**< IP address mode: 0 for dynamic IP address, 1 for static IP address. */
uint8_t ip_mode; /**< IP address mode: 0 for dynamic IP address, 1 for static IP address. */
uint32_t ip_addr; /**< IP address. */
} SetDeviceIPModeRequest;
@@ -263,23 +446,34 @@ typedef struct {
* The response body of getting device's IP mode.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t ip_mode; /**< IP address mode: 0 for dynamic IP address, 1 for static IP address. */
uint32_t ip_addr; /**< IP address. */
} GetDeviceIPModeResponse;
uint8_t ret_code; /**< Return code. */
uint8_t ip_mode; /**< IP address mode: 0 for dynamic IP address, 1 for static IP address. */
uint32_t ip_addr; /**< IP address. */
uint32_t net_mask; /**< Subnet mask. */
uint32_t gw_addr; /**< Gateway address. */
} GetDeviceIpModeResponse;
/**
* The request body of the command for setting static device's IP mode.
*/
typedef struct {
uint32_t ip_addr; /**< IP address. */
uint32_t net_mask; /**< Subnet mask. */
uint32_t gw_addr; /**< Gateway address. */
} SetStaticDeviceIpModeRequest;
/**
* The body of heartbeat response.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t state; /**< Working state. */
uint8_t feature; /**< LiDAR feature. */
uint8_t ret_code; /**< Return code. */
uint8_t state; /**< Working state. */
uint8_t feature; /**< LiDAR feature. */
StatusUnion error_union; /**< LiDAR work state. */
} HeartbeatResponse;
/**
* The request body for the command of setting LiDAR's parameters.
* The request body for the command of setting Livox LiDAR's parameters.
*/
typedef struct {
float roll; /**< Roll angle, unit: degree. */
@@ -291,7 +485,7 @@ typedef struct {
} LidarSetExtrinsicParameterRequest;
/**
* The response body of getting LiDAR's parameters.
* The response body of getting Livox LiDAR's parameters.
*/
typedef struct {
uint8_t ret_code;
@@ -303,28 +497,64 @@ typedef struct {
int32_t z; /**< Z translation, unit: mm. */
} LidarGetExtrinsicParameterResponse;
/**
* The response body of getting the Livox LiDAR's fan state.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t state; /**< Fan state: 1 for fan is on, 0 for fan is off. */
} LidarGetFanStateResponse;
/**
* The response body of getting the Livox LiDAR's point cloud return mode.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t mode; /**< Point cloud return mode, refer to \ref PointCloudReturnMode. */
} LidarGetPointCloudReturnModeResponse;
/**
* The response body of getting the Livox LiDAR's IMU push frequency.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t freq; /**< IMU push frequency, refer to \ref ImuFreq. */
} LidarGetImuPushFrequencyResponse;
/**
* The response body of setting the Livox LiDAR's Sync time.
*/
typedef struct {
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint32_t mircrosecond;
} LidarSetUtcSyncTimeRequest;
/**
* The response body of querying the information of LiDAR units connected to the Livox Hub.
*/
typedef struct {
uint8_t ret_code; /**< Return code from device. */
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of device_info_list. */
ConnectedLidarInfo device_info_list[1]; /**< Connected lidars information. */
ConnectedLidarInfo device_info_list[1]; /**< Connected lidars information list. */
} HubQueryLidarInformationResponse;
/**
* The request body of setting LiDAR units working mode.
* The request body of setting Livox Hub's working mode.
*/
typedef struct {
uint8_t count; /**< Number of LiDAR units to set. */
uint8_t count; /**< Count of config_list. */
LidarModeRequestItem config_list[1]; /**< LiDAR mode configuration list. */
} HubSetModeRequest;
/**
* The response of setting LiDAR units working mode.
* The response of setting Livox Hub's working mode.
*/
typedef struct {
uint8_t ret_code; /**< Return code from device. */
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of ret_state_list. */
ReturnCode ret_state_list[1]; /**< Return status list. */
} HubSetModeResponse;
@@ -342,7 +572,7 @@ typedef struct {
*/
typedef struct {
uint8_t count; /**< Count of cfg_param_list. */
ExtrinsicParameterRequestItem parameter_list[1]; /**< Configuration parameter list. */
ExtrinsicParameterRequestItem parameter_list[1]; /**< Extrinsic parameter configuration list. */
} HubSetExtrinsicParameterRequest;
/**
@@ -351,7 +581,7 @@ typedef struct {
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of ret_code_list. */
ReturnCode ret_code_list[1]; /**< Return code */
ReturnCode ret_code_list[1]; /**< Return code list. */
} HubSetExtrinsicParameterResponse;
/**
@@ -367,44 +597,146 @@ typedef struct {
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Number of LiDAR units connected to the Livox Hub. */
ExtrinsicParameterResponseItem parameter_list[1]; /**< Postion parameters of connected LiDAR unit(s). */
uint8_t count; /**< Count of code_list. */
ExtrinsicParameterResponseItem parameter_list[1]; /**< Extrinsic parameter list. */
} HubGetExtrinsicParameterResponse;
/**
* The response body of getting sub LiDAR's state.
* The response body of getting sub LiDAR's state conneted to Hub.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Number of LiDAR connected to the Livox Hub. */
LidarStateItem state_list[1]; /**< Device information of connected LiDAR units. */
uint8_t count; /**< Count of state_list. */
LidarStateItem state_list[1]; /**< LiDAR units state list. */
} HubQueryLidarStatusResponse;
/**
* The request body of toggling the LiDAR units rain and fog mode.
* The request body of toggling the Livox Hub's rain and fog mode.
*/
typedef struct {
uint8_t count; /**< Number of LiDAR units connected to the Livox Hub. */
RainFogSuppressRequestItem lidar_cfg_list[1]; /**< Command data of connected LiDAR units. */
uint8_t count; /**< Count of lidar_cfg_list. */
RainFogSuppressRequestItem lidar_cfg_list[1]; /**< Rain fog suppress configuration list. */
} HubRainFogSuppressRequest;
/**
* The response body of toggling the LiDAR units rain and fog mode.
* The response body of toggling the Livox Hub's rain and fog mode.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of ret_state_list. */
ReturnCode ret_state_list[1]; /**< Return code */
ReturnCode ret_state_list[1]; /**< Return state list */
} HubRainFogSuppressResponse;
/**
* The response body of getting hub slots' power state.
* The response body of getting Hub slots' power state.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint16_t slot_power_state; /**< Slot power status. */
} HubQuerySlotPowerStatusResponse;
/**
* The request body of controlling the sub LiDAR's fan state conneted to Hub.
*/
typedef struct {
uint8_t count; /**< Count of lidar_cfg_list. */
FanControlRequestItem lidar_cfg_list[1]; /**< Fan control configuration list. */
} HubFanControlRequest;
/**
* The response body of controlling the sub LiDAR's fan state conneted to Hub.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of return_list. */
ReturnCode return_list[1]; /**< Return list */
} HubFanControlResponse;
/**
* The request body of getting the sub LiDAR's fan state conneted to Hub.
*/
typedef struct {
uint8_t count; /**< Count of lidar_cfg_list. */
GetFanStateRequestItem lidar_cfg_list[1]; /**< Get Fan state list. */
} HubGetFanStateRequest;
/**
* The response body of getting the sub LiDAR's fan state conneted to Hub.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of return_list. */
GetFanStateResponseItem return_list[1]; /**< Fan state list. */
} HubGetFanStateResponse;
/**
* The request body of setting point cloud return mode of sub LiDAR conneted to Hub.
*/
typedef struct {
uint8_t count; /**< Count of lidar_cfg_list. */
SetPointCloudReturnModeRequestItem lidar_cfg_list[1]; /**< Point cloud return mode configuration list. */
} HubSetPointCloudReturnModeRequest;
/**
* The response body of setting point cloud return mode of sub LiDAR conneted to Hub.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of return_list. */
ReturnCode return_list[1]; /**< Return list. */
} HubSetPointCloudReturnModeResponse;
/**
* The request body of getting sub LiDAR's point cloud return mode conneted to Hub.
*/
typedef struct {
uint8_t count; /**< Count of lidar_cfg_list. */
GetPointCloudReturnModeRequestItem lidar_cfg_list[1]; /**< Get point cloud return mode list. */
} HubGetPointCloudReturnModeRequest;
/**
* The response body of getting sub LiDAR's point cloud return mode conneted to Hub.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of return_list. */
GetPointCloudReturnModeResponseItem return_list[1]; /**< Point cloud return mode list. */
} HubGetPointCloudReturnModeResponse;
/**
* The request body of setting IMU push frequency of sub LiDAR conneted to Hub.
*/
typedef struct {
uint8_t count; /**< Count of lidar_cfg_list. */
SetImuPushFrequencyRequestItem lidar_cfg_list[1]; /**< IMU push frequency configuration list. */
} HubSetImuPushFrequencyRequest;
/**
* The response body of setting IMU push frequency of sub LiDAR conneted to Hub.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of return_list. */
ReturnCode return_list[1]; /**< Return list. */
} HubSetImuPushFrequencyResponse;
/**
* The request body of getting sub LiDAR's IMU push frequency conneted to Hub.
*/
typedef struct {
uint8_t count; /**< Count of lidar_cfg_list. */
GetImuPushFrequencyRequestItem lidar_cfg_list[1]; /**< Get IMU push frequency list. */
} HubGetImuPushFrequencyRequest;
/**
* The response body of getting sub LiDAR's IMU push frequency conneted to Hub.
*/
typedef struct {
uint8_t ret_code; /**< Return code. */
uint8_t count; /**< Count of return_list. */
GetImuPushFrequencyResponseItem return_list[1]; /**< IMU push frequency list. */
} HubGetImuPushFrequencyResponse;
#pragma pack()
#endif // LIVOX_DEF_H_
+438 -98
View File
@@ -101,36 +101,36 @@ void SetDeviceStateUpdateCallback(DeviceStateUpdateCallback cb);
* @param broadcast_code device's broadcast code.
* @param handle device handle. For Livox Hub, the handle is always 31; for LiDAR units connected to the Livox Hub,
* the corresponding handle is (slot-1)*3+id-1.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t AddHubToConnect(const char *broadcast_code, uint8_t *handle);
livox_status AddHubToConnect(const char *broadcast_code, uint8_t *handle);
/**
* Add a broadcast code to the connecting list and only devices with broadcast code in this list will be connected. The
* broadcast code is unique for every device.
* @param broadcast_code device's broadcast code.
* @param handle device handle. The handle is the same as the order calling AddLidarToConnect starting from 0.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t AddLidarToConnect(const char *broadcast_code, uint8_t *handle);
livox_status AddLidarToConnect(const char *broadcast_code, uint8_t *handle);
/**
* Get all connected devices' information.
* @param devices list of connected devices' information.
* @param size number of devices connected.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t GetConnectedDevices(DeviceInfo *devices, uint8_t *size);
livox_status GetConnectedDevices(DeviceInfo *devices, uint8_t *size);
/**
* Function type of callback that queries device's information.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*DeviceInformationCallback)(uint8_t status,
typedef void (*DeviceInformationCallback)(livox_status status,
uint8_t handle,
DeviceInformationResponse *response,
void *client_data);
@@ -140,9 +140,9 @@ typedef void (*DeviceInformationCallback)(uint8_t status,
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t QueryDeviceInformation(uint8_t handle, DeviceInformationCallback cb, void *client_data);
livox_status QueryDeviceInformation(uint8_t handle, DeviceInformationCallback cb, void *client_data);
/**
* Callback function for receiving point cloud data.
@@ -164,29 +164,29 @@ void SetDataCallback(uint8_t handle, DataCallback cb, void *client_data);
/**
* Function type of callback with 1 byte of response.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*CommonCommandCallback)(uint8_t status, uint8_t handle, uint8_t response, void *client_data);
typedef void (*CommonCommandCallback)(livox_status status, uint8_t handle, uint8_t response, void *client_data);
/**
* Start hub sampling.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubStartSampling(CommonCommandCallback cb, void *client_data);
livox_status HubStartSampling(CommonCommandCallback cb, void *client_data);
/**
* Stop the Livox Hub's sampling.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubStopSampling(CommonCommandCallback cb, void *client_data);
livox_status HubStopSampling(CommonCommandCallback cb, void *client_data);
/**
* Get the LiDAR unit handle used in the Livox Hub data callback function from slot and id.
@@ -194,85 +194,133 @@ uint8_t HubStopSampling(CommonCommandCallback cb, void *client_data);
* @param id Livox Hub's id.
* @return LiDAR unit handle.
*/
uint8_t HubGetLidarHandle(uint8_t slot, uint8_t id);
livox_status HubGetLidarHandle(uint8_t slot, uint8_t id);
/**
* Command to change point cloud coordinate system to cartesian coordinate.
* Disconnect divice.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t SetCartesianCoordinate(uint8_t handle, CommonCommandCallback cb, void *client_data);
livox_status DisconnectDevice(uint8_t handle, CommonCommandCallback cb, void *client_data);
/**
* Change point cloud coordinate system to cartesian coordinate.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status SetCartesianCoordinate(uint8_t handle, CommonCommandCallback cb, void *client_data);
/**
* Change point cloud coordinate system to spherical coordinate.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t SetSphericalCoordinate(uint8_t handle, CommonCommandCallback cb, void *client_data);
livox_status SetSphericalCoordinate(uint8_t handle, CommonCommandCallback cb, void *client_data);
/**
* Callback of the error status message.
* kStatusSuccess on successful return, see \ref LivoxStatus for other
* @param handle device handle.
* @param response response from the device.
*/
typedef void (*ErrorMessageCallback)(uint8_t handle, ErrorMessage *message);
typedef void (*ErrorMessageCallback)(livox_status status, uint8_t handle, ErrorMessage *message);
/**
* Add error status callback for the device.
* error code.
* @param handle device handle.
* @param cb callback for the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t SetErrorMessageCallback(uint8_t handle, ErrorMessageCallback cb);
livox_status SetErrorMessageCallback(uint8_t handle, ErrorMessageCallback cb);
/**
* Set device's IP mode.
* @note \ref SetStaticDynamicIP only supports setting Hub or Mid40/100's IP mode.
* If you want to set Horizon or Tele's IP mode, see \ref SetStaticIp and \ref SetDynamicIp.
* @param handle device handle.
* @param req request sent to device.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t SetStaticDynamicIP(uint8_t handle,
SetDeviceIPModeRequest *req,
CommonCommandCallback cb,
void *client_data);
livox_status SetStaticDynamicIP(uint8_t handle,
SetDeviceIPModeRequest *req,
CommonCommandCallback cb,
void *client_data);
/**
* Set device's static IP mode.
* @note Mid40/100 is not supported to set subnet mask and gateway address.
* \ref SetStaticDeviceIpModeRequest's setting: net_mask and gw_addr will not take effect on Mid40/100.
* @param handle device handle.
* @param req request sent to device.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status SetStaticIp(uint8_t handle,
SetStaticDeviceIpModeRequest *req,
CommonCommandCallback cb,
void *client_data);
/**
* Set device's dynamic IP mode.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status SetDynamicIp(uint8_t handle,
CommonCommandCallback cb,
void *client_data);
/**
* Callback function that gets device's IP information.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*GetDeviceIPInformationCallback)(uint8_t status,
uint8_t handle,
GetDeviceIPModeResponse *response,
void *client_data);
typedef void (*GetDeviceIpInformationCallback)(livox_status status,
uint8_t handle,
GetDeviceIpModeResponse *response,
void *client_data);
/**
* Get device's IP mode.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t GetDeviceIPInformation(uint8_t handle, GetDeviceIPInformationCallback cb, void *client_data);
livox_status GetDeviceIpInformation(uint8_t handle, GetDeviceIpInformationCallback cb, void *client_data);
/**
* Reboot device.
* @note \ref RebootDevice is not supported for Mid40/100
* @param handle device handle.
* @param timeout reboot device after [timeout] ms.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status RebootDevice(uint8_t handle, uint16_t timeout, CommonCommandCallback cb, void * client_data);
/**
* @c HubQueryLidarInformation response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubQueryLidarInformationCallback)(uint8_t status,
typedef void (*HubQueryLidarInformationCallback)(livox_status status,
uint8_t handle,
HubQueryLidarInformationResponse *response,
void *client_data);
@@ -281,19 +329,19 @@ typedef void (*HubQueryLidarInformationCallback)(uint8_t status,
* Query the information of LiDARs connected to the hub.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubQueryLidarInformation(HubQueryLidarInformationCallback cb, void *client_data);
livox_status HubQueryLidarInformation(HubQueryLidarInformationCallback cb, void *client_data);
/**
* @c HubSetMode response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubSetModeCallback)(uint8_t status, uint8_t handle, HubSetModeResponse *response, void *client_data);
typedef void (*HubSetModeCallback)(livox_status status, uint8_t handle, HubSetModeResponse *response, void *client_data);
/**
* Set the mode of LiDAR unit connected to the Livox Hub.
@@ -301,47 +349,46 @@ typedef void (*HubSetModeCallback)(uint8_t status, uint8_t handle, HubSetModeRes
* @param length length of req.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubSetMode(HubSetModeRequest *req, uint16_t length, HubSetModeCallback cb, void *client_data);
livox_status HubSetMode(HubSetModeRequest *req, uint16_t length, HubSetModeCallback cb, void *client_data);
/**
* @c HubQueryLidarStatus response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubQueryLidarStatusCallback)(uint8_t status, uint8_t handle, HubQueryLidarStatusResponse *response, void *client_data);
typedef void (*HubQueryLidarStatusCallback)(livox_status status, uint8_t handle, HubQueryLidarStatusResponse *response, void *client_data);
/**
* Get the state of LiDAR units connected to the Livox Hub.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubQueryLidarStatus(HubQueryLidarStatusCallback cb, void *client_data);
livox_status HubQueryLidarStatus(HubQueryLidarStatusCallback cb, void *client_data);
/**
* Toggle the power supply of designated slots.
* @param req request whether to enable or disable the power of designated slots.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubControlSlotPower(HubControlSlotPowerRequest *req, CommonCommandCallback cb, void *client_data);
livox_status HubControlSlotPower(HubControlSlotPowerRequest *req, CommonCommandCallback cb, void *client_data);
/**
* @c HubSetExtrinsicParameter response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubSetExtrinsicParameterCallback)(uint8_t status,
typedef void (*HubSetExtrinsicParameterCallback)(livox_status status,
uint8_t handle,
HubSetExtrinsicParameterResponse *response,
void *client_data);
@@ -352,22 +399,22 @@ typedef void (*HubSetExtrinsicParameterCallback)(uint8_t status,
* @param length the request's length.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubSetExtrinsicParameter(HubSetExtrinsicParameterRequest *req,
uint16_t length,
HubSetExtrinsicParameterCallback cb,
void *client_data);
livox_status HubSetExtrinsicParameter(HubSetExtrinsicParameterRequest *req,
uint16_t length,
HubSetExtrinsicParameterCallback cb,
void *client_data);
/**
* @c HubGetExtrinsicParameter response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubGetExtrinsicParameterCallback)(uint8_t status,
typedef void (*HubGetExtrinsicParameterCallback)(livox_status status,
uint8_t handle,
HubGetExtrinsicParameterResponse *response,
void *client_data);
@@ -376,29 +423,28 @@ typedef void (*HubGetExtrinsicParameterCallback)(uint8_t status,
* Get extrinsic parameters of LiDAR units connected to the Livox Hub.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubGetExtrinsicParameter(HubGetExtrinsicParameterCallback cb, void *client_data);
livox_status HubGetExtrinsicParameter(HubGetExtrinsicParameterCallback cb, void *client_data);
/**
* Turn on or off the calculation of extrinsic parameters.
* @param enable the request whether enable or disable calculating the extrinsic parameters.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubExtrinsicParameterCalculation(bool enable, CommonCommandCallback cb, void *client_data);
livox_status HubExtrinsicParameterCalculation(bool enable, CommonCommandCallback cb, void *client_data);
/**
* @c HubRainFogSuppress response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubRainFogSuppressCallback)(uint8_t status,
typedef void (*HubRainFogSuppressCallback)(livox_status status,
uint8_t handle,
HubRainFogSuppressResponse *response,
void *client_data);
@@ -409,48 +455,201 @@ typedef void (*HubRainFogSuppressCallback)(uint8_t status,
* @param length the request's length.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubRainFogSuppress(HubRainFogSuppressRequest *req,
uint16_t length,
HubRainFogSuppressCallback cb,
void *client_data);
livox_status HubRainFogSuppress(HubRainFogSuppressRequest *req,
uint16_t length,
HubRainFogSuppressCallback cb,
void *client_data);
/**
* @c HubQuerySlotPowerStatus response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void(*HubQuerySlotPowerStatusCallback)(uint8_t status, uint8_t handle, HubQuerySlotPowerStatusResponse *response, void *client_data);
typedef void(*HubQuerySlotPowerStatusCallback)(livox_status status, uint8_t handle, HubQuerySlotPowerStatusResponse *response, void *client_data);
/**
* Get the power supply state of each hub slot.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t HubQuerySlotPowerStatus(HubQuerySlotPowerStatusCallback cb, void *client_data);
livox_status HubQuerySlotPowerStatus(HubQuerySlotPowerStatusCallback cb, void *client_data);
/**
* @c HubFanControl response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubFanControlCallback)(livox_status status,
uint8_t handle,
HubFanControlResponse *response,
void *client_data);
/**
* Turn on or off the fan of LiDAR unit connected to the Livox Hub.
* @param req Fan control of LiDAR units.
* @param length length of req.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status HubFanControl(HubFanControlRequest *req, uint16_t length, HubFanControlCallback cb, void *client_data);
/**
* @c HubGetFanControl response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubGetFanStateCallback)(livox_status status,
uint8_t handle,
HubGetFanStateResponse *response,
void *client_data);
/**
* Get fan state of LiDAR unit connected to the Livox Hub.
* @param req Get fan state of LiDAR units.
* @param length length of req.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status HubGetFanState(HubGetFanStateRequest *req,
uint16_t length,
HubGetFanStateCallback cb,
void *client_data);
/**
* @c HubSetPointCloudReturnMode response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubSetPointCloudReturnModeCallback)(livox_status status,
uint8_t handle,
HubSetPointCloudReturnModeResponse *response,
void *client_data);
/**
* Set point cloud return mode of LiDAR units connected to the Livox Hub.
* @param req set point cloud return mode of LiDAR units.
* @param length the request's length.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status HubSetPointCloudReturnMode(HubSetPointCloudReturnModeRequest *req,
uint16_t length,
HubSetPointCloudReturnModeCallback cb,
void *client_data);
/**
* @c HubGetPointCloudReturnMode response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubGetPointCloudReturnModeCallback)(livox_status status,
uint8_t handle,
HubGetPointCloudReturnModeResponse *response,
void *client_data);
/**
* Get point cloud return mode of LiDAR unit connected to the Livox Hub.
* @param req Get point cloud return mode of LiDAR units.
* @param length length of req.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status HubGetPointCloudReturnMode(HubGetPointCloudReturnModeRequest *req,
uint16_t length,
HubGetPointCloudReturnModeCallback cb,
void *client_data);
/**
* @c HubSetImuPushFrequency response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubSetImuPushFrequencyCallback)(livox_status status,
uint8_t handle,
HubSetImuPushFrequencyResponse *response,
void *client_data);
/**
* Set IMU push frequency of LiDAR units connected to the Livox Hub.
* @param req set IMU push frequency of LiDAR units.
* @param length the request's length.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status HubSetImuPushFrequency(HubSetImuPushFrequencyRequest *req,
uint16_t length,
HubSetImuPushFrequencyCallback cb,
void *client_data);
/**
* @c HubGetImuPushFrequency response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*HubGetImuPushFrequencyCallback)(livox_status status,
uint8_t handle,
HubGetImuPushFrequencyResponse *response,
void *client_data);
/**
* Get IMU push frequency of LiDAR units connected to the Livox Hub.
* @param req get IMU push frequency of LiDAR units.
* @param length the request's length.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status HubGetImuPushFrequency(HubGetImuPushFrequencyRequest *req,
uint16_t length,
HubGetImuPushFrequencyCallback cb,
void *client_data);
/**
* Start LiDAR sampling.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t LidarStartSampling(uint8_t handle, CommonCommandCallback cb, void *client_data);
livox_status LidarStartSampling(uint8_t handle, CommonCommandCallback cb, void *client_data);
/**
* Stop LiDAR sampling.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t LidarStopSampling(uint8_t handle, CommonCommandCallback cb, void *client_data);
livox_status LidarStopSampling(uint8_t handle, CommonCommandCallback cb, void *client_data);
/**
* Set LiDAR mode.
@@ -460,53 +659,194 @@ uint8_t LidarStopSampling(uint8_t handle, CommonCommandCallback cb, void *client
* @param mode the mode to change.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t LidarSetMode(uint8_t handle, LidarMode mode, CommonCommandCallback cb, void *client_data);
livox_status LidarSetMode(uint8_t handle, LidarMode mode, CommonCommandCallback cb, void *client_data);
/**
* Set LiDAR extrinsic parameters.
* @param handle device handle.
* @param param the parameters to write.
* @param req the parameters to write.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t LidarSetExtrinsicParameter(uint8_t handle,
LidarSetExtrinsicParameterRequest *req,
CommonCommandCallback cb,
void *client_data);
livox_status LidarSetExtrinsicParameter(uint8_t handle,
LidarSetExtrinsicParameterRequest *req,
CommonCommandCallback cb,
void *client_data);
/**
* @c LidarGetExtrinsicParameter response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref ResponseStatus for other
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*LidarGetExtrinsicParameterCallback)(uint8_t status,
uint8_t handle,
LidarGetExtrinsicParameterResponse *response,
void *client_data);
typedef void (*LidarGetExtrinsicParameterCallback)(livox_status status,
uint8_t handle,
LidarGetExtrinsicParameterResponse *response,
void *client_data);
/**
* Get LiDAR extrinsic parameters.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t LidarGetExtrinsicParameter(uint8_t handle, LidarGetExtrinsicParameterCallback cb, void *client_data);
livox_status LidarGetExtrinsicParameter(uint8_t handle, LidarGetExtrinsicParameterCallback cb, void *client_data);
/**
* Enable and disable the rain/fog suppression.
* @note \ref LidarRainFogSuppress only support for Mid40/100.
* @param handle device handle.
* @param enable enable and disable the rain/fog suppression.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarRainFogSuppress(uint8_t handle, bool enable, CommonCommandCallback cb, void *client_data);
/**
* Turn off the fan.
* @note \ref LidarTurnOffFan is not supported for Mid40/100.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref ResponseStatus for other error code.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
uint8_t LidarRainFogSuppress(uint8_t handle, bool enable, CommonCommandCallback cb, void *client_data);
livox_status LidarTurnOffFan(uint8_t handle, CommonCommandCallback cb, void *client_data);
/**
* Turn on the fan.
* @note \ref LidarTurnOnFan is not supported for Mid40/100.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarTurnOnFan(uint8_t handle, CommonCommandCallback cb, void *client_data);
/**
* @c LidarGetFanState response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*LidarGetFanStateCallback)(livox_status status,
uint8_t handle,
LidarGetFanStateResponse *response,
void *client_data);
/**
* Get state of the fan.
* @note \ref LidarGetFanState is not supported for Mid40/100.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarGetFanState(uint8_t handle, LidarGetFanStateCallback cb, void * client_data) ;
/**
* Set point cloud return mode.
* @note \ref LidarSetPointCloudReturnMode is not supported for Mid40/100.
* @param handle device handle.
* @param mode point cloud return mode.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarSetPointCloudReturnMode(uint8_t handle, PointCloudReturnMode mode, CommonCommandCallback cb, void * client_data);
/**
* @c LidaGetPointCloudReturnMode response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*LidarGetPointCloudReturnModeCallback)(livox_status status,
uint8_t handle,
LidarGetPointCloudReturnModeResponse *response,
void *client_data);
/**
* Get point cloud return mode.
* @note \ref LidarGetPointCloudReturnMode is not supported for Mid40/100.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarGetPointCloudReturnMode(uint8_t handle, LidarGetPointCloudReturnModeCallback cb, void * client_data);
/**
* Set IMU push frequency.
* @note \ref LidarSetImuPushFrequency is not supported for Mid40/100.
* @param handle device handle.
* @param freq IMU push frequency.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarSetImuPushFrequency(uint8_t handle, ImuFreq freq, CommonCommandCallback cb, void * client_data);
/**
* @c LidaGetImuPushFrequency response callback function.
* @param status kStatusSuccess on successful return, kStatusTimeout on timeout, see \ref LivoxStatus for other
* error code.
* @param handle device handle.
* @param response response from the device.
* @param client_data user data associated with the command.
*/
typedef void (*LidarGetImuPushFrequencyCallback)(livox_status status,
uint8_t handle,
LidarGetImuPushFrequencyResponse *response,
void *client_data);
/**
* Get IMU push frequency.
* @note \ref LidarGetImuPushFrequency is not supported for Mid40/100.
* @param handle device handle.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarGetImuPushFrequency(uint8_t handle, LidarGetImuPushFrequencyCallback cb, void * client_data);
/**
* Set GPRMC formate synchronization time.
* @param handle device handle.
* @param rmc GPRMC\GNRMC format data.
* @param rmc_length lenth of gprmc.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarSetRmcSyncTime(uint8_t handle,
const char* rmc,
uint16_t rmc_length,
CommonCommandCallback cb,
void *client_data);
/**
* Set UTC formate synchronization time.
* @param handle device handle.
* @param req UTC format data.
* @param cb callback for the command.
* @param client_data user data associated with the command.
* @return kStatusSuccess on successful return, see \ref LivoxStatus for other error code.
*/
livox_status LidarSetUtcSyncTime(uint8_t handle,
LidarSetUtcSyncTimeRequest* req,
CommonCommandCallback cb,
void *client_data);
#ifdef __cplusplus
}
+33 -31
View File
@@ -34,18 +34,18 @@ namespace livox {
class CommandCallback {
public:
virtual ~CommandCallback() {}
virtual void operator()(uint8_t handle, void *data) = 0;
virtual void operator()(livox_status status,uint8_t handle, void *data) = 0;
};
template <class T, class ResponseType>
class MemberFunctionCallback : public CommandCallback {
public:
typedef void (T::*MemFn)(uint8_t status, uint8_t handle, ResponseType *data);
typedef void (T::*MemFn)(livox_status status, uint8_t handle, ResponseType *data);
MemberFunctionCallback(T *cls, MemFn func) : this_(cls), func_(func) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status, uint8_t handle, void *data) {
if (this_) {
(this_->*func_)((data == NULL) ? kStatusTimeout : kStatusSuccess, handle, static_cast<ResponseType *>(data));
(this_->*func_)(status, handle, static_cast<ResponseType *>(data));
}
}
@@ -57,14 +57,16 @@ class MemberFunctionCallback : public CommandCallback {
template <class T>
class MemberFunctionCallback<T, uint8_t> : public CommandCallback {
public:
typedef void (T::*MemFn)(uint8_t status, uint8_t handle, uint8_t response);
typedef void (T::*MemFn)(livox_status status, uint8_t handle, uint8_t response);
MemberFunctionCallback(T *cls, MemFn func) : this_(cls), func_(func) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status, uint8_t handle, void *data) {
if (this_) {
(this_->*func_)((data == NULL) ? kStatusTimeout : kStatusSuccess,
handle,
static_cast<uint8_t>(reinterpret_cast<uintptr_t>(data)));
if (data == NULL) {
(this_->*func_)(status, handle, 0);
} else {
(this_->*func_)(status, handle, static_cast<uint8_t>(reinterpret_cast<uintptr_t>(data)));
}
}
}
@@ -83,13 +85,13 @@ boost::shared_ptr<CommandCallback> MakeCommandCallback(T *cls,
template <class T>
class FunctionStatusCallback : public CommandCallback {
public:
typedef void (*Fn)(uint8_t status, uint8_t handle, T *data, void *client_data);
typedef void (*Fn)(livox_status status, uint8_t handle, T *data, void *client_data);
public:
FunctionStatusCallback(Fn func, void *client_data) : func_(func), client_data_(client_data) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status, uint8_t handle, void *data) {
if (func_) {
(*func_)((data == NULL) ? kStatusTimeout : kStatusSuccess, handle, static_cast<T *>(data), client_data_);
(*func_)(status, handle, static_cast<T *>(data), client_data_);
}
}
@@ -101,16 +103,16 @@ class FunctionStatusCallback : public CommandCallback {
template <>
class FunctionStatusCallback<uint8_t> : public CommandCallback {
public:
typedef void (*Fn)(uint8_t status, uint8_t handle, uint8_t data, void *client_data);
typedef void (*Fn)(livox_status status, uint8_t handle, uint8_t data, void *client_data);
public:
FunctionStatusCallback(Fn func, void *client_data) : func_(func), client_data_(client_data) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status, uint8_t handle, void *data) {
if (func_) {
if (data == NULL) {
(*func_)(kStatusTimeout, handle, 0, client_data_);
(*func_)(status, handle, 0, client_data_);
} else {
(*func_)(kStatusSuccess, handle, *(uint8_t *)data, client_data_);
(*func_)(status, handle, *(uint8_t *)data, client_data_);
}
}
}
@@ -129,13 +131,13 @@ boost::shared_ptr<CommandCallback> MakeCommandCallback(typename FunctionStatusCa
template <class T>
class MessageCallback : public CommandCallback {
public:
typedef void (*Fn)(uint8_t handle, T *data);
typedef void (*Fn)(livox_status status, uint8_t handle, T *data);
public:
MessageCallback(const Fn &func) : func_(func) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status, uint8_t handle, void *data) {
if (func_) {
(*func_)(handle, static_cast<T *>(data));
(*func_)(status, handle, static_cast<T *>(data));
}
}
@@ -146,13 +148,13 @@ class MessageCallback : public CommandCallback {
template <class ResponseType>
class BoostFunctionMessageCallback : public CommandCallback {
public:
typedef boost::function<void(uint8_t, ResponseType *)> Fn;
typedef boost::function<void(livox_status, uint8_t, ResponseType *)> Fn;
public:
BoostFunctionMessageCallback(const Fn &func) : func_(func) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status, uint8_t handle, void *data) {
if (func_) {
func_(handle, static_cast<ResponseType *>(data));
func_(status, handle, static_cast<ResponseType *>(data));
}
}
@@ -175,12 +177,12 @@ boost::shared_ptr<CommandCallback> MakeMessageCallback(typename BoostFunctionMes
template <class T, class ResponseType>
class MemberMessageCallback : public CommandCallback {
public:
typedef void (T::*MemFn)(uint8_t handle, ResponseType *data);
typedef void (T::*MemFn)(livox_status status, uint8_t handle, ResponseType *data);
MemberMessageCallback(T *cls, MemFn func) : this_(cls), func_(func) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status,uint8_t handle, void *data) {
if (this_) {
(this_->*func_)(handle, (ResponseType *)data);
(this_->*func_)(status, handle, (ResponseType *)data);
}
}
@@ -202,12 +204,12 @@ class BoostFunctionCallback : public CommandCallback {
public:
typedef boost::function<void(uint8_t, uint8_t, ResponseType *)> Fn;
BoostFunctionCallback(const Fn &func) : func_(func) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status,uint8_t handle, void *data) {
if (func_) {
if (data == NULL) {
func_(kStatusTimeout, handle, NULL);
func_(status, handle, NULL);
} else {
func_(kStatusSuccess, handle, (ResponseType *)data);
func_(status, handle, (ResponseType *)data);
}
}
}
@@ -221,12 +223,12 @@ class BoostFunctionCallback<uint8_t> : public CommandCallback {
public:
typedef boost::function<void(uint8_t, uint8_t, uint8_t)> Fn;
BoostFunctionCallback(const Fn &func) : func_(func) {}
void operator()(uint8_t handle, void *data) {
void operator()(livox_status status,uint8_t handle, void *data) {
if (func_) {
if (data == NULL) {
func_(kStatusTimeout, handle, 0);
func_(status, handle, 0);
} else {
func_(kStatusSuccess, handle, static_cast<uint8_t>(reinterpret_cast<uintptr_t>(data)));
func_(status, handle, static_cast<uint8_t>(reinterpret_cast<uintptr_t>(data)));
}
}
}
+7 -1
View File
@@ -39,6 +39,7 @@ bool IOLoop::Init() {
if (mem_pool_ == NULL) {
return false;
}
#ifdef WIN32
apr_status_t rv =
apr_pollset_create(&pollset_, kMaxPollCount, mem_pool_, APR_POLLSET_WAKEABLE);
@@ -80,6 +81,12 @@ void IOLoop::RemoveDelegate(apr_socket_t *sock, IOLoopDelegate *) {
PostTask(boost::bind(&IOLoop::RemoveDelegateAsync, this, sock));
}
void IOLoop::RemoveDelegateSync(apr_socket_t *sock) {
apr_os_thread_t thread_id = apr_os_thread_current();
assert(apr_os_thread_equal(this->thread_id_, thread_id));
RemoveDelegateAsync(sock);
}
void IOLoop::Loop() {
apr_int32_t num = 0;
const apr_pollfd_t *ret_pfd = NULL;
@@ -88,7 +95,6 @@ void IOLoop::Loop() {
if (rv == APR_SUCCESS) {
for (int i = 0; i < num; i++) {
ClientData *data = static_cast<ClientData *>(ret_pfd[i].client_data);
;
if (data) {
IOLoopDelegate *delegate = data->first;
if (delegate) {
+4
View File
@@ -60,9 +60,12 @@ class IOLoop : public noncopyable {
void Uninit();
void AddDelegate(apr_socket_t *sock, IOLoopDelegate *delegate, void *data = NULL);
void RemoveDelegate(apr_socket_t *sock, IOLoopDelegate *delegate);
void RemoveDelegateSync(apr_socket_t *sock);
void Loop();
bool Wakeup();
void PostTask(const IOLoopTask &task);
void SetThreadId (apr_os_thread_t thread_id) { thread_id_ = thread_id; }
apr_os_thread_t GetThreadId () { return thread_id_; }
private:
void AddDelegateAsync(apr_socket_t *sock, IOLoopDelegate *delegate, void *data);
@@ -80,6 +83,7 @@ class IOLoop : public noncopyable {
bool enable_timer_;
bool enable_wake_;
std::vector<IOLoopTask> pending_tasks_;
apr_os_thread_t thread_id_;
};
} // namespace livox
+3
View File
@@ -35,6 +35,9 @@ void IOThread::ThreadFunc() {
if (loop_ == NULL) {
return;
}
apr_os_thread_t thread_id = apr_os_thread_current();
loop_->SetThreadId(thread_id);
while (!IsQuit()) {
loop_->Loop();
}
+27 -20
View File
@@ -26,9 +26,9 @@
#ifdef WIN32
#include <boost/scoped_array.hpp>
#include <Winsock2.h>
#include <Iphlpapi.h>
#include <iphlpapi.h>
#include <string>
#pragma comment(lib,"Iphlpapi.lib")
#pragma comment(lib,"iphlpapi.lib")
#pragma comment(lib,"ws2_32.lib")
#else
#include <ifaddrs.h>
@@ -36,11 +36,13 @@
namespace livox {
namespace util {
apr_socket_t *CreateBindSocket(uint16_t port, apr_pool_t *mem_pool, bool nonblock) {
apr_socket_t *CreateBindSocket(uint16_t port, apr_pool_t *mem_pool, bool reuse_port, bool nonblock) {
apr_sockaddr_t *sa = NULL;
apr_socket_t *s = NULL;
apr_status_t rv = APR_SUCCESS;
rv = apr_sockaddr_info_get(&sa, NULL, APR_INET, port, 0, mem_pool);
if (rv != APR_SUCCESS) {
return NULL;
@@ -51,6 +53,15 @@ apr_socket_t *CreateBindSocket(uint16_t port, apr_pool_t *mem_pool, bool nonbloc
return NULL;
}
if (reuse_port) {
rv = apr_socket_opt_set(s, APR_SO_REUSEADDR, 1);
if (rv != APR_SUCCESS) {
apr_socket_close(s);
s = NULL;
return NULL;
}
}
rv = apr_socket_bind(s, sa);
if (rv != APR_SUCCESS) {
apr_socket_close(s);
@@ -87,7 +98,7 @@ bool GetAdapterState(const IP_ADAPTER_INFO *pAdapter)
return true;
}
bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
bool FindLocalIp(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
bool found = false;
ULONG ulOutbufLen = sizeof(IP_ADAPTER_INFO);
boost::scoped_array<uint8_t> pAdapterInfo(new uint8_t[ulOutbufLen]);
@@ -99,29 +110,25 @@ bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
IP_ADAPTER_INFO *pAdapter = reinterpret_cast<IP_ADAPTER_INFO *>(pAdapterInfo.get());
if (NO_ERROR == dlRetVal && pAdapter != NULL) {
while (pAdapter != NULL) {
if (GetAdapterState(pAdapter)) {
std::string str_ip = pAdapter->IpAddressList.IpAddress.String;
std::string str_mask = pAdapter->IpAddressList.IpMask.String;
ULONG host_ip = inet_addr(const_cast<char *>(str_ip.c_str()));
ULONG host_mask = inet_addr(const_cast<char *>(str_mask.c_str()));
while (GetAdapterState(pAdapter)) {
std::string str_ip = pAdapter->IpAddressList.IpAddress.String;
std::string str_mask = pAdapter->IpAddressList.IpMask.String;
ULONG host_ip = inet_addr(const_cast<char *>(str_ip.c_str()));
ULONG host_mask = inet_addr(const_cast<char *>(str_mask.c_str()));
if ((host_ip & host_mask) ==
(client_addr.sin_addr.S_un.S_addr & host_mask)) {
local_ip = host_ip;
found = true;
break;
}
if ((host_ip & host_mask) ==
(client_addr.sin_addr.S_un.S_addr & host_mask)) {
local_ip = host_ip;
found = true;
break;
}
pAdapter = pAdapter->Next;
}
}
return found;
}
#else
bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
bool FindLocalIp(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
struct ifaddrs *if_addrs = NULL, *addrs = NULL;
if (getifaddrs(&if_addrs) == -1) {
return false;
@@ -153,4 +160,4 @@ bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
}
#endif
} // namespace util
} // namespace livox
} // namespace livox
+2 -2
View File
@@ -34,8 +34,8 @@
namespace livox {
namespace util {
apr_socket_t *CreateBindSocket(uint16_t port, apr_pool_t *mem_pool, bool nonblock = true);
bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip);
apr_socket_t *CreateBindSocket(uint16_t port, apr_pool_t *mem_pool, bool reuse_port = false, bool nonblock = true);
bool FindLocalIp(const struct sockaddr_in &client_addr, uint32_t &local_ip);
} // namespace util
} // namespace livox
+1
View File
@@ -26,6 +26,7 @@
#define LIVOX_THREAD_BASE_H_
#include <apr_general.h>
#include <apr_thread_proc.h>
#include <apr_portable.h>
#include <boost/atomic/atomic.hpp>
#include "noncopyable.h"
@@ -149,7 +149,12 @@ void CommandChannel::OnTimer(apr_time_t now) {
void CommandChannel::Uninit() {
if (sock_) {
loop_->RemoveDelegate(sock_, this);
apr_os_thread_t thread_id = apr_os_thread_current();
if (apr_os_thread_equal(loop_->GetThreadId(), thread_id)) {
loop_->RemoveDelegateSync(sock_);
} else {
loop_->RemoveDelegate(sock_, this);
}
loop_ = NULL;
apr_socket_close(sock_);
sock_ = NULL;
@@ -195,6 +200,9 @@ void CommandChannel::SendInternal(const Command &command) {
if (rv == APR_SUCCESS) {
rv = apr_socket_sendto(sock_, sa, 0, (const char *)buf, &apr_size);
}
if (rv != APR_SUCCESS) {
(*command.cb)(kStatusSendFailed, handle_, NULL);
}
apr_pool_destroy(subpool);
}
@@ -226,7 +234,7 @@ void CommandChannel::OnHeartbeatAck(const CommPacket &) {
}
void CommandChannel::DeviceDisconnect(uint8_t handle) {
DeviceRemove(handle);
DeviceRemove(handle,kEventDisconnect);
}
void CommandChannel::Send(const Command &command) {
@@ -61,6 +61,32 @@ uint16_t GetCommandTimeout(uint8_t command_set, uint8_t command_id) {
return KDefaultTimeOut;
}
bool IsSubLidarException(const Command &command) {
if (device_manager().device_mode() == kDeviceModeLidar) {
return false;
}
if (!(command.packet.cmd_set == kCommandSetGeneral &&
command.packet.cmd_code == kCommandIDGeneralPushAbnormalState)) {
return false;
}
HubErrorCode* hub_error_code = static_cast<HubErrorCode *>((void *)command.packet.data);
if (hub_error_code->lidar_link_status == 0x01) {
return true;
}
return false;
}
bool IsMidDeviceIpResponse(const Command &command) {
return command.packet.cmd_set == kCommandSetGeneral &&
command.packet.cmd_code == kCommandIDGeneralGetDeviceIpInformation &&
command.packet.data_len != sizeof(GetDeviceIpModeResponse);
}
void OnSubLidarDisconnect() {
device_manager().UpdateDevices(DeviceInfo(), kEventHubConnectionChange);
}
bool CommandHandler::AddDevice(const DeviceInfo &info) {
if (impl_ == NULL) {
DeviceMode mode = static_cast<DeviceMode>(device_manager().device_mode());
@@ -109,14 +135,14 @@ void CommandHandler::OnCommand(uint8_t handle, const Command &command) {
}
}
bool CommandHandler::SendCommand(uint8_t handle,
uint8_t command_set,
uint8_t command_id,
uint8_t *data,
uint16_t length,
const shared_ptr<CommandCallback> &cb) {
livox_status CommandHandler::SendCommand(uint8_t handle,
uint8_t command_set,
uint8_t command_id,
uint8_t *data,
uint16_t length,
const shared_ptr<CommandCallback> &cb) {
if (impl_ == NULL) {
return false;
return kStatusHandlerImplNotExist;
}
Command cmd(handle,
@@ -128,24 +154,41 @@ bool CommandHandler::SendCommand(uint8_t handle,
length,
GetCommandTimeout(command_set, command_id),
cb);
bool result = impl_->SendCommand(handle, cmd);
livox_status result = impl_->SendCommand(handle, cmd);
return result;
}
bool CommandHandler::RegisterPush(uint8_t handle,
uint8_t command_set,
uint8_t command_id,
const shared_ptr<CommandCallback> &cb) {
livox_status CommandHandler::RegisterPush(uint8_t handle,
uint8_t command_set,
uint8_t command_id,
const shared_ptr<CommandCallback> &cb) {
lock_guard<mutex> lock(mutex_);
Command req(handle, kCommandTypeMsg, command_set, command_id, 0, NULL, 0, 0, cb);
message_registers_.insert(make_pair(MakeKey(command_set, command_id), req));
return true;
return kStatusSuccess;
}
void CommandHandler::OnCommandAck(uint8_t handle, const Command &command) {
if (command.cb != NULL) {
(*command.cb)(handle, command.packet.data);
if (command.cb == NULL) {
return;
}
if (command.packet.data == NULL) {
(*command.cb)(kStatusTimeout, handle, command.packet.data);
return;
}
if (IsMidDeviceIpResponse(command)) {
GetDeviceIpModeResponse response;
memcpy(&response, command.packet.data, command.packet.data_len);
uint8_t net_mask[4] = {255, 255, 255, 0};
memcpy(&response.net_mask, net_mask, 4);
uint8_t gw_addr[4] = {192, 168, 1, 1};
memcpy(&response.gw_addr, gw_addr, 4);
(*command.cb)(kStatusSuccess, handle, (uint8_t *)&response);
return;
}
(*command.cb)(kStatusSuccess, handle, command.packet.data);
}
void CommandHandler::OnCommandMsg(uint8_t handle, const Command &command) {
@@ -161,10 +204,13 @@ void CommandHandler::OnCommandMsg(uint8_t handle, const Command &command) {
}
}
}
if (IsSubLidarException(command)) {
OnSubLidarDisconnect();
}
for (list<Command>::iterator ite = commands.begin(); ite != commands.end(); ++ite) {
if (ite->cb) {
(*ite->cb)(handle, command.packet.data);
(*ite->cb)(kStatusSuccess, handle, command.packet.data);
}
}
}
+11 -11
View File
@@ -46,17 +46,17 @@ class CommandHandler : public noncopyable {
bool AddDevice(const DeviceInfo &info);
void RemoveDevice(uint8_t handle);
bool SendCommand(uint8_t handle,
uint8_t command_set,
uint8_t command_id,
uint8_t *data,
uint16_t length,
const boost::shared_ptr<CommandCallback> &cb);
livox_status SendCommand(uint8_t handle,
uint8_t command_set,
uint8_t command_id,
uint8_t *data,
uint16_t length,
const boost::shared_ptr<CommandCallback> &cb);
bool RegisterPush(uint8_t handle,
uint8_t command_set,
uint8_t command_id,
const boost::shared_ptr<CommandCallback> &cb);
livox_status RegisterPush(uint8_t handle,
uint8_t command_set,
uint8_t command_id,
const boost::shared_ptr<CommandCallback> &cb);
void OnCommand(uint8_t handle, const Command &command);
@@ -84,7 +84,7 @@ class CommandHandlerImpl : public CommandChannelDelegate {
virtual bool AddDevice(const DeviceInfo &info) = 0;
virtual bool RemoveDevice(uint8_t handle) = 0;
virtual bool SendCommand(uint8_t handle, const Command &command) = 0;
virtual livox_status SendCommand(uint8_t handle, const Command &command) = 0;
virtual void OnCommand(uint8_t handle, const Command &command) {
if (handler_) {
+564 -177
View File
@@ -31,6 +31,9 @@
#include "livox_def.h"
#include "livox_sdk.h"
# define HMS_PARSE_BUF (128)
# define YY_PARSE_BUF (128)
using std::pair;
using std::vector;
using namespace livox;
@@ -43,7 +46,7 @@ void SetBroadcastCallback(DeviceBroadcastCallback cb) {
device_manager().SetDeviceBroadcastCallback(cb);
}
uint8_t AddHubToConnect(const char *broadcast_code, uint8_t *handle) {
livox_status AddHubToConnect(const char *broadcast_code, uint8_t *handle) {
bool result = device_manager().AddListeningDevice(broadcast_code, kDeviceModeHub, *handle);
if (result) {
return kStatusSuccess;
@@ -52,7 +55,7 @@ uint8_t AddHubToConnect(const char *broadcast_code, uint8_t *handle) {
}
}
uint8_t AddLidarToConnect(const char *broadcast_code, uint8_t *handle) {
livox_status AddLidarToConnect(const char *broadcast_code, uint8_t *handle) {
bool result = device_manager().AddListeningDevice(broadcast_code, kDeviceModeLidar, *handle);
if (result) {
return kStatusSuccess;
@@ -61,7 +64,7 @@ uint8_t AddLidarToConnect(const char *broadcast_code, uint8_t *handle) {
}
}
uint8_t GetConnectedDevices(DeviceInfo *devices, uint8_t *size) {
livox_status GetConnectedDevices(DeviceInfo *devices, uint8_t *size) {
if (devices == NULL || size == NULL) {
return kStatusFailure;
}
@@ -79,284 +82,668 @@ void SetDataCallback(uint8_t handle, DataCallback cb, void *client_data) {
data_handler().AddDataListener(handle, cb, client_data);
}
uint8_t DeviceSampleControl(uint8_t handle, bool enable, CommonCommandCallback cb, void *data) {
livox_status DeviceSampleControl(uint8_t handle, bool enable, CommonCommandCallback cb, void *client_data) {
uint8_t req = enable;
bool result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralControlSample,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralControlSample,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
uint8_t LidarStartSampling(uint8_t handle, CommonCommandCallback cb, void *data) {
livox_status LidarFanControl(uint8_t handle, bool enable, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
uint8_t req = static_cast<uint8_t>(enable);
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarControlFan,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
livox_status SetDeviceIp(uint8_t handle, SetDeviceIpExtendModeRequest *req, CommonCommandCallback cb, void *client_data) {
livox_status result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralConfigureStaticDynamicIp,
(uint8_t*)req,
sizeof(*req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
bool ChecksumRmc(const char* buff_begin, const char* buff_end) {
//checksum $GPRMC/$GNRMC format : *hh
const uint8_t head_size = strlen("$");
const uint8_t tail_size = strlen("hh");
char tail[3] = { 0 };
uint32_t tail_num = 0;
uint8_t crc = 0;
buff_begin += head_size;
for ( ; buff_begin < buff_end; buff_begin++) {
if (*buff_begin == '*') {
if (buff_begin + tail_size <= buff_end) {
strncpy(tail, &buff_begin[1], tail_size);
sscanf(tail, "%x", &tail_num);
crc ^= (uint8_t)tail_num;
if (crc == 0) {
return true;
}
break;
}
}
crc ^= *buff_begin;
}
return false;
}
bool ParseRmcTime(const char* rmc, uint16_t rmc_len, LidarSetUtcSyncTimeRequest* utc_time_req) {
const char* rmc_begin = strstr(rmc, "$GPRMC");
if (rmc_begin == NULL) {
rmc_begin = strstr(rmc, "$GNRMC");
}
if (rmc_begin == NULL) {
return false;
}
if (!ChecksumRmc(rmc_begin, rmc + rmc_len)) {
return false;
}
char utc_hms_buff[HMS_PARSE_BUF] = { 0 };
char utc_yy_buff[YY_PARSE_BUF] = { 0 };
int hour = 0, minute = 0, second = 0, millisecond = 0;
memset(utc_time_req, 0, sizeof(LidarSetUtcSyncTimeRequest));
if (4 != sscanf(rmc_begin,
"$G%*[NP]RMC,%[^,],%*C,%*f,%*C,%*f,%*C,%*f,%*f,%2hhu%2hhu%[^,],%*f,",
&utc_hms_buff[0],
&(utc_time_req->day),
&(utc_time_req->month),
&utc_yy_buff[0])) {
return false;
}
int time_buff_size = strlen(utc_yy_buff);
uint8_t temp_time = 0;
switch (time_buff_size) {
case sizeof("yyyy")-1:
if (strncmp(utc_yy_buff, "2000", strlen("2000")) < 0) {
return false;
}
if (1 != sscanf(utc_yy_buff, "%*C%*C%2hhu", &(utc_time_req->year))) {
return false;
}
temp_time = utc_time_req->day;
utc_time_req->day = utc_time_req->month;
utc_time_req->month = temp_time;
break;
case sizeof("yy")-1:
if (1 != sscanf(utc_yy_buff, "%2hhu", &(utc_time_req->year))) {
return false;
}
break;
default:
return false;
}
time_buff_size = strlen(utc_hms_buff);
switch (time_buff_size) {
case sizeof("hhmmss")-1:
if (3 != sscanf(utc_hms_buff, "%2d%2d%2d", &hour, &minute, &second)) {
return false;
}
break;
case sizeof("hhmmss.s")-1:
case sizeof("hhmmss.ss")-1:
case sizeof("hhmmss.sss")-1:
if (4 != sscanf(utc_hms_buff, "%2d%2d%2d.%2d", &hour, &minute, &second, &millisecond)) {
return false;
}
break;
default:
return false;
}
utc_time_req->mircrosecond = (minute * 60 * 1000 + second * 1000 + millisecond) * 1000;
return true;
}
livox_status LidarStartSampling(uint8_t handle, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar) {
return kStatusNotSupported;
}
return DeviceSampleControl(handle, true, cb, data);
return DeviceSampleControl(handle, true, cb, client_data);
}
uint8_t LidarStopSampling(uint8_t handle, CommonCommandCallback cb, void *data) {
livox_status LidarStopSampling(uint8_t handle, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar) {
return kStatusNotSupported;
}
return DeviceSampleControl(handle, false, cb, data);
return DeviceSampleControl(handle, false, cb, client_data);
}
uint8_t HubStartSampling(CommonCommandCallback cb, void *client_data) {
livox_status HubStartSampling(CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
return DeviceSampleControl(kHubDefaultHandle, true, cb, client_data);
}
uint8_t HubStopSampling(CommonCommandCallback cb, void *client_data) {
livox_status HubStopSampling(CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
return DeviceSampleControl(kHubDefaultHandle, false, cb, client_data);
}
uint8_t HubGetLidarHandle(uint8_t slot, uint8_t id) {
livox_status HubGetLidarHandle(uint8_t slot, uint8_t id) {
return (slot - 1) * 3 + id - 1;
}
uint8_t QueryDeviceInformation(uint8_t handle, DeviceInformationCallback cb, void *data) {
bool result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralDeviceInfo,
NULL,
0,
MakeCommandCallback<DeviceInformationResponse>(cb, data));
return result ? kStatusSuccess : kStatusFailure;
livox_status QueryDeviceInformation(uint8_t handle, DeviceInformationCallback cb, void *client_data) {
livox_status result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralDeviceInfo,
NULL,
0,
MakeCommandCallback<DeviceInformationResponse>(cb, client_data));
return result;
}
uint8_t SetCartesianCoordinate(uint8_t handle, CommonCommandCallback cb, void *client_data) {
livox_status DisconnectDevice(uint8_t handle, CommonCommandCallback cb, void *client_data) {
livox_status result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralDisconnect,
NULL,
0,
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
livox_status SetCartesianCoordinate(uint8_t handle, CommonCommandCallback cb, void *client_data) {
uint8_t req = 0;
bool result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralCoordinateSystem,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralCoordinateSystem,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
uint8_t SetSphericalCoordinate(uint8_t handle, CommonCommandCallback cb, void *client_data) {
livox_status SetSphericalCoordinate(uint8_t handle, CommonCommandCallback cb, void *client_data) {
uint8_t req = 1;
bool result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralCoordinateSystem,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralCoordinateSystem,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
uint8_t SetErrorMessageCallback(uint8_t handle, ErrorMessageCallback cb) {
bool result = command_handler().RegisterPush(
livox_status SetErrorMessageCallback(uint8_t handle, ErrorMessageCallback cb) {
livox_status result = command_handler().RegisterPush(
handle, kCommandSetGeneral, kCommandIDGeneralPushAbnormalState, MakeMessageCallback<ErrorMessage>(cb));
return result ? kStatusSuccess : kStatusFailure;
return result;
}
uint8_t SetStaticDynamicIP(uint8_t handle,
SetDeviceIPModeRequest *req,
CommonCommandCallback cb,
void *client_data) {
bool result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralConfigureStaticDynamicIP,
(uint8_t *)req,
sizeof(*req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status SetStaticDynamicIP(uint8_t handle,
SetDeviceIPModeRequest *req,
CommonCommandCallback cb,
void *client_data) {
if(device_manager().device_mode() == kDeviceModeLidar
&& !device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
SetDeviceIpExtendModeRequest ext_req;
ext_req.ip_mode = req->ip_mode;
ext_req.ip_addr = req->ip_addr;
uint8_t net_mask[4] = {255, 255, 255, 0};
memcpy(&ext_req.net_mask, net_mask, 4);
uint8_t gw_addr[4] = {192, 168, 1, 1};
memcpy(&ext_req.gw_addr, gw_addr, 4);
return SetDeviceIp(handle, &ext_req, cb, client_data);
}
uint8_t GetDeviceIPInformation(uint8_t handle, GetDeviceIPInformationCallback cb, void *client_data) {
bool result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralGetDeviceIPInformation,
NULL,
0,
MakeCommandCallback<GetDeviceIPModeResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status SetDynamicIp(uint8_t handle, CommonCommandCallback cb, void *client_data) {
SetDeviceIpExtendModeRequest req;
req.ip_mode = kLidarDynamicIpMode;
return SetDeviceIp(handle, &req, cb, client_data);
}
uint8_t LidarSetMode(uint8_t handle, LidarMode mode, CommonCommandCallback cb, void *client_data) {
livox_status SetStaticIp(uint8_t handle,
SetStaticDeviceIpModeRequest *req,
CommonCommandCallback cb,
void *client_data) {
SetDeviceIpExtendModeRequest static_ip_req = { kLidarStaticIpMode,req->ip_addr,req->net_mask,req->gw_addr};
return SetDeviceIp(handle, &static_ip_req, cb, client_data);
}
livox_status GetDeviceIpInformation(uint8_t handle, GetDeviceIpInformationCallback cb, void *client_data) {
livox_status result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralGetDeviceIpInformation,
NULL,
0,
MakeCommandCallback<GetDeviceIpModeResponse>(cb, client_data));
return result;
}
livox_status RebootDevice(uint8_t handle, uint16_t timeout, CommonCommandCallback cb, void * client_data) {
if(device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(handle,
kCommandSetGeneral,
kCommandIDGeneralRebootDevice,
(uint8_t *)(&timeout),
sizeof(timeout),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
livox_status LidarSetMode(uint8_t handle, LidarMode mode, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar) {
return kStatusNotSupported;
}
uint8_t req = static_cast<uint8_t>(mode);
bool result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarSetMode,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarSetMode,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
uint8_t LidarSetExtrinsicParameter(uint8_t handle,
LidarSetExtrinsicParameterRequest *req,
CommonCommandCallback cb,
void *client_data) {
livox_status LidarSetExtrinsicParameter(uint8_t handle,
LidarSetExtrinsicParameterRequest *req,
CommonCommandCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarSetExtrinsicParameter,
(uint8_t *)req,
sizeof(*req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarSetExtrinsicParameter,
(uint8_t *)req,
sizeof(*req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
uint8_t LidarGetExtrinsicParameter(uint8_t handle, LidarGetExtrinsicParameterCallback cb, void *client_data) {
livox_status LidarGetExtrinsicParameter(uint8_t handle, LidarGetExtrinsicParameterCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarGetExtrinsicParameter,
NULL,
0,
MakeCommandCallback<LidarGetExtrinsicParameterResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarGetExtrinsicParameter,
NULL,
0,
MakeCommandCallback<LidarGetExtrinsicParameterResponse>(cb, client_data));
return result;
}
uint8_t LidarRainFogSuppress(uint8_t handle, bool enable, CommonCommandCallback cb, void *data) {
livox_status LidarRainFogSuppress(uint8_t handle, bool enable, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| !device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
uint8_t req = static_cast<uint8_t>(enable);
bool result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarControlRainFogSuppression,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarControlRainFogSuppression,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
uint8_t HubQueryLidarInformation(HubQueryLidarInformationCallback cb, void *client_data) {
livox_status LidarTurnOnFan(uint8_t handle, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
return LidarFanControl(handle, true, cb, client_data);
}
livox_status LidarTurnOffFan(uint8_t handle, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
return LidarFanControl(handle, false, cb, client_data);
}
livox_status LidarGetFanState(uint8_t handle, LidarGetFanStateCallback cb, void * data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarGetFanState,
NULL,
0,
MakeCommandCallback<LidarGetFanStateResponse>(cb, data));
return result;
}
livox_status LidarSetPointCloudReturnMode(uint8_t handle, PointCloudReturnMode mode, CommonCommandCallback cb, void * data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
uint8_t req = static_cast<uint8_t>(mode);
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarSetPointCloudReturnMode,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, data));
return result;
}
livox_status LidarGetPointCloudReturnMode(uint8_t handle, LidarGetPointCloudReturnModeCallback cb, void * client_data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarGetPointCloudReturnMode,
NULL,
0,
MakeCommandCallback<LidarGetPointCloudReturnModeResponse>(cb, client_data));
return result;
}
livox_status LidarSetImuPushFrequency(uint8_t handle, ImuFreq freq, CommonCommandCallback cb, void * client_data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
uint8_t req = static_cast<uint8_t>(freq);
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarSetImuPushFrequency,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
livox_status LidarGetImuPushFrequency(uint8_t handle, LidarGetImuPushFrequencyCallback cb, void * data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarGetImuPushFrequency,
NULL,
0,
MakeCommandCallback<LidarGetImuPushFrequencyResponse>(cb, data));
return result;
}
livox_status HubQueryLidarInformation(HubQueryLidarInformationCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubQueryLidarInformation,
NULL,
0,
MakeCommandCallback<HubQueryLidarInformationResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubQueryLidarInformation,
NULL,
0,
MakeCommandCallback<HubQueryLidarInformationResponse>(cb, client_data));
return result;
}
uint8_t HubSetMode(HubSetModeRequest *req, uint16_t length, HubSetModeCallback cb, void *client_data) {
livox_status HubSetMode(HubSetModeRequest *req, uint16_t length, HubSetModeCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubSetMode,
(uint8_t *)req,
length,
MakeCommandCallback<HubSetModeResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubSetMode,
(uint8_t *)req,
length,
MakeCommandCallback<HubSetModeResponse>(cb, client_data));
return result;
}
uint8_t HubControlSlotPower(HubControlSlotPowerRequest *req, CommonCommandCallback cb, void *client_data) {
livox_status HubControlSlotPower(HubControlSlotPowerRequest *req, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubControlSlotPower,
(uint8_t *)req,
sizeof(*req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubControlSlotPower,
(uint8_t *)req,
sizeof(*req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
uint8_t HubSetExtrinsicParameter(HubSetExtrinsicParameterRequest *req,
uint16_t length,
HubSetExtrinsicParameterCallback cb,
void *client_data) {
livox_status HubSetExtrinsicParameter(HubSetExtrinsicParameterRequest *req,
uint16_t length,
HubSetExtrinsicParameterCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubSetExtrinsicParameter,
(uint8_t *)req,
length,
MakeCommandCallback<HubSetExtrinsicParameterResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubSetExtrinsicParameter,
(uint8_t *)req,
length,
MakeCommandCallback<HubSetExtrinsicParameterResponse>(cb, client_data));
return result;
}
uint8_t HubGetExtrinsicParameter(HubGetExtrinsicParameterCallback cb, void *client_data) {
livox_status HubGetExtrinsicParameter(HubGetExtrinsicParameterCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubGetExtrinsicParameter,
NULL,
0,
MakeCommandCallback<HubGetExtrinsicParameterResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubGetExtrinsicParameter,
NULL,
0,
MakeCommandCallback<HubGetExtrinsicParameterResponse>(cb, client_data));
return result;
}
uint8_t HubQueryLidarStatus(HubQueryLidarStatusCallback cb, void *client_data) {
livox_status HubQueryLidarStatus(HubQueryLidarStatusCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubQueryLidarDeviceStatus,
NULL,
0,
MakeCommandCallback<HubQueryLidarStatusResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubQueryLidarDeviceStatus,
NULL,
0,
MakeCommandCallback<HubQueryLidarStatusResponse>(cb, client_data));
return result;
}
uint8_t HubExtrinsicParameterCalculation(bool enable, CommonCommandCallback cb, void *client_data) {
livox_status HubExtrinsicParameterCalculation(bool enable, CommonCommandCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
uint8_t req = static_cast<uint8_t>(enable);
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubExtrinsicParameterCalculation,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubExtrinsicParameterCalculation,
&req,
sizeof(req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
uint8_t HubRainFogSuppress(HubRainFogSuppressRequest *req,
uint16_t length,
HubRainFogSuppressCallback cb,
livox_status HubRainFogSuppress(HubRainFogSuppressRequest *req,
uint16_t length,
HubRainFogSuppressCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubRainFogSuppression,
(uint8_t *)req,
length,
MakeCommandCallback<HubRainFogSuppressResponse>(cb, client_data));
return result;
}
livox_status HubQuerySlotPowerStatus(HubQuerySlotPowerStatusCallback cb, void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubQuerySlotPowerStatus,
NULL,
0,
MakeCommandCallback<HubQuerySlotPowerStatusResponse>(cb, client_data));
return result;
}
livox_status HubFanControl(HubFanControlRequest *req,
uint16_t length,
HubFanControlCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubRainFogSuppression,
(uint8_t *)req,
length,
MakeCommandCallback<HubRainFogSuppressResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubControlFan,
(uint8_t *)req,
length,
MakeCommandCallback<HubFanControlResponse>(cb, client_data));
return result;
}
uint8_t HubQuerySlotPowerStatus(HubQuerySlotPowerStatusCallback cb, void *client_data) {
livox_status HubGetFanState(HubGetFanStateRequest *req,
uint16_t length,
HubGetFanStateCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
bool result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubQuerySlotPowerStatus,
NULL,
0,
MakeCommandCallback<HubQuerySlotPowerStatusResponse>(cb, client_data));
return result ? kStatusSuccess : kStatusFailure;
}
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubGetFanState,
(uint8_t *)req,
length,
MakeCommandCallback<HubGetFanStateResponse>(cb, client_data));
return result;
}
livox_status HubSetPointCloudReturnMode(HubSetPointCloudReturnModeRequest *req,
uint16_t length,
HubSetPointCloudReturnModeCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubSetPointCloudReturnMode,
(uint8_t *)req,
length,
MakeCommandCallback<HubSetPointCloudReturnModeResponse>(cb, client_data));
return result;
}
livox_status HubGetPointCloudReturnMode(HubGetPointCloudReturnModeRequest *req,
uint16_t length,
HubGetPointCloudReturnModeCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubGetPointCloudReturnMode,
(uint8_t *)req,
length,
MakeCommandCallback<HubGetPointCloudReturnModeResponse>(cb, client_data));
return result;
}
livox_status HubSetImuPushFrequency(HubSetImuPushFrequencyRequest *req,
uint16_t length,
HubSetImuPushFrequencyCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubSetImuPushFrequency,
(uint8_t *)req,
length,
MakeCommandCallback<HubSetImuPushFrequencyResponse>(cb, client_data));
return result;
}
livox_status HubGetImuPushFrequency(HubGetImuPushFrequencyRequest *req,
uint16_t length,
HubGetImuPushFrequencyCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeHub) {
return kStatusNotSupported;
}
livox_status result = command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
kCommandIDHubGetImuPushFrequency,
(uint8_t *)req,
length,
MakeCommandCallback<HubGetImuPushFrequencyResponse>(cb, client_data));
return result;
}
livox_status LidarSetUtcSyncTime(uint8_t handle,
LidarSetUtcSyncTimeRequest* req,
CommonCommandCallback cb ,
void *client_data) {
livox_status result = command_handler().SendCommand(handle,
kCommandSetLidar,
kCommandIDLidarSetSyncTime,
(uint8_t *)req,
sizeof(*req),
MakeCommandCallback<uint8_t>(cb, client_data));
return result;
}
livox_status LidarSetRmcSyncTime(uint8_t handle,
const char* rmc,
uint16_t rmc_length,
CommonCommandCallback cb,
void *client_data) {
if (device_manager().device_mode() != kDeviceModeLidar
|| device_manager().IsLidarMid40(handle)) {
return kStatusNotSupported;
}
LidarSetUtcSyncTimeRequest utc_time_req;
if (!ParseRmcTime(rmc, rmc_length, &utc_time_req)) {
return kStatusFailure;
}
return LidarSetUtcSyncTime(handle, &utc_time_req, cb, client_data);
}
+85 -3
View File
@@ -75,11 +75,15 @@ typedef enum {
/**
* General command set, set the IP of the a device.
*/
kCommandIDGeneralConfigureStaticDynamicIP = 8,
kCommandIDGeneralConfigureStaticDynamicIp = 8,
/**
* General command set, get the IP of the a device.
*/
kCommandIDGeneralGetDeviceIPInformation = 9,
kCommandIDGeneralGetDeviceIpInformation = 9,
/**
* General command set, reboot a device.
*/
kCommandIDGeneralRebootDevice = 0x0a,
/**
* ******************************************************
@@ -97,6 +101,7 @@ static const uint16_t GeneralCommandTimeout[kCommandIDGeneralCommandCount] = {KD
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut};
/** Enum that represents the command id. */
@@ -117,7 +122,34 @@ typedef enum {
* Lidar command set, enable or disable the rain/fog suppression of a LiDAR.
*/
kCommandIDLidarControlRainFogSuppression = 3,
/**
* Lidar command set, turn on\off fan of a LiDAR.
*/
kCommandIDLidarControlFan = 4,
/**
* Lidar command set, get fan state of a LiDAR.
*/
kCommandIDLidarGetFanState = 5,
/**
* Lidar command set, set point cloud return mode of a LiDAR.
*/
kCommandIDLidarSetPointCloudReturnMode = 6,
/**
* Lidar command set, get point cloud return mode of a LiDAR.
*/
kCommandIDLidarGetPointCloudReturnMode = 7,
/**
* Lidar command set, set IMU push frequency of a LiDAR.
*/
kCommandIDLidarSetImuPushFrequency = 8,
/**
* Lidar command set, get IMU push frequency of a LiDAR.
*/
kCommandIDLidarGetImuPushFrequency = 9,
/**
* Lidar command set, set synchronization time of a LiDAR.
*/
kCommandIDLidarSetSyncTime = 0x0a,
/**
* ******************************************************
* Don't add command id after kCommandIDLidarCommandCount.
@@ -126,6 +158,13 @@ typedef enum {
} LidarCommandID;
static const uint16_t LidarCommandTimeout[kCommandIDLidarCommandCount] = {KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut};
@@ -168,6 +207,30 @@ typedef enum {
* Hub command set, get the power supply state of each hub slot.
*/
kCommandIDHubQuerySlotPowerStatus = 8,
/**
* Hub command set, turn on\off fan of the connected Livox LiDAR.
*/
kCommandIDHubControlFan = 9,
/**
* Hub command set, get the fan state of the connected Livox LiDAR.
*/
kCommandIDHubGetFanState = 0x0a,
/**
* Hub command set, set point cloud return mode of the connected Livox LiDAR.
*/
kCommandIDHubSetPointCloudReturnMode = 0x0b,
/**
* Hub command set, get point cloud return mode of the connected Livox LiDAR.
*/
kCommandIDHubGetPointCloudReturnMode = 0x0c,
/**
* Hub command set, set IMU push frequency of the connected Livox LiDAR.
*/
kCommandIDHubSetImuPushFrequency = 0x0d,
/**
* Hub command set, get IMU push frequency of the connected Livox LiDAR.
*/
kCommandIDHubGetImuPushFrequency = 0x0e,
/**
* ******************************************************
@@ -177,6 +240,12 @@ typedef enum {
} HubCommandID;
static const uint16_t HubCommandTimeout[kCommandIDHubCommandCount] = {KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
KDefaultTimeOut,
@@ -197,5 +266,18 @@ typedef enum {
/** message type, which is sent at a specified frequency. */
kCommandTypeMsg = 2
} CommandType;
#pragma pack(1)
/**
* The request body of the command for setting device's IP mode.
*/
typedef struct {
uint8_t ip_mode; /**< IP address mode: 0 for dynamic IP address, 1 for static IP address. */
uint32_t ip_addr; /**< IP address. */
uint32_t net_mask; /**< Subnet mask. */
uint32_t gw_addr; /**< Gateway address. */
} SetDeviceIpExtendModeRequest;
#pragma pack()
} // namespace livox
#endif // LIVOX_SDK_COMMAND_IMPL_H
@@ -46,12 +46,12 @@ bool HubCommandHandlerImpl::AddDevice(const DeviceInfo &info) {
return true;
}
bool HubCommandHandlerImpl::SendCommand(uint8_t, const Command &command) {
livox_status HubCommandHandlerImpl::SendCommand(uint8_t, const Command &command) {
if (channel_ == NULL) {
return false;
return kStatusChannelNotExist;
}
channel_->SendAsync(command);
return true;
return kStatusSuccess;
}
bool HubCommandHandlerImpl::RemoveDevice(uint8_t) {
@@ -36,7 +36,7 @@ class HubCommandHandlerImpl : public CommandHandlerImpl {
void Uninit();
bool AddDevice(const DeviceInfo &info);
bool RemoveDevice(uint8_t handle);
bool SendCommand(uint8_t handle, const Command &command);
livox_status SendCommand(uint8_t handle, const Command &command);
private:
apr_pool_t *mem_pool_;
@@ -42,20 +42,25 @@ bool LidarCommandHandlerImpl::AddDevice(const DeviceInfo &info) {
return true;
}
bool LidarCommandHandlerImpl::SendCommand(uint8_t handle, const Command &command) {
livox_status LidarCommandHandlerImpl::SendCommand(uint8_t handle, const Command &command) {
CommandChannel *channel = NULL;
bool found = false;
for (list<DeviceItem>::iterator ite = devices_.begin(); ite != devices_.end(); ++ite) {
if (ite->info.handle == handle) {
found = true;
channel = ite->channel.get();
break;
}
}
if (channel) {
channel->SendAsync(command);
return true;
if (!found) {
return kStatusInvalidHandle;
}
return false;
if (!channel) {
return kStatusChannelNotExist;
}
channel->SendAsync(command);
return kStatusSuccess;
}
bool LidarCommandHandlerImpl::RemoveDevice(uint8_t handle) {
@@ -38,7 +38,7 @@ class LidarCommandHandlerImpl : public CommandHandlerImpl {
bool AddDevice(const DeviceInfo &info);
bool RemoveDevice(uint8_t handle);
bool SendCommand(uint8_t handle, const Command &command);
livox_status SendCommand(uint8_t handle, const Command &command);
private:
typedef struct {
+24 -8
View File
@@ -29,8 +29,6 @@
namespace livox {
static const size_t kSphericalCoordinatePointSize = 9;
static const size_t kCartesianCoordinatePointSize = 13;
static const size_t kPrefixDataSize = 18;
DataHandler &data_handler() {
@@ -91,12 +89,30 @@ void DataHandler::OnDataCallback(uint8_t handle, void *data, uint16_t size) {
return;
}
DataCallback cb = callbacks_[handle];
if (lidar_data->data_type == 0) {
size = (size - kPrefixDataSize) / kCartesianCoordinatePointSize;
} else if (lidar_data->data_type == 1) {
size = (size - kPrefixDataSize) / kSphericalCoordinatePointSize;
} else {
return;
switch (lidar_data->data_type) {
case kCartesian:
size = (size - kPrefixDataSize) / sizeof(LivoxRawPoint);
break;
case kSpherical:
size = (size - kPrefixDataSize) / sizeof(LivoxSpherPoint);
break;
case kExtendCartesian:
size = (size - kPrefixDataSize) / sizeof(LivoxExtendRawPoint);
break;
case kExtendSpherical:
size = (size - kPrefixDataSize) / sizeof(LivoxExtendSpherPoint);
break;
case kDualExtendCartesian:
size = (size - kPrefixDataSize) / sizeof(LivoxDualExtendRawPoint);
break;
case kDualExtendSpherical:
size = (size - kPrefixDataSize) / sizeof(LivoxDualExtendSpherPoint);
break;
case kImu:
size = (size - kPrefixDataSize) / sizeof(LivoxImuPoint);
break;
default:
return;
}
if (cb) {
//LOG_INFO(" device_sn: {}", device_sn);
+37 -22
View File
@@ -66,7 +66,7 @@ bool DeviceDiscovery::Start(IOLoop *loop) {
return false;
}
loop_ = loop;
sock_ = util::CreateBindSocket(kListenPort, mem_pool_);
sock_ = util::CreateBindSocket(kListenPort, mem_pool_, true);
if (sock_ == NULL) {
LOG_ERROR("DeviceDiscovery Create Socket Failed");
return false;
@@ -84,7 +84,7 @@ void DeviceDiscovery::OnData(apr_socket_t *sock, void *) {
comm_port_->UpdateCacheWrIdx(size);
if (rv != APR_SUCCESS) {
LOG_ERROR(" Receive Failed {}", PrintAPRStatus(rv));
LOG_WARN(" Receive Failed {}", PrintAPRStatus(rv));
return;
}
CommPacket packet;
@@ -137,6 +137,7 @@ void DeviceDiscovery::OnTimer(apr_time_t now) {
void DeviceDiscovery::Uninit() {
if (sock_) {
loop_->RemoveDelegate(sock_, this);
apr_socket_close(sock_);
sock_ = NULL;
}
@@ -156,24 +157,10 @@ void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr
return;
}
BroadcastDeviceInfo *device_info = (BroadcastDeviceInfo *)packet.data;
string broadcast_code = device_info->broadcast_code;
LOG_INFO(" Boradcast broadcast code: {}", broadcast_code);
device_manager().BroadcastDevices(device_info);
DeviceInfo lidar_info;
bool found = device_manager().FindDevice(broadcast_code, lidar_info);
if (!found || device_manager().IsDeviceConnected(lidar_info.handle)) {
return;
}
++port_count;
strncpy(lidar_info.broadcast_code, broadcast_code.c_str(), sizeof(lidar_info.broadcast_code));
lidar_info.cmd_port = kListenPort + kCmdPortOffset + port_count;
lidar_info.data_port = kListenPort + kDataPortOffset + port_count;
lidar_info.type = device_info->dev_type;
lidar_info.state = kLidarStateUnknown;
lidar_info.feature = kLidarFeatureNone;
lidar_info.status.status_code = 0;
BroadcastDeviceInfo device_info;
memcpy((void*)(&device_info),(void*)(packet.data),(sizeof(BroadcastDeviceInfo)-sizeof(device_info.ip)));
string broadcast_code = device_info.broadcast_code;
LOG_INFO(" Broadcast broadcast code: {}", broadcast_code);
char ip[16];
memset(&ip, 0, sizeof(ip));
@@ -182,6 +169,31 @@ void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr
LOG_ERROR(PrintAPRStatus(rv));
return;
}
strncpy(device_info.ip, ip, sizeof(device_info.ip));
device_manager().BroadcastDevices(&device_info);
DeviceInfo lidar_info;
bool found = device_manager().FindDevice(broadcast_code, lidar_info);
if (!found) {
LOG_INFO("Broadcast code : {} not add to connect", broadcast_code);
}
if (!found || device_manager().IsDeviceConnected(lidar_info.handle)) {
return;
}
++port_count;
strncpy(lidar_info.broadcast_code, broadcast_code.c_str(), sizeof(lidar_info.broadcast_code));
lidar_info.cmd_port = kListenPort + kCmdPortOffset + port_count;
lidar_info.data_port = kListenPort + kDataPortOffset + port_count;
lidar_info.sensor_port = kListenPort + kSensorPortOffset + port_count;
lidar_info.type = device_info.dev_type;
lidar_info.state = kLidarStateUnknown;
lidar_info.feature = kLidarFeatureNone;
lidar_info.status.progress = 0;
strncpy(lidar_info.ip, ip, sizeof(lidar_info.ip));
apr_pool_t *pool = NULL;
rv = apr_pool_create(&pool, mem_pool_);
@@ -206,11 +218,12 @@ void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr
do {
HandshakeRequest handshake_req;
uint32_t local_ip = 0;
if (util::FindLocalIP(addr->sa.sin, local_ip) == false) {
if (util::FindLocalIp(addr->sa.sin, local_ip) == false) {
result = false;
LOG_INFO("LocalIp and DeviceIp are not in same subnet");
break;
}
LOG_INFO(" LocalIP: {}", inet_ntoa(*(struct in_addr *)&local_ip));
LOG_INFO("LocalIP: {}", inet_ntoa(*(struct in_addr *)&local_ip));
LOG_INFO("Command Port: {}", lidar_info.cmd_port);
LOG_INFO("Data Port: {}", lidar_info.data_port);
CommPacket packet;
@@ -218,6 +231,7 @@ void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr
handshake_req.ip_addr = local_ip;
handshake_req.cmd_port = lidar_info.cmd_port;
handshake_req.data_port = lidar_info.data_port;
handshake_req.sensor_port = lidar_info.sensor_port;
packet.packet_type = kCommandTypeAck;
packet.seq_num = CommandChannel::GenerateSeq();
packet.cmd_set = kCommandSetGeneral;
@@ -245,6 +259,7 @@ void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr
}
}
DeviceDiscovery &device_discovery() {
static DeviceDiscovery discovery;
return discovery;
+3
View File
@@ -71,6 +71,9 @@ class DeviceDiscovery : public noncopyable, IOLoop::IOLoopDelegate {
static const apr_port_t kCmdPortOffset = 500;
/** data port number start offset. */
static const apr_port_t kDataPortOffset = 1000;
/** sensor port number start offset. */
static const apr_port_t kSensorPortOffset = 1000;
static uint16_t port_count;
apr_socket_t *sock_;
+50 -16
View File
@@ -61,6 +61,7 @@ void DeviceManager::Uninit() {
connected_cb_ = NULL;
device_mode_ = kDeviceModeNone;
lock_guard<mutex> lock(mutex_);
for (DeviceContainer::iterator ite = devices_.begin(); ite != devices_.end(); ++ite) {
ite->clear();
}
@@ -93,8 +94,14 @@ bool DeviceManager::AddDevice(const DeviceInfo &device) {
void DeviceManager::RemoveDevice(uint8_t handle) {
lock_guard<mutex> lock(mutex_);
if (handle < devices_.size()) {
devices_[handle].connected = false;
if (device_mode_ == kDeviceModeHub) {
for (DeviceContainer::iterator ite = devices_.begin(); ite != devices_.end(); ++ite) {
ite->connected = false;
}
} else if (device_mode_ == kDeviceModeLidar) {
if (handle < devices_.size()) {
devices_[handle].connected = false;
}
}
LOG_INFO(" Device {} removed ", (uint16_t)handle);
}
@@ -111,7 +118,7 @@ void DeviceManager::UpdateDevices(const DeviceInfo &device, DeviceEvent type) {
}
if (device_mode_ == kDeviceModeHub) {
if (type == kEventConnect) {
if (type == kEventHubConnectionChange) {
LOG_DEBUG("Send Query lidars command");
command_handler().SendCommand(kHubDefaultHandle,
kCommandSetHub,
@@ -120,16 +127,23 @@ void DeviceManager::UpdateDevices(const DeviceInfo &device, DeviceEvent type) {
0,
MakeCommandCallback<DeviceManager, HubQueryLidarInformationResponse>(
this, &DeviceManager::HubLidarInfomationCallback));
} else if (connected_cb_) {
connected_cb_(&device, type);
} else {
if (connected_cb_) {
connected_cb_(&device, type);
}
}
}
}
void DeviceManager::HubLidarInfomationCallback(uint8_t status, uint8_t, HubQueryLidarInformationResponse *response) {
void DeviceManager::HubLidarInfomationCallback(livox_status status, uint8_t, HubQueryLidarInformationResponse *response) {
if (status == kStatusSuccess) {
{
lock_guard<mutex> lock(mutex_);
for (DeviceContainer::iterator ite = devices_.begin(); ite != devices_.end(); ++ite) {
if (ite->info.handle != kHubDefaultHandle) {
ite->connected = false;
}
}
for (int i = 0; i < response->count; i++) {
std::size_t index = (response->device_info_list[i].slot - 1) * 3 + response->device_info_list[i].id - 1;
if (index < devices_.size()) {
@@ -142,7 +156,7 @@ void DeviceManager::HubLidarInfomationCallback(uint8_t status, uint8_t, HubQuery
}
}
if (connected_cb_) {
connected_cb_(&(devices_[kHubDefaultHandle].info), kEventConnect);
connected_cb_(&(devices_[kHubDefaultHandle].info), kEventHubConnectionChange);
}
} else {
LOG_ERROR("Failed to query lidars information connected to hub.");
@@ -190,7 +204,6 @@ bool DeviceManager::FindDevice(uint8_t handle, DeviceInfo &info) {
if (handle >= devices_.size()) {
return false;
}
info = devices_[handle].info;
return true;
}
@@ -230,12 +243,20 @@ void DeviceManager::UpdateDeviceState(uint8_t handle, const HeartbeatResponse &r
info.feature = static_cast<LidarFeature>(response.feature);
update = true;
}
if (info.status.progress != response.error_union.progress) {
LOG_INFO(
" Update progress {}, device connect {}", (uint16_t)response.error_union.progress, devices_[handle].connected);
info.status.progress = response.error_union.progress;
update = true;
if (response.state == kLidarStateInit) {
if (info.status.progress != response.error_union.progress) {
LOG_INFO(
" Update progress {}, device connect {}", (uint16_t)response.error_union.progress, devices_[handle].connected);
info.status.progress = response.error_union.progress;
update = true;
}
} else {
if (info.status.status_code.error_code != response.error_union.status_code.error_code) {
info.status.status_code.error_code = response.error_union.status_code.error_code;
update = true;
}
}
if (devices_[handle].connected && update == true) {
if (connected_cb_) {
connected_cb_(&info, kEventStateChange);
@@ -243,6 +264,15 @@ void DeviceManager::UpdateDeviceState(uint8_t handle, const HeartbeatResponse &r
}
}
bool DeviceManager::IsLidarMid40(uint8_t handle) {
DeviceInfo lidar_info;
bool found = device_manager().FindDevice(handle, lidar_info);
if ( found && lidar_info.type == kDeviceTypeLidarMid40) {
return true;
}
return false;
}
DeviceManager &device_manager() {
static DeviceManager lidar_manager;
return lidar_manager;
@@ -252,17 +282,21 @@ void DeviceFound(const DeviceInfo &lidar_data) {
device_manager().AddDevice(lidar_data);
command_handler().AddDevice(lidar_data);
data_handler().AddDevice(lidar_data);
device_manager().UpdateDevices(lidar_data, kEventConnect);
if (device_manager().device_mode() == kDeviceModeHub) {
device_manager().UpdateDevices(lidar_data, kEventHubConnectionChange);
} else {
device_manager().UpdateDevices(lidar_data, kEventConnect);
}
}
void DeviceRemove(uint8_t handle) {
void DeviceRemove(uint8_t handle, DeviceEvent device_event) {
DeviceInfo info;
bool found = device_manager().FindDevice(handle, info);
device_manager().RemoveDevice(handle);
command_handler().RemoveDevice(handle);
data_handler().RemoveDevice(handle);
if (found) {
device_manager().UpdateDevices(info, kEventDisconnect);
device_manager().UpdateDevices(info, device_event);
}
}
+3 -2
View File
@@ -94,13 +94,14 @@ class DeviceManager : public noncopyable {
void SetDeviceBroadcastCallback(const boost::function<void(const BroadcastDeviceInfo *info)> &cb) {
broadcast_cb_ = cb;
}
void HubLidarInfomationCallback(uint8_t status, uint8_t handle, HubQueryLidarInformationResponse *response);
void HubLidarInfomationCallback(livox_status status, uint8_t handle, HubQueryLidarInformationResponse *response);
DeviceMode device_mode() { return device_mode_; }
void BroadcastDevices(const BroadcastDeviceInfo *info);
void UpdateDevices(const DeviceInfo &device, DeviceEvent type);
void UpdateDeviceState(uint8_t handle, const HeartbeatResponse &response);
void GetConnectedDevices(std::vector<DeviceInfo> &devices);
bool AddListeningDevice(const std::string &broadcast_code, DeviceMode mode, uint8_t &handle);
bool IsLidarMid40(uint8_t handle);
private:
typedef struct _DetailDeviceInfo {
@@ -149,7 +150,7 @@ class DeviceManager : public noncopyable {
DeviceManager &device_manager();
void DeviceFound(const DeviceInfo &data);
void DeviceRemove(uint8_t handle);
void DeviceRemove(uint8_t handle,DeviceEvent device_event);
} // namespace livox
+11 -1
View File
@@ -30,6 +30,7 @@
#include "device_manager.h"
using namespace livox;
IOThread *g_thread = NULL;
static bool is_initialized = false;
void GetLivoxSdkVersion(LivoxSdkVersion *version) {
if (version != NULL) {
@@ -40,6 +41,10 @@ void GetLivoxSdkVersion(LivoxSdkVersion *version) {
}
bool Init() {
if (is_initialized) {
return false;
}
bool result = false;
do {
InitLogger();
@@ -78,10 +83,14 @@ bool Init() {
apr_terminate();
}
is_initialized = result;
return result;
}
void Uninit() {
if (!is_initialized) {
return;
}
if (g_thread) {
g_thread->Quit();
g_thread->Join();
@@ -97,9 +106,10 @@ void Uninit() {
delete g_thread;
g_thread = NULL;
}
UninitLogger();
apr_terminate();
is_initialized = false;
}
bool Start() {