main.cc
Go to the documentation of this file.
1 // BSD License
2 //
3 // Copyright (c) 2021, Ascent Robotics, Inc.
4 // All rights reserved.
5 
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of Ascent Robotics, Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29 
30 // Author Thomas Kostas/thomas.kostas@ascent.ai
31 
32 #include <stdexcept>
33 #include <string>
34 
35 #include <ros/console.h>
36 #include <ros/ros.h>
37 
39 
40 namespace
41 {
42 std::vector<
43  std::unique_ptr<cpu_temperature_diagnostics::CpuTemperatureDiagnostic>>
44 create_diagnostics(std::string& prefix)
45 {
48 
49  std::vector<
50  std::unique_ptr<cpu_temperature_diagnostics::CpuTemperatureDiagnostic>>
51  diag_vec;
52 
53  for (auto& chip : chips)
54  {
55  auto new_diag = std::make_unique<
57  diag_vec.push_back(std::move(new_diag));
58  }
59 
60  return diag_vec;
61 }
62 
63 void diagnose(
64  std::vector<
65  std::unique_ptr<cpu_temperature_diagnostics::CpuTemperatureDiagnostic>>&
66  diag_vec)
67 {
68  for (auto& diagnostic : diag_vec)
69  {
70  diagnostic->emit_diagnostics();
71  }
72 }
73 
74 void configure_diagnostics(
75  ros::NodeHandle& node_handle,
76  std::vector<
77  std::unique_ptr<cpu_temperature_diagnostics::CpuTemperatureDiagnostic>>&
78  diag_vec)
79 {
80  if (int max_temp_override;
81  node_handle.getParam("max_temp_override", max_temp_override))
82  {
83  ROS_WARN_STREAM("Maximum temperature set to " +
84  std::to_string(max_temp_override));
85  for (auto& diag : diag_vec)
86  {
87  diag->max_temp_override(max_temp_override);
88  }
89  }
90 
91  if (int critical_temp_override;
92  node_handle.getParam("critical_temp_override", critical_temp_override))
93  {
94  ROS_WARN_STREAM("Critical temperature set to " +
95  std::to_string(critical_temp_override));
96  for (auto& diag : diag_vec)
97  {
98  diag->critical_temp_override(critical_temp_override);
99  }
100  }
101 }
102 
103 } // namespace
104 int main(int argc, char* argv[])
105 {
106  sensors_init(nullptr);
107  ros::init(argc, argv, "sensors_diagnostics");
108  ros::NodeHandle node_handle("~");
109  std::string prefix;
110 
111  if (!node_handle.getParam("prefix", prefix))
112  {
113  std::string err = "prefix parameter is missing";
114  ROS_ERROR_STREAM(err);
115  exit(1);
116  }
117 
118  auto diag_vec = create_diagnostics(prefix);
119  configure_diagnostics(node_handle, diag_vec);
120 
121  auto current_timer = node_handle.createTimer(
122  ros::Duration(1),
123  [&diag_vec](const ros::TimerEvent&) { diagnose(diag_vec); });
124  ros::spin();
125  sensors_cleanup();
126  return 0;
127 }
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void spin()
#define ROS_WARN_STREAM(args)
int main(int argc, char *argv[])
Definition: main.cc:104
#define ROS_ERROR_STREAM(args)
std::vector< SensorChip > get_chips_with_prefix(const std::string &name)
Definition: sensor_chip.cc:95


cpu_temperature_diagnostics
Author(s):
autogenerated on Mon Feb 28 2022 22:08:46