00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00036 // ORIGINAL BELOW 00037 /* 00038 * File: BufferedAsyncSerial.h 00039 * Author: Terraneo Federico 00040 * Distributed under the Boost Software License, Version 1.0. 00041 * Created on January 6, 2011, 3:31 PM 00042 */ 00043 00044 #include <pressure_cells/AsyncSerial.h> 00045 00046 #ifndef BUFFEREDASYNCSERIAL_H 00047 #define BUFFEREDASYNCSERIAL_H 00048 00053 class BufferedAsyncSerial:public AsyncSerial { 00054 public: 00055 BufferedAsyncSerial ( ); 00056 00068 BufferedAsyncSerial ( const std::string & devname, unsigned int baud_rate, 00069 boost::asio::serial_port_base::parity opt_parity = 00070 boost::asio::serial_port_base::parity ( boost:: 00071 asio::serial_port_base::parity:: 00072 none ), 00073 boost::asio::serial_port_base::character_size opt_csize = 00074 boost::asio::serial_port_base::character_size ( 8 ), 00075 boost::asio::serial_port_base::flow_control opt_flow = 00076 boost::asio::serial_port_base::flow_control ( boost:: 00077 asio::serial_port_base::flow_control:: 00078 none ), 00079 boost::asio::serial_port_base::stop_bits opt_stop = 00080 boost::asio::serial_port_base::stop_bits ( boost:: 00081 asio::serial_port_base::stop_bits:: 00082 one ) ); 00083 00090 size_t read ( char *data, size_t size ); 00091 00096 std::vector < char >read ( ); 00097 00105 std::string readString ( ); 00106 00116 std::string readStringUntil ( const std::string delim = "\n" ); 00117 00118 virtual ~ BufferedAsyncSerial ( ); 00119 00120 private: 00121 00125 void readCallback ( const char *data, size_t len ); 00126 00134 static std::vector < char >::iterator findStringInVector ( std::vector < char >&v, 00135 const std::string & s ); 00136 00137 std::vector < char >readQueue; 00138 boost::mutex readQueueMutex; 00139 }; 00140 00141 #endif //BUFFEREDASYNCSERIAL_H