AsyncUDPClient.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 
24 // -- END LICENSE BLOCK ------------------------------------------------
25 
26 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
34 
35 #ifndef SICK_SAFETYSCANNERS_COMMUNICATION_ASYNCUDPCLIENT_H
36 #define SICK_SAFETYSCANNERS_COMMUNICATION_ASYNCUDPCLIENT_H
37 
38 #include <ros/ros.h>
39 
40 #include <functional>
41 #include <iostream>
42 
43 #include <boost/array.hpp>
44 #include <boost/asio.hpp>
45 #include <boost/cstdint.hpp>
46 #include <boost/function.hpp>
47 
49 
50 
51 namespace sick {
52 namespace communication {
53 
58 {
59 public:
63  typedef boost::function<void(const sick::datastructure::PacketBuffer&)> PacketHandler;
64 
72  AsyncUDPClient(const PacketHandler& packet_handler,
73  boost::asio::io_service& io_service,
74  const uint16_t& local_port = 0);
75 
83  AsyncUDPClient(const PacketHandler& packet_handler,
84  boost::asio::io_service& io_service,
85  const boost::asio::ip::address_v4 host_ip,
86  const boost::asio::ip::address_v4 multi_ip,
87  const uint16_t& local_port = 0);
88 
92  virtual ~AsyncUDPClient();
93 
97  void runService();
98 
103  unsigned short getLocalPort();
104 
105 private:
107 
108  PacketHandler m_packet_handler;
109 
110  std::shared_ptr<boost::asio::io_service::work> m_io_work_ptr;
111  boost::asio::io_service& m_io_service;
112  std::shared_ptr<boost::asio::ip::udp::socket> m_socket_ptr;
113  boost::asio::ip::udp::endpoint m_remote_endpoint;
114 
115  void startReceive();
116  void handleReceive(const boost::system::error_code& error, const std::size_t& bytes_transferred);
117 
118 
119  AsyncUDPClient(AsyncUDPClient&); // block default copy constructor
120 };
121 } // namespace communication
122 } // namespace sick
123 
124 #endif // SICK_SAFETYSCANNERS_COMMUNICATION_ASYNCUDPCLIENT_H
boost::array< uint8_t, MAXSIZE > ArrayBuffer
Typedef for an arraybuffer which can be read from the sensor.
Definition: PacketBuffer.h:67
An asynchronous udp client.
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.
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


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Fri Apr 2 2021 02:45:41