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 <boost/algorithm/string.hpp>
11 #include "ros1_parser.h"
12 
14 {
15  uint8_t status;
17  std::string key;
18  std::string value;
19 };
20 
22 {
23  std::vector<StampedDiagnostic_> diagnostics;
24 };
25 //-----------------------------------------------------
26 
27 namespace ros
28 {
29 namespace serialization
30 {
31 template <>
33 {
34  template <typename Stream, typename T>
35  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 <>
47 {
48  template <typename Stream, typename T>
49  inline static void allInOne(Stream& stream, T m)
50  {
51  stream.next(m.diagnostics);
52  }
54 };
55 
56 } // namespace serialization
57 } // namespace ros
58 
59 //-----------------------------------------------------
60 
62 {
63  public:
64  FiveAiDiagnosticMsg(const std::string& topic_name,
65  PJ::PlotDataMapRef& plot_data)
66  : RosMessageParser(topic_name, plot_data)
67  {}
68 
69  bool parseMessage(MessageRef msg, double& timestamp) override
70  {
71  NodeDiagnostics_ diagnostic;
72  ros::serialization::IStream is(const_cast<uint8_t*>(msg.data()), msg.size());
73  ros::serialization::deserialize(is, diagnostic);
74 
75  for (const StampedDiagnostic_& diag : diagnostic.diagnostics)
76  {
77  timestamp = diag.stamp.toSec();
78 
79  double value = 0;
80  bool parsed = PJ::ParseDouble(diag.value, value,
81  _config.remove_suffix_from_strings,
82  _config.boolean_strings_to_number);
83 
84  std::string replaced_key = diag.key;
85  std::replace(replaced_key.begin(), replaced_key.end(), ' ', '_');
86 
87  if (parsed)
88  {
89  auto key = fmt::format("{}/{}/value", _topic_name, replaced_key);
90  auto& series = getSeries(key);
91  series.pushBack({ timestamp, value });
92  }
93  else
94  {
95  auto key = fmt::format("{}/{}/value", _topic_name, replaced_key);
96  auto& series = getStringSeries(key);
97  series.pushBack({ timestamp, diag.value });
98  }
99 
100  {
101  auto key = fmt::format("{}/{}/status", _topic_name, replaced_key);
102  auto& series = getSeries(key);
103  series.pushBack({ timestamp, static_cast<double>(diag.status) });
104  }
105 
106  }
107  return true;
108  }
109 
110 };
111 
112 #endif // FIVEAI_STAMPED_DIAGNOSTIC_H
#define ROS_DECLARE_ALLINONE_SERIALIZER
size_t size() const
bool parseMessage(MessageRef msg, double &timestamp) override
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
const uint8_t * data() const
FiveAiDiagnosticMsg(const std::string &topic_name, PJ::PlotDataMapRef &plot_data)
std::vector< StampedDiagnostic_ > diagnostics
void deserialize(Stream &stream, T &t)


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