Skip to content

Commit

Permalink
Port back feature from nobleo-noetic-devel where we also report the m…
Browse files Browse the repository at this point in the history
…essage that made stuff go bad
  • Loading branch information
Ferry Schoenmakers committed Feb 1, 2024
1 parent 999cd03 commit 2d987ad
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions diagnostic_aggregator/src/aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ void Aggregator::publishData()
diag_toplevel_state.level = DiagnosticStatus::STALE;
int max_level = -1;
int min_level = 255;
uint non_ok_status_depth = 0;
std::shared_ptr<DiagnosticStatus> msg_to_report;

std::vector<std::shared_ptr<DiagnosticStatus>> processed;
{
Expand All @@ -229,27 +231,61 @@ void Aggregator::publishData()
}
for (const auto & msg : processed) {
diag_array.status.push_back(*msg);
const uint depth = static_cast<uint>(std::count(msg->name.begin(), msg->name.end(), '/'));

if (msg->level > max_level) {
max_level = msg->level;
non_ok_status_depth = depth;
msg_to_report = msg;
}
if (msg->level == max_level && depth > non_ok_status_depth)
{
// On non okay diagnostics also copy the deepest message to toplevel state
non_ok_status_depth = depth;
msg_to_report = msg;
}
if (msg->level < min_level) {
min_level = msg->level;
}
}
// When a non-ok item was found, copy the complete status message once
if (max_level > DiagnosticStatus::OK)
{
diag_toplevel_state.name = msg_to_report->name;
diag_toplevel_state.message = msg_to_report->message;
diag_toplevel_state.hardware_id = msg_to_report->hardware_id;
diag_toplevel_state.values = msg_to_report->values;
}

std::vector<std::shared_ptr<DiagnosticStatus>> processed_other =
other_analyzer_->report();
for (const auto & msg : processed_other) {
diag_array.status.push_back(*msg);
const uint depth = static_cast<uint>(std::count(msg->name.begin(), msg->name.end(), '/'));

if (msg->level > max_level) {
max_level = msg->level;
non_ok_status_depth = depth;
msg_to_report = msg;
}
if (msg->level == max_level && depth > non_ok_status_depth)
{
// On non okay diagnostics also copy the deepest message to toplevel state
non_ok_status_depth = depth;
msg_to_report = msg;
}
if (msg->level < min_level) {
min_level = msg->level;
}
}
// When a non-ok item was found, copy the complete status message once
if (max_level > DiagnosticStatus::OK)
{
diag_toplevel_state.name = msg_to_report->name;
diag_toplevel_state.message = msg_to_report->message;
diag_toplevel_state.hardware_id = msg_to_report->hardware_id;
diag_toplevel_state.values = msg_to_report->values;
}

diag_array.header.stamp = clock_->now();
agg_pub_->publish(diag_array);
Expand Down

0 comments on commit 2d987ad

Please sign in to comment.