diff --git a/system/leader_election_converter/README.md b/system/leader_election_converter/README.md index 75058f2c91036..5d6dd0a5bf1f4 100644 --- a/system/leader_election_converter/README.md +++ b/system/leader_election_converter/README.md @@ -8,45 +8,43 @@ The leader election converter node is responsible for relaying UDP packets and R The availability converter subscribes `/system/operation_mode/availability` and `/vehicle/status/mrm_state`, adds them together into a structure called `Availability` and sends it as a udp packet. - ### Interface -| Interface Type | Interface Name | Data Type | Description | -| -------------- | ------------------------------------- | ------------------------------------------------- | ---------------------------------- | -| subscriber | `/system/operation_mode/availability` | `tier4_system_msgs/msg/OperationModeAvailability` | Usable behavior of the ego. | -| subscriber | `/vehicle/status/mrm_state` | `autoware_auto_vehicle_msgs/msg/ControlModeReport`| Ego control mode. | -| udp sender | none | `struct Availability` | Combination of the above two. | - +| Interface Type | Interface Name | Data Type | Description | +| -------------- | ------------------------------------- | -------------------------------------------------- | ----------------------------- | +| subscriber | `/system/operation_mode/availability` | `tier4_system_msgs/msg/OperationModeAvailability` | Usable behavior of the ego. | +| subscriber | `/vehicle/status/mrm_state` | `autoware_auto_vehicle_msgs/msg/ControlModeReport` | Ego control mode. | +| udp sender | none | `struct Availability` | Combination of the above two. | ## mrm converte + The mrm converter subscribes `/system/fail_safe/mrm_state` into a structure called `MrmState` and sends it as a UDP packet. In addition, it receives a udp packet`MrmState` and publish `/system/mrm_request`. ### Interface -| Interface Type | Interface Name | Data Type | Description | -| -------------- | ------------------------------------- | ------------------------------------------------- | ---------------------------------- | -| subscriber | `/system/fail_safe/mrm_state` | `tier4_system_msgs/msg/MrmState` | MRM status of each ECU. | -| udp sender | none | `struct MrmState` | Same as above. | -| publisher | `/system/election/mrm_request` | `tier4_system_msgs/msg/MrmBehavior` | Request of MRM behavior. | -| udp receiver | none | `struct MrmRequest` | Same as above. | - +| Interface Type | Interface Name | Data Type | Description | +| -------------- | ------------------------------ | ----------------------------------- | ------------------------ | +| subscriber | `/system/fail_safe/mrm_state` | `tier4_system_msgs/msg/MrmState` | MRM status of each ECU. | +| udp sender | none | `struct MrmState` | Same as above. | +| publisher | `/system/election/mrm_request` | `tier4_system_msgs/msg/MrmBehavior` | Request of MRM behavior. | +| udp receiver | none | `struct MrmRequest` | Same as above. | ## log converter -The log converter receive udp packets into a structure called `ElectionCommunication` and `ElectionStatus`, and publish `/system/election/communication`, + +The log converter receive udp packets into a structure called `ElectionCommunication` and `ElectionStatus`, and publish `/system/election/communication`, `/system/election/status`, and `/system/fail_safe/over_all/mrm_state`. ### Interface -| Interface Type | Interface Name | Data Type | Description | -| -------------- | ------------------------------------- | ------------------------------------------------- | ---------------------------------- | -| udp receiver | none | `struct ElectionCommunication` | messages amoung election nodes. | -| udp receiver | none | `struct ElectionStatus` | Leader Election status. | -| publisher | `/system/election/communication` | `tier4_system_msgs/msg/ElectionCommunication` | messages amoung election nodes. | -| publisher | `/system/election/status` | `tier4_system_msgs/msg/MrmState` | Leader Election status. | -| publisher | `/system/fail_safe/over_all/mrm_state`| `autoware_adapi_v1_msgs/msg/mrm_state` | System-wode MRM status. | +| Interface Type | Interface Name | Data Type | Description | +| -------------- | -------------------------------------- | --------------------------------------------- | ------------------------------- | +| udp receiver | none | `struct ElectionCommunication` | messages amoung election nodes. | +| udp receiver | none | `struct ElectionStatus` | Leader Election status. | +| publisher | `/system/election/communication` | `tier4_system_msgs/msg/ElectionCommunication` | messages amoung election nodes. | +| publisher | `/system/election/status` | `tier4_system_msgs/msg/MrmState` | Leader Election status. | +| publisher | `/system/fail_safe/over_all/mrm_state` | `autoware_adapi_v1_msgs/msg/mrm_state` | System-wode MRM status. | ## Parameters {{ json_to_markdown("system/leader_election_converter/schema/leader_election_converter.schema.json") }} - diff --git a/system/leader_election_converter/launch/leader_election_converter.launch.xml b/system/leader_election_converter/launch/leader_election_converter.launch.xml index d3737bd3eba6b..34ab3a8212336 100644 --- a/system/leader_election_converter/launch/leader_election_converter.launch.xml +++ b/system/leader_election_converter/launch/leader_election_converter.launch.xml @@ -1,4 +1,4 @@ - + diff --git a/system/leader_election_converter/package.xml b/system/leader_election_converter/package.xml index 1a86e5339a2ee..d9341c8fe2df3 100644 --- a/system/leader_election_converter/package.xml +++ b/system/leader_election_converter/package.xml @@ -10,11 +10,11 @@ ament_cmake_auto autoware_cmake + autoware_adapi_v1_msgs + autoware_auto_vehicle_msgs rclcpp rclcpp_components tier4_system_msgs - autoware_auto_vehicle_msgs - autoware_adapi_v1_msgs ament_lint_auto autoware_lint_common diff --git a/system/leader_election_converter/src/common/converter/availability_converter.cpp b/system/leader_election_converter/src/common/converter/availability_converter.cpp index ad822e86e0192..6edb0f89e51d1 100644 --- a/system/leader_election_converter/src/common/converter/availability_converter.cpp +++ b/system/leader_election_converter/src/common/converter/availability_converter.cpp @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "availability_converter.hpp" #include "rclcpp/rclcpp.hpp" -#include "availability_converter.hpp" namespace leader_election_converter { -AvailabilityConverter::AvailabilityConverter(rclcpp::Node * node) -: node_(node) {} +AvailabilityConverter::AvailabilityConverter(rclcpp::Node * node) : node_(node) +{ +} void AvailabilityConverter::setUdpSender(const std::string & dest_ip, const std::string & dest_port) { @@ -30,22 +31,27 @@ void AvailabilityConverter::setUdpSender(const std::string & dest_ip, const std: void AvailabilityConverter::setSubscriber() { const auto qos = rclcpp::QoS(1).transient_local(); - availability_callback_group_ = node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive); + availability_callback_group_ = + node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive); rclcpp::SubscriptionOptions availability_options = rclcpp::SubscriptionOptions(); availability_options.callback_group = availability_callback_group_; - control_mode_callback_group_ = node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive, false); + control_mode_callback_group_ = + node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive, false); rclcpp::SubscriptionOptions control_mode_options = rclcpp::SubscriptionOptions(); - control_mode_options.callback_group = control_mode_callback_group_; - auto not_executed_callback = []([[maybe_unused]] const typename autoware_auto_vehicle_msgs::msg::ControlModeReport::ConstSharedPtr msg) {}; + control_mode_options.callback_group = control_mode_callback_group_; + auto not_executed_callback = []([[maybe_unused]] const typename autoware_auto_vehicle_msgs::msg:: + ControlModeReport::ConstSharedPtr msg) {}; - sub_operation_mode_availability_ = node_->create_subscription( - "~/input/operation_mode_availability", qos, - std::bind(&AvailabilityConverter::convertToUdp, this, std::placeholders::_1), availability_options); + sub_operation_mode_availability_ = + node_->create_subscription( + "~/input/operation_mode_availability", qos, + std::bind(&AvailabilityConverter::convertToUdp, this, std::placeholders::_1), + availability_options); - sub_control_mode_ = node_->create_subscription( - "~/input/control_mode", qos, not_executed_callback, control_mode_options); - + sub_control_mode_ = + node_->create_subscription( + "~/input/control_mode", qos, not_executed_callback, control_mode_options); } void AvailabilityConverter::convertToUdp( diff --git a/system/leader_election_converter/src/common/converter/availability_converter.hpp b/system/leader_election_converter/src/common/converter/availability_converter.hpp index edac136d9bd6c..2f4434cd008b2 100644 --- a/system/leader_election_converter/src/common/converter/availability_converter.hpp +++ b/system/leader_election_converter/src/common/converter/availability_converter.hpp @@ -12,16 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef COMMON__AVAILABILITY_CONVERTER_HPP_ -#define COMMON__AVAILABILITY_CONVERTER_HPP_ +#ifndef COMMON__CONVERTER__AVAILABILITY_CONVERTER_HPP_ +#define COMMON__CONVERTER__AVAILABILITY_CONVERTER_HPP_ -#include -#include +#include "udp_sender.hpp" #include -#include "udp_sender.hpp" - +#include +#include namespace leader_election_converter { @@ -41,25 +40,26 @@ struct Availability class AvailabilityConverter { - public: AvailabilityConverter(rclcpp::Node * node); ~AvailabilityConverter() = default; void setUdpSender(const std::string & dest_ip, const std::string & dest_port); void setSubscriber(); - void convertToUdp(const tier4_system_msgs::msg::OperationModeAvailability::ConstSharedPtr availability_msg); + void convertToUdp( + const tier4_system_msgs::msg::OperationModeAvailability::ConstSharedPtr availability_msg); private: - rclcpp::Node * node_; - std::unique_ptr> udp_availability_sender_; - rclcpp::CallbackGroup::SharedPtr availability_callback_group_; - rclcpp::CallbackGroup::SharedPtr control_mode_callback_group_; - rclcpp::Subscription::SharedPtr sub_control_mode_; - rclcpp::Subscription::SharedPtr sub_operation_mode_availability_; - + rclcpp::Node * node_; + std::unique_ptr> udp_availability_sender_; + rclcpp::CallbackGroup::SharedPtr availability_callback_group_; + rclcpp::CallbackGroup::SharedPtr control_mode_callback_group_; + rclcpp::Subscription::SharedPtr + sub_control_mode_; + rclcpp::Subscription::SharedPtr + sub_operation_mode_availability_; }; } // namespace leader_election_converter -#endif // COMMON__AVAILABILITY_CONVERTER_HPP_ +#endif // COMMON__CONVERTER__AVAILABILITY_CONVERTER_HPP_ diff --git a/system/leader_election_converter/src/common/converter/log_converter.cpp b/system/leader_election_converter/src/common/converter/log_converter.cpp index 51071dc638d5f..656322469d009 100644 --- a/system/leader_election_converter/src/common/converter/log_converter.cpp +++ b/system/leader_election_converter/src/common/converter/log_converter.cpp @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "rclcpp/rclcpp.hpp" #include "log_converter.hpp" +#include "rclcpp/rclcpp.hpp" + namespace leader_election_converter { LogConverter::LogConverter(rclcpp::Node * node) -: node_(node), -is_election_comunication_running_(true), -is_election_status_running_(true) -{} +: node_(node), is_election_comunication_running_(true), is_election_status_running_(true) +{ +} LogConverter::~LogConverter() { @@ -38,15 +38,20 @@ LogConverter::~LogConverter() } } -void LogConverter::setUdpElectionCommunicatioinReceiver(const std::string & src_ip, const std::string & src_port) +void LogConverter::setUdpElectionCommunicatioinReceiver( + const std::string & src_ip, const std::string & src_port) { - udp_election_comunication_thread_ = std::thread(&LogConverter::startUdpElectionCommunicationReceiver, this, src_ip, src_port); + udp_election_comunication_thread_ = + std::thread(&LogConverter::startUdpElectionCommunicationReceiver, this, src_ip, src_port); } -void LogConverter::startUdpElectionCommunicationReceiver(const std::string & src_ip, const std::string & src_port) +void LogConverter::startUdpElectionCommunicationReceiver( + const std::string & src_ip, const std::string & src_port) { try { - udp_election_comunication_receiver_ = std::make_unique>(src_ip, src_port, std::bind(&LogConverter::convertElectionCommunicationToTopic, this, std::placeholders::_1)); + udp_election_comunication_receiver_ = std::make_unique>( + src_ip, src_port, + std::bind(&LogConverter::convertElectionCommunicationToTopic, this, std::placeholders::_1)); while (is_election_comunication_running_) { udp_election_comunication_receiver_->receive(); } @@ -55,15 +60,20 @@ void LogConverter::startUdpElectionCommunicationReceiver(const std::string & src } } -void LogConverter::setUdpElectionStatusReceiver(const std::string & src_ip, const std::string & src_port) +void LogConverter::setUdpElectionStatusReceiver( + const std::string & src_ip, const std::string & src_port) { - udp_election_status_thread_ = std::thread(&LogConverter::startUdpElectionStatusReceiver, this, src_ip, src_port); + udp_election_status_thread_ = + std::thread(&LogConverter::startUdpElectionStatusReceiver, this, src_ip, src_port); } -void LogConverter::startUdpElectionStatusReceiver(const std::string & src_ip, const std::string & src_port) +void LogConverter::startUdpElectionStatusReceiver( + const std::string & src_ip, const std::string & src_port) { try { - udp_election_status_receiver_ = std::make_unique>(src_ip, src_port, std::bind(&LogConverter::convertElectionStatusToTopic, this, std::placeholders::_1)); + udp_election_status_receiver_ = std::make_unique>( + src_ip, src_port, + std::bind(&LogConverter::convertElectionStatusToTopic, this, std::placeholders::_1)); while (is_election_status_running_) { udp_election_status_receiver_->receive(); } @@ -74,8 +84,9 @@ void LogConverter::startUdpElectionStatusReceiver(const std::string & src_ip, co void LogConverter::setPublisher() { - pub_election_comunication_ = node_->create_publisher( - "~/output/election_communication", rclcpp::QoS{1}); + pub_election_comunication_ = + node_->create_publisher( + "~/output/election_communication", rclcpp::QoS{1}); pub_election_status_ = node_->create_publisher( "~/output/election_status", rclcpp::QoS{1}); pub_over_all_mrm_state_ = node_->create_publisher( diff --git a/system/leader_election_converter/src/common/converter/log_converter.hpp b/system/leader_election_converter/src/common/converter/log_converter.hpp index 12adb5ab35ecb..3f83ffd0c2074 100644 --- a/system/leader_election_converter/src/common/converter/log_converter.hpp +++ b/system/leader_election_converter/src/common/converter/log_converter.hpp @@ -12,21 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef COMMON__LOG_CONVERTER_HPP_ -#define COMMON__LOG_CONVERTER_HPP_ +#ifndef COMMON__CONVERTER__LOG_CONVERTER_HPP_ +#define COMMON__CONVERTER__LOG_CONVERTER_HPP_ +#include "udp_receiver.hpp" +#include "udp_sender.hpp" + +#include + +#include #include #include #include -#include -#include -#include #include - -#include "udp_sender.hpp" -#include "udp_receiver.hpp" - +#include namespace leader_election_converter { @@ -59,12 +59,14 @@ class LogConverter LogConverter(rclcpp::Node * node); ~LogConverter(); - void setUdpElectionCommunicatioinReceiver(const std::string & src_ip, const std::string & src_port); + void setUdpElectionCommunicatioinReceiver( + const std::string & src_ip, const std::string & src_port); void setUdpElectionStatusReceiver(const std::string & src_ip, const std::string & src_port); void setPublisher(); private: - void startUdpElectionCommunicationReceiver(const std::string & src_ip, const std::string & src_port); + void startUdpElectionCommunicationReceiver( + const std::string & src_ip, const std::string & src_port); void startUdpElectionStatusReceiver(const std::string & src_ip, const std::string & src_port); void convertElectionCommunicationToTopic(const ElectionCommunication & node_msg); void convertElectionStatusToTopic(const ElectionStatus & status); @@ -72,7 +74,8 @@ class LogConverter rclcpp::Node * node_; std::unique_ptr> udp_election_comunication_receiver_; std::unique_ptr> udp_election_status_receiver_; - rclcpp::Publisher::SharedPtr pub_election_comunication_; + rclcpp::Publisher::SharedPtr + pub_election_comunication_; rclcpp::Publisher::SharedPtr pub_election_status_; rclcpp::Publisher::SharedPtr pub_over_all_mrm_state_; @@ -84,4 +87,4 @@ class LogConverter } // namespace leader_election_converter -#endif // COMMON__LOG_CONVERTER_HPP_ +#endif // COMMON__CONVERTER__LOG_CONVERTER_HPP_ diff --git a/system/leader_election_converter/src/common/converter/mrm_converter.cpp b/system/leader_election_converter/src/common/converter/mrm_converter.cpp index 72d6fbe51a747..4f873f85d4696 100644 --- a/system/leader_election_converter/src/common/converter/mrm_converter.cpp +++ b/system/leader_election_converter/src/common/converter/mrm_converter.cpp @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "rclcpp/rclcpp.hpp" #include "mrm_converter.hpp" +#include "rclcpp/rclcpp.hpp" + namespace leader_election_converter { -MrmConverter::MrmConverter(rclcpp::Node * node) -: node_(node), -is_udp_receiver_running_(true) +MrmConverter::MrmConverter(rclcpp::Node * node) : node_(node), is_udp_receiver_running_(true) { } @@ -46,7 +45,8 @@ void MrmConverter::setUdpReceiver(const std::string & src_ip, const std::string void MrmConverter::startUdpReceiver(const std::string & src_ip, const std::string & src_port) { try { - udp_mrm_request_receiver_ = std::make_unique>(src_ip, src_port, std::bind(&MrmConverter::convertToTopic, this, std::placeholders::_1)); + udp_mrm_request_receiver_ = std::make_unique>( + src_ip, src_port, std::bind(&MrmConverter::convertToTopic, this, std::placeholders::_1)); while (is_udp_receiver_running_) { udp_mrm_request_receiver_->receive(); } @@ -63,8 +63,8 @@ void MrmConverter::setSubscriber() options.callback_group = callback_group_; sub_mrm_state_ = node_->create_subscription( - "~/input/mrm_state", qos, - std::bind(&MrmConverter::convertToUdp, this, std::placeholders::_1), options); + "~/input/mrm_state", qos, std::bind(&MrmConverter::convertToUdp, this, std::placeholders::_1), + options); } void MrmConverter::setPublisher() @@ -73,7 +73,8 @@ void MrmConverter::setPublisher() "~/output/mrm_request", rclcpp::QoS{1}); } -void MrmConverter::convertToUdp(const tier4_system_msgs::msg::MrmState::ConstSharedPtr mrm_state_msg) +void MrmConverter::convertToUdp( + const tier4_system_msgs::msg::MrmState::ConstSharedPtr mrm_state_msg) { MrmState mrm_state; mrm_state.state = mrm_state_msg->state; diff --git a/system/leader_election_converter/src/common/converter/mrm_converter.hpp b/system/leader_election_converter/src/common/converter/mrm_converter.hpp index 18aea9d3006fd..2f38f15e0cd66 100644 --- a/system/leader_election_converter/src/common/converter/mrm_converter.hpp +++ b/system/leader_election_converter/src/common/converter/mrm_converter.hpp @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef COMMON__MRM_CONVERTER_HPP_ -#define COMMON__MRM_CONVERTER_HPP_ +#ifndef COMMON__CONVERTER__MRM_CONVERTER_HPP_ +#define COMMON__CONVERTER__MRM_CONVERTER_HPP_ -#include -#include +#include "udp_receiver.hpp" +#include "udp_sender.hpp" #include -#include -#include -#include "udp_sender.hpp" -#include "udp_receiver.hpp" +#include +#include +#include +#include namespace leader_election_converter { @@ -69,4 +69,4 @@ class MrmConverter } // namespace leader_election_converter -#endif // COMMON__MRM_CONVERTER_HPP_ +#endif // COMMON__CONVERTER__MRM_CONVERTER_HPP_ diff --git a/system/leader_election_converter/src/common/converter/udp_receiver.hpp b/system/leader_election_converter/src/common/converter/udp_receiver.hpp index 834e285e74efc..39abce0812029 100644 --- a/system/leader_election_converter/src/common/converter/udp_receiver.hpp +++ b/system/leader_election_converter/src/common/converter/udp_receiver.hpp @@ -13,47 +13,48 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef COMMON__UDP_RECEIVER_HPP_ -#define COMMON__UDP_RECEIVER_HPP_ +#ifndef COMMON__CONVERTER__UDP_RECEIVER_HPP_ +#define COMMON__CONVERTER__UDP_RECEIVER_HPP_ -#include -#include -#include -#include +#include +#include #include -#include +#include +#include #include -#include -#include -#include +#include +#include +#include +#include namespace leader_election_converter { - -template + +template class UdpReceiver { public: - using CallbackType = std::function; + using CallbackType = std::function; UdpReceiver(const std::string & ip, const std::string & port); UdpReceiver(const std::string & ip, const std::string & port, CallbackType callback); UdpReceiver(const std::string & ip, const std::string & port, bool is_non_blocking); - UdpReceiver(const std::string & ip, const std::string & port, bool is_non_blocking, CallbackType callback); + UdpReceiver( + const std::string & ip, const std::string & port, bool is_non_blocking, CallbackType callback); ~UdpReceiver(); - bool receive(T & data); // for non callback - void receive(); // for callback + bool receive(T & data); // for non callback + void receive(); // for callback private: int socketfd_; - struct addrinfo *res_; + struct addrinfo * res_; CallbackType callback_; void setCallback(CallbackType callback); }; -template +template UdpReceiver::UdpReceiver(const std::string & ip, const std::string & port) { struct addrinfo hints; @@ -78,14 +79,14 @@ UdpReceiver::UdpReceiver(const std::string & ip, const std::string & port) } } -template +template UdpReceiver::UdpReceiver(const std::string & ip, const std::string & port, CallbackType callback) : UdpReceiver(ip, port) { setCallback(callback); } -template +template UdpReceiver::UdpReceiver(const std::string & ip, const std::string & port, bool is_non_blocking) : UdpReceiver(ip, port) { @@ -98,14 +99,15 @@ UdpReceiver::UdpReceiver(const std::string & ip, const std::string & port, bo } } -template -UdpReceiver::UdpReceiver(const std::string & ip, const std::string & port, bool is_non_blocking, CallbackType callback) +template +UdpReceiver::UdpReceiver( + const std::string & ip, const std::string & port, bool is_non_blocking, CallbackType callback) : UdpReceiver(ip, port, is_non_blocking) { setCallback(callback); } -template +template UdpReceiver::~UdpReceiver() { shutdown(socketfd_, SHUT_RDWR); @@ -113,13 +115,13 @@ UdpReceiver::~UdpReceiver() close(socketfd_); } -template +template void UdpReceiver::setCallback(CallbackType callback) { callback_ = callback; } -template +template bool UdpReceiver::receive(T & data) { struct sockaddr_storage addr; @@ -134,7 +136,7 @@ bool UdpReceiver::receive(T & data) return true; } -template +template void UdpReceiver::receive() { T data; @@ -145,4 +147,4 @@ void UdpReceiver::receive() } // namespace leader_election_converter -#endif // COMMON__UDP_RECEIVER_HPP_ +#endif // COMMON__CONVERTER__UDP_RECEIVER_HPP_ diff --git a/system/leader_election_converter/src/common/converter/udp_sender.hpp b/system/leader_election_converter/src/common/converter/udp_sender.hpp index be06e152dfce8..866fd1b7fcfb9 100644 --- a/system/leader_election_converter/src/common/converter/udp_sender.hpp +++ b/system/leader_election_converter/src/common/converter/udp_sender.hpp @@ -12,22 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef COMMON__UDP_SENDER_HPP_ -#define COMMON__UDP_SENDER_HPP_ +#ifndef COMMON__CONVERTER__UDP_SENDER_HPP_ +#define COMMON__CONVERTER__UDP_SENDER_HPP_ -#include -#include -#include -#include #include -#include +#include +#include #include +#include +#include +#include namespace leader_election_converter { - -template + +template class UdpSender { public: @@ -38,10 +38,10 @@ class UdpSender private: int socketfd_; - struct addrinfo *res_; + struct addrinfo * res_; }; -template +template UdpSender::UdpSender(const std::string & ip, const std::string & port) { struct addrinfo hints; @@ -60,7 +60,7 @@ UdpSender::UdpSender(const std::string & ip, const std::string & port) } } -template +template UdpSender::~UdpSender() { shutdown(socketfd_, SHUT_RDWR); @@ -68,7 +68,7 @@ UdpSender::~UdpSender() close(socketfd_); } -template +template void UdpSender::send(const T & data) { if (sendto(socketfd_, &data, sizeof(T), 0, res_->ai_addr, res_->ai_addrlen) < 0) { @@ -76,7 +76,6 @@ void UdpSender::send(const T & data) } } -} // namespace leader_election_converterl - +} // namespace leader_election_converter -#endif // COMMON__UDP_SENDER_HPP_ +#endif // COMMON__CONVERTER__UDP_SENDER_HPP_ diff --git a/system/leader_election_converter/src/node/leader_election_converter.cpp b/system/leader_election_converter/src/node/leader_election_converter.cpp index 32eb845f38f61..a90af167688de 100644 --- a/system/leader_election_converter/src/node/leader_election_converter.cpp +++ b/system/leader_election_converter/src/node/leader_election_converter.cpp @@ -23,34 +23,35 @@ LeaderElectionConverter::LeaderElectionConverter(const rclcpp::NodeOptions & nod mrm_converter_(this), log_converter_(this) { - availability_dest_ip_ = declare_parameter("availability_dest_ip"); - availability_dest_port_ = declare_parameter("availability_dest_port"); - mrm_state_dest_ip_ = declare_parameter("mrm_state_dest_ip"); - mrm_state_dest_port_ = declare_parameter("mrm_state_dest_port"); - mrm_request_src_ip_ = declare_parameter("mrm_request_src_ip"); - mrm_request_src_port_ = declare_parameter("mrm_request_src_port"); - election_communication_src_ip_ = declare_parameter("election_communication_src_ip"); - election_communication_src_port_ = declare_parameter("election_communication_src_port"); - election_status_src_ip_ = declare_parameter("election_status_src_ip"); - election_status_src_port_ = declare_parameter("election_status_src_port"); - - // convert udp packets of availability to topics - availability_converter_.setUdpSender(availability_dest_ip_, availability_dest_port_); - availability_converter_.setSubscriber(); - - // convert topics of mrm state to udp packets - mrm_converter_.setUdpSender(mrm_state_dest_ip_, mrm_state_dest_port_); - mrm_converter_.setSubscriber(); - - // convert udp packets of mrm request to topics - mrm_converter_.setPublisher(); - mrm_converter_.setUdpReceiver(mrm_request_src_ip_, mrm_request_src_port_); - - - // convert udp packets of election info to topics - log_converter_.setPublisher(); - log_converter_.setUdpElectionCommunicatioinReceiver(election_communication_src_ip_, election_communication_src_port_); - log_converter_.setUdpElectionStatusReceiver(election_status_src_ip_, election_status_src_port_); + availability_dest_ip_ = declare_parameter("availability_dest_ip"); + availability_dest_port_ = declare_parameter("availability_dest_port"); + mrm_state_dest_ip_ = declare_parameter("mrm_state_dest_ip"); + mrm_state_dest_port_ = declare_parameter("mrm_state_dest_port"); + mrm_request_src_ip_ = declare_parameter("mrm_request_src_ip"); + mrm_request_src_port_ = declare_parameter("mrm_request_src_port"); + election_communication_src_ip_ = declare_parameter("election_communication_src_ip"); + election_communication_src_port_ = + declare_parameter("election_communication_src_port"); + election_status_src_ip_ = declare_parameter("election_status_src_ip"); + election_status_src_port_ = declare_parameter("election_status_src_port"); + + // convert udp packets of availability to topics + availability_converter_.setUdpSender(availability_dest_ip_, availability_dest_port_); + availability_converter_.setSubscriber(); + + // convert topics of mrm state to udp packets + mrm_converter_.setUdpSender(mrm_state_dest_ip_, mrm_state_dest_port_); + mrm_converter_.setSubscriber(); + + // convert udp packets of mrm request to topics + mrm_converter_.setPublisher(); + mrm_converter_.setUdpReceiver(mrm_request_src_ip_, mrm_request_src_port_); + + // convert udp packets of election info to topics + log_converter_.setPublisher(); + log_converter_.setUdpElectionCommunicatioinReceiver( + election_communication_src_ip_, election_communication_src_port_); + log_converter_.setUdpElectionStatusReceiver(election_status_src_ip_, election_status_src_port_); } } // namespace leader_election_converter diff --git a/system/leader_election_converter/src/node/leader_election_converter.hpp b/system/leader_election_converter/src/node/leader_election_converter.hpp index de35afd905544..f33ba60bb7b24 100644 --- a/system/leader_election_converter/src/node/leader_election_converter.hpp +++ b/system/leader_election_converter/src/node/leader_election_converter.hpp @@ -15,11 +15,13 @@ #ifndef NODE__LEADER_ELECTION_CONVERTER_HPP_ #define NODE__LEADER_ELECTION_CONVERTER_HPP_ -#include -#include #include "availability_converter.hpp" -#include "mrm_converter.hpp" #include "log_converter.hpp" +#include "mrm_converter.hpp" + +#include + +#include namespace leader_election_converter { @@ -33,7 +35,7 @@ class LeaderElectionConverter : public rclcpp::Node std::string availability_dest_ip_; std::string availability_dest_port_; std::string mrm_state_dest_ip_; - std::string mrm_state_dest_port_; + std::string mrm_state_dest_port_; std::string mrm_request_src_ip_; std::string mrm_request_src_port_; std::string election_communication_src_ip_;