fiveai_stamped_diagnostic.h
Go to the documentation of this file.
1 #ifndef FIVEAI_STAMPED_DIAGNOSTIC_H
2 #define FIVEAI_STAMPED_DIAGNOSTIC_H
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 
8 #include <ros/types.h>
9 #include <ros/serialization.h>
10 #include "ros_parser_base.h"
11 #include <absl/strings/str_cat.h>
12 #include <absl/strings/charconv.h>
13 
15 {
16  uint8_t status;
18  std::string key;
19  std::string value;
20 };
21 
23 {
24  std::vector< StampedDiagnostic_ > diagnostics;
25 };
26 //-----------------------------------------------------
27 
28 namespace ros
29 {
30 namespace serialization
31 {
32 
33 template<> struct Serializer< ::StampedDiagnostic_ >
34 {
35  template<typename Stream, typename T> inline static void allInOne(Stream& stream, T m)
36  {
37  stream.next(m.status);
38  stream.next(m.stamp);
39  stream.next(m.key);
40  stream.next(m.value);
41  }
43 };
44 
45 template<> struct Serializer< ::NodeDiagnostics_ >
46 {
47  template<typename Stream, typename T> inline static void allInOne(Stream& stream, T m)
48  {
49  stream.next(m.diagnostics);
50  }
52 };
53 
54 } // namespace serialization
55 } // namespace ros
56 
57 //-----------------------------------------------------
58 
59 
61 {
62 public:
63 
64  FiveAiDiagnosticMsg() = default;
65 
66  static const std::string& getCompatibleKey()
67  {
68  static std::string temp = "b47994f5f7cab18367c65bedb56d7f75";
69  return temp;
70  }
71 
72  const std::unordered_set<std::string>& getCompatibleKeys() const override
73  {
74  static std::unordered_set<std::string> temp = { getCompatibleKey() };
75  return temp;
76  }
77 
78  virtual void pushMessageRef(const std::string& ,
79  const MessageRef& msg,
80  double timestamp) override
81  {
82  NodeDiagnostics_ diagnostic;
83  ros::serialization::IStream is( const_cast<uint8_t*>(msg.data()), msg.size() );
84  ros::serialization::deserialize(is, diagnostic);
85 
86  for( const auto& it: diagnostic.diagnostics)
87  {
88  if( _use_header_stamp )
89  {
90  timestamp = it.stamp.toSec();
91  }
92  const char *start_ptr = it.value.data();
93  double val = 0;
94  auto res = absl::from_chars (start_ptr, start_ptr + it.value.size(), val);
95  if( start_ptr == res.ptr ) continue;
96 
97  auto data_it = _data.find( it.key );
98  if( data_it == _data.end() )
99  {
100  data_it = _data.emplace( std::piecewise_construct,
101  std::forward_as_tuple(it.key),
102  std::forward_as_tuple(it.key)
103  ).first;
104  }
105  data_it->second.pushBack( { timestamp, val } );
106  }
107  }
108 
109  void extractData(PlotDataMapRef& plot_map, const std::string& prefix) override
110  {
111  for (auto& it: _data)
112  {
113  appendData(plot_map,
114  absl::StrCat(prefix, "/", it.first),
115  it.second);
116  }
117  }
118 
119 private:
120  std::unordered_map<std::string,PlotData> _data;
121 };
122 
123 
124 
125 #endif // FIVEAI_STAMPED_DIAGNOSTIC_H
std::unordered_map< std::string, PlotData > _data
virtual void pushMessageRef(const std::string &, const MessageRef &msg, double timestamp) override
#define ROS_DECLARE_ALLINONE_SERIALIZER
const std::unordered_set< std::string > & getCompatibleKeys() const override
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
size_t size() const
void extractData(PlotDataMapRef &plot_map, const std::string &prefix) override
std::vector< StampedDiagnostic_ > diagnostics
const uint8_t * data() const
static const std::string & getCompatibleKey()
from_chars_result from_chars(const char *first, const char *last, double &value, chars_format fmt)
void deserialize(Stream &stream, T &t)


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