23 #ifndef JAIABOT_SRC_LIB_HEALTH_HEALTH_H
24 #define JAIABOT_SRC_LIB_HEALTH_HEALTH_H
32 template <
typename HuborBotStatus>
34 const goby::middleware::protobuf::VehicleHealth& vehicle_health,
35 bool truncate_to_fit_dccl =
true)
37 status.set_health_state(vehicle_health.state());
39 status.clear_warning();
41 if (vehicle_health.state() != goby::middleware::protobuf::HEALTH__OK)
43 auto add_errors_and_warnings =
44 [&status](
const goby::middleware::protobuf::ThreadHealth& health) {
46 for (
auto error : jaiabot_health.error())
48 for (
auto warning : jaiabot_health.warning())
52 for (
const auto& proc : vehicle_health.process())
54 add_errors_and_warnings(proc.main());
55 for (
const auto& thread : proc.main().child()) add_errors_and_warnings(thread);
58 const int max_errors = HuborBotStatus::descriptor()
59 ->FindFieldByName(
"error")
64 const int max_warnings = HuborBotStatus::descriptor()
65 ->FindFieldByName(
"warning")
70 if (truncate_to_fit_dccl && status.error_size() > max_errors)
72 status.mutable_error()->Truncate(max_errors - 1);
75 if (truncate_to_fit_dccl && status.warning_size() > max_warnings)
77 status.mutable_warning()->Truncate(max_warnings - 1);