diff --git a/livox_ros2_driver/livox_ros2_driver/lds_hub.cpp b/livox_ros2_driver/livox_ros2_driver/lds_hub.cpp index d757985..3f4feda 100644 --- a/livox_ros2_driver/livox_ros2_driver/lds_hub.cpp +++ b/livox_ros2_driver/livox_ros2_driver/lds_hub.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "rapidjson/document.h" #include "rapidjson/filereadstream.h" @@ -157,10 +158,16 @@ void LdsHub::OnHubDataCb(uint8_t hub_handle, LivoxEthPacket *data, } void LdsHub::OnDeviceBroadcast(const BroadcastDeviceInfo *info) { + // Store warning status per broadcast code to avoid showing the same warning + static std::unordered_set whitelist_warning_shown_map; + if (info == NULL) { return; } + // Convert broadcast code to string + std::string broadcast_code(info->broadcast_code); + if (info->dev_type != kDeviceTypeHub) { printf("It's not a hub : %s\n", info->broadcast_code); return; @@ -171,8 +178,12 @@ void LdsHub::OnDeviceBroadcast(const BroadcastDeviceInfo *info) { info->broadcast_code); } else { if (!g_lds_hub->IsBroadcastCodeExistInWhitelist(info->broadcast_code)) { - printf("Not in the whitelist, please add %s to if want to connect!\n", - info->broadcast_code); + // Check if the warning for this broadcast code was already shown + if (whitelist_warning_shown_map.find(broadcast_code) == whitelist_warning_shown_map.end()) { + printf("Not in the whitelist, please add %s to if want to connect!\n", + info->broadcast_code); + whitelist_warning_shown_map.insert(broadcast_code); + } return; } } diff --git a/livox_ros2_driver/livox_ros2_driver/lds_lidar.cpp b/livox_ros2_driver/livox_ros2_driver/lds_lidar.cpp index da2aa65..1317197 100644 --- a/livox_ros2_driver/livox_ros2_driver/lds_lidar.cpp +++ b/livox_ros2_driver/livox_ros2_driver/lds_lidar.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "rapidjson/document.h" #include "rapidjson/filereadstream.h" @@ -172,10 +173,16 @@ void LdsLidar::OnLidarDataCb(uint8_t handle, LivoxEthPacket *data, } void LdsLidar::OnDeviceBroadcast(const BroadcastDeviceInfo *info) { + // Store warning status per broadcast code to avoid showing the same warning + static std::unordered_set whitelist_warning_shown_map; + if (info == nullptr) { return; } + // Convert broadcast code to string + std::string broadcast_code(info->broadcast_code); + if (info->dev_type == kDeviceTypeHub) { printf("In lidar mode, couldn't connect a hub : %s\n", info->broadcast_code); @@ -187,8 +194,12 @@ void LdsLidar::OnDeviceBroadcast(const BroadcastDeviceInfo *info) { info->broadcast_code); } else { if (!g_lds_ldiar->IsBroadcastCodeExistInWhitelist(info->broadcast_code)) { - printf("Not in the whitelist, please add %s to if want to connect!\n", - info->broadcast_code); + // Check if the warning for this broadcast code was already shown + if (whitelist_warning_shown_map.find(broadcast_code) == whitelist_warning_shown_map.end()) { + printf("Not in the whitelist, please add %s to if want to connect!\n", + info->broadcast_code); + whitelist_warning_shown_map.insert(broadcast_code); + } return; } }