PX4 ROS 2 Interface Library
Library to interface with PX4 from a companion computer using ROS 2
message_version.hpp
1 /****************************************************************************
2  * Copyright (c) 2025 PX4 Development Team.
3  * SPDX-License-Identifier: BSD-3-Clause
4  ****************************************************************************/
5 
12 #pragma once
13 
14 #include <rclcpp/rclcpp.hpp>
15 #include <string>
16 #include <type_traits>
17 
18 namespace px4_ros2 {
19 
28 template <typename T, typename = void>
29 struct HasMessageVersion : std::false_type {};
30 
32 template <typename T>
33 struct HasMessageVersion<T, std::void_t<decltype(T::MESSAGE_VERSION)>> : std::true_type {};
34 
40 static inline bool isRmwZenoh()
41 {
42  const char* rmw_id = rmw_get_implementation_identifier();
43  return std::string(rmw_id) == "rmw_zenoh_cpp";
44 }
45 
53 template <typename T>
54 std::string getMessageNameVersion()
55 {
56  if (isRmwZenoh()) {
57  return "";
58  }
59  if constexpr (HasMessageVersion<T>::value) {
60  if (T::MESSAGE_VERSION == 0) {
61  return "";
62  }
63  return "_v" + std::to_string(T::MESSAGE_VERSION);
64  } else {
65  return "";
66  }
67 }
68 
69 } // namespace px4_ros2
Trait to check if a message type T has a MESSAGE_VERSION constant.
Definition: message_version.hpp:29