AsyncTCPClient.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_ASYNCTCPCLIENT_H
36 #define SICK_SAFETYSCANNERS_COMMUNICATION_ASYNCTCPCLIENT_H
37 
38 #include <ros/ros.h>
39 
40 #include <functional>
41 #include <iostream>
42 #include <thread>
43 
44 #include <boost/array.hpp>
45 #include <boost/asio.hpp>
46 #include <boost/cstdint.hpp>
47 #include <boost/function.hpp>
48 #include <boost/thread/condition.hpp>
49 #include <boost/thread/mutex.hpp>
50 
52 
53 namespace sick {
54 namespace communication {
55 
63 {
64 public:
69  typedef boost::function<void(const sick::datastructure::PacketBuffer&)> PacketHandler;
70 
79  AsyncTCPClient(const PacketHandler& packet_handler,
80  boost::asio::io_service& io_service,
81  const boost::asio::ip::address_v4& server_ip,
82  const uint16_t& server_port);
83 
87  virtual ~AsyncTCPClient();
88 
92  void doConnect();
93 
97  void doDisconnect();
98 
104  void doSendAndReceive(const std::vector<uint8_t>& sendBuffer);
105 
109  void initiateReceive();
110 
116  void setPacketHandler(const PacketHandler& packet_handler);
117 
118 private:
120 
121  PacketHandler m_packet_handler;
122 
123  std::shared_ptr<boost::asio::io_service::work> m_io_work_ptr;
124  boost::asio::io_service& m_io_service;
125  std::shared_ptr<boost::asio::ip::tcp::socket> m_socket_ptr;
126  boost::asio::ip::tcp::endpoint m_remote_endpoint;
127  std::thread m_service_thread;
128 
129  boost::condition m_connect_condition;
130  boost::mutex m_connect_mutex;
131  boost::mutex m_socket_mutex;
132 
133  void startReceive();
134  void handleReceive(const boost::system::error_code& error, const std::size_t& bytes_transferred);
135 
136 
137  AsyncTCPClient(AsyncTCPClient&); // block default copy constructor
138 
139  void handleSendAndReceive(const boost::system::error_code& error,
140  const std::size_t& bytes_transferred);
141 };
142 } // namespace communication
143 } // namespace sick
144 
145 #endif // SICK_SAFETYSCANNERS_COMMUNICATION_ASYNCTCPCLIENT_H
boost::array< uint8_t, MAXSIZE > ArrayBuffer
Typedef for an arraybuffer which can be read from the sensor.
Definition: PacketBuffer.h:67
boost::function< void(const sick::datastructure::PacketBuffer &)> PacketHandler
Typedef to a function referencing a packet handler. This can be passed to the class and therefore be ...
void initiateReceive()
Initiates the listening for a message from the server.
datastructure::PacketBuffer::ArrayBuffer m_recv_buffer
void doSendAndReceive(const std::vector< uint8_t > &sendBuffer)
Start a cycle of sensing a command and waiting got the return.
void handleReceive(const boost::system::error_code &error, const std::size_t &bytes_transferred)
void doConnect()
Establishes a connection from the host to the sensor.
AsyncTCPClient(const PacketHandler &packet_handler, boost::asio::io_service &io_service, const boost::asio::ip::address_v4 &server_ip, const uint16_t &server_port)
Constructor of the asynchronous tcp client.
void handleSendAndReceive(const boost::system::error_code &error, const std::size_t &bytes_transferred)
boost::asio::io_service & m_io_service
virtual ~AsyncTCPClient()
The destructor of the asynchronous tcp client.
void doDisconnect()
Disconnects the host from the sensor.
boost::asio::ip::tcp::endpoint m_remote_endpoint
std::shared_ptr< boost::asio::ip::tcp::socket > m_socket_ptr
void setPacketHandler(const PacketHandler &packet_handler)
Sets the packet handler function.
A asynchronous tcp 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