Fixposition SDK 0.0.0-heads/main-0-g97f6014
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
ros1.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 * \endverbatim
9 *
10 * @file
11 * @brief Fixposition SDK: ROS1 types and utils
12 *
13 * @page FPSDK_COMMON_ROS1 ROS1 types and utils
14 *
15 * **API**: fpsdk_common/ros1.hpp and fpsdk::common::ros1
16 *
17 */
18#ifndef __FPSDK_COMMON_ROS1_HPP__
19#define __FPSDK_COMMON_ROS1_HPP__
20
21/* LIBC/STL */
22#include <cstdint>
23#include <memory>
24
25/* EXTERNAL */
26#include <nlohmann/json.hpp>
27
28/* ROS */
29#pragma GCC diagnostic push
30#pragma GCC diagnostic ignored "-Wpedantic"
31#pragma GCC diagnostic ignored "-Wunused-parameter"
32#pragma GCC diagnostic ignored "-Wshadow"
33#pragma GCC diagnostic ignored "-Wunused-function"
34//
35#include <nav_msgs/Odometry.h>
36#include <sensor_msgs/Image.h>
37#include <sensor_msgs/Imu.h>
38#include <sensor_msgs/Temperature.h>
39#include <tf2_msgs/TFMessage.h>
40//
41#include <ros/serialization.h>
42//
43#pragma GCC diagnostic pop
44
45/* PACKAGE */
46
47namespace fpsdk {
48namespace common {
49/**
50 * @brief ROS1 types and utils
51 */
52namespace ros1 {
53/* ****************************************************************************************************************** */
54
55#ifndef _DOXYGEN_
56// Helper for ros de-serialization. We could DeserializeMessage() using ros::serialization::deserialize(IStream(buf),
57// msg). However, the IStream() wants a mutable buffer, which is not nice. ConstBuffer() provides the Stream() interface
58// without needing the mutability of the buffer itself.
59struct ConstBuffer
60{
61 ConstBuffer(const std::vector<uint8_t>& buf)
62 : data_{ buf.data() }, end_{ buf.data() + static_cast<uint32_t>(buf.size()) }
63 {
64 }
65 ConstBuffer(const uint8_t* data, size_t size) : data_(data), end_(data + static_cast<uint32_t>(size))
66 {
67 }
68
69 static const ros::serialization::StreamType stream_type = ros::serialization::stream_types::Input;
70 inline const uint8_t* getData()
71 {
72 return data_;
73 }
74 inline const uint8_t* advance(uint32_t len)
75 {
76 const uint8_t* old_data = data_;
77 data_ += len;
78 if (data_ > end_) {
79 ros::serialization::throwStreamOverrun();
80 }
81 return old_data;
82 }
83 inline uint32_t getLength()
84 {
85 return static_cast<uint32_t>(end_ - data_);
86 }
87
88 template <typename T>
89 inline void next(T& t)
90 {
91 ros::serialization::deserialize(*this, t);
92 }
93
94 template <typename T>
95 inline ConstBuffer& operator>>(T& t)
96 {
97 ros::serialization::deserialize(*this, t);
98 return *this;
99 }
100
101 private:
102 const uint8_t* data_;
103 const uint8_t* end_;
104};
105#endif // _DOXYGEN_
106
107/**
108 * @brief Deserialise ROS1 message
109 *
110 * @tparam RosMsgT The ROS1 message type
111 * @param[in] buf The serialised ROS message
112 * @param[out] msg The deserialised ROS message
113 */
114template <typename RosMsgT>
115inline void DeserializeMessage(const std::vector<uint8_t>& buf, RosMsgT& msg)
116{
117#if FPSDK_USE_ROS1
118 ros::serialization::IStream s((uint8_t*)buf.data(), static_cast<uint32_t>(buf.size())); // :-(
119 ros::serialization::deserialize(s, msg);
120#else
121 ConstBuffer m(buf);
122 ros::serialization::Serializer<RosMsgT>::read(m, msg);
123#endif
124}
125
126/* ****************************************************************************************************************** */
127} // namespace ros1
128} // namespace common
129} // namespace fpsdk
130#endif // __FPSDK_COMMON_ROS1_HPP__
ROS1 types and utils.
Definition ros1.hpp:52
void DeserializeMessage(const std::vector< uint8_t > &buf, RosMsgT &msg)
Deserialise ROS1 message.
Definition ros1.hpp:115
Fixposition SDK: Common library.
Definition doc.hpp:21
Fixposition SDK.