38 namespace communication {
    40                                boost::asio::io_service& io_service,
    41                                const boost::asio::ip::address_v4& server_ip,
    42                                const uint16_t& server_port)
    43   : m_packet_handler(packet_handler)
    45   , m_io_service(io_service)
    54   catch (std::exception& e)
    56     ROS_ERROR(
"Exception while creating socket: %s", e.what());
    67   boost::system::error_code ec;
    68   m_socket_ptr->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
    71     ROS_ERROR(
"Error shutting socket down: %i", ec.value());
    75     ROS_INFO(
"TCP Connection successfully shutdown");
    81     ROS_ERROR(
"Error closing Socket: %i", ec.value());
    85     ROS_INFO(
"TCP Socket successfully closed.");
    96       ROS_ERROR(
"TCP error code: %i", ec.value());
   100       ROS_INFO(
"TCP connection successfully established.");
   118                            boost::asio::buffer(sendBuffer),
   119                            [
this](boost::system::error_code ec, std::size_t bytes_send) {
   132                                 [
this](boost::system::error_code ec, std::size_t bytes_recvd) {
   143                                           const std::size_t& bytes_transferred)
   146   if (!error || error == boost::asio::error::message_size)
   152     ROS_ERROR(
"Error in tcp handle send and receive: %i", error.value());
   160                                    const std::size_t& bytes_transferred)
   169     ROS_ERROR(
"Error in tcp handle receive: %i", error.value());
 boost::mutex m_connect_mutex
 
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 ...
 
A packetbuffer for the raw data from the sensor. 
 
void initiateReceive()
Initiates the listening for a message from the server. 
 
datastructure::PacketBuffer::ArrayBuffer m_recv_buffer
 
AsyncTCPClient(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 handleReceive(const boost::system::error_code &error, const std::size_t &bytes_transferred)
 
void doConnect()
Establishes a connection from the host to the sensor. 
 
boost::condition m_connect_condition
 
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
 
boost::mutex m_socket_mutex
 
void setPacketHandler(const PacketHandler &packet_handler)
Sets the packet handler function. 
 
void doSendAndReceive(const sick::datastructure::PacketBuffer::VectorBuffer &sendBuffer)
Start a cycle of sensing a command and waiting got the return. 
 
std::shared_ptr< boost::asio::io_service::work > m_io_work_ptr
 
std::vector< uint8_t > VectorBuffer
Typedef for a vector buffer, to sort the incoming packets. 
 
PacketHandler m_packet_handler