JaiaBot 2.0.0
JaiaBot micro-AUV software
 
Loading...
Searching...
No Matches
health.h
Go to the documentation of this file.
1// Copyright 2022:
2// JaiaRobotics LLC
3// File authors:
4// Toby Schneider <toby@gobysoft.org>
5//
6//
7// This file is part of the JaiaBot Project Libraries
8// ("The Jaia Libraries").
9//
10// The Jaia Libraries are free software: you can redistribute them and/or modify
11// them under the terms of the GNU Lesser General Public License as published by
12// the Free Software Foundation, either version 2.1 of the License, or
13// (at your option) any later version.
14//
15// The Jaia Libraries are distributed in the hope that they will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public License
21// along with the Jaia Libraries. If not, see <http://www.gnu.org/licenses/>.
22
23#ifndef JAIABOT_SRC_LIB_HEALTH_HEALTH_H
24#define JAIABOT_SRC_LIB_HEALTH_HEALTH_H
25
27
28namespace jaiabot
29{
30namespace health
31{
32template <typename HuborBotStatus>
33void populate_status_from_health(HuborBotStatus& status,
34 const goby::middleware::protobuf::VehicleHealth& vehicle_health,
35 bool truncate_to_fit_dccl = true)
36{
37 status.set_health_state(vehicle_health.state());
38 status.clear_error();
39 status.clear_warning();
40
41 if (vehicle_health.state() != goby::middleware::protobuf::HEALTH__OK)
42 {
43 auto add_errors_and_warnings =
44 [&status](const goby::middleware::protobuf::ThreadHealth& health) {
45 const auto& jaiabot_health = health.GetExtension(jaiabot::protobuf::jaiabot_thread);
46 for (auto error : jaiabot_health.error())
47 status.add_error(static_cast<jaiabot::protobuf::Error>(error));
48 for (auto warning : jaiabot_health.warning())
49 status.add_warning(static_cast<jaiabot::protobuf::Warning>(warning));
50 };
51
52 for (const auto& proc : vehicle_health.process())
53 {
54 add_errors_and_warnings(proc.main());
55 for (const auto& thread : proc.main().child()) add_errors_and_warnings(thread);
56 }
57
58 const int max_errors = HuborBotStatus::descriptor()
59 ->FindFieldByName("error")
60 ->options()
61 .GetExtension(dccl::field)
62 .max_repeat();
63
64 const int max_warnings = HuborBotStatus::descriptor()
65 ->FindFieldByName("warning")
66 ->options()
67 .GetExtension(dccl::field)
68 .max_repeat();
69
70 if (truncate_to_fit_dccl && status.error_size() > max_errors)
71 {
72 status.mutable_error()->Truncate(max_errors - 1);
74 }
75 if (truncate_to_fit_dccl && status.warning_size() > max_warnings)
76 {
77 status.mutable_warning()->Truncate(max_warnings - 1);
79 }
80 }
81}
82
83} // namespace health
84} // namespace jaiabot
85
86#endif
void populate_status_from_health(HuborBotStatus &status, const goby::middleware::protobuf::VehicleHealth &vehicle_health, bool truncate_to_fit_dccl=true)
Definition health.h:33
@ ERROR__TOO_MANY_ERRORS_TO_REPORT_ALL
Definition health.pb.h:287
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::goby::middleware::protobuf::ThreadHealth, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::jaiabot::protobuf::ThreadHealth >, 11, false > jaiabot_thread
Definition health.pb.h:3862
@ WARNING__TOO_MANY_WARNINGS_TO_REPORT_ALL
Definition health.pb.h:414