39 namespace communication {
41 boost::asio::io_service& io_service,
42 const uint16_t& local_port)
43 : m_packet_handler(packet_handler)
44 , m_io_service(io_service)
50 auto endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), local_port);
53 catch (
const std::exception& e)
55 ROS_ERROR(
"Exception while creating socket: %s", e.what());
61 boost::asio::io_service& io_service,
62 const boost::asio::ip::address_v4 host_ip,
63 const boost::asio::ip::address_v4 interface_ip,
64 const uint16_t& local_port)
68 if (!host_ip.is_multicast())
70 ROS_ERROR(
"Provided Host IP is not in the Multicast range!");
73 if (interface_ip.is_unspecified())
76 ROS_ERROR(
"Provided Interface IP is unspecified! Set it to the Interface IP which receives the " 77 "multicast packages.");
85 auto endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), local_port);
87 m_socket_ptr->set_option(boost::asio::ip::multicast::join_group(host_ip, interface_ip));
89 catch (
const std::exception& e)
91 ROS_ERROR(
"Exception while creating socket: %s", e.what());
105 [
this](boost::system::error_code ec, std::size_t bytes_recvd) {
111 const std::size_t& bytes_transferred)
120 ROS_ERROR(
"Error in UDP handle receive: %i", error.value());
A packetbuffer for the raw data from the sensor.
unsigned short getLocalPort()
Returns the actual port assigned to the local machine.
void handleReceive(const boost::system::error_code &error, const std::size_t &bytes_transferred)
boost::asio::ip::udp::endpoint m_remote_endpoint
void runService()
Start the listening loop for the udp data packets.
PacketHandler m_packet_handler
std::shared_ptr< boost::asio::ip::udp::socket > m_socket_ptr
boost::asio::io_service & m_io_service
AsyncUDPClient(const PacketHandler &packet_handler, boost::asio::io_service &io_service, const uint16_t &local_port=0)
Constructor of the asynchronous udp client.
datastructure::PacketBuffer::ArrayBuffer m_recv_buffer
boost::function< void(const sick::datastructure::PacketBuffer &)> PacketHandler
Typedef to a reference to a function. Will be used to process the incoming packets.
virtual ~AsyncUDPClient()
The destructor of the asynchronous udp client.
std::shared_ptr< boost::asio::io_service::work > m_io_work_ptr