sick_tim_common_tcp.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013, Freiburg University
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  * 
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Osnabrück University nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  *  Created on: 15.11.2013
00030  *
00031  *      Authors:
00032  *         Christian Dornhege <c.dornhege@googlemail.com>
00033  */
00034 
00035 #ifndef SICK_TIM3XX_COMMON_TCP_H
00036 #define SICK_TIM3XX_COMMON_TCP_H
00037 
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include <boost/asio.hpp>
00042 
00043 #include "sick_tim_common.h"
00044 
00045 namespace sick_tim
00046 {
00047 
00048 class SickTimCommonTcp : public SickTimCommon
00049 {
00050 public:
00051   SickTimCommonTcp(const std::string &hostname, const std::string &port, int &timelimit, AbstractParser* parser);
00052   virtual ~SickTimCommonTcp();
00053 
00054 protected:
00055   virtual int init_device();
00056   virtual int close_device();
00057 
00059   virtual int sendSOPASCommand(const char* request, std::vector<unsigned char> * reply);
00060 
00062 
00067   virtual int get_datagram(unsigned char* receiveBuffer, int bufferSize, int* actual_length);
00068  
00069   // Helpers for boost asio
00070   int readWithTimeout(size_t timeout_ms, char *buffer, int buffer_size, int *bytes_read = 0, bool *exception_occured = 0);
00071   void handleRead(boost::system::error_code error, size_t bytes_transfered);
00072   void checkDeadline();
00073 
00074 private:
00075   boost::asio::io_service io_service_;
00076   boost::asio::ip::tcp::socket socket_;
00077   boost::asio::deadline_timer deadline_;
00078   boost::asio::streambuf input_buffer_;
00079   boost::system::error_code ec_;
00080   size_t bytes_transfered_;
00081 
00082   std::string hostname_;
00083   std::string port_;
00084   int timelimit_;
00085 };
00086 
00087 inline void SickTimCommonTcp::handleRead(boost::system::error_code error, size_t bytes_transfered)
00088 {
00089     ec_ = error;
00090     bytes_transfered_ += bytes_transfered;
00091 }
00092 
00093 } /* namespace sick_tim */
00094 #endif /* SICK_TIM3XX_COMMON_TCP_H */
00095 


sick_tim
Author(s): Jochen Sprickerhof , Martin Günther , Sebastian Pütz
autogenerated on Thu May 9 2019 02:32:02