@@ -108,7 +108,9 @@ void LivoxLidarCallback::LidarInfoChangeCallback(const uint32_t handle,
108108 // process, silently breaking the other driver instance that owns it.
109109 // Log once per foreign IP to avoid flooding the console on every
110110 // periodic SDK re-discovery event.
111+ static std::mutex s_foreign_mutex;
111112 static std::unordered_set<uint32_t > s_logged_foreign;
113+ std::lock_guard<std::mutex> lock (s_foreign_mutex);
112114 if (s_logged_foreign.insert (handle).second ) {
113115 LIVOX_WARN (" [%s] ignoring lidar — not in this instance's config"
114116 " (likely owned by another driver process)" ,
@@ -175,8 +177,11 @@ void LivoxLidarCallback::LidarInfoChangeCallback(const uint32_t handle,
175177 LIVOX_INFO (" [%s] no config commands needed, state -> Sampling" ,
176178 IpNumToString (handle).c_str ());
177179 } else {
178- LIVOX_INFO (" [%s] waiting for %u config ack(s) before Sampling" ,
179- IpNumToString (handle).c_str (), pending_bits);
180+ // Count set bits using Brian Kernighan's algorithm (each iteration clears the lowest set bit).
181+ uint32_t pending_count = 0 ;
182+ for (uint32_t b = pending_bits; b != 0 ; b &= (b - 1 )) { ++pending_count; }
183+ LIVOX_INFO (" [%s] waiting for %u config ack(s) before Sampling (pending mask=0x%x)" ,
184+ IpNumToString (handle).c_str (), pending_count, pending_bits);
180185 }
181186 } // free lock for set_bits
182187
@@ -205,9 +210,13 @@ void LivoxLidarCallback::WorkModeChangedCallback(livox_status status,
205210 void *client_data) {
206211 if (status != kLivoxLidarStatusSuccess ) {
207212 // Track per-handle retry count to surface persistent failures.
213+ static std::mutex s_retry_mutex;
208214 static std::unordered_map<uint32_t , int > s_retry_count;
209- int & retries = s_retry_count[handle];
210- ++retries;
215+ int retries;
216+ {
217+ std::lock_guard<std::mutex> lock (s_retry_mutex);
218+ retries = ++s_retry_count[handle];
219+ }
211220 LIVOX_WARN (" [%s] work mode change failed (status=%d), retry #%d" ,
212221 IpNumToString (handle).c_str (), static_cast <int >(status), retries);
213222 std::this_thread::sleep_for (std::chrono::seconds (1 ));
@@ -245,8 +254,13 @@ void LivoxLidarCallback::SetDataTypeCallback(livox_status status, uint32_t handl
245254 LivoxLidarCallback::SetDataTypeCallback, client_data);
246255 LIVOX_WARN (" [%s] set data type timed out, retrying..." , IpNumToString (handle).c_str ());
247256 } else {
248- LIVOX_ERROR (" [%s] set data type failed: ret_code=%d error_key=%d" ,
249- IpNumToString (handle).c_str (), response->ret_code , response->error_key );
257+ if (response) {
258+ LIVOX_ERROR (" [%s] set data type failed: ret_code=%d error_key=%d" ,
259+ IpNumToString (handle).c_str (), response->ret_code , response->error_key );
260+ } else {
261+ LIVOX_ERROR (" [%s] set data type failed: status=%d (no response payload)" ,
262+ IpNumToString (handle).c_str (), static_cast <int >(status));
263+ }
250264 }
251265 return ;
252266}
@@ -278,8 +292,13 @@ void LivoxLidarCallback::SetPatternModeCallback(livox_status status, uint32_t ha
278292 LivoxLidarCallback::SetPatternModeCallback, client_data);
279293 LIVOX_WARN (" [%s] set scan pattern timed out, retrying..." , IpNumToString (handle).c_str ());
280294 } else {
281- LIVOX_ERROR (" [%s] set scan pattern failed: ret_code=%d error_key=%d" ,
282- IpNumToString (handle).c_str (), response->ret_code , response->error_key );
295+ if (response) {
296+ LIVOX_ERROR (" [%s] set scan pattern failed: ret_code=%d error_key=%d" ,
297+ IpNumToString (handle).c_str (), response->ret_code , response->error_key );
298+ } else {
299+ LIVOX_ERROR (" [%s] set scan pattern failed: status=%d (no response payload)" ,
300+ IpNumToString (handle).c_str (), static_cast <int >(status));
301+ }
283302 }
284303 return ;
285304}
@@ -311,8 +330,13 @@ void LivoxLidarCallback::SetBlindSpotCallback(livox_status status, uint32_t hand
311330 LivoxLidarCallback::SetBlindSpotCallback, client_data);
312331 LIVOX_WARN (" [%s] set blind spot timed out, retrying..." , IpNumToString (handle).c_str ());
313332 } else {
314- LIVOX_ERROR (" [%s] set blind spot failed: ret_code=%d error_key=%d" ,
315- IpNumToString (handle).c_str (), response->ret_code , response->error_key );
333+ if (response) {
334+ LIVOX_ERROR (" [%s] set blind spot failed: ret_code=%d error_key=%d" ,
335+ IpNumToString (handle).c_str (), response->ret_code , response->error_key );
336+ } else {
337+ LIVOX_ERROR (" [%s] set blind spot failed: status=%d (no response payload)" ,
338+ IpNumToString (handle).c_str (), static_cast <int >(status));
339+ }
316340 }
317341 return ;
318342}
@@ -344,8 +368,13 @@ void LivoxLidarCallback::SetDualEmitCallback(livox_status status, uint32_t handl
344368 LivoxLidarCallback::SetDualEmitCallback, client_data);
345369 LIVOX_WARN (" [%s] set dual emit timed out, retrying..." , IpNumToString (handle).c_str ());
346370 } else {
347- LIVOX_ERROR (" [%s] set dual emit failed: ret_code=%d error_key=%d" ,
348- IpNumToString (handle).c_str (), response->ret_code , response->error_key );
371+ if (response) {
372+ LIVOX_ERROR (" [%s] set dual emit failed: ret_code=%d error_key=%d" ,
373+ IpNumToString (handle).c_str (), response->ret_code , response->error_key );
374+ } else {
375+ LIVOX_ERROR (" [%s] set dual emit failed: status=%d (no response payload)" ,
376+ IpNumToString (handle).c_str (), static_cast <int >(status));
377+ }
349378 }
350379 return ;
351380}
0 commit comments