diagnostic_msg.h
Go to the documentation of this file.
1 #ifndef DIAGNOSTIC_MSG_H
2 #define DIAGNOSTIC_MSG_H
3 
4 #include "ros_parser_base.h"
5 #include <diagnostic_msgs/DiagnosticArray.h>
6 #include <absl/strings/str_cat.h>
8 
10 {
11 public:
12 
14  {
15  _header_data.emplace_back( "/header/seq" );
16  _header_data.emplace_back( "/header/stamp" );
17  }
18 
19  static const std::string& getCompatibleKey()
20  {
22  return str;
23  }
24 
25  const std::unordered_set<std::string>& getCompatibleKeys() const override
26  {
27  static std::unordered_set<std::string> temp = { getCompatibleKey() };
28  return temp;
29  }
30 
31  virtual void pushMessageRef(const std::string& ,
32  const MessageRef& msg,
33  double timestamp) override
34  {
35  diagnostic_msgs::DiagnosticArray status_array;
36  ros::serialization::IStream is( const_cast<uint8_t*>(msg.data()), msg.size() );
37  ros::serialization::deserialize(is, status_array);
38 
39  if( _use_header_stamp )
40  {
41  timestamp = status_array.header.stamp.toSec();
42  }
43 
44  _header_data[0].pushBack( {timestamp, (double)status_array.header.seq} );
45  _header_data[1].pushBack( {timestamp, status_array.header.stamp.toSec()} );
46 
47  for( const auto& status: status_array.status)
48  {
49  for( const auto& kv: status.values)
50  {
51  const char *start_ptr = kv.value.data();
52  double val = 0;
53  auto res = absl::from_chars (start_ptr, start_ptr + kv.value.size(), val);
54  if( start_ptr == res.ptr ) continue;
55 
56  std::string status_prefix;
57  if( status.hardware_id.empty()){
58  status_prefix = absl::StrCat( "/", status.name, "/",
59  kv.key );
60  }
61  else {
62  status_prefix = absl::StrCat( "/",status.hardware_id, "/",
63  status.name, "/",
64  kv.key );
65  }
66  auto it = _data.find(status_prefix);
67  if( it == _data.end() )
68  {
69  it = _data.emplace( std::piecewise_construct,
70  std::forward_as_tuple(status_prefix),
71  std::forward_as_tuple(status_prefix)
72  ).first;
73  }
74  it->second.pushBack( { timestamp, val } );
75  }
76  }
77 
78  }
79 
80  void extractData(PlotDataMapRef& plot_map, const std::string& prefix) override
81  {
82  for (auto& it: _header_data)
83  {
84  appendData(plot_map, prefix + it.name(), it);
85  }
86  for (auto& it: _data)
87  {
88  appendData(plot_map, prefix + it.first, it.second);
89  }
90  }
91 
92 private:
93  std::vector<PlotData> _header_data;
94  std::unordered_map<std::string,PlotData> _data;
95 };
96 
97 
98 
99 #endif // DIAGNOSTIC_MSG_H
std::vector< PlotData > _header_data
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
size_t size() const
virtual void pushMessageRef(const std::string &, const MessageRef &msg, double timestamp) override
const std::unordered_set< std::string > & getCompatibleKeys() const override
static const std::string & getCompatibleKey()
const uint8_t * data() const
static const char * value()
std::unordered_map< std::string, PlotData > _data
from_chars_result from_chars(const char *first, const char *last, double &value, chars_format fmt)
static void appendData(PlotDataMapRef &destination_plot_map, const std::string &field_name, PlotData &in_data)
void extractData(PlotDataMapRef &plot_map, const std::string &prefix) override
void deserialize(Stream &stream, T &t)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17