@@ -392,55 +392,74 @@ void AMLifeCycle::addStatistics(diagnostic_updater::DiagnosticStatusWrapper& dsw
392
392
dsw.summary ((uint8_t )status, " update" );
393
393
}
394
394
395
- AMStatReset& AMLifeCycle::configureHzStats (AMStatReset& stats )
395
+ void AMLifeCycle::configureStat (AMStat& stat, std::string name, std::string category )
396
396
{
397
397
int unassigned=UINT_MAX;
398
- int hz_target = unassigned;
399
- int hz_min_error =unassigned;
400
- int hz_min_warn=unassigned;
401
- int hz_max_warn=unassigned;
402
- int hz_max_error=unassigned;
403
- const std::string prefix = stats.getShortName ();
404
- const std::string hz_prefix=prefix + " /hz/" ;
405
- const std::string target_key =hz_prefix + " target" ;
406
- const std::string error_min_key=hz_prefix + " error/min" ;
407
- const std::string warn_min_key =hz_prefix + " warn/min" ;
408
- const std::string warn_max_key =hz_prefix + " warn/max" ;
409
- const std::string error_max_key=hz_prefix + " error/max" ;
398
+ int target = unassigned;
399
+ int min_error =unassigned;
400
+ int min_warn=unassigned;
401
+ int max_warn=unassigned;
402
+ int max_error=unassigned;
403
+ std::string prefix = name + " /" ;
404
+
405
+ if (!category.empty ())
406
+ {
407
+ prefix = prefix + category + " /" ;
408
+ }
409
+
410
+ const std::string target_key =prefix + " target" ;
411
+ const std::string error_min_key=prefix + " error/min" ;
412
+ const std::string warn_min_key =prefix + " warn/min" ;
413
+ const std::string warn_max_key =prefix + " warn/max" ;
414
+ const std::string error_max_key=prefix + " error/max" ;
410
415
411
416
// set all if target is provided
412
- if (param<int >(target_key, hz_target , 0 ))
417
+ if (param<int >(target_key, target , 0 ))
413
418
{
414
419
// give 5% tolerance in either direction for warning, 10% for error. Override default values as desired
415
- const int warning_offset = std::ceil (hz_target * 0.05 );
420
+ const int warning_offset = std::ceil (target * 0.05 );
416
421
const int error_offset = 2 * warning_offset;
417
422
// don't go below zero because that doesn't make any sense for hz.
418
- hz_min_error =std::max (0 ,hz_target - error_offset);
419
- hz_min_warn =std::max (0 ,hz_target - warning_offset);
420
- hz_max_warn=hz_target + warning_offset;
421
- hz_max_error=hz_target + error_offset;
422
- stats .setWarnError (hz_min_error, hz_min_warn, hz_max_warn, hz_max_error );
423
+ min_error =std::max (0 ,target - error_offset);
424
+ min_warn =std::max (0 ,target - warning_offset);
425
+ max_warn=target + warning_offset;
426
+ max_error=target + error_offset;
427
+ stat .setWarnError (min_error, min_warn, max_warn, max_error );
423
428
}
424
429
// override individual boundary configs if provided
425
- if (param<int >(error_min_key, hz_min_error, hz_min_error ))
430
+ if (param<int >(error_min_key, min_error, min_error ))
426
431
{
427
- stats .setMinError (hz_min_error );
432
+ stat .setMinError (min_error );
428
433
}
429
- if (param<int >(warn_min_key, hz_min_warn, hz_min_warn ))
434
+ if (param<int >(warn_min_key, min_warn, min_warn ))
430
435
{
431
- stats .setMinWarn (hz_min_warn );
436
+ stat .setMinWarn (min_warn );
432
437
}
433
- if (param<int >(warn_max_key, hz_max_warn, hz_max_warn ))
438
+ if (param<int >(warn_max_key, max_warn, max_warn ))
434
439
{
435
- stats .setMaxWarn (hz_max_warn );
440
+ stat .setMaxWarn (max_warn );
436
441
}
437
- if (param<int >(error_max_key, hz_max_error, hz_max_error ))
442
+ if (param<int >(error_max_key, max_error, max_error ))
438
443
{
439
- stats.setMaxError (hz_max_error);
440
- }
444
+ stat.setMaxError (max_error);
445
+ }
446
+ }
441
447
442
- return stats;
448
+ void AMLifeCycle::configureStat (AMStat& stat)
449
+ {
450
+ configureStat (stat,stat.getLongName ());
443
451
}
452
+
453
+ AMStatReset& AMLifeCycle::configureHzStat (AMStatReset& stat)
454
+ {
455
+ configureStat (stat, stat.getLongName (), " hz" );
456
+ }
457
+
458
+ AMStatReset& AMLifeCycle::configureHzStats (AMStatReset& stats)
459
+ {
460
+ configureStat (stats, stats.getShortName (), " hz" );
461
+ }
462
+
444
463
void AMLifeCycle::sendNodeUpdate ()
445
464
{
446
465
brain_box_msgs::LifeCycleState msg;
0 commit comments