Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions udp_driver/include/udp_driver/udp_socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class UdpSocket
void close();
bool isOpen() const;
void bind();
void joinMulticast(std::string & multicast_addr);

/*
* Blocking Send Operation
Expand Down
4 changes: 4 additions & 0 deletions udp_driver/params/example_udp_multicast_params.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**:
ros__parameters:
ip: "239.255.0.1"
port: 22017
1 change: 1 addition & 0 deletions udp_driver/src/udp_receiver_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ LNI::CallbackReturn UdpReceiverNode::on_configure(const lc::State & state)
m_udp_driver->init_receiver(m_ip, m_port);
m_udp_driver->receiver()->open();
m_udp_driver->receiver()->bind();
m_udp_driver->receiver()->joinMulticast(m_ip);
m_udp_driver->receiver()->asyncReceive(
std::bind(&UdpReceiverNode::receiver_callback, this, std::placeholders::_1));
} catch (const std::exception & ex) {
Expand Down
13 changes: 13 additions & 0 deletions udp_driver/src/udp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,18 @@ void UdpSocket::bind()
m_udp_socket.bind(m_host_endpoint);
}

void UdpSocket::joinMulticast(std::string & multicast_addr)
{
if (address::from_string(multicast_addr).is_v4() &&
address::from_string(multicast_addr).to_v4().is_multicast())
{
m_udp_socket.set_option(
asio::ip::multicast::join_group(address::from_string(multicast_addr).to_v4()));
RCLCPP_INFO(
rclcpp::get_logger("UdpSocket::multicast"),
"Joined multicast group: %s", multicast_addr.c_str());
}
}

} // namespace udp_driver
} // namespace drivers