diff --git a/autoware_iv_external_api_adaptor/CMakeLists.txt b/autoware_iv_external_api_adaptor/CMakeLists.txt index fe0c41dd5da..e0c07d6cadf 100644 --- a/autoware_iv_external_api_adaptor/CMakeLists.txt +++ b/autoware_iv_external_api_adaptor/CMakeLists.txt @@ -15,6 +15,7 @@ find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() ament_auto_add_library(${PROJECT_NAME} SHARED + src/cpu_usage.cpp src/diagnostics.cpp src/door.cpp src/emergency.cpp @@ -31,6 +32,7 @@ ament_auto_add_library(${PROJECT_NAME} SHARED src/velocity.cpp src/version.cpp ) +rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::CpuUsage") rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Diagnostics") rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Door") rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Emergency") diff --git a/autoware_iv_external_api_adaptor/src/cpu_usage.cpp b/autoware_iv_external_api_adaptor/src/cpu_usage.cpp new file mode 100644 index 00000000000..4854e93bef5 --- /dev/null +++ b/autoware_iv_external_api_adaptor/src/cpu_usage.cpp @@ -0,0 +1,36 @@ +// Copyright 2021 Tier IV, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "cpu_usage.hpp" + +#include + +namespace external_api +{ + +CpuUsage::CpuUsage(const rclcpp::NodeOptions & options) : Node("cpu_usage", options) +{ + pub_cpu_usage_ = create_publisher( + "/api/external/get/cpu_usage", rclcpp::QoS(1)); + sub_cpu_usage_ = create_subscription( + "/system/system_monitor/cpu_monitor/cpu_usage", rclcpp::QoS(1), + [this](const tier4_external_api_msgs::msg::CpuUsage::SharedPtr msg) { + pub_cpu_usage_->publish(*msg); + }); +} + +} // namespace external_api + +#include "rclcpp_components/register_node_macro.hpp" +RCLCPP_COMPONENTS_REGISTER_NODE(external_api::CpuUsage) diff --git a/autoware_iv_external_api_adaptor/src/cpu_usage.hpp b/autoware_iv_external_api_adaptor/src/cpu_usage.hpp new file mode 100644 index 00000000000..e41c81120bf --- /dev/null +++ b/autoware_iv_external_api_adaptor/src/cpu_usage.hpp @@ -0,0 +1,39 @@ +// Copyright 2021 Tier IV, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef CPU_USAGE_HPP_ +#define CPU_USAGE_HPP_ + +#include "rclcpp/rclcpp.hpp" +#include "tier4_api_utils/tier4_api_utils.hpp" + +#include "tier4_external_api_msgs/msg/cpu_status.hpp" +#include "tier4_external_api_msgs/msg/cpu_usage.hpp" + +namespace external_api +{ + +class CpuUsage : public rclcpp::Node +{ +public: + explicit CpuUsage(const rclcpp::NodeOptions & options); + +private: + rclcpp::Publisher::SharedPtr pub_cpu_usage_; + rclcpp::Subscription::SharedPtr sub_cpu_usage_; +}; + +} // namespace external_api + +#endif // CPU_USAGE_HPP_