rplidar_driver_serial.h
Go to the documentation of this file.
00001 /*
00002  *  RPLIDAR SDK
00003  *
00004  *  Copyright (c) 2009 - 2014 RoboPeak Team
00005  *  http://www.robopeak.com
00006  *  Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd.
00007  *  http://www.slamtec.com
00008  *
00009  */
00010 /*
00011  * Redistribution and use in source and binary forms, with or without 
00012  * modification, are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice, 
00015  *    this list of conditions and the following disclaimer.
00016  *
00017  * 2. Redistributions in binary form must reproduce the above copyright notice, 
00018  *    this list of conditions and the following disclaimer in the documentation 
00019  *    and/or other materials provided with the distribution.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00023  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00024  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00025  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00027  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00028  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00029  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00030  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00031  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  */
00034 
00035 #pragma once
00036 
00037 namespace rp { namespace standalone{ namespace rplidar {
00038 
00039 class SerialChannelDevice :public ChannelDevice
00040 {
00041 public:
00042     rp::hal::serial_rxtx  * _rxtxSerial;
00043     bool _closePending;
00044 
00045     SerialChannelDevice():_rxtxSerial(rp::hal::serial_rxtx::CreateRxTx()){}
00046 
00047     bool bind(const char * portname, uint32_t baudrate)
00048     {
00049         _closePending = false;
00050         return _rxtxSerial->bind(portname, baudrate);
00051     }
00052     bool open()
00053     {
00054         return _rxtxSerial->open();
00055     }
00056     void close()
00057     {
00058         _closePending = true;
00059         _rxtxSerial->cancelOperation();
00060         _rxtxSerial->close();
00061     }
00062     void flush()
00063     {
00064         _rxtxSerial->flush(0);
00065     }
00066     bool waitfordata(size_t data_count,_u32 timeout = -1, size_t * returned_size = NULL)
00067     {
00068         if (_closePending) return false;
00069         return (_rxtxSerial->waitfordata(data_count, timeout, returned_size) == rp::hal::serial_rxtx::ANS_OK);
00070     }
00071     int senddata(const _u8 * data, size_t size)
00072     {
00073         return _rxtxSerial->senddata(data, size) ;
00074     }
00075     int recvdata(unsigned char * data, size_t size)
00076     {
00077         size_t lenRec = 0;
00078         lenRec = _rxtxSerial->recvdata(data, size);
00079         return lenRec;
00080     }
00081     void setDTR()
00082     {
00083         _rxtxSerial->setDTR();
00084     }
00085     void clearDTR()
00086     {
00087         _rxtxSerial->clearDTR();
00088     }
00089     void ReleaseRxTx()
00090     {
00091         rp::hal::serial_rxtx::ReleaseRxTx(_rxtxSerial);
00092     }
00093 };
00094 
00095 class RPlidarDriverSerial : public RPlidarDriverImplCommon
00096 {
00097 public:
00098 
00099     RPlidarDriverSerial();
00100     virtual ~RPlidarDriverSerial();
00101     virtual u_result connect(const char * port_path,  _u32 baudrate, _u32 flag = 0);
00102     virtual void disconnect();
00103 
00104 };
00105 
00106 }}}


rplidar_ros
Author(s):
autogenerated on Mon Mar 18 2019 02:34:23