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 <string>
15 #include <type_traits>
16 
17 namespace px4_ros2
18 {
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 
35 
41 static bool isRmwZenoh()
42 {
43  const char * rmw_id = rmw_get_implementation_identifier();
44  return std::string(rmw_id) == "rmw_zenoh_cpp";
45 }
46 
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) {return "";}
61  return "_v" + std::to_string(T::MESSAGE_VERSION);
62  } else {
63  return "";
64  }
65 }
66 
67 
68 } // namespace px4_ros2
Trait to check if a message type T has a MESSAGE_VERSION constant.
Definition: message_version.hpp:29