|
| 1 | +/* |
| 2 | + * Copyright 2024 Gus Meyer. |
| 3 | + * |
| 4 | + * This file is part of the mavros package and subject to the license terms |
| 5 | + * in the top-level LICENSE file of the mavros repository. |
| 6 | + * https://github.com/mavlink/mavros/tree/master/LICENSE.md |
| 7 | + */ |
| 8 | +/** |
| 9 | + * @brief Open Drone ID plugin to satisfy remote ID requirements |
| 10 | + * @file open_drone_id.cpp |
| 11 | + * @author Gus Meyer <[email protected]> |
| 12 | + * |
| 13 | + * @addtogroup plugin |
| 14 | + * @{ |
| 15 | + */ |
| 16 | + |
| 17 | + |
| 18 | +#include "rcpputils/asserts.hpp" |
| 19 | +#include "mavros/mavros_uas.hpp" |
| 20 | +#include "mavros/plugin.hpp" |
| 21 | +#include "mavros/plugin_filter.hpp" |
| 22 | + |
| 23 | +#include "mavros_msgs/msg/basic_id.hpp" |
| 24 | +#include "mavros_msgs/msg/operator_id.hpp" |
| 25 | +#include "mavros_msgs/msg/self_id.hpp" |
| 26 | +#include "mavros_msgs/msg/system.hpp" |
| 27 | +#include "mavros_msgs/msg/system_update.hpp" |
| 28 | + |
| 29 | +namespace mavros { |
| 30 | +namespace extra_plugins { |
| 31 | +using namespace std::placeholders; // NOLINT |
| 32 | + |
| 33 | +/** |
| 34 | + * @brief Open Drone ID plugin |
| 35 | + * |
| 36 | + * Sends Open Drone ID data to the FCU |
| 37 | + */ |
| 38 | +class OpenDroneIDPlugin : public plugin::Plugin |
| 39 | +{ |
| 40 | +public: |
| 41 | + explicit OpenDroneIDPlugin(plugin::UASPtr uas_) |
| 42 | + : Plugin(uas_, "open_drone_id") |
| 43 | + { |
| 44 | + basic_id_sub = node->create_subscription<mavros_msgs::msg::BasicID>( |
| 45 | + "~/basic_id", 1, std::bind( |
| 46 | + &OpenDroneIDPlugin::basic_id_cb, this, |
| 47 | + _1)); |
| 48 | + |
| 49 | + operator_id_sub = node->create_subscription<mavros_msgs::msg::OperatorID>( |
| 50 | + "~/operator_id", 1, std::bind( |
| 51 | + &OpenDroneIDPlugin::operator_id_cb, this, |
| 52 | + _1)); |
| 53 | + |
| 54 | + self_id_sub = node->create_subscription<mavros_msgs::msg::SelfID>( |
| 55 | + "~/self_id", 1, std::bind( |
| 56 | + &OpenDroneIDPlugin::self_id_cb, this, |
| 57 | + _1)); |
| 58 | + |
| 59 | + system_sub = node->create_subscription<mavros_msgs::msg::System>( |
| 60 | + "~/system", 1, std::bind( |
| 61 | + &OpenDroneIDPlugin::system_cb, this, |
| 62 | + _1)); |
| 63 | + |
| 64 | + system_update_sub = node->create_subscription<mavros_msgs::msg::SystemUpdate>( |
| 65 | + "~/system_update", 1, std::bind( |
| 66 | + &OpenDroneIDPlugin::system_update_cb, this, |
| 67 | + _1)); |
| 68 | + } |
| 69 | + |
| 70 | + Subscriptions get_subscriptions() |
| 71 | + { |
| 72 | + return { }; |
| 73 | + } |
| 74 | + |
| 75 | +private: |
| 76 | + rclcpp::Subscription<mavros_msgs::msg::BasicID>::SharedPtr basic_id_sub; |
| 77 | + rclcpp::Subscription<mavros_msgs::msg::OperatorID>::SharedPtr operator_id_sub; |
| 78 | + rclcpp::Subscription<mavros_msgs::msg::SelfID>::SharedPtr self_id_sub; |
| 79 | + rclcpp::Subscription<mavros_msgs::msg::System>::SharedPtr system_sub; |
| 80 | + rclcpp::Subscription<mavros_msgs::msg::SystemUpdate>::SharedPtr system_update_sub; |
| 81 | + |
| 82 | + |
| 83 | + void basic_id_cb(const mavros_msgs::msg::BasicID::SharedPtr msg) |
| 84 | + { |
| 85 | + mavlink::common::msg::OPEN_DRONE_ID_BASIC_ID basic_id{}; |
| 86 | + |
| 87 | + basic_id.id_type = msg->id_type; |
| 88 | + basic_id.ua_type = msg->ua_type; |
| 89 | + |
| 90 | + size_t length = std::min(basic_id.uas_id.size(), msg->uas_id.size()); |
| 91 | + std::memcpy(basic_id.uas_id.data(), msg->uas_id.data(), length); |
| 92 | + |
| 93 | + uas->send_message(basic_id); |
| 94 | + } |
| 95 | + |
| 96 | + void operator_id_cb(const mavros_msgs::msg::OperatorID::SharedPtr msg) |
| 97 | + { |
| 98 | + mavlink::common::msg::OPEN_DRONE_ID_OPERATOR_ID operator_id{}; |
| 99 | + |
| 100 | + operator_id.operator_id_type = msg->operator_id_type; |
| 101 | + |
| 102 | + size_t length = std::min(operator_id.operator_id.size(), msg->operator_id.size()); |
| 103 | + std::memcpy(operator_id.operator_id.data(), msg->operator_id.data(), length); |
| 104 | + |
| 105 | + uas->send_message(operator_id); |
| 106 | + } |
| 107 | + |
| 108 | + void self_id_cb(const mavros_msgs::msg::SelfID::SharedPtr msg) |
| 109 | + { |
| 110 | + mavlink::common::msg::OPEN_DRONE_ID_SELF_ID self_id{}; |
| 111 | + self_id.description_type = msg->description_type; |
| 112 | + |
| 113 | + size_t length = std::min(self_id.description.size(), msg->description.size()); |
| 114 | + std::memcpy(self_id.description.data(), msg->description.data(), length); |
| 115 | + |
| 116 | + uas->send_message(self_id); |
| 117 | + } |
| 118 | + |
| 119 | + void system_cb(const mavros_msgs::msg::System::SharedPtr msg) |
| 120 | + { |
| 121 | + mavlink::common::msg::OPEN_DRONE_ID_SYSTEM system{}; |
| 122 | + |
| 123 | + system.operator_location_type = msg->operator_location_type; |
| 124 | + system.classification_type = msg->classification_type; |
| 125 | + system.operator_latitude = msg->operator_latitude; |
| 126 | + system.operator_longitude = msg->operator_longitude; |
| 127 | + system.area_count = msg->area_count; |
| 128 | + system.area_radius = msg->area_radius; |
| 129 | + system.area_ceiling = msg->area_ceiling; |
| 130 | + system.area_floor = msg->area_floor; |
| 131 | + system.category_eu = msg->category_eu; |
| 132 | + system.class_eu = msg->class_eu; |
| 133 | + system.operator_altitude_geo = msg->operator_altitude_geo; |
| 134 | + system.timestamp = msg->timestamp; |
| 135 | + |
| 136 | + uas->send_message(system); |
| 137 | + } |
| 138 | + |
| 139 | + void system_update_cb(const mavros_msgs::msg::SystemUpdate::SharedPtr msg) |
| 140 | + { |
| 141 | + mavlink::common::msg::OPEN_DRONE_ID_SYSTEM_UPDATE system_update{}; |
| 142 | + |
| 143 | + system_update.operator_latitude = msg->operator_latitude; |
| 144 | + system_update.operator_longitude = msg->operator_longitude; |
| 145 | + system_update.operator_altitude_geo = msg->operator_altitude_geo; |
| 146 | + system_update.timestamp = msg->timestamp; |
| 147 | + |
| 148 | + uas->send_message(system_update); |
| 149 | + } |
| 150 | + |
| 151 | +}; |
| 152 | +} // namespace extra_plugins |
| 153 | +} // namespace mavros |
| 154 | + |
| 155 | +#include <mavros/mavros_plugin_register_macro.hpp> // NOLINT |
| 156 | +MAVROS_PLUGIN_REGISTER(mavros::extra_plugins::OpenDroneIDPlugin) |
0 commit comments