diff --git a/sample/lidar_lvx_file/main.cpp b/sample/lidar_lvx_file/main.cpp index 3f7bb38..924238e 100644 --- a/sample/lidar_lvx_file/main.cpp +++ b/sample/lidar_lvx_file/main.cpp @@ -222,6 +222,11 @@ void OnDeviceInfoChange(const DeviceInfo *info, DeviceEvent type) { } } +void OnDeviceInfoChangeExtra(int param, const DeviceInfo *info, DeviceEvent type) { + // ... Do stuff with the extra param +} + + /** Callback function when broadcast message received. * You need to add listening device broadcast code and set the point cloud data callback in this function. */ @@ -238,6 +243,15 @@ void OnDeviceBroadcast(const BroadcastDeviceInfo *info) { } } +struct OptBcast{ + int a; + int b; +}; + +void OnDeviceBroadcastExtra(OptBcast o, const BroadcastDeviceInfo *info) { + // ... Do stuff with the extra param +} + /** Wait until no new device arriving in 2 second. */ void WaitForDevicesReady( ) { bool device_ready = false; @@ -391,14 +405,19 @@ int main(int argc, const char *argv[]) { printf("Livox SDK version %d.%d.%d .\n", _sdkversion.major, _sdkversion.minor, _sdkversion.patch); memset(devices, 0, sizeof(devices)); + using namespace std::placeholders; + /** Set the callback function receiving broadcast message from Livox LiDAR. */ - SetBroadcastCallback(OnDeviceBroadcast); + OptBcast bcastopts; + std::function cb_bcast(std::bind(OnDeviceBroadcastExtra, bcastopts, _1)); + SetBroadcastCallback(cb_bcast); /** Set the callback function called when device state change, * which means connection/disconnection and changing of LiDAR state. */ - SetDeviceStateUpdateCallback(OnDeviceInfoChange); + std::function cb_device_state(std::bind(OnDeviceInfoChangeExtra, 1, _1, _2)); + SetDeviceStateUpdateCallback(cb_device_state); /** Start the device discovering routine. */ if (!Start()) { @@ -457,4 +476,4 @@ int main(int argc, const char *argv[]) { /** Uninitialize Livox-SDK. */ Uninit(); -} \ No newline at end of file +} diff --git a/sdk_core/include/livox_sdk.h b/sdk_core/include/livox_sdk.h index cc80a62..ea72078 100644 --- a/sdk_core/include/livox_sdk.h +++ b/sdk_core/include/livox_sdk.h @@ -25,7 +25,10 @@ #ifndef LIVOX_SDK_H_ #define LIVOX_SDK_H_ + + #ifdef __cplusplus +#include extern "C" { #endif @@ -100,6 +103,8 @@ typedef void (*DeviceStateUpdateCallback)(const DeviceInfo *device, DeviceEvent */ void SetDeviceStateUpdateCallback(DeviceStateUpdateCallback cb); + + /** * 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. @@ -261,7 +266,7 @@ livox_status SetStaticDynamicIP(uint8_t handle, void *client_data); /** * Set device's static IP mode. - * @note Mid40/100 is not supported to set subnet mask and gateway address. + * @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. @@ -857,6 +862,11 @@ livox_status LidarSetUtcSyncTime(uint8_t handle, #ifdef __cplusplus } + + +void SetDeviceStateUpdateCallback(const std::function &cb); +void SetBroadcastCallback(const std::function &cb ); + #endif #endif // LIVOX_SDK_H_ diff --git a/sdk_core/src/command_handler/command_impl.cpp b/sdk_core/src/command_handler/command_impl.cpp index 99a9ebc..9fefd28 100644 --- a/sdk_core/src/command_handler/command_impl.cpp +++ b/sdk_core/src/command_handler/command_impl.cpp @@ -42,10 +42,18 @@ void SetDeviceStateUpdateCallback(DeviceStateUpdateCallback cb) { device_manager().SetDeviceConnectedCallback(cb); } +void SetDeviceStateUpdateCallback(const std::function &cb){ + device_manager().SetDeviceConnectedCallback(cb); +} + void SetBroadcastCallback(DeviceBroadcastCallback cb) { device_manager().SetDeviceBroadcastCallback(cb); } +void SetBroadcastCallback(const std::function &cb ){ + device_manager().SetDeviceBroadcastCallback(cb); +} + livox_status AddHubToConnect(const char *broadcast_code, uint8_t *handle) { bool result = device_manager().AddListeningDevice(broadcast_code, kDeviceModeHub, *handle); if (result) { @@ -317,7 +325,7 @@ livox_status SetStaticDynamicIP(uint8_t handle, livox_status SetDynamicIp(uint8_t handle, CommonCommandCallback cb, void *client_data) { SetDeviceIpExtendModeRequest req; - req.ip_mode = kLidarDynamicIpMode; + req.ip_mode = kLidarDynamicIpMode; return SetDeviceIp(handle, &req, cb, client_data); } @@ -403,7 +411,7 @@ livox_status LidarGetExtrinsicParameter(uint8_t handle, LidarGetExtrinsicParamet } livox_status LidarRainFogSuppress(uint8_t handle, bool enable, CommonCommandCallback cb, void *client_data) { - if (device_manager().device_mode() != kDeviceModeLidar + if (device_manager().device_mode() != kDeviceModeLidar || !device_manager().IsLidarMid40(handle)) { return kStatusNotSupported; } @@ -629,9 +637,9 @@ livox_status HubQuerySlotPowerStatus(HubQuerySlotPowerStatusCallback cb, void *c return result; } -livox_status HubFanControl(HubFanControlRequest *req, - uint16_t length, - HubFanControlCallback cb, +livox_status HubFanControl(HubFanControlRequest *req, + uint16_t length, + HubFanControlCallback cb, void *client_data) { if (device_manager().device_mode() != kDeviceModeHub) { return kStatusNotSupported; @@ -645,9 +653,9 @@ livox_status HubFanControl(HubFanControlRequest *req, return result; } -livox_status HubGetFanState(HubGetFanStateRequest *req, - uint16_t length, - HubGetFanStateCallback cb, +livox_status HubGetFanState(HubGetFanStateRequest *req, + uint16_t length, + HubGetFanStateCallback cb, void *client_data) { if (device_manager().device_mode() != kDeviceModeHub) { return kStatusNotSupported; @@ -661,9 +669,9 @@ livox_status HubGetFanState(HubGetFanStateRequest *req, return result; } -livox_status HubSetPointCloudReturnMode(HubSetPointCloudReturnModeRequest *req, - uint16_t length, - HubSetPointCloudReturnModeCallback cb, +livox_status HubSetPointCloudReturnMode(HubSetPointCloudReturnModeRequest *req, + uint16_t length, + HubSetPointCloudReturnModeCallback cb, void *client_data) { if (device_manager().device_mode() != kDeviceModeHub) { return kStatusNotSupported; @@ -677,9 +685,9 @@ livox_status HubSetPointCloudReturnMode(HubSetPointCloudReturnModeRequest *req, return result; } -livox_status HubGetPointCloudReturnMode(HubGetPointCloudReturnModeRequest *req, - uint16_t length, - HubGetPointCloudReturnModeCallback cb, +livox_status HubGetPointCloudReturnMode(HubGetPointCloudReturnModeRequest *req, + uint16_t length, + HubGetPointCloudReturnModeCallback cb, void *client_data) { if (device_manager().device_mode() != kDeviceModeHub) { return kStatusNotSupported; @@ -693,9 +701,9 @@ livox_status HubGetPointCloudReturnMode(HubGetPointCloudReturnModeRequest *req, return result; } -livox_status HubSetImuPushFrequency(HubSetImuPushFrequencyRequest *req, - uint16_t length, - HubSetImuPushFrequencyCallback cb, +livox_status HubSetImuPushFrequency(HubSetImuPushFrequencyRequest *req, + uint16_t length, + HubSetImuPushFrequencyCallback cb, void *client_data) { if (device_manager().device_mode() != kDeviceModeHub) { return kStatusNotSupported; @@ -709,9 +717,9 @@ livox_status HubSetImuPushFrequency(HubSetImuPushFrequencyRequest *req, return result; } -livox_status HubGetImuPushFrequency(HubGetImuPushFrequencyRequest *req, - uint16_t length, - HubGetImuPushFrequencyCallback cb, +livox_status HubGetImuPushFrequency(HubGetImuPushFrequencyRequest *req, + uint16_t length, + HubGetImuPushFrequencyCallback cb, void *client_data) { if (device_manager().device_mode() != kDeviceModeHub) { return kStatusNotSupported; @@ -756,7 +764,7 @@ livox_status LidarSetRmcSyncTime(uint8_t handle, return kStatusNotSupported; } } - + LidarSetUtcSyncTimeRequest utc_time_req; if (!ParseRmcTime(rmc, rmc_length, &utc_time_req)) { return kStatusFailure;