ros2_parser.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "rclcpp/rclcpp.hpp"
4 #include "rmw/rmw.h"
5 #include "rmw/types.h"
6 #include "rosbag2_cpp/typesupport_helpers.hpp"
7 #include "rosidl_typesupport_introspection_cpp/message_introspection.hpp"
9 
10 #include <PlotJuggler/plotdata.h>
11 #include "parser_configuration.h"
12 
13 //namespace ros2
14 //{
15 //using MessageRef = rcutils_uint8_array_t;
16 //}
17 
18 using namespace PJ;
19 
20 struct TopicInfo{
21  std::string name;
22  std::string type;
23  const rosidl_message_type_support_t* type_support;
24 };
25 
27 {
28  public:
29  Ros2MessageParser(const std::string& topic_name, PJ::PlotDataMapRef& plot_data):
30  RosMessageParser(topic_name, plot_data)
31  {}
32 
33  const rosidl_message_type_support_t* typeSupport() const
34  {
35  return _type_support;
36  }
37 
38  protected:
39  const rosidl_message_type_support_t* _type_support = nullptr;
40 };
41 
42 
43 template <typename T>
45 {
46  public:
47  BuiltinMessageParser(const std::string& topic_name, PlotDataMapRef& plot_data)
48  : Ros2MessageParser(topic_name, plot_data)
49  {
50  _type_support = rosidl_typesupport_cpp::get_message_type_support_handle<T>();
51  }
52 
53  virtual bool parseMessage(MessageRef serialized_msg,
54  double& timestamp)
55  {
56  rcutils_uint8_array_t msg_ref;
57  msg_ref.buffer = serialized_msg.data();
58  msg_ref.buffer_length = serialized_msg.size();
59  T msg;
60  if (RMW_RET_OK != rmw_deserialize(&msg_ref, _type_support, &msg))
61  {
62  throw std::runtime_error("failed to deserialize message");
63  }
64  parseMessageImpl(msg, timestamp);
65  return true;
66  }
67 
68  virtual void parseMessageImpl(const T& msg, double& timestamp) = 0;
69 };
70 
72 {
73  public:
74  IntrospectionParser(const std::string& topic_name,
75  const std::string& topic_type,
76  PlotDataMapRef& plot_data)
77  : Ros2MessageParser(topic_name, plot_data),
78  _intropection_parser(topic_name, topic_type)
79  {
80  _type_support = _intropection_parser.topicInfo().type_support;
81  }
82 
83  bool parseMessage(MessageRef serialized_msg, double& timestamp) override;
84 
85  private:
88 };
89 
91 {
92  public:
93 
95 
96  void registerMessageType(const std::string& topic_name,
97  const std::string& topic_type);
98 
99  const rosidl_message_type_support_t* typeSupport(const std::string& topic_name) const;
100 };
101 
102 
size_t size() const
IntrospectionParser(const std::string &topic_name, const std::string &topic_type, PlotDataMapRef &plot_data)
Definition: ros2_parser.h:74
virtual bool parseMessage(MessageRef serialized_msg, double &timestamp)
Definition: ros2_parser.h:53
Ros2Introspection::FlatMessage _flat_msg
Definition: ros2_parser.h:87
std::string name
Definition: ros2_parser.h:21
BuiltinMessageParser(const std::string &topic_name, PlotDataMapRef &plot_data)
Definition: ros2_parser.h:47
Ros2Introspection::Parser _intropection_parser
Definition: ros2_parser.h:86
Ros2MessageParser(const std::string &topic_name, PJ::PlotDataMapRef &plot_data)
Definition: ros2_parser.h:29
Ros2CompositeParser(PlotDataMapRef &plot_data)
Definition: ros2_parser.h:94
const rosidl_message_type_support_t * typeSupport() const
Definition: ros2_parser.h:33
std::string type
Definition: ros2_parser.h:22
const uint8_t * data() const
const rosidl_message_type_support_t * type_support
Definition: ros2_parser.h:23
msg


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