39 #ifndef DIAGNOSTIC_STATUS_ITEM_H 40 #define DIAGNOSTIC_STATUS_ITEM_H 46 #include <diagnostic_msgs/DiagnosticStatus.h> 47 #include <diagnostic_msgs/KeyValue.h> 48 #include <boost/shared_ptr.hpp> 59 std::string::size_type pos = 0;
60 while ((pos = output_name.find(slash_str, pos)) != std::string::npos)
62 output_name.replace(pos, slash_str.size(),
" ");
74 Level_OK = diagnostic_msgs::DiagnosticStatus::OK,
85 if (val == diagnostic_msgs::DiagnosticStatus::OK)
87 if (val == diagnostic_msgs::DiagnosticStatus::WARN)
89 if (val == diagnostic_msgs::DiagnosticStatus::ERROR)
94 ROS_ERROR(
"Attempting to convert %d into DiagnosticLevel. Values are: {0: OK, 1: Warning, 2: Error, 3: Stale}", val);
103 if (val == diagnostic_msgs::DiagnosticStatus::OK)
105 if (val == diagnostic_msgs::DiagnosticStatus::WARN)
107 if (val == diagnostic_msgs::DiagnosticStatus::ERROR)
112 ROS_ERROR(
"Attempting to convert diagnostic level %d into string. Values are: {0: \"OK\", 1: \"Warning\", 2: \"Error\", 3: \"Stale\"}", val);
131 if (chaff.size() == 0)
136 std::size_t last_slash = output_name.rfind(
"/");
139 if (output_name.find(chaff) == last_slash + 1)
140 output_name.replace(last_slash + 1, chaff.size(),
"");
142 if (output_name.find(
":", last_slash) == last_slash + 1)
143 output_name= start_of_name + output_name.substr(last_slash + 2);
145 while (output_name.find(
" ", last_slash) == last_slash + 1)
146 output_name = start_of_name + output_name.substr(last_slash + 2);
178 bool update(
const diagnostic_msgs::DiagnosticStatus *status);
225 for (
unsigned int i = 0; i <
values_.size(); ++i)
241 for (
unsigned int i = 0; i <
values_.size(); ++i)
258 std::vector<diagnostic_msgs::KeyValue>
values_;
263 #endif //DIAGNOSTIC_STATUS_ITEM_H
std::string valToMsg(const int val)
Converts int to message {0: 'OK', 1: 'Warning', 2: 'Error', 3: 'Stale' }.
DiagnosticLevel valToLevel(const int val)
Converts in to DiagnosticLevel. Values: [0, 3].
std::string getValue(const std::string &key) const
Returns value for given key, "" if doens't exist.
std::string getName() const
Returns name of DiagnosticStatus message.
std::string getMessage() const
Get message field of DiagnosticStatus.
StatusItem(const diagnostic_msgs::DiagnosticStatus *status)
Constructed from const DiagnosticStatus*.
std::string removeLeadingNameChaff(const std::string &input_name, const std::string &chaff)
Removes redundant prefixes from status name.
DiagnosticLevel getLevel() const
DiagnosticLevel
Level of StatusItem. OK, Warn, Error, Stale.
const ros::Time getLastUpdateTime() const
Returns the time since last update for this item.
bool hasKey(const std::string &key) const
Returns true if item has key in values KeyValues.
std::string getHwId() const
Returns hardware ID field of DiagnosticStatus message.
std::vector< diagnostic_msgs::KeyValue > values_
Helper class to hold, store DiagnosticStatus messages.
std::string getOutputName(const std::string item_name)
Replace "/" with "" in output name, to avoid confusing robot monitor.
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.
bool update(const diagnostic_msgs::DiagnosticStatus *status)
Must have same name as original status or it won't update.