status_item.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
38 
39 using namespace diagnostic_aggregator;
40 using namespace std;
41 
42 StatusItem::StatusItem(const diagnostic_msgs::DiagnosticStatus *status)
43 {
44  level_ = valToLevel(status->level);
45  name_ = status->name;
46  message_ = status->message;
47  hw_id_ = status->hardware_id;
48  values_ = status->values;
49 
50  output_name_ = getOutputName(name_);
51 
52  update_time_ = ros::Time::now();
53 }
54 
55 StatusItem::StatusItem(const string item_name, const string message, const DiagnosticLevel level)
56 {
57  name_ = item_name;
58  message_ = message;
59  level_ = level;
60  hw_id_ = "";
61 
62  output_name_ = getOutputName(name_);
63 
64  update_time_ = ros::Time::now();
65 }
66 
68 
69 bool StatusItem::update(const diagnostic_msgs::DiagnosticStatus *status)
70 {
71  if (name_ != status->name)
72  {
73  ROS_ERROR("Incorrect name when updating StatusItem. Expected %s, got %s", name_.c_str(), status->name.c_str());
74  return false;
75  }
76 
77  double update_interval = (ros::Time::now() - update_time_).toSec();
78  if (update_interval < 0)
79  ROS_WARN("StatusItem is being updated with older data. Negative update time: %f", update_interval);
80 
81  level_ = valToLevel(status->level);
82  message_ = status->message;
83  hw_id_ = status->hardware_id;
84  values_ = status->values;
85 
86  update_time_ = ros::Time::now();
87 
88  return true;
89 }
90 
92 {
93  boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> status(new diagnostic_msgs::DiagnosticStatus());
94 
95  if (path == "/")
96  status->name = "/" + output_name_;
97  else
98  status->name = path + "/" + output_name_;
99 
100  status->level = level_;
101  status->message = message_;
102  status->hardware_id = hw_id_;
103  status->values = values_;
104 
105  if (stale)
106  status->level = Level_Stale;
107 
108  return status;
109 }
110 
diagnostic_aggregator::StatusItem::~StatusItem
~StatusItem()
Definition: status_item.cpp:67
diagnostic_aggregator
Definition: aggregator.h:61
diagnostic_aggregator::StatusItem::toStatusMsg
boost::shared_ptr< diagnostic_msgs::DiagnosticStatus > toStatusMsg(const std::string &path, const bool stale=false) const
Prepends "path/" to name, makes item stale if "stale" true.
Definition: status_item.cpp:91
boost::shared_ptr
diagnostic_aggregator::valToLevel
DiagnosticLevel valToLevel(const int val)
Converts in to DiagnosticLevel. Values: [0, 3].
Definition: status_item.h:115
status_item.h
name_
std::string name_
Definition: gtest-all.cc:3761
testing::internal::string
::std::string string
Definition: gtest.h:1979
diagnostic_aggregator::DiagnosticLevel
DiagnosticLevel
Level of StatusItem. OK, Warn, Error, Stale.
Definition: status_item.h:104
diagnostic_aggregator::getOutputName
std::string getOutputName(const std::string item_name)
Replace "/" with "" in output name, to avoid confusing robot monitor.
Definition: status_item.h:87
diagnostic_aggregator::StatusItem::update
bool update(const diagnostic_msgs::DiagnosticStatus *status)
Must have same name as original status or it won't update.
Definition: status_item.cpp:69
ROS_WARN
#define ROS_WARN(...)
diagnostic_aggregator::StatusItem::StatusItem
StatusItem(const diagnostic_msgs::DiagnosticStatus *status)
Constructed from const DiagnosticStatus*.
Definition: status_item.cpp:42
std
ROS_ERROR
#define ROS_ERROR(...)
diagnostic_aggregator::Level_Stale
@ Level_Stale
Definition: status_item.h:109
diag_pub.status
status
Definition: diag_pub.py:54
ros::Time::now
static Time now()


diagnostic_aggregator
Author(s): Kevin Watts, Brice Rebsamen
autogenerated on Tue Nov 15 2022 03:17:13