ros1_parsers/diagnostic_msg.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <diagnostic_msgs/DiagnosticArray.h>
4 #include <boost/spirit/include/qi.hpp>
5 #include <boost/algorithm/string.hpp>
6 #include "fmt/format.h"
7 #include "ros1_parser.h"
8 #include "header_msg.h"
9 
10 class DiagnosticMsgParser : public BuiltinMessageParser<diagnostic_msgs::DiagnosticArray>
11 {
12 public:
13  DiagnosticMsgParser(const std::string& topic_name, PJ::PlotDataMapRef& plot_data)
14  : BuiltinMessageParser<diagnostic_msgs::DiagnosticArray>(topic_name, plot_data)
15  , _header_parser(topic_name + "/header", plot_data)
16  {
17  }
18 
19  virtual void parseMessageImpl(const diagnostic_msgs::DiagnosticArray& msg,
20  double& timestamp) override
21  {
22  _header_parser.parse(msg.header, timestamp, _config.use_header_stamp);
23 
24  std::string key;
25 
26  for (const auto& status : msg.status)
27  {
28  for (const auto& kv : status.values)
29  {
30  double value = 0;
31 
32  if (status.hardware_id.empty())
33  {
34  key = fmt::format("{}/{}/{}", _topic_name, status.name, kv.key);
35  }
36  else
37  {
38  key = fmt::format("{}/{}/{}/{}", _topic_name, status.hardware_id, status.name, kv.key);
39  }
40 
41  bool parsed = PJ::ParseDouble(kv.value, value,
44  if (parsed)
45  {
46  auto& series = getSeries(key);
47  series.pushBack({ timestamp, value });
48  }
49  else{
50  if(_plot_data.numeric.count(key) == 0)
51  {
52  auto& series = getStringSeries(key);
53  series.pushBack( { timestamp, kv.value} );
54  }
55  }
56  }
57  }
58  }
59 
60 private:
62 
63 };
DiagnosticMsgParser(const std::string &topic_name, PJ::PlotDataMapRef &plot_data)
PJ::StringSeries & getStringSeries(const std::string &key)
PlotDataMapRef & _plot_data
virtual void parseMessageImpl(const diagnostic_msgs::DiagnosticArray &msg, double &timestamp) override
PJ::PlotData & getSeries(const std::string &key)
TimeseriesMap numeric
void parse(const std_msgs::Header &msg, double &timestamp, bool use_header_stamp)
bool ParseDouble(const std::string &str, double &value, bool remover_suffix, bool parse_boolean)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&... args)
Definition: core.h:2081
std::string _topic_name


plotjuggler_ros
Author(s): Davide Faconti
autogenerated on Fri Jun 23 2023 02:28:03